instancer: don't break on unsupported condition formats

continue checking subsequent condition tables in case the other may
be format=1 and may reference a pinned axis; in which case, these
conditions need to be dropped from the condition set, or the whole
record needs to be dropped if the instance coordinate is outside the
condition range.
Condition tables within a condition set are associated with a AND
boolean operator, so if any one doesn't match, the whole set doesn't
apply. Even if we don't recognize one condition format, if we do
ascertain that another condition table does not match the current
partial instance location, we can drop the FeatureVariation record
since it doesn't apply.
This commit is contained in:
Cosimo Lupo 2019-05-30 13:05:07 +01:00
parent 874947c00b
commit b878b867c0
No known key found for this signature in database
GPG Key ID: 20D4A261E4A0E642
2 changed files with 8 additions and 5 deletions

View File

@ -474,7 +474,6 @@ def _instantiateFeatureVariations(table, fvarAxes, location):
)
applies = False
newConditions.append(condition)
break
if retainRecord and newConditions:
record.ConditionSet.ConditionTable = newConditions

View File

@ -1316,18 +1316,22 @@ class InstantiateFeatureVariationsTest(object):
)
]
)
gsub = font["GSUB"].table
featureVariations = gsub.FeatureVariations
featureVariations = font["GSUB"].table.FeatureVariations
rec1 = featureVariations.FeatureVariationRecord[0]
assert len(rec1.ConditionSet.ConditionTable) == 2
rec1.ConditionSet.ConditionTable[0].Format = 2
with CapturingLogHandler("fontTools.varLib.instancer", "WARNING") as captor:
instancer.instantiateFeatureVariations(font, {"wght": 0})
instancer.instantiateFeatureVariations(font, {"wdth": 0})
captor.assertRegex(
r"Condition table 0 of FeatureVariationRecord 0 "
r"has unsupported format \(2\); ignored"
)
# check that record with unsupported condition format is kept
# check that record with unsupported condition format (but whose other
# conditions do not reference pinned axes) is kept as is
featureVariations = font["GSUB"].table.FeatureVariations
assert featureVariations.FeatureVariationRecord[0] is rec1
assert len(rec1.ConditionSet.ConditionTable) == 2
assert rec1.ConditionSet.ConditionTable[0].Format == 2