Merge pull request #2684 from fonttools/fix-ps-name-regression

[designspaceLib] Don't make up bad PS names when no STAT data
This commit is contained in:
Jany Belluz 2022-07-07 13:54:41 +01:00 committed by GitHub
commit d3f21dea11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 14 deletions

View File

@ -88,21 +88,30 @@ def getStatNames(
# Then build names for all these languages, but fallback to English
# whenever a translation is missing.
labels = _getAxisLabelsForUserLocation(doc.axes, userLocation)
languages = set(language for label in labels for language in label.labelNames)
languages.add("en")
for language in languages:
styleName = " ".join(
label.labelNames.get(language, label.defaultName)
for label in labels
if not label.elidable
)
if not styleName and doc.elidedFallbackName is not None:
styleName = doc.elidedFallbackName
styleNames[language] = styleName
if labels:
languages = set(language for label in labels for language in label.labelNames)
languages.add("en")
for language in languages:
styleName = " ".join(
label.labelNames.get(language, label.defaultName)
for label in labels
if not label.elidable
)
if not styleName and doc.elidedFallbackName is not None:
styleName = doc.elidedFallbackName
styleNames[language] = styleName
postScriptFontName = None
if "en" in familyNames and "en" in styleNames:
postScriptFontName = f"{familyNames['en']}-{styleNames['en']}".replace(" ", "")
if "en" not in familyNames or "en" not in styleNames:
# Not enough information to compute PS names of styleMap names
return StatNames(
familyNames=familyNames,
styleNames=styleNames,
postScriptFontName=None,
styleMapFamilyNames={},
styleMapStyleName=None,
)
postScriptFontName = f"{familyNames['en']}-{styleNames['en']}".replace(" ", "")
styleMapStyleName, regularUserLocation = _getRibbiStyle(doc, userLocation)

View File

@ -0,0 +1,56 @@
<designspace format="4.0">
<axes>
<axis default="400" maximum="800" minimum="200" name="Weight" tag="wght">
<map input="200" output="0" />
<map input="400" output="250" />
<map input="800" output="1000" />
</axis>
</axes>
<sources>
<source familyname="DS5BreakTest" filename="DS5BreakTest-Extralight.ufo" stylename="ExtraLight Condensed">
<location>
<dimension name="Weight" xvalue="0" />
</location>
</source>
<source familyname="DS5BreakTest" filename="DS5BreakTest-Regular.ufo" stylename="Regular">
<location>
<dimension name="Weight" xvalue="250" />
</location>
</source>
<source familyname="DS5BreakTest" filename="DS5BreakTest-Extrabold.ufo" stylename="ExtraBold">
<location>
<dimension name="Weight" xvalue="1000" />
</location>
</source>
</sources>
<instances>
<instance familyname="DS5BreakTest" stylename="ExtraLight">
<location>
<dimension name="Weight" xvalue="0" />
</location>
</instance>
<instance familyname="DS5BreakTest" stylename="Regular">
<location>
<dimension name="Weight" xvalue="250" />
</location>
</instance>
<instance familyname="DS5BreakTest" stylename="Medium">
<location>
<dimension name="Weight" xvalue="400" />
</location>
</instance>
<instance familyname="DS5BreakTest" stylename="Bold">
<location>
<dimension name="Weight" xvalue="750" />
</location>
</instance>
<instance familyname="DS5BreakTest" stylename="ExtraBold">
<location>
<dimension name="Weight" xvalue="1000" />
</location>
</instance>
</instances>
</designspace>

View File

@ -59,3 +59,20 @@ def test_detect_ribbi_aktiv(datadir):
styleMapFamilyNames={"en": "Aktiv Grotesk Cd"},
styleMapStyleName="bold italic",
)
def test_getStatNames_on_ds4_doesnt_make_up_bad_names(datadir):
"""See this issue on GitHub: https://github.com/googlefonts/ufo2ft/issues/630
When as in the example, there's no STAT data present, the getStatName
shouldn't try making up a postscript name.
"""
doc = DesignSpaceDocument.fromfile(datadir / "DS5BreakTest.designspace")
assert getStatNames(doc, {"Weight": 600, "Width": 125, "Italic": 1}) == StatNames(
familyNames={"en": "DS5BreakTest"},
styleNames={},
postScriptFontName=None,
styleMapFamilyNames={},
styleMapStyleName=None,
)