From 026f9aae34316c8e9e5fcb87f62c9401d72165a5 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 09:53:07 -0600 Subject: [PATCH 1/4] fix(text): vertical type sets roman letters upright, one per em, as Photoshop does (#9470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vertical type laid Latin letters and digits on their side (the word turned 90°), and called that Photoshop's default. Photoshop's Vertical Type tool stacks them upright, one character per em down the column: the run's BaselineDirection is 1 (withStream); 2 (rotated) turns them. - doc: CharStyle::rotate_roman (false = upright, the default). - text/psd: BaselineDirection is read (a run without one takes the style sheet's, which Photoshop writes as 2) and written back. - text/layout: in vertical type, roman characters take the upright path unless their run rotates them. Each is given one em down the column (a second shaping pass sets its letter spacing from the shaped advance), with pair kerning off between the stacked letters. Co-Authored-By: Claude Opus 5.5 --- crates/doc/src/text.rs | 6 +++ crates/engine/src/type_styles_cmds.rs | 1 + crates/text/src/layout.rs | 77 ++++++++++++++++++++++++--- crates/text/src/psd.rs | 23 ++++++++ crates/text/src/vertical_tests.rs | 44 ++++++++++++--- 5 files changed, 138 insertions(+), 13 deletions(-) diff --git a/crates/doc/src/text.rs b/crates/doc/src/text.rs index a4b9ca2fa34..055444c1e9b 100644 --- a/crates/doc/src/text.rs +++ b/crates/doc/src/text.rs @@ -101,6 +101,11 @@ pub struct CharStyle { pub variations: Vec, /// BCP-47 language tag (affects shaping and line breaking). pub language: Option, + /// Vertical type: roman text (Latin, digits) runs rotated 90° clockwise along the column + /// (PSD `BaselineDirection` 2) instead of standing upright one character per em + /// (`BaselineDirection` 1, what Photoshop's Vertical Type tool sets, #9470). CJK text stands + /// upright either way. + pub rotate_roman: bool, /// Applied character style (id in [`crate::TextStyles`]); `None` = "None". Attributes above /// stay fully resolved; differences from the style are local overrides. #[serde(skip_serializing_if = "Option::is_none")] @@ -135,6 +140,7 @@ impl Default for CharStyle { features: Vec::new(), variations: Vec::new(), language: None, + rotate_roman: false, style_sheet: None, } } diff --git a/crates/engine/src/type_styles_cmds.rs b/crates/engine/src/type_styles_cmds.rs index 4cbb2092dc2..7fc58a5ec4b 100644 --- a/crates/engine/src/type_styles_cmds.rs +++ b/crates/engine/src/type_styles_cmds.rs @@ -111,6 +111,7 @@ fn perturbed_char() -> CharStyle { features: vec![FontFeature { tag: "\u{1}".into(), value: 9 }], variations: vec![FontVariation { axis: "\u{1}".into(), value: -1.0 }], language: Some("\u{1}".into()), + rotate_roman: true, style_sheet: None, } } diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index 4936b33c635..dc5b1671392 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -10,8 +10,10 @@ //! into text space: a line becomes a column running top to bottom, and successive columns advance //! right to left. Within a column, CJK characters stay upright (centred on the column, placed with //! the font's vertical metrics: `VORG`, `vhea`/`vmtx`, else the ideographic em box) and use the -//! font's vertical alternates (`vert`) for punctuation, brackets and the long-vowel mark; other -//! text (Latin, digits) runs rotated 90° clockwise, Photoshop's default. Lines, clusters, carets +//! font's vertical alternates (`vert`) for punctuation, brackets and the long-vowel mark. Other +//! text (Latin, digits) stands upright one character per em too, as Photoshop's Vertical Type tool +//! sets it, or runs rotated 90° clockwise where its style says so (`CharStyle::rotate_roman`, +//! PSD `BaselineDirection` 2; #9470). Lines, clusters, carets //! and hit tests stay in line space; [`TextLayout::to_text`] / [`TextLayout::to_line`] convert. use std::borrow::Cow; @@ -608,8 +610,30 @@ impl Layouter { let fallback: Vec = fonts.fallback_stack().map(str::to_string).collect(); let si0 = style_at(prange.start); let si_end = run_starts.partition_point(|&rs| rs < content_end).max(si0 + 1).min(out.styles.len()); - // Shapes the paragraph, each tab widened by its letter spacing in `tab_spacing` (px). - let build = |lcx: &mut LayoutContext, fcx: &mut parley::FontContext, tab_spacing: &[f32]| -> Layout { + // Vertical type's upright roman characters (#9470), as byte ranges in `ptext` with their + // letter spacing (px) and em (px): each takes one em down the column, as Photoshop + // sets them, where shaping gives it its horizontal advance. + let mut roman: Vec<(Range, f32, f32, usize)> = Vec::new(); + if vertical { + for (ri, st) in out.styles.iter().enumerate().take(si_end).skip(si0) { + let rs = run_starts[ri]; + let (a, z) = (rs.max(prange.start), (rs + runs[ri].len).min(content_end)); + if a >= z || st.rotate_roman { + continue; + } + let base = a - prange.start + prefix.len(); + let piece = ptext.get(base..base + (z - a)).unwrap_or(""); + let px = st.size_pt * k; + for (i, ch) in piece.char_indices() { + if vertical_class(ch) == VClass::Rotate && !ch.is_whitespace() { + roman.push(((base + i)..(base + i + ch.len_utf8()), st.tracking / 1000.0 * px, px, ri)); + } + } + } + } + // Shapes the paragraph, each tab widened by its letter spacing in `tab_spacing` (px) + // and each upright roman character by its spacing in `roman_spacing` (px). + let build = |lcx: &mut LayoutContext, fcx: &mut parley::FontContext, tab_spacing: &[f32], roman_spacing: &[f32]| -> Layout { let mut b = lcx.ranged_builder(fcx, &ptext, 1.0, false); // Paragraph-start style as the default (covers the direction mark and empty // paragraphs), then every run piece intersecting this paragraph. @@ -647,7 +671,11 @@ impl Layouter { b.push(StyleProperty::Brush(RunBrush(ri as u32, cls as u8)), r); }; for (i, ch) in piece.char_indices() { - let cls = vertical_class(ch); + // Roman text stands upright too unless the run rotates it (#9470). + let cls = match vertical_class(ch) { + VClass::Rotate if !st.rotate_roman => VClass::Upright, + cls => cls, + }; match seg { Some((_, c)) if c == cls => {} Some((from, c)) => { @@ -673,6 +701,13 @@ impl Layouter { for (&at, &spacing) in tabs.iter().zip(tab_spacing) { b.push(StyleProperty::LetterSpacing(spacing), at..at + 1); } + for ((range, _, _, ri), &spacing) in roman.iter().zip(roman_spacing) { + b.push(StyleProperty::LetterSpacing(spacing), range.clone()); + // Pair kerning is horizontal: none between letters stacked upright. + let mut feats = feature_list(&out.styles[*ri], small_caps[*ri]); + feats.push("\"kern\" 0".into()); + b.push(StyleProperty::FontFeatures(FontFeatures::Source(Cow::Owned(feats.join(", ")))), range.clone()); + } b.build(&ptext) }; let indent_start = ps.start_indent_pt * k; @@ -728,14 +763,23 @@ impl Layouter { // Break again with the tab widths that layout gives until they agree; if they don't // settle, keep the safe layout. let wide = if wraps { tab_px } else { 0.0 }; - let mut layout = build(&mut self.lcx, &mut fonts.fcx, &vec![wide; tabs.len()]); + let mut roman_spacing: Vec = roman.iter().map(|r| r.1).collect(); + let mut layout = build(&mut self.lcx, &mut fonts.fcx, &vec![wide; tabs.len()], &roman_spacing); + if !roman.is_empty() { + // Shaped advances (with the letter spacing) → spacing that makes each one em. The + // clusters are read from broken lines; the real break follows the rebuild. + let _ = break_lines(&mut layout); + let advances = cluster_advances(&layout, &roman); + roman_spacing = roman.iter().zip(&advances).map(|((_, track, em, _), a)| a.map_or(*track, |a| em + track - (a - track))).collect(); + layout = build(&mut self.lcx, &mut fonts.fcx, &vec![wide; tabs.len()], &roman_spacing); + } let (mut area_slots, mut area_full) = break_lines(&mut layout); if wraps && !tabs.is_empty() { let first = tab_widths(&layout, &tabs, &out.styles, indent_start, first_indent, tab_px); let mut want: Vec = first.iter().map(|t| t.width).collect(); for _ in 0..4 { let spacing: Vec = first.iter().zip(&want).map(|(t, w)| w / t.scale - (t.advance - tab_px)).collect(); - let mut next = build(&mut self.lcx, &mut fonts.fcx, &spacing); + let mut next = build(&mut self.lcx, &mut fonts.fcx, &spacing, &roman_spacing); let (next_slots, next_full) = break_lines(&mut next); let got: Vec = tab_widths(&next, &tabs, &out.styles, indent_start, first_indent, tab_px).iter().map(|t| t.width).collect(); if got.iter().zip(&want).all(|(a, b)| (a - b).abs() < 0.01) { @@ -1379,6 +1423,25 @@ struct TabWidth { /// The width of each tab (offsets `tabs` in the paragraph text) on the broken lines of `layout`, /// before kerning and alignment. +/// The shaped advance (px, letter spacing included) of the cluster starting each of `ranges` +/// (sorted byte ranges of the shaped text), `None` where no cluster starts there. +fn cluster_advances(layout: &Layout, ranges: &[(Range, f32, f32, usize)]) -> Vec> { + let mut out = vec![None; ranges.len()]; + for line in layout.lines() { + for item in line.items() { + let PositionedLayoutItem::GlyphRun(gr) = item else { + continue; + }; + for c in gr.run().visual_clusters() { + if let Ok(i) = ranges.binary_search_by_key(&c.text_range().start, |r| r.0.start) { + out[i] = Some(c.advance()); + } + } + } + } + out +} + fn tab_widths(layout: &Layout, tabs: &[usize], styles: &[CharStyle], indent: f32, first_indent: f32, interval: f32) -> Vec { let mut out: Vec = tabs.iter().map(|_| TabWidth { advance: interval, scale: 1.0, width: interval }).collect(); for (li, line) in layout.lines().enumerate() { diff --git a/crates/text/src/psd.rs b/crates/text/src/psd.rs index 13f3244801a..e3b5d74b56f 100644 --- a/crates/text/src/psd.rs +++ b/crates/text/src/psd.rs @@ -687,6 +687,9 @@ pub(crate) fn char_style(base: &[Option<&E>], d: &E, fonts: &[String], k: f32) - Some(2) => FontBaseline::Subscript, _ => FontBaseline::Normal, }; + // Vertical type's roman text: 2 rotated along the column, 1 upright (#9470). A run without + // its own value takes the style sheet's, which Photoshop writes as 2. + s.rotate_roman = g("BaselineDirection").and_then(E::as_i64) == Some(2); if let Some(c) = g("FillColor") { // Positions matter (alpha, then the channels): a non-finite entry voids the colour. let v: Vec = c.get("Values").and_then(E::as_array).map(|a| a.iter().filter_map(E::as_f64).collect()).unwrap_or_default(); @@ -930,6 +933,7 @@ pub(crate) fn style_sheet_data(s: &CharStyle, font: usize, k: f32) -> E { FontBaseline::Subscript => 2, }), ), + ("BaselineDirection".into(), E::Int(if s.rotate_roman { 2 } else { 1 })), ("Underline".into(), E::Bool(s.underline)), ("Strikethrough".into(), E::Bool(s.strikethrough)), ("Ligatures".into(), E::Bool(s.ligatures)), @@ -1915,6 +1919,25 @@ mod nonfinite_tests { assert_eq!(char_style(&[], &d, &[], 1.0).size_pt, 24.0); } + /// #9470: `BaselineDirection` sets vertical type's roman text upright (1, what Photoshop's + /// Vertical Type tool writes in the run) or rotated (2); a run without one takes the style + /// sheet's (Photoshop's default sheet says 2). It is written back. + #[test] + fn baseline_direction_round_trips() { + let sheet = parse(b"<< /BaselineDirection 2 >>").unwrap(); + let upright = parse(b"<< /BaselineDirection 1 >>").unwrap(); + assert!(!char_style(&[Some(&sheet)], &upright, &[], 1.0).rotate_roman, "the run's own value wins"); + let plain = parse(b"<< /FontSize 24.0 >>").unwrap(); + assert!(char_style(&[Some(&sheet)], &plain, &[], 1.0).rotate_roman, "else the sheet's"); + assert!(!char_style(&[], &plain, &[], 1.0).rotate_roman, "none at all: upright"); + for rotate in [false, true] { + let s = CharStyle { rotate_roman: rotate, ..Default::default() }; + let data = style_sheet_data(&s, 0, 1.0); + assert_eq!(data.get("BaselineDirection").and_then(E::as_i64), Some(if rotate { 2 } else { 1 })); + assert_eq!(char_style(&[Some(&sheet)], &data, &[], 1.0).rotate_roman, rotate); + } + } + /// #5645: `FontBaseline` (1 superscript, 2 subscript) is read and written back. #[test] fn font_baseline_round_trips() { diff --git a/crates/text/src/vertical_tests.rs b/crates/text/src/vertical_tests.rs index 0da13b3497f..7cd87bc4fd9 100644 --- a/crates/text/src/vertical_tests.rs +++ b/crates/text/src/vertical_tests.rs @@ -19,6 +19,15 @@ fn vertical(text: &str, family: &str, size_pt: f32) -> TextLayer { } } +/// [`vertical`] with its roman text rotated along the column (PSD `BaselineDirection` 2). +fn rotated(text: &str, family: &str, size_pt: f32) -> TextLayer { + let mut t = vertical(text, family, size_pt); + for r in &mut t.runs { + r.style.rotate_roman = true; + } + t +} + /// An engine with an installed Japanese font registered, and that font's family. fn cjk_engine() -> Option<(TextEngine, String)> { #[cfg(not(target_arch = "wasm32"))] @@ -53,7 +62,7 @@ fn classes_follow_vertical_orientation() { #[test] fn latin_is_rotated_and_runs_down_columns_right_to_left() { let mut e = TextEngine::new(); - let l = e.layout(&vertical("abc\nde", "Inter", 20.0), 72.0); + let l = e.layout(&rotated("abc\nde", "Inter", 20.0), 72.0); assert!(l.vertical); assert_eq!(l.lines.len(), 2); assert!(l.glyphs.iter().all(|g| g.orient == GlyphOrient::Rotated)); @@ -67,16 +76,36 @@ fn latin_is_rotated_and_runs_down_columns_right_to_left() { // Rotated text is centred on the column through the anchor (x = 0): its baseline sits left. assert!(a.x < 0.0 && a.x > -10.0, "{a:?}"); // Bounds: one column for "abc" is taller than wide. - let one = e.layout(&vertical("abcdef", "Inter", 20.0), 72.0); + let one = e.layout(&rotated("abcdef", "Inter", 20.0), 72.0); let [x0, y0, x1, y1] = one.bounds().unwrap(); assert!((y1 - y0) > 2.0 * (x1 - x0), "{:?}", one.bounds()); assert!((x0 + 10.0).abs() < 1e-3 && (x1 - 10.0).abs() < 1e-3 && y0.abs() < 1e-3); } +/// #9470: Photoshop's Vertical Type tool sets roman text upright, one character per em down the +/// column (`BaselineDirection` 1): a word is a stack of letters, not the word turned on its side. +#[test] +fn latin_stands_upright_one_per_em_by_default() { + let mut e = TextEngine::new(); + let l = e.layout(&vertical("VERTICAL", "Inter", 36.0), 72.0); + assert!(l.vertical); + assert!(l.glyphs.iter().all(|g| g.orient == GlyphOrient::Upright), "{:?}", l.glyphs); + // One em (36 px) per character down a single column. + let steps: Vec = l.glyphs.windows(2).map(|w| w[1].y - w[0].y).collect(); + assert!(steps.iter().all(|d| (d - 36.0).abs() < 0.5), "{steps:?}"); + assert!(l.glyphs.windows(2).all(|w| (w[1].x - w[0].x).abs() < 6.0), "one column: {:?}", l.glyphs); + // Rendered: a narrow stack about 8 em tall, much taller than the rotated word. + let at = Affine::translate(200.0, 40.0); + let (_, up) = e.render(&TextLayer { transform: at, ..vertical("VERTICAL", "Inter", 36.0) }, 72.0, PixelFormat::RGBA8); + let (_, turned) = e.render(&TextLayer { transform: at, ..rotated("VERTICAL", "Inter", 36.0) }, 72.0, PixelFormat::RGBA8); + assert!(up.rect.width() < 40 && up.rect.height() > 7 * 36, "{:?}", up.rect); + assert!(up.rect.height() > turned.rect.height() + 50, "{:?} vs {:?}", up.rect, turned.rect); +} + #[test] fn rotated_render_ink_is_taller_than_wide() { let mut e = TextEngine::new(); - let horizontal = TextLayer { orientation: Orientation::Horizontal, ..vertical("Vertical", "Inter", 30.0) }; + let horizontal = TextLayer { orientation: Orientation::Horizontal, ..rotated("Vertical", "Inter", 30.0) }; let (_, h) = e.render(&TextLayer { transform: Affine::translate(100.0, 50.0), ..horizontal.clone() }, 72.0, PixelFormat::RGBA8); let (_, v) = e.render(&TextLayer { transform: Affine::translate(100.0, 50.0), orientation: Orientation::Vertical, ..horizontal }, 72.0, PixelFormat::RGBA8); assert!(h.rect.width() > h.rect.height()); @@ -109,7 +138,7 @@ fn caret_hit_test_and_arrow_geometry_follow_columns() { #[test] fn box_text_wraps_columns_within_the_box_height() { let mut e = TextEngine::new(); - let t = TextLayer { shape: TextShape::Box { x: 10.0, y: 20.0, width: 200.0, height: 60.0 }, ..vertical("ab cd ef gh ij kl mn op", "Inter", 20.0) }; + let t = TextLayer { shape: TextShape::Box { x: 10.0, y: 20.0, width: 200.0, height: 60.0 }, ..rotated("ab cd ef gh ij kl mn op", "Inter", 20.0) }; let l = e.layout(&t, 72.0); assert!(l.lines.len() >= 3, "{}", l.lines.len()); let [x0, y0, x1, y1] = l.bounds().unwrap(); @@ -163,8 +192,11 @@ fn cjk_is_upright_centred_with_vertical_alternates() { } else { assert_eq!(dash.orient, GlyphOrient::Rotated); } - // Latin inside vertical CJK runs rotated. - assert_eq!(g[9].orient, GlyphOrient::Rotated); + // Latin inside vertical CJK stands upright (Photoshop's Vertical Type tool), or rotated when + // its style says so. + assert_eq!(g[9].orient, GlyphOrient::Upright); + let r = e.layout(&rotated(text, &fam, 40.0), 72.0); + assert_eq!(r.glyphs[9].orient, GlyphOrient::Rotated); // Punctuation squeeze: 、「 takes 1.5 em down the column, ト、 keeps full cells. let s = e.layout(&vertical("ト、「東", &fam, 40.0), 72.0); let cx: Vec = s.clusters.iter().map(|c| c.x).collect(); From 0db137ac7957131899809b4d42a8cc04960fa6a5 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 10:26:40 -0600 Subject: [PATCH 2/4] Vertical type: half-width katakana and Hangul keep their rotation CodeRabbit on #9478: the upright default for roman text also caught half-width katakana and Hangul, which vertical_class rotates like other half-width text; this PR leaves CJK as it was. Only roman characters now stand upright and take one em. tab_widths gets its doc comment back. Test: half_width_cjk_stays_rotated_beside_upright_roman Co-Authored-By: Claude Opus 5.5 --- crates/text/src/layout.rs | 14 ++++++++++---- crates/text/src/vertical_tests.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index dc5b1671392..64001d2763d 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -625,7 +625,7 @@ impl Layouter { let piece = ptext.get(base..base + (z - a)).unwrap_or(""); let px = st.size_pt * k; for (i, ch) in piece.char_indices() { - if vertical_class(ch) == VClass::Rotate && !ch.is_whitespace() { + if upright_roman(ch) && !ch.is_whitespace() { roman.push(((base + i)..(base + i + ch.len_utf8()), st.tracking / 1000.0 * px, px, ri)); } } @@ -673,7 +673,7 @@ impl Layouter { for (i, ch) in piece.char_indices() { // Roman text stands upright too unless the run rotates it (#9470). let cls = match vertical_class(ch) { - VClass::Rotate if !st.rotate_roman => VClass::Upright, + VClass::Rotate if !st.rotate_roman && upright_roman(ch) => VClass::Upright, cls => cls, }; match seg { @@ -1421,8 +1421,12 @@ struct TabWidth { width: f32, } -/// The width of each tab (offsets `tabs` in the paragraph text) on the broken lines of `layout`, -/// before kerning and alignment. +/// Whether vertical type sets `c` upright when its style doesn't rotate roman text (#9470): the +/// rotating class except half-width katakana and Hangul, which keep their rotated setting. +fn upright_roman(c: char) -> bool { + vertical_class(c) == VClass::Rotate && !(0xFF61..=0xFFDC).contains(&(c as u32)) +} + /// The shaped advance (px, letter spacing included) of the cluster starting each of `ranges` /// (sorted byte ranges of the shaped text), `None` where no cluster starts there. fn cluster_advances(layout: &Layout, ranges: &[(Range, f32, f32, usize)]) -> Vec> { @@ -1442,6 +1446,8 @@ fn cluster_advances(layout: &Layout, ranges: &[(Range, f32, f32 out } +/// The width of each tab (offsets `tabs` in the paragraph text) on the broken lines of `layout`, +/// before kerning and alignment. fn tab_widths(layout: &Layout, tabs: &[usize], styles: &[CharStyle], indent: f32, first_indent: f32, interval: f32) -> Vec { let mut out: Vec = tabs.iter().map(|_| TabWidth { advance: interval, scale: 1.0, width: interval }).collect(); for (li, line) in layout.lines().enumerate() { diff --git a/crates/text/src/vertical_tests.rs b/crates/text/src/vertical_tests.rs index 7cd87bc4fd9..1ba1ca0bf14 100644 --- a/crates/text/src/vertical_tests.rs +++ b/crates/text/src/vertical_tests.rs @@ -102,6 +102,20 @@ fn latin_stands_upright_one_per_em_by_default() { assert!(up.rect.height() > turned.rect.height() + 50, "{:?} vs {:?}", up.rect, turned.rect); } +/// CodeRabbit on #9478: half-width katakana and Hangul keep their rotated setting; only roman +/// text stands upright by default (#9470 leaves CJK as it was). +#[test] +fn half_width_cjk_stays_rotated_beside_upright_roman() { + let mut e = TextEngine::new(); + for text in ["アイウ", "ᄀᄁᆪ"] { + let l = e.layout(&vertical(text, "Inter", 24.0), 72.0); + assert!(!l.glyphs.is_empty()); + assert!(l.glyphs.iter().all(|g| g.orient == GlyphOrient::Rotated), "{text}: {:?}", l.glyphs); + } + let l = e.layout(&vertical("A", "Inter", 24.0), 72.0); + assert!(l.glyphs.iter().all(|g| g.orient == GlyphOrient::Upright), "roman stays upright"); +} + #[test] fn rotated_render_ink_is_taller_than_wide() { let mut e = TextEngine::new(); From 7f0917781785358927186ed67984fe83d3a55331 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 10:41:24 -0600 Subject: [PATCH 3/4] Vertical type: upright roman letters don't join into ligatures CodeRabbit on #9478 (outside-diff comment, layout.rs 763-782): standard, contextual and discretionary ligatures stayed on in upright roman runs, so a font's "fi" became one glyph and broke one letter per em. They are off there now, as kerning already was. Test: upright_roman_letters_stay_apart_without_ligatures (uses an installed font with an fi ligature; skips where none is found) Co-Authored-By: Claude Opus 5.5 --- crates/text/src/layout.rs | 5 ++-- crates/text/src/vertical_tests.rs | 40 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index 64001d2763d..a4ec1d3506c 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -703,9 +703,10 @@ impl Layouter { } for ((range, _, _, ri), &spacing) in roman.iter().zip(roman_spacing) { b.push(StyleProperty::LetterSpacing(spacing), range.clone()); - // Pair kerning is horizontal: none between letters stacked upright. + // Pair kerning is horizontal: none between letters stacked upright. Nor ligatures: + // each letter stands alone, one per em. let mut feats = feature_list(&out.styles[*ri], small_caps[*ri]); - feats.push("\"kern\" 0".into()); + feats.extend(["kern", "liga", "clig", "dlig"].map(|f| format!("\"{f}\" 0"))); b.push(StyleProperty::FontFeatures(FontFeatures::Source(Cow::Owned(feats.join(", ")))), range.clone()); } b.build(&ptext) diff --git a/crates/text/src/vertical_tests.rs b/crates/text/src/vertical_tests.rs index 1ba1ca0bf14..1f36298b342 100644 --- a/crates/text/src/vertical_tests.rs +++ b/crates/text/src/vertical_tests.rs @@ -102,6 +102,46 @@ fn latin_stands_upright_one_per_em_by_default() { assert!(up.rect.height() > turned.rect.height() + 50, "{:?} vs {:?}", up.rect, turned.rect); } +/// An engine with an installed font that joins "fi" into one ligature glyph, and its family. +fn ligature_engine() -> Option<(TextEngine, String)> { + #[cfg(not(target_arch = "wasm32"))] + for path in [ + "/System/Library/Fonts/Supplemental/Hoefler Text.ttc", + "/System/Library/Fonts/Supplemental/Baskerville.ttc", + "/System/Library/Fonts/Supplemental/Didot.ttc", + "/System/Library/Fonts/Times.ttc", + "/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf", + "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", + "/usr/share/fonts/truetype/liberation/LiberationSerif-Regular.ttf", + "C:\\Windows\\Fonts\\calibri.ttf", + "C:\\Windows\\Fonts\\cambria.ttc", + ] { + let Ok(bytes) = std::fs::read(path) else { continue }; + let mut e = TextEngine::new(); + for fam in e.fonts.register_font_data(bytes) { + let flat = TextLayer { orientation: Orientation::Horizontal, ..vertical("fi", &fam, 30.0) }; + if e.layout(&flat, 72.0).glyphs.len() == 1 { + return Some((e, fam)); + } + } + } + eprintln!("no installed font with an fi ligature found: skipping"); + None +} + +/// CodeRabbit on #9478: upright roman letters never join into a ligature; "fi" and "ffl" are +/// one glyph per letter, one em apart. +#[test] +fn upright_roman_letters_stay_apart_without_ligatures() { + let Some((mut e, fam)) = ligature_engine() else { return }; + for text in ["fi", "ffl", "office"] { + let l = e.layout(&vertical(text, &fam, 30.0), 72.0); + assert_eq!(l.glyphs.len(), text.chars().count(), "{fam} {text}: one glyph per letter: {:?}", l.glyphs); + let steps: Vec = l.glyphs.windows(2).map(|w| w[1].y - w[0].y).collect(); + assert!(steps.iter().all(|d| (d - 30.0).abs() < 0.5), "{fam} {text}: one em apart: {steps:?}"); + } +} + /// CodeRabbit on #9478: half-width katakana and Hangul keep their rotated setting; only roman /// text stands upright by default (#9470 leaves CJK as it was). #[test] From cc208ee0440bbdf1858565dca49667272a490c56 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 11:12:50 -0600 Subject: [PATCH 4/4] Re-run CI The Windows integration job aborted in photocraft-gpu's parity::soft_shapes_match_the_cpu with 0xc0000374 (heap corruption) inside the Microsoft Basic Render Driver (DX12 WARP); this PR only touches the text crate. Co-Authored-By: Claude Opus 5.5