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 19, 2023
1 parent b14a29c commit 4457995
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Lib/fontTools/varLib/instancer/featureVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

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 +55,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 61 in Lib/fontTools/varLib/instancer/featureVars.py

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L59 - L61 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 +105,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 4457995

Please sign in to comment.