[designspaceLib] Don't make up bad PS names when no STAT data
See GitHub issue: https://github.com/googlefonts/ufo2ft/issues/630
This commit is contained in:
parent
4d2e5351a7
commit
b5f9499d2d
@ -88,6 +88,7 @@ def getStatNames(
|
||||
# Then build names for all these languages, but fallback to English
|
||||
# whenever a translation is missing.
|
||||
labels = _getAxisLabelsForUserLocation(doc.axes, userLocation)
|
||||
if labels:
|
||||
languages = set(language for label in labels for language in label.labelNames)
|
||||
languages.add("en")
|
||||
for language in languages:
|
||||
@ -100,8 +101,16 @@ def getStatNames(
|
||||
styleName = doc.elidedFallbackName
|
||||
styleNames[language] = styleName
|
||||
|
||||
postScriptFontName = None
|
||||
if "en" in familyNames and "en" in styleNames:
|
||||
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)
|
||||
|
56
Tests/designspaceLib/data/DS5BreakTest.designspace
Normal file
56
Tests/designspaceLib/data/DS5BreakTest.designspace
Normal 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>
|
@ -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,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user