improv text decoration visuals
This commit is contained in:
parent
c12b3a9bf2
commit
6ef1ccbeed
2 changed files with 14 additions and 6 deletions
|
|
@ -1385,13 +1385,13 @@ impl Buffer {
|
|||
|
||||
pub fn render<R: Renderer>(&self, renderer: &mut R, color: Color) {
|
||||
for run in self.layout_runs() {
|
||||
// draw decorations before glyphs so text renders on top
|
||||
render_decoration(renderer, &run, color);
|
||||
for glyph in run.glyphs {
|
||||
let physical_glyph = glyph.physical((0., run.line_y), 1.0);
|
||||
let glyph_color = glyph.color_opt.map_or(color, |some| some);
|
||||
renderer.glyph(physical_glyph, glyph_color);
|
||||
}
|
||||
// draw decorations after glyphs so strikethrough is over the glyphs
|
||||
render_decoration(renderer, &run, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,9 @@ fn draw_decoration_group<R: Renderer>(
|
|||
.underline_color_opt
|
||||
.or(first.color_opt)
|
||||
.unwrap_or(default_color);
|
||||
let thickness = (first.underline_metrics.thickness * font_size).max(1.0);
|
||||
let thickness = (first.underline_metrics.thickness * font_size)
|
||||
.max(1.0)
|
||||
.ceil();
|
||||
let y = run.line_y - first.underline_metrics.offset * font_size;
|
||||
renderer.rectangle(x_start as i32, y as i32, width, thickness as u32, color);
|
||||
}
|
||||
|
|
@ -93,7 +95,9 @@ fn draw_decoration_group<R: Renderer>(
|
|||
.underline_color_opt
|
||||
.or(first.color_opt)
|
||||
.unwrap_or(default_color);
|
||||
let thickness = (first.underline_metrics.thickness * font_size).max(1.0);
|
||||
let thickness = (first.underline_metrics.thickness * font_size)
|
||||
.max(1.0)
|
||||
.ceil();
|
||||
let gap = thickness;
|
||||
let y = run.line_y - first.underline_metrics.offset * font_size;
|
||||
renderer.rectangle(x_start as i32, y as i32, width, thickness as u32, color);
|
||||
|
|
@ -113,7 +117,9 @@ fn draw_decoration_group<R: Renderer>(
|
|||
.strikethrough_color_opt
|
||||
.or(first.color_opt)
|
||||
.unwrap_or(default_color);
|
||||
let thickness = (first.strikethrough_metrics.thickness * font_size).max(1.0);
|
||||
let thickness = (first.strikethrough_metrics.thickness * font_size)
|
||||
.max(1.0)
|
||||
.ceil();
|
||||
let y = run.line_y - first.strikethrough_metrics.offset * font_size;
|
||||
renderer.rectangle(x_start as i32, y as i32, width, thickness as u32, color);
|
||||
}
|
||||
|
|
@ -125,7 +131,9 @@ fn draw_decoration_group<R: Renderer>(
|
|||
.or(first.color_opt)
|
||||
.unwrap_or(default_color);
|
||||
// we're reusing underline thickness for overline
|
||||
let thickness = (first.underline_metrics.thickness * font_size).max(1.0);
|
||||
let thickness = (first.underline_metrics.thickness * font_size)
|
||||
.max(1.0)
|
||||
.ceil();
|
||||
let y = run.line_top; //TODO: this should be run.line_y - ascent
|
||||
// but we don't have ascent in GlyphLayout
|
||||
// using line_top as an approximation for now, which should be good enough for most fonts
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue