From 985bbf42e684ef5b5a9312a6abf075aeafbaf5b9 Mon Sep 17 00:00:00 2001 From: ItsGlucose <111288263+ItsGlucose@users.noreply.github.com> Date: Wed, 11 Nov 2026 02:53:31 +0000 Subject: [PATCH] Apply glyph mark offsets in CosmicTextSystem layout (#66799) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary `CosmicTextSystem` built `ShapedGlyph` positions from `glyph.x` and `glyph.y` only, dropping cosmic-text's `x_offset` and `y_offset`. Those offsets are how the shaper stacks combining marks on their base glyph. As a result, GPOS mark-to-base positioning was lost: marks rendered at the pen position, to the right of the base. This uses `glyph.x + glyph.x_offset * font_size` and `glyph.y - glyph.y_offset * font_size`, matching `cosmic_text::LayoutGlyph::physical`. This also affects fonts that decompose precomposed characters through `ccmp`, such as Estedad, where `i`/`j` are separate base + mark glyphs. Closes #60387. Related: #61158 (same bug with Thai combining marks). ## Testing ```sh cargo test -p gpui_wgpu combining_marks_are_positioned_over_their_base --lib ``` Before the fix: ```text combining mark positioned after its base: mark.x=6.888px, next.x=6.888px ``` After: ```text 1 passed; 0 failed ``` The test shapes `v` + U+0304 with IBM Plex Sans, which has no precomposed `v`-macron glyph, and asserts the mark is positioned between the base and the next glyph. Manual test: verified in a GPUI app on Linux/Wayland with Estedad 8.5. Before, `i`/`j` dots were displaced; after, they stack correctly. I did not manually test the full Zed editor UI with JuliaMono. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). This is text shaping, not layout chrome. - [x] Tests cover the new or changed behavior. Release Notes: - Fixed combining marks such as `v̄` rendering to the right of their base glyph on Linux. - [GPUI] Fixed combining marks such as `v̄` rendering to the right of their base glyph on Linux. --- crates/gpui_wgpu/src/cosmic_text_system.rs | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/gpui_wgpu/src/cosmic_text_system.rs b/crates/gpui_wgpu/src/cosmic_text_system.rs index 775067518c6..7d738affa57 100644 --- a/crates/gpui_wgpu/src/cosmic_text_system.rs +++ b/crates/gpui_wgpu/src/cosmic_text_system.rs @@ -816,7 +816,10 @@ impl CosmicTextSystemState { let shaped_glyph = ShapedGlyph { id: GlyphId(glyph.glyph_id as u32), - position: point(glyph.x.into(), glyph.y.into()), + position: point( + (glyph.x + glyph.x_offset * f32::from(font_size)).into(), + (glyph.y - glyph.y_offset * f32::from(font_size)).into(), + ), index: glyph.start, is_emoji, }; @@ -1369,6 +1372,29 @@ mod tests { Ok(text_system.layout_line(text, gpui::px(14.0), &runs)) } + #[test] + fn combining_marks_are_positioned_over_their_base() -> Result<()> { + let text_system = text_system()?; + let layout = layout_text(&text_system, "v\u{0304}v")?; + let glyphs = layout + .runs + .iter() + .flat_map(|run| run.glyphs.iter()) + .collect::>(); + assert_eq!(glyphs.len(), 3); + let base = glyphs[0].position; + let mark = glyphs[1].position; + let next = glyphs[2].position; + assert!(mark.x > base.x); + assert!( + mark.x < next.x, + "combining mark positioned after its base: mark.x={:?}, next.x={:?}", + mark.x, + next.x + ); + Ok(()) + } + /// Mirrors the original crash: mixed-direction text reaching the shaper /// through `shape_text`, which only splits lines on `\n`. #[test]