From 6ef1ccbeedd4f781fa3a32fda27d339468ca3b83 Mon Sep 17 00:00:00 2001 From: Hojjat Date: Tue, 24 Feb 2026 14:34:08 -0700 Subject: [PATCH] improv text decoration visuals --- src/buffer.rs | 4 ++-- src/render.rs | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index d021b76..a20f8f3 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1385,13 +1385,13 @@ impl Buffer { pub fn render(&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); } } } diff --git a/src/render.rs b/src/render.rs index 57bea32..fdb9b63 100644 --- a/src/render.rs +++ b/src/render.rs @@ -84,7 +84,9 @@ fn draw_decoration_group( .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( .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( .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( .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