EPS file fonts: decide carried or fallback per family and style

The warning took a family as carried when any style of it was, so a
named bold beside a carried regular lost its fallback warning. Carried
and fallback are now decided per family and style, and a family can be
named in both sentences.
This commit is contained in:
JonRC committed 2026-11-23 00:53:54 -03:00
1 parent 610849efa3
commit a6511830f2
2 files changed
+32 -13

No files matched your search

+17 -13
View File
@@ -320,17 +320,18 @@ fn read_checked(bytes: &[u8], editing_data: bool, trust: bool, names: NameEncodi
}
/// The families of the type in `d` (its layers and its symbols) that aren't available, each once
/// in the order the type comes, at most [`MAX_MISSING_FONTS`]: the document's, whether its type
/// came from the page or from an editing copy, and none for type only measured or outlined. Those
/// drawn in fonts the file carries (bound to the document's type) come first, the rest second.
/// in the order the type comes, at most [`MAX_MISSING_FONTS`] a list: the document's, whether its
/// type came from the page or from an editing copy, and none for type only measured or outlined.
/// The first list holds those drawn in fonts the file carries (bound to the document's type), the
/// second those in the fallback font; a family whose styles differ in that is in both.
fn missing_fonts(d: &Document) -> (Vec<String>, Vec<String>) {
let db = vectorcraft_text::FontDb::global();
let mut bound: HashSet<String> = HashSet::new();
let mut bound: HashSet<(String, String)> = HashSet::new();
let mut find_bound = |n: &Node| {
if let NodeKind::Text(t) = &n.kind {
for font in t.file_fonts_in_use() {
if t.file_fonts.as_ref().and_then(|fonts| fonts.face(&font.key)).is_some() {
bound.insert(font.family.clone());
bound.insert((font.family.clone(), font.style.clone()));
}
}
}
@@ -339,26 +340,29 @@ fn missing_fonts(d: &Document) -> (Vec<String>, Vec<String>) {
for s in &d.symbols {
s.art.walk(&mut find_bound);
}
let mut checked: HashSet<String> = HashSet::new();
let mut missing: Vec<String> = Vec::new();
let mut checked: HashSet<(String, String)> = HashSet::new();
let (mut carried, mut missing): (Vec<String>, Vec<String>) = (Vec::new(), Vec::new());
let mut add = |n: &Node| {
let NodeKind::Text(t) = &n.kind else { return };
for run in &t.runs {
let family = run.style.font_family.as_str();
if missing.len() >= MAX_MISSING_FONTS || family.is_empty() || checked.contains(family) {
let key = (run.style.font_family.clone(), run.style.font_style.clone());
if key.0.is_empty() || checked.contains(&key) {
continue;
}
checked.insert(family.to_string());
if db.find_family(family).is_none() {
missing.push(family.to_string());
if db.find_family(&key.0).is_none() {
let list = if bound.contains(&key) { &mut carried } else { &mut missing };
if list.len() < MAX_MISSING_FONTS && !list.contains(&key.0) {
list.push(key.0.clone());
}
}
checked.insert(key);
}
};
d.walk(&mut add);
for s in &d.symbols {
s.art.walk(&mut add);
}
missing.into_iter().partition(|family| bound.contains(family))
(carried, missing)
}
/// [`import_names`] before the type's fonts are checked (a `.ai` when `ai_file`, see [`import_ai`]).
+15
View File
@@ -178,6 +178,21 @@ fn embedded_type1_type_draws_with_the_files_glyphs() {
assert!(t.runs.iter().all(|r| r.style.tracking == 0.0), "{:?}", t.runs);
}
/// A family whose regular style the file carries but whose bold it only names: the regular is
/// drawn in the kept font and the bold in the fallback font, and the warning says both.
#[test]
fn a_carried_style_leaves_a_named_style_of_its_family_in_the_fallback_warning() {
let r = program(OWN, false, "/TestOne findfont 50 scalefont setfont 10 20 moveto (A) show /TestOne-Bold 12 selectfont 10 80 moveto (x) show");
assert_eq!(texts(&r).iter().map(|t| t.runs[0].style.font_style.as_str()).collect::<Vec<_>>(), ["Regular", "Bold"]);
assert_eq!(
r.warnings,
[
"fonts that aren't available show as the file draws them, in the fonts it carries, until their text is edited (then in the fallback font): Test One",
"fonts that aren't available show in the fallback font until they are: Test One",
]
);
}
/// Type in a font the file only names keeps the fallback font, and the spacing set for it, also
/// when its family and style are those of a font the file carries (`TestOne-Roman` beside the
/// embedded `TestOne`): only type shown in the carried font gets the font kept from it.