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