diff --git a/crates/engine/src/cmd/docinfo.rs b/crates/engine/src/cmd/docinfo.rs index d261582f3c..f33e65c099 100644 --- a/crates/engine/src/cmd/docinfo.rs +++ b/crates/engine/src/cmd/docinfo.rs @@ -174,9 +174,10 @@ fn font_use(used: &super::fonts::UsedFont, uses: usize) -> (Value, (String, Stri (json!({ "font": label, "type": kind, "uses": uses }), (label, format!("{name}; {count}"))) } -/// Counts text object `t` once for each font its runs are set in. +/// Counts text object `t` once for each font its runs are drawn in, a composite font's parts in +/// place of its name ([`super::fonts::run_fonts`]). fn count_fonts(fonts: &mut BTreeMap, t: &vectorcraft_doc::TextObject) { - let own: BTreeSet = t.runs.iter().map(|r| super::fonts::font_of(&r.style)).collect(); + let own: BTreeSet = t.runs.iter().flat_map(super::fonts::run_fonts).collect(); for font in own { *fonts.entry(font).or_default() += 1; } @@ -1015,6 +1016,31 @@ mod tests { assert_eq!((i["fontUses"].clone(), i["sections"][0]["rows"].clone()), (json!([]), json!([]))); } + /// Type set in a composite font counts as a use of the fonts of the parts its characters fall + /// in, as Find Font lists them, not of the composite font's name. + #[test] + fn info_fonts_count_the_parts_of_a_composite_font() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 200, "height": 200})).unwrap(); + let font = json!({"name": "DI Uses Composite", "parts": { + "kanji": {"font": "Source Sans 3"}, + "roman": {"font": "JetBrains Mono"}, + "numerals": {"font": "Inter"}, + }}); + s.execute("type.compositeFonts.set", &json!({"fonts": [font]})).unwrap(); + s.execute("text.create", &json!({"x": 10, "y": 20, "text": "Ab1", "font": "DI Uses Composite"})).unwrap(); + s.execute("text.create", &json!({"x": 10, "y": 50, "text": "12", "font": "DI Uses Composite"})).unwrap(); + let i = s.execute("document.info", &json!({"category": "fonts"})).unwrap(); + assert_eq!(i["fonts"], json!(["Inter Regular", "JetBrains Mono Regular"])); + assert_eq!( + i["fontUses"], + json!([ + {"font": "Inter Regular", "type": "truetype", "uses": 2}, + {"font": "JetBrains Mono Regular", "type": "truetype", "uses": 1}, + ]) + ); + } + /// Document Info › Objects gives the paths' total length in the document's units (#1958): an /// open line, a closed rectangle's perimeter and a compound path's pieces count, a guide doesn't. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index fba3b3cac1..d84b54865b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7472,8 +7472,9 @@ result carries the same files as a zip (`{name: ".zip", dataBase64}`, entr `document.info {selectionOnly?, category?, format?: "text"}` adds `sections` (`[{id, title, rows: [[label, value]]}]`: document, objects, graphicStyles, brushes, spotColors, patterns, gradients, symbols, fonts, fontDetails, linkedImages, embeddedImages, repeats), `fonts` (the fonts the document's type uses, the type in opacity masks and in the art of -its symbols and pattern swatches included, which the fonts and fontDetails categories list; with `selectionOnly`, the -fonts of the selected type), `fontUses` (`[{font, type, uses}]`: each font of `fonts`, in order, as the fonts +its symbols and pattern swatches included, type in a composite font giving the fonts of the parts its characters fall +in, which the fonts and fontDetails categories list; with `selectionOnly`, the fonts of the selected type), +`fontUses` (`[{font, type, uses}]`: each font of `fonts`, in order, as the fonts category's rows give it, such as `TrueType; 2 uses`: `type` is `truetype` or `opentype` by the outlines of the face the type is drawn in (`glyf`, or `CFF` or `CFF2`), `unknown` for a font not installed in the family and style it names; `uses` is the number of text objects set in the font, each counted once however many of its runs use it, the