Merge pull request #9646

This commit is contained in:
autocraft-bot[bot]
2026-12-06 05:05:14 +00:00
+19 -1
View File
@@ -177,12 +177,18 @@ fn substitutes_by_name(family: &str) -> (&'static [&'static str], bool) {
"symbol" | "wingdings" | "wingdings 2" | "wingdings 3" | "segoe ui symbol" | "webdings" => (SYMBOL, true),
// Serif faces with no open clone of their own: the generic serif list, as for any font.
_ if KNOWN_SERIFS.contains(&f.as_str()) => (SERIF, false),
_ if f.contains("mono") || f.contains("code") => (MONO, false),
_ if is_mono_name(&f) => (MONO, false),
_ if f.contains("serif") && !f.contains("sans") => (SERIF, false),
_ => (SANS, false),
}
}
/// Whether `f` (lowercased) names a monospace/coding font by whole word, so `Unicode`,
/// `Monotype`, and `Barcode` do not match `code` or `mono` (#9542).
fn is_mono_name(f: &str) -> bool {
f.split(|c: char| !c.is_ascii_alphanumeric()).any(|w| matches!(w, "mono" | "monospace" | "monospaced" | "code"))
}
/// Ascent and descent (em) of Word's symbol fonts, which aren't open fonts. Their characters are
/// drawn from other faces (`wordcraft_doc::symbol_fonts`), but Word sizes a line by the font
/// itself: a Symbol bullet makes its line taller than the text alone. The values are those Word's
@@ -1289,4 +1295,16 @@ mod tests {
let cached = fallback_list_cache().lock().unwrap_or_else(|e| e.into_inner()).classes.len();
assert!(cached >= 2, "{cached} lists classified");
}
/// #9542: whole-word `mono`/`code` names take the monospace fallback, while sans and script
/// fonts containing `unicode`, `monotype`, or `barcode` keep the generic sans fallback.
#[test]
fn mono_and_code_fallback_matches_whole_words_not_unicode_monotype_or_barcode() {
for mono in ["Fira Code", "Source Code Pro", "JetBrains Mono", "Noto Sans Mono", "Monospace"] {
assert!(uses_generic_serif_or_monospace_fallback(mono), "{mono} should use MONO");
}
for sans in ["Lucida Sans Unicode", "Monotype Corsiva", "Free 3 of 9 Barcode"] {
assert!(!uses_generic_serif_or_monospace_fallback(sans), "{sans} should not use MONO");
}
}
}