From 263eba2ef6430c570cd3cce5c2266a495075d95f Mon Sep 17 00:00:00 2001 From: austin62jake <340374338+austin62jake@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:15:20 -0500 Subject: [PATCH] Test bottom-justified TrueType text with any common installed font The test used Arial only, so it skipped on Linux and macOS CI. It now uses the first of Arial, Helvetica, DejaVuSans, Verdana or Liberation Sans that is installed (as the fonts crate's other TrueType tests do), and keeps the Arial-specific checks for Arial. Co-Authored-By: Claude Opus 5.5 --- crates/fonts/src/lib.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/fonts/src/lib.rs b/crates/fonts/src/lib.rs index 8ca1bc62f..5bbae6883 100644 --- a/crates/fonts/src/lib.rs +++ b/crates/fonts/src/lib.rs @@ -875,21 +875,25 @@ mod justify_tests { /// With a TrueType font, a bottom-justified text's alignment point is at the face's descent, /// where its descenders end, as AutoCAD places it (#2229: Arial's is 0.296 of the height). - /// Skips when Arial isn't installed. + /// Uses the first of these common fonts that is installed (Windows, macOS and Linux each have + /// one); skips without any. #[test] fn a_bottom_justified_truetype_text_sits_on_its_descent() { - let Some(face) = ttf::find("Arial") else { return }; + let found = ["Arial", "Helvetica", "DejaVuSans", "Verdana", "LiberationSans-Regular"].into_iter().find_map(|n| ttf::find(n).map(|f| (n, f))); + let Some((name, face)) = found else { return }; let ratio = ttf::descent_ratio(&face).unwrap(); - assert!((ratio - 0.296).abs() < 0.01, "Arial's descent over cap height: {ratio}"); let font = TextFont::Outline(face); let (sh, start) = placed(&font, "gjpqy", Align::Left, VAlign::Bottom); - assert!((start.y - ratio * H).abs() < 1e-9, "{start:?}"); - // The descenders reach the alignment point's line: h/3 left them 0.1 above it. - let (lo, _) = ink_y(&sh); - assert!(lo.abs() < 0.02 * H, "descender bottom {lo} from the alignment point"); + assert!((start.y - ratio * H).abs() < 1e-9, "{name}: {start:?}"); + if name == "Arial" { + assert!((ratio - 0.296).abs() < 0.01, "Arial's descent over cap height: {ratio}"); + // The descenders reach the alignment point's line: h/3 left them 0.1 above it. + let (lo, _) = ink_y(&sh); + assert!(lo.abs() < 0.02 * H, "descender bottom {lo} from the alignment point"); + } // And Middle centres the ink, as with the stroke font. let (sh, _) = placed(&font, "Tg 1234 ABC", Align::Middle, VAlign::Baseline); let (lo, hi) = ink_y(&sh); - assert!(((lo + hi) / 2.0).abs() < 1e-9, "{lo}..{hi}"); + assert!(((lo + hi) / 2.0).abs() < 1e-9, "{name}: {lo}..{hi}"); } }