From fe8cd6660e2336575137918c82bb0d8065211bd5 Mon Sep 17 00:00:00 2001 From: HassanKhan Date: Mon, 16 Nov 2026 11:11:39 +0500 Subject: [PATCH 1/2] test(text): Tsume check takes nothing where a cluster has no blank space (#7821) optical_kerning_keeps_the_tsume_of_a_letter_with_coloured_harakat also runs on an installed Arabic face. In macOS's Arial (5.01.2x) the initial beh and its fatha fill their whole cell, so Tsume rightly takes nothing, but the test required it to move something. The installed-face check now measures each cluster's blank space first: with some, Tsume must move the glyphs; with none, it must move nothing. The test font stays strict. --- crates/text/src/tests/harakat.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/text/src/tests/harakat.rs b/crates/text/src/tests/harakat.rs index 4e11921a6f..1a310ada27 100644 --- a/crates/text/src/tests/harakat.rs +++ b/crates/text/src/tests/harakat.rs @@ -454,18 +454,23 @@ fn check_spaced_harakat(db: &FontDb, family: &str) { } /// Right to left, with harakat coloured apart, Optical kerning keeps the Tsume of each letter's -/// cluster as it does in "HOH": the glyphs move as far with Optical kerning as without it. +/// cluster as it does in "HOH": the glyphs move as far with Optical kerning as without it. The test +/// font leaves blank space beside both letters' ink, so its Tsume must move something; an installed +/// face may not (#7821: Arial's initial beh and its fatha fill its cell), and there the Tsume takes +/// nothing, with or without Optical kerning. #[test] fn optical_kerning_keeps_the_tsume_of_a_letter_with_coloured_harakat() { let db = FontDb::with_font_dirs(vec![]); assert_eq!(db.add_font(crate::test_fonts::lam_alef_font(b"rlig").unwrap()), 1); - check_optical_tsume(&db, crate::test_fonts::lam_alef_family(b"rlig")); + check_optical_tsume(&db, crate::test_fonts::lam_alef_family(b"rlig"), true); if let Some(face) = arabic_face("optical_kerning_keeps_the_tsume_of_a_letter_with_coloured_harakat") { - check_optical_tsume(FontDb::global(), &face.family); + check_optical_tsume(FontDb::global(), &face.family, false); } } -fn check_optical_tsume(db: &FontDb, family: &str) { +/// `strict`: every letter's cluster must leave blank space beside its ink, so its Tsume must move +/// or narrow something. +fn check_optical_tsume(db: &FontDb, family: &str, strict: bool) { const WORD: &str = "بَبَ"; // ب 0, fatha 2, ب 4, fatha 6 let set = |optical: bool, letter: Option| { let mut t = text_with_harakat(WORD, family, Some(red())); @@ -479,11 +484,27 @@ fn check_optical_tsume(db: &FontDb, family: &str) { // Tsume of the line's first cluster only narrows its advance and moves no glyph. let xs = |t: &TextObject| layout(db, t).glyphs.iter().flat_map(|g| [g.xf.as_coeffs()[4], g.advance]).collect::>(); assert!(xs(&set(true, None)).iter().zip(xs(&set(false, None))).any(|(a, b)| (a - b).abs() > 1e-6), "{family}: Optical moves the pair"); + // The blank space Tsume shares out: between the letter's cluster's cell (from its glyphs' + // shared origin, as long as their advances) and its glyphs' ink, on each side, without Tsume. + let plain = layout(db, &set(false, None)); + let blank = |letter: usize| { + let cluster: Vec<_> = plain.glyphs.iter().filter(|g| g.byte == letter).collect(); + let start = cluster.iter().map(|g| g.origin.x).fold(f64::INFINITY, f64::min); + let end = start + cluster.iter().map(|g| g.advance).sum::(); + let ink = cluster.iter().filter(|g| !g.outline.elements().is_empty()).map(|g| g.outline.bounding_box()); + let (lo, hi) = ink.fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), b| (lo.min(b.x0), hi.max(b.x1))); + (lo - start).clamp(0.0, end - start) + (end - hi).clamp(0.0, end - start) + }; // Each letter in turn: the first one's cluster ends the pair, the second one's starts it. for letter in [0, 4] { let moved = |optical: bool| xs(&set(optical, Some(letter))).iter().zip(xs(&set(optical, None))).map(|(a, b)| a - b).collect::>(); let (without, with_optical) = (moved(false), moved(true)); - assert!(without.iter().any(|m| m.abs() > 1e-3), "{family} {letter}: Tsume moves or narrows the glyphs: {without:?}"); + let blank = blank(letter); + if strict || blank > 1e-3 { + assert!(without.iter().any(|m| m.abs() > 1e-3), "{family} {letter}: Tsume moves or narrows the glyphs ({blank} blank): {without:?}"); + } else { + assert!(without.iter().all(|m| m.abs() < 1e-6), "{family} {letter}: no blank space ({blank}), Tsume takes nothing: {without:?}"); + } assert!( without.len() == with_optical.len() && without.iter().zip(&with_optical).all(|(a, b)| (a - b).abs() < 1e-6), "{family} {letter}: {without:?} {with_optical:?}" From ee8c90b6f68565f6cdc2254ea009e46426d2367d Mon Sep 17 00:00:00 2001 From: HassanKhan Date: Mon, 16 Nov 2026 11:19:34 +0500 Subject: [PATCH 2/2] test(text): one tolerance for the Tsume blank-space branch and its movement check (#7821) --- crates/text/src/tests/harakat.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/text/src/tests/harakat.rs b/crates/text/src/tests/harakat.rs index 1a310ada27..4281cf9a5d 100644 --- a/crates/text/src/tests/harakat.rs +++ b/crates/text/src/tests/harakat.rs @@ -500,8 +500,8 @@ fn check_optical_tsume(db: &FontDb, family: &str, strict: bool) { let moved = |optical: bool| xs(&set(optical, Some(letter))).iter().zip(xs(&set(optical, None))).map(|(a, b)| a - b).collect::>(); let (without, with_optical) = (moved(false), moved(true)); let blank = blank(letter); - if strict || blank > 1e-3 { - assert!(without.iter().any(|m| m.abs() > 1e-3), "{family} {letter}: Tsume moves or narrows the glyphs ({blank} blank): {without:?}"); + if strict || blank > 1e-6 { + assert!(without.iter().any(|m| m.abs() > 1e-6), "{family} {letter}: Tsume moves or narrows the glyphs ({blank} blank): {without:?}"); } else { assert!(without.iter().all(|m| m.abs() < 1e-6), "{family} {letter}: no blank space ({blank}), Tsume takes nothing: {without:?}"); }