[instancer] Check if an axis has values before requiring it to be found (#3319)
* Check if an axis has values before requiring it to be found * Add test
This commit is contained in:
parent
52414cc5f1
commit
49570c3599
@ -134,6 +134,14 @@ def updateNameTable(varfont, axisLimits):
|
||||
def checkAxisValuesExist(stat, axisValues, axisCoords):
|
||||
seen = set()
|
||||
designAxes = stat.DesignAxisRecord.Axis
|
||||
hasValues = set()
|
||||
for value in stat.AxisValueArray.AxisValue:
|
||||
if value.Format in (1, 2, 3):
|
||||
hasValues.add(designAxes[value.AxisIndex].AxisTag)
|
||||
elif value.Format == 4:
|
||||
for rec in value.AxisValueRecord:
|
||||
hasValues.add(designAxes[rec.AxisIndex].AxisTag)
|
||||
|
||||
for axisValueTable in axisValues:
|
||||
axisValueFormat = axisValueTable.Format
|
||||
if axisValueTable.Format in (1, 2, 3):
|
||||
@ -150,7 +158,7 @@ def checkAxisValuesExist(stat, axisValues, axisCoords):
|
||||
if axisTag in axisCoords and rec.Value == axisCoords[axisTag]:
|
||||
seen.add(axisTag)
|
||||
|
||||
missingAxes = set(axisCoords) - seen
|
||||
missingAxes = (set(axisCoords) - seen) & hasValues
|
||||
if missingAxes:
|
||||
missing = ", ".join(f"'{i}': {axisCoords[i]}" for i in missingAxes)
|
||||
raise ValueError(f"Cannot find Axis Values {{{missing}}}")
|
||||
|
@ -333,3 +333,21 @@ def test_updateNameTable_existing_subfamily_name_is_not_regular(varfont):
|
||||
instancer.names.updateNameTable(varfont, {"wght": 100})
|
||||
expected = {(2, 3, 1, 0x409): "Regular", (17, 3, 1, 0x409): "Thin"}
|
||||
_test_name_records(varfont, expected, isNonRIBBI=True)
|
||||
|
||||
|
||||
def test_name_irrelevant_axes(varfont):
|
||||
# Cannot update name table if not on a named axis value location
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
location = {"wght": 400, "wdth": 90}
|
||||
instance = instancer.instantiateVariableFont(
|
||||
varfont, location, updateFontNames=True
|
||||
)
|
||||
assert "Cannot find Axis Values" in str(excinfo.value)
|
||||
|
||||
# Now let's make the wdth axis "irrelevant" to naming (no axis values)
|
||||
varfont["STAT"].table.AxisValueArray.AxisValue.pop(6)
|
||||
varfont["STAT"].table.AxisValueArray.AxisValue.pop(4)
|
||||
location = {"wght": 400, "wdth": 90}
|
||||
instance = instancer.instantiateVariableFont(
|
||||
varfont, location, updateFontNames=True
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user