Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Stop Std14::recognise mapping sans-serif font names to Times

NetterSilverab815b50a664
diff --git a/crates/fonts/src/std14.rs b/crates/fonts/src/std14.rs
index 0556b112c..aae657501 100644
--- a/crates/fonts/src/std14.rs
+++ b/crates/fonts/src/std14.rs
@@ -81,7 +81,7 @@ impl Std14 {
if has("times") {
return Some((times(), Match::Alias));
}
- if has("serif") || has("roman") {
+ if (has("serif") && !has("sans")) || has("roman") {
return Some((times(), Match::FamilyHint));
}
if has("helvetica") || has("arial") {
@@ -125,6 +125,12 @@ impl Std14 {
mod tests {
use super::*;
+ #[test]
+ fn sans_serif_names_are_not_mapped_to_times() {
+ assert!(!matches!(Std14::recognise("SansSerif"), Some((Std14::TimesRoman, _))));
+ assert_eq!(Std14::recognise("Arial-SansSerif"), Some((Std14::Helvetica, Match::Alias)));
+ }
+
/// Widths from the published Core14 metrics, typed in here by hand so the table is checked
/// against the specification rather than against whatever produced it.
#[test]