From 0db6dddc60dc55fc2fb466cd3b1460fee2a02b65 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 2 Dec 2026 06:34:37 -0800 Subject: [PATCH] Type: Font Sheet lists composite fonts lacking sample glyphs as fallbacks A composite font's entry was never named in `fallback`, even when the part that sets the sample lacked a glyph it needs. The entry now checks each grapheme's part face for the characters layout draws, in the sample's numeral system, through the new `FontDb::composite_drawn_coverage`. --- .../src/cmd/addons/typetools/font_sheet.rs | 4 +++- .../cmd/addons/typetools/font_sheet/tests.rs | 24 +++++++++++++++++++ crates/text/src/fontdb/composite.rs | 19 +++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/addons/typetools/font_sheet.rs b/crates/engine/src/cmd/addons/typetools/font_sheet.rs index bb009540e4..edc72587cc 100644 --- a/crates/engine/src/cmd/addons/typetools/font_sheet.rs +++ b/crates/engine/src/cmd/addons/typetools/font_sheet.rs @@ -213,7 +213,9 @@ fn font_sheet_in(s: &mut Session, p: &Value, db: &FontDb) -> Result { // that sets the sample names a font or style that doesn't load. let composite = db.composite_font(&family).is_some(); let (loads, covers) = if composite { - (db.composite_coverage(&family, &[text.as_str()]).is_some_and(|c| c.status == FontMatch::Exact), true) + // Glyph coverage is checked on the characters layout draws, in the sample's numeral system. + let covers = db.composite_drawn_coverage(&family, &[text.as_str()], sample.digits).is_none_or(|c| c.lacking.is_empty()); + (db.composite_coverage(&family, &[text.as_str()]).is_some_and(|c| c.status == FontMatch::Exact), covers) } else { let wanted = db.canonical(&family, "").0; match db.face(&sample.font_family, &sample.font_style) { diff --git a/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs b/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs index ffa62df82b..f1b207025b 100644 --- a/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs +++ b/crates/engine/src/cmd/addons/typetools/font_sheet/tests.rs @@ -409,6 +409,30 @@ fn a_composite_font_with_an_unavailable_part_style_is_left_out() { assert_eq!(steps(&s), before.1); } +/// A composite font whose parts load but lack a glyph the sample needs stays on the sheet and is +/// named in `fallback`, as a plain font is. +#[test] +fn a_composite_font_lacking_a_sample_glyph_is_named_as_a_fallback() { + let mut s = session(); + let font = json!({"name": "CF Sheet Lacking", "parts": {"kanji": {"font": "Source Sans 3"}, "roman": {"font": "Inter"}}}); + s.execute("type.compositeFonts.set", &json!({"fonts": [font]})).unwrap(); + let rtl = "\u{5e9}\u{5dc}\u{5d5}\u{5dd}"; + let coverage = FontDb::global().composite_coverage("CF Sheet Lacking", &[rtl]).unwrap(); + assert_eq!(coverage.status, vectorcraft_text::FontMatch::Exact); + assert!(!coverage.lacking.is_empty()); + let r = s.execute(COMMAND, &json!({"families": ["CF Sheet Lacking"], "text": rtl})).unwrap(); + assert_eq!((&r["count"], &r["skipped"]), (&json!(1), &json!([])), "{r}"); + assert_eq!(r["fallback"], json!(["CF Sheet Lacking"]), "{r}"); + assert!(r["warning"].as_str().is_some_and(|w| w.contains("lack glyphs") && w.contains("CF Sheet Lacking")), "{r}"); + // A variation selector needs no glyph of its own, and digits are checked in the sample's numeral system. + let r = s.execute(COMMAND, &json!({"families": ["CF Sheet Lacking"], "text": "A\u{fe0f}"})).unwrap(); + assert_eq!(r["fallback"], json!([]), "{r}"); + s.execute("charStyle.edit", &json!({"name": "[Normal Character Style]", "to": "[Normal Character Style]", "attrs": {"digits": "hindi"}})) + .unwrap(); + let r = s.execute(COMMAND, &json!({"families": ["CF Sheet Lacking"], "text": "1"})).unwrap(); + assert_eq!(r["fallback"], json!(["CF Sheet Lacking"]), "{r}"); +} + #[test] fn labels_without_overlap_need_no_additional_layouts() { use vectorcraft_text::test_fonts::{ink_work_on_this_thread, layouts_on_this_thread}; diff --git a/crates/text/src/fontdb/composite.rs b/crates/text/src/fontdb/composite.rs index 1ac538b7a0..371d8e2574 100644 --- a/crates/text/src/fontdb/composite.rs +++ b/crates/text/src/fontdb/composite.rs @@ -12,7 +12,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use unicode_segmentation::UnicodeSegmentation; use vectorcraft_doc::text::CompositeClasses; -use vectorcraft_doc::{CharClass, CompositeClass, CompositeFont, CompositePart, TextObject, TextRun}; +use vectorcraft_doc::{CharClass, CompositeClass, CompositeFont, CompositePart, Digits, TextObject, TextRun}; use super::face::FALLBACK_FAMILY; use super::{Arc, FontDb, FontFace, FontMatch}; @@ -242,6 +242,17 @@ impl FontDb { /// match, and the characters (neither whitespace nor control characters, sorted, each once) /// that their part's face lacks. `None` when `name` is no composite font. pub fn composite_coverage(&self, name: &str, texts: &[&str]) -> Option { + self.coverage_of(name, texts, None) + } + + /// [`FontDb::composite_coverage`] of the characters layout draws in numeral system `digits`: + /// each grapheme cluster's part is chosen by its own first character, and the part's face is + /// checked for the cluster's drawn characters ([`crate::drawn_chars`]). + pub fn composite_drawn_coverage(&self, name: &str, texts: &[&str], digits: Digits) -> Option { + self.coverage_of(name, texts, Some(digits)) + } + + fn coverage_of(&self, name: &str, texts: &[&str], digits: Option) -> Option { let f = self.composite_font(name)?; let rank = |m: FontMatch| match m { FontMatch::Exact => 0, @@ -272,7 +283,11 @@ impl FontDb { if worst.as_ref().is_none_or(|(w, _)| rank(m) > rank(*w)) { worst = Some((m, found.as_ref().map(|(face, _)| face.clone()))); } - lacking.extend(g.chars().filter(|c| !c.is_whitespace() && !c.is_control() && !found.as_ref().is_some_and(|(face, _)| face.covers(*c)))); + match digits { + Some(d) => lacking.extend(crate::drawn_chars(g, d).filter(|c| !found.as_ref().is_some_and(|(face, _)| face.covers(*c)))), + None => lacking + .extend(g.chars().filter(|c| !c.is_whitespace() && !c.is_control() && !found.as_ref().is_some_and(|(face, _)| face.covers(*c)))), + } } lacking.sort_unstable(); lacking.dedup();