From 0e15681adb16cbf6534b489048a442dc46e14ea7 Mon Sep 17 00:00:00 2001 From: leyoda Date: Thu, 23 Apr 2026 22:31:26 +0200 Subject: [PATCH] Apply upstream PR #503 (fix monospace width rounding) --- src/shape.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/shape.rs b/src/shape.rs index ec98963..9153a62 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -2903,9 +2903,12 @@ impl ShapeLine { 0.0 }, ); - if let Some(match_em_width) = match_mono_em_width { - // Round to nearest monospace width - x_advance = ((x_advance / match_em_width).round()) * match_em_width; + if let Some(mono_width) = match_mono_width { + // Round to nearest multiple of the monospace cell width + let cells = (x_advance / mono_width).round(); + // Ensure visible glyphs occupy at least one cell + let cells = if x_advance > 0.0 { cells.max(1.0) } else { cells }; + x_advance = cells * mono_width; } if hinting == Hinting::Enabled { x_advance = x_advance.round();