Underline
This commit is contained in:
parent
47ccbdcec5
commit
ab6052705a
@ -89,4 +89,9 @@ impl ColorModel {
|
||||
cell.attrs.foreground.as_ref().unwrap_or(&self.fg_color)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn actual_cell_sp<'a>(&'a self, cell: &'a Cell) -> &'a Color {
|
||||
cell.attrs.special.as_ref().unwrap_or(&self.sp_color)
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,8 @@ pub struct CellMetrics {
|
||||
pub line_height: f64,
|
||||
pub char_width: f64,
|
||||
pub ascent: f64,
|
||||
pub underline_position: f64,
|
||||
pub underline_thickness: f64,
|
||||
pub pango_ascent: i32,
|
||||
pub pango_descent: i32,
|
||||
pub pango_char_width: i32,
|
||||
@ -76,6 +78,7 @@ pub struct CellMetrics {
|
||||
|
||||
impl CellMetrics {
|
||||
fn new(font_metrics: &pango::FontMetrics) -> Self {
|
||||
|
||||
CellMetrics {
|
||||
pango_ascent: font_metrics.get_ascent(),
|
||||
pango_descent: font_metrics.get_descent(),
|
||||
@ -84,6 +87,11 @@ impl CellMetrics {
|
||||
line_height: (font_metrics.get_ascent() + font_metrics.get_descent()) as f64 /
|
||||
pango::SCALE as f64,
|
||||
char_width: font_metrics.get_approximate_digit_width() as f64 / pango::SCALE as f64,
|
||||
underline_position: (font_metrics.get_ascent() -
|
||||
font_metrics.get_underline_position()) as
|
||||
f64 / pango::SCALE as f64,
|
||||
underline_thickness: font_metrics.get_underline_thickness() as f64 /
|
||||
pango::SCALE as f64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,6 @@ pub fn render(
|
||||
color_model: &color::ColorModel,
|
||||
mode: &mode::Mode,
|
||||
) {
|
||||
// TODO: underline
|
||||
// TODO: undercurl
|
||||
ctx.set_source_rgb(
|
||||
color_model.bg_color.0,
|
||||
color_model.bg_color.1,
|
||||
@ -32,6 +30,8 @@ pub fn render(
|
||||
let &CellMetrics {
|
||||
line_height,
|
||||
char_width,
|
||||
underline_position,
|
||||
underline_thickness,
|
||||
..
|
||||
} = font_ctx.cell_metrics();
|
||||
let mut line_y = 0.0;
|
||||
@ -44,9 +44,10 @@ pub fn render(
|
||||
for col in 0..line.line.len() {
|
||||
let cell = &line.line[col];
|
||||
|
||||
let (bg, fg) = color_model.cell_colors(cell);
|
||||
|
||||
// draw cell
|
||||
if let Some(item) = line.item_line[col].as_ref() {
|
||||
let (bg, fg) = color_model.cell_colors(cell);
|
||||
|
||||
if let Some(bg) = bg {
|
||||
ctx.set_source_rgb(bg.0, bg.1, bg.2);
|
||||
@ -74,6 +75,25 @@ pub fn render(
|
||||
}
|
||||
}
|
||||
|
||||
if cell.attrs.underline || cell.attrs.undercurl {
|
||||
if cell.attrs.undercurl {
|
||||
let sp = color_model.actual_cell_sp(cell);
|
||||
ctx.set_source_rgba(sp.0, sp.1, sp.2, 0.7);
|
||||
ctx.set_dash(&[4.0, 2.0], 0.0);
|
||||
ctx.set_line_width(underline_thickness);
|
||||
ctx.move_to(line_x, line_y + underline_position);
|
||||
ctx.line_to(line_x + char_width, line_y + underline_position);
|
||||
ctx.stroke();
|
||||
ctx.set_dash(&[], 0.0);
|
||||
} else if cell.attrs.underline {
|
||||
ctx.set_source_rgb(fg.0, fg.1, fg.2);
|
||||
ctx.set_line_width(underline_thickness);
|
||||
ctx.move_to(line_x, line_y + underline_position);
|
||||
ctx.line_to(line_x + char_width, line_y + underline_position);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
if row == cursor_row && col == cursor_col {
|
||||
ctx.move_to(line_x, line_y);
|
||||
cursor.draw(
|
||||
|
Loading…
Reference in New Issue
Block a user