1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Fix tab character advance width after harfrust shaping

The text shaper doesn't handle tab stops — override the advance width
to TAB_SIZE × space width in layout_shaped_run, matching the previous
character-by-character behavior.
This commit is contained in:
gcailly
2026-03-27 12:23:37 +01:00
parent 4a37a07de7
commit 210b54ad82
5 changed files with 17 additions and 9 deletions

View File

@@ -194,7 +194,7 @@ fn layout_shaped_run(
{
let glyph_id = skrifa::GlyphId::new(info.glyph_id);
let cluster = info.cluster;
let x_advance_px = pos.x_advance as f32 * px_scale;
let mut x_advance_px = pos.x_advance as f32 * px_scale;
let x_offset_px = pos.x_offset as f32 * px_scale;
let y_offset_px = -(pos.y_offset as f32 * px_scale); // harfrust Y+ up → screen Y+ down
@@ -203,6 +203,14 @@ fn layout_shaped_run(
.and_then(|s| s.chars().next())
.unwrap_or('\u{FFFD}');
// Tab is a layout concept, not a glyph — the shaper doesn't know about tab stops.
// Override the advance width to TAB_SIZE × space width.
if chr == '\t' {
let (_, space_info) = font.glyph_info(' ');
x_advance_px =
crate::text::TAB_SIZE as f32 * space_info.advance_width_unscaled.0 * px_scale;
}
// Apply extra_letter_spacing only at cluster boundaries,
// never between glyphs within the same cluster (e.g. base + mark).
let is_new_cluster = ctx.prev_cluster.is_none_or(|pc| pc != cluster);