Skip to content

Commit

Permalink
Convert fallback langs to strings at parse time, rather than at match…
Browse files Browse the repository at this point in the history
… time.
  • Loading branch information
xorgy committed Apr 19, 2024
1 parent beebdb5 commit 53985b0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/fontique/backend/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct SystemFonts {
pub name_map: Arc<FamilyNameMap>,
pub generic_families: Arc<GenericFamilyMap>,
family_map: HashMap<FamilyId, FamilyInfo>,
locale_fallback: Box<[(LanguageIdentifier, FamilyId)]>,
locale_fallback: Box<[(Box<str>, FamilyId)]>,
script_fallback: Box<[(Script, FamilyId)]>,
}

Expand Down Expand Up @@ -114,13 +114,15 @@ impl SystemFonts {
}) {
for lang in langs {
if let Some(scr) = lang.strip_prefix("und-") {
// Undefined lang for script-only fallbacks
script_fallback.push((scr.into(), *family));
} else if let Ok(locale) =
LanguageIdentifier::try_from_bytes(
lang.as_bytes(),
)
{
if let Some(scr) = locale.script {
// Also fallback for the script on its own
script_fallback
.push((scr.as_str().into(), *family));
if "Hant" == scr.as_str() {
Expand All @@ -133,7 +135,8 @@ impl SystemFonts {
.push(("Hani".into(), *family));
}
}
locale_fallback.push((locale, *family));
locale_fallback
.push((locale.to_string().into(), *family));
}
}
}
Expand All @@ -142,7 +145,7 @@ impl SystemFonts {
// when postScriptName is unavailable.
}

// family-specific fallback families, currently unimplimented
// family-specific fallback families, currently unimplemented
// because it requires a GenericFamily to be plumbed through
// the `RangedStyle` `font_stack` from `resolve` where it is
// currently thrown away.
Expand Down Expand Up @@ -181,7 +184,7 @@ impl SystemFonts {
.and_then(|li| {
self.locale_fallback
.iter()
.find(|(lid, _)| li == lid.to_string())
.find(|(lid, _)| li == lid.as_ref())
.map(|(_, fid)| *fid)
})
.or_else(|| {
Expand Down

0 comments on commit 53985b0

Please sign in to comment.