mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 17:05:55 +01:00
Document Info: Fonts counts the parts of a composite font
Type set in a composite font counted as one use of the composite font's name, with the type of that name's face. Each text object now counts once for each font its runs are drawn in: the fonts of the composite font's parts its characters fall in, as `fonts` and Find Font already list them. Docs: docs/mcp.md.
This commit is contained in:
1 parent
6c352a3ba2
commit
42e967a4dd
2 files changed
+31
-4
No files matched your search
@@ -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<super::fonts::UsedFont, usize>, t: &vectorcraft_doc::TextObject) {
|
||||
let own: BTreeSet<super::fonts::UsedFont> = t.runs.iter().map(|r| super::fonts::font_of(&r.style)).collect();
|
||||
let own: BTreeSet<super::fonts::UsedFont> = 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]
|
||||
|
||||
+3
-2
@@ -7472,8 +7472,9 @@ result carries the same files as a zip (`{name: "<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
|
||||
|
||||
Reference in new issue
Block a user