Skip to content

Commit

Permalink
More exactly match fontmake language prioritization
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Oct 8, 2024
1 parent 2642949 commit 63ed907
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
40 changes: 29 additions & 11 deletions glyphs-reader/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2133,17 +2133,35 @@ impl TryFrom<RawFont> for Font {

let mut names = BTreeMap::new();
for name in from.properties {
// We don't support full l10n of names, just the limited capability of glyphsLib
// See <https://github.com/googlefonts/fontc/issues/1011>
name.value
.or_else(|| {
name.values
.iter()
.find(|v| v.language == "dflt")
.map(|v| v.value.clone())
})
.or_else(|| name.values.first().map(|v| v.value.clone()))
.and_then(|value| names.insert(name.key, value));
if name.value.is_some() {
name.value
} else {
// We don't support full l10n of names, just the limited capability of glyphsLib
// See <https://github.com/googlefonts/fontc/issues/1011>
// In order of preference: dflt, default, ENG, whatever is first
// <https://github.com/googlefonts/glyphsLib/blob/1cb4fc5ae2cf385df95d2b7768e7ab4eb60a5ac3/Lib/glyphsLib/classes.py#L3155-L3161>
name.values
.iter()
.enumerate()
// (score [lower better], index)
.map(|(i, n)| match n.language.as_str() {
"dflt" => (-3, i),
"default" => (-2, i),
"ENG" => (-1, i),
_ => (i as i32, i),
})
.reduce(
|(best_score, best_index), (candidate_score, candidate_index)| {
if best_score < candidate_score {
(best_score, best_index)
} else {
(candidate_score, candidate_index)
}
},
)
.map(|(_, i)| name.values[i].value.clone())
}
.and_then(|value| names.insert(name.key, value));
}
names.insert("familyNames".into(), from.family_name);
if let Some(version) = names.remove("versionString") {
Expand Down
20 changes: 18 additions & 2 deletions resources/testdata/glyphs3/TheBestNames.glyphs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ value = "The greatest weight var";
key = copyrights;
values = (
{
language = default;
value = "Wrong answer";
},
{
language = dflt;
value = "Copy!";
}
Expand Down Expand Up @@ -337,7 +341,15 @@ value = "Licensed to thrill";
key = sampleTexts;
values = (
{
language = dflt;
language = MEH;
value = "Don't pull this text";
},
{
language = ENG;
value = "Also bad";
},
{
language = default;
value = "Sam pull text";
}
);
Expand All @@ -346,7 +358,11 @@ value = "Sam pull text";
key = compatibleFullNames;
values = (
{
language = dflt;
language = WRONG;
value = "For the BeOS only";
},
{
language = ENG;
value = "For the Mac's only";
}
);
Expand Down

0 comments on commit 63ed907

Please sign in to comment.