From 5b2c7bb0fbd48c632480f885a39b840ce5cf5d08 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Wed, 4 Nov 2026 19:34:32 -0700 Subject: [PATCH] Fonts: a font's family name falls back to the family when the typographic one is blank (CodeRabbit on #2803) --- crates/fonts/src/ttf.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fonts/src/ttf.rs b/crates/fonts/src/ttf.rs index 5125d0a24..29a8b686c 100644 --- a/crates/fonts/src/ttf.rs +++ b/crates/fonts/src/ttf.rs @@ -83,14 +83,14 @@ impl Face { pub fn has_glyph(&self, c: char) -> bool { self.font().is_some_and(|f| f.charmap().map(c).is_some()) } - /// The family name, as the font gives it. + /// The family name, as the font gives it (the typographic family, else the family when that + /// is missing or blank). pub fn family_name(&self) -> Option { let f = self.font()?; - [skrifa::string::StringId::TYPOGRAPHIC_FAMILY_NAME, skrifa::string::StringId::FAMILY_NAME] - .into_iter() - .find_map(|id| f.localized_strings(id).next().map(|s| s.to_string())) - .map(|s| s.chars().filter(|c| !c.is_control()).take(80).collect::()) - .filter(|s| !s.trim().is_empty()) + [skrifa::string::StringId::TYPOGRAPHIC_FAMILY_NAME, skrifa::string::StringId::FAMILY_NAME].into_iter().find_map(|id| { + let s = f.localized_strings(id).next()?.to_string(); + Some(s.chars().filter(|c| !c.is_control()).take(80).collect::()).filter(|s| !s.trim().is_empty()) + }) } /// The glyph ids the face's character map gives `chars` (`None` for an unmapped one).