tinymist_world/font/
info.rs#[allow(dead_code)]
pub fn typst_typographic_family(mut family: &str) -> &str {
const SEPARATORS: [char; 3] = [' ', '-', '_'];
const MODIFIERS: &[&str] = &[
"extra", "ext", "ex", "x", "semi", "sem", "sm", "demi", "dem", "ultra",
];
#[rustfmt::skip]
const SUFFIXES: &[&str] = &[
"normal", "italic", "oblique", "slanted",
"thin", "th", "hairline", "light", "lt", "regular", "medium", "med",
"md", "bold", "bd", "demi", "extb", "black", "blk", "bk", "heavy",
"narrow", "condensed", "cond", "cn", "cd", "compressed", "expanded", "exp"
];
let mut extra = [].as_slice();
let newcm = family.starts_with("NewCM") || family.starts_with("NewComputerModern");
if newcm {
extra = &["book"];
}
family = family.trim().trim_start_matches('.');
let lower = family.to_ascii_lowercase();
let mut len = usize::MAX;
let mut trimmed = lower.as_str();
while trimmed.len() < len {
len = trimmed.len();
let mut t = trimmed;
let mut shortened = false;
while let Some(s) = SUFFIXES.iter().chain(extra).find_map(|s| t.strip_suffix(s)) {
shortened = true;
t = s;
}
if !shortened {
break;
}
if let Some(s) = t.strip_suffix(SEPARATORS) {
trimmed = s;
t = s;
}
if let Some(t) = MODIFIERS.iter().find_map(|s| t.strip_suffix(s)) {
if let Some(stripped) = t.strip_suffix(SEPARATORS) {
trimmed = stripped;
}
}
}
family = &family[..len];
if newcm {
family = family.trim_end_matches("10");
}
match family {
"Noto Sans Symbols2" => "Noto Sans Symbols 2",
"NewComputerModern" => "New Computer Modern",
"NewComputerModernMono" => "New Computer Modern Mono",
"NewComputerModernSans" => "New Computer Modern Sans",
"NewComputerModernMath" => "New Computer Modern Math",
"NewCMUncial" | "NewComputerModernUncial" => "New Computer Modern Uncial",
other => other,
}
}