1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -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

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6436ef7757244daed8a054134d6750dc0c065af8cbe0594a67508ab01ea21b32
size 12494
oid sha256:e9f87f8505c6f870f7ea77cbfa2a5653c843f3f9289aabb11968d6d1d5116ee8
size 12510

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b78651f74588e0ed3df925d19198d4b4015b304290f9488a26554a530c3c7b18
size 29419
oid sha256:21872867be61c9da3aa9a7daffe5c6d3ca49839c4049db4dab3c35531e1b5f82
size 29389

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b9336e6359c14b41618bc52824c462ac200b7eb3af832922b3b4fcca74b1f2d4
size 13087
oid sha256:aed720986b765ea02b3879eea68148750208e55ea14e22747ef578240baa33d6
size 13099

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3103d471640e36c2442ab9b8abd07c3f2d4bf4e1fa61f0ba30060f9a164b91bb
size 31906
oid sha256:e9d6dca1082393f24c50b4ed2acf37bfc049d11d9a5e97ed8f69dc7a431039a7
size 31917

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);