Skip to content

Commit

Permalink
[instancer] Allow null ConditionSet
Browse files Browse the repository at this point in the history
Fixes #3211
  • Loading branch information
behdad committed Jul 20, 2023
1 parent 8707a1d commit b0cf3e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Lib/fontTools/varLib/instancer/featureVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

def _featureVariationRecordIsUnique(rec, seen):
conditionSet = []
for cond in rec.ConditionSet.ConditionTable:
conditionSets = (
rec.ConditionSet.ConditionTable if rec.ConditionSet is not None else []
)
for cond in conditionSets:
if cond.Format != 1:
# can't tell whether this is duplicate, assume is unique
return True
Expand Down Expand Up @@ -54,6 +57,10 @@ def _instantiateFeatureVariationRecord(
from fontTools.varLib.instancer import NormalizedAxisTripleAndDistances

default_triple = NormalizedAxisTripleAndDistances(-1, 0, +1)
if record.ConditionSet is None:
record.ConditionSet = ot.ConditionSet()
record.ConditionSet.ConditionTable = []
record.ConditionSet.ConditionCount = 0

Check warning on line 63 in Lib/fontTools/varLib/instancer/featureVars.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/instancer/featureVars.py#L61-L63

Added lines #L61 - L63 were not covered by tests
for i, condition in enumerate(record.ConditionSet.ConditionTable):
if condition.Format == 1:
axisIdx = condition.AxisIndex
Expand Down Expand Up @@ -100,6 +107,8 @@ def _instantiateFeatureVariationRecord(

if newConditions is not None and shouldKeep:
record.ConditionSet.ConditionTable = newConditions
if not newConditions:
record.ConditionSet = None
shouldKeep = True
else:
shouldKeep = False
Expand Down
3 changes: 2 additions & 1 deletion Tests/varLib/instancer/instancer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,8 @@ def test_varComposite(self):

def _conditionSetAsDict(conditionSet, axisOrder):
result = {}
for cond in conditionSet.ConditionTable:
conditionSets = conditionSet.ConditionTable if conditionSet is not None else []
for cond in conditionSets:
assert cond.Format == 1
axisTag = axisOrder[cond.AxisIndex]
result[axisTag] = (cond.FilterRangeMinValue, cond.FilterRangeMaxValue)
Expand Down

0 comments on commit b0cf3e1

Please sign in to comment.