summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-24 15:08:00 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-24 15:08:00 +0100
commit09077d6382e89a72c954edf99cfc3f014206ce7a (patch)
tree895b3fc4240680e67ffdf85c4f36874c42dfd6ce
parent151765bb3ef3c87a461b6922d97a1d98ff1c2fac (diff)
Fix more bad font names
-rw-r--r--src/font/book.rs50
-rw-r--r--tests/src/tests.rs1
2 files changed, 44 insertions, 7 deletions
diff --git a/src/font/book.rs b/src/font/book.rs
index 7e43033e..a6e41860 100644
--- a/src/font/book.rs
+++ b/src/font/book.rs
@@ -199,7 +199,10 @@ impl FontInfo {
// up.
let family = {
let mut family = find_name(ttf, name_id::FAMILY)?;
- if family.starts_with("Noto") || family.starts_with("NewComputerModern") {
+ if family.starts_with("Noto")
+ || family.starts_with("NewCM")
+ || family.starts_with("NewComputerModern")
+ {
family = find_name(ttf, name_id::FULL_NAME)?;
}
typographic_family(&family).to_string()
@@ -221,9 +224,18 @@ impl FontInfo {
(_, true) => FontStyle::Oblique,
};
- let weight = FontWeight::from_number(ttf.weight().to_number());
- let stretch = FontStretch::from_number(ttf.width().to_number());
+ let weight = {
+ let mut number = ttf.weight().to_number();
+ if (family.starts_with("NewCM")
+ || family.starts_with("New Computer Modern"))
+ && full.contains("book")
+ {
+ number += 50;
+ }
+ FontWeight::from_number(number)
+ };
+ let stretch = FontStretch::from_number(ttf.width().to_number());
FontVariant { style, weight, stretch }
};
@@ -318,6 +330,12 @@ fn typographic_family(mut family: &str) -> &str {
"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"];
+ }
+
// Trim spacing and weird leading dots in Apple fonts.
family = family.trim().trim_start_matches('.');
@@ -331,9 +349,16 @@ fn typographic_family(mut family: &str) -> &str {
len = trimmed.len();
// Find style suffix.
- let Some(mut t) = SUFFIXES.iter().find_map(|s| trimmed.strip_suffix(s)) else {
+ 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;
- };
+ }
// Strip optional separator.
if let Some(s) = t.strip_suffix(SEPARATORS) {
@@ -350,10 +375,21 @@ fn typographic_family(mut family: &str) -> &str {
}
}
+ // Apply style suffix trimming.
+ family = &family[..len];
+
+ if newcm {
+ family = family.trim_end_matches("10");
+ }
+
// Fix bad names.
- match &family[..len] {
+ 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",
- "NewComputerModernMath-Book" => "New Computer Modern Math Book",
+ "NewCMUncial" | "NewComputerModernUncial" => "New Computer Modern Uncial",
other => other,
}
}
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index 8895ccdd..62e6f3f5 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -220,6 +220,7 @@ impl TestWorld {
// Search for fonts.
let mut fonts = vec![];
for entry in WalkDir::new(FONT_DIR)
+ .sort_by_file_name()
.into_iter()
.filter_map(|e| e.ok())
.filter(|entry| entry.file_type().is_file())