Apply upstream PR #503 (fix monospace width rounding)

This commit is contained in:
Lionel DARNIS 2026-04-23 22:31:26 +02:00
parent c24886c247
commit 0e15681adb

View file

@ -2903,9 +2903,12 @@ impl ShapeLine {
0.0 0.0
}, },
); );
if let Some(match_em_width) = match_mono_em_width { if let Some(mono_width) = match_mono_width {
// Round to nearest monospace width // Round to nearest multiple of the monospace cell width
x_advance = ((x_advance / match_em_width).round()) * match_em_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 { if hinting == Hinting::Enabled {
x_advance = x_advance.round(); x_advance = x_advance.round();