[instancer] Implement L4 featureVariations
This commit is contained in:
parent
bce11dfc85
commit
1ff1a537e8
@ -694,7 +694,7 @@ def _limitFeatureVariationConditionRange(condition, axisLimit):
|
||||
|
||||
|
||||
def _instantiateFeatureVariationRecord(
|
||||
record, recIdx, location, fvarAxes, axisIndexMap
|
||||
record, recIdx, axisLimits, fvarAxes, axisIndexMap
|
||||
):
|
||||
applies = True
|
||||
newConditions = []
|
||||
@ -702,18 +702,20 @@ def _instantiateFeatureVariationRecord(
|
||||
if condition.Format == 1:
|
||||
axisIdx = condition.AxisIndex
|
||||
axisTag = fvarAxes[axisIdx].axisTag
|
||||
if axisTag in location:
|
||||
|
||||
minValue = condition.FilterRangeMinValue
|
||||
maxValue = condition.FilterRangeMaxValue
|
||||
v = location[axisTag]
|
||||
triple = _expand(axisLimits.get(axisTag, (-1, 0, +1)))
|
||||
v = triple[1]
|
||||
if not (minValue <= v <= maxValue):
|
||||
# condition not met so remove entire record
|
||||
applies = False
|
||||
# condition not met so remove entire record
|
||||
if triple[0] > maxValue or triple[2] < minValue:
|
||||
newConditions = None
|
||||
break
|
||||
else:
|
||||
# axis not pinned, keep condition with remapped axis index
|
||||
applies = False
|
||||
|
||||
if axisTag in axisIndexMap:
|
||||
# remap axis index
|
||||
condition.AxisIndex = axisIndexMap[axisTag]
|
||||
newConditions.append(condition)
|
||||
else:
|
||||
@ -746,6 +748,7 @@ def _limitFeatureVariationRecord(record, axisLimits, axisOrder):
|
||||
# keep condition with updated limits and remapped axis index
|
||||
condition.FilterRangeMinValue = newRange.minimum
|
||||
condition.FilterRangeMaxValue = newRange.maximum
|
||||
if newRange.minimum != -1 or newRange.maximum != +1:
|
||||
newConditions.append(condition)
|
||||
else:
|
||||
# condition out of range, remove entire record
|
||||
@ -779,7 +782,7 @@ def _instantiateFeatureVariations(table, fvarAxes, axisLimits):
|
||||
|
||||
for i, record in enumerate(table.FeatureVariations.FeatureVariationRecord):
|
||||
applies, shouldKeep = _instantiateFeatureVariationRecord(
|
||||
record, i, location, fvarAxes, axisIndexMap
|
||||
record, i, axisLimits, fvarAxes, axisIndexMap
|
||||
)
|
||||
if shouldKeep:
|
||||
shouldKeep = _limitFeatureVariationRecord(record, axisLimits, axisOrder)
|
||||
@ -790,7 +793,7 @@ def _instantiateFeatureVariations(table, fvarAxes, axisLimits):
|
||||
if applies and not featureVariationApplied:
|
||||
assert record.FeatureTableSubstitution.Version == 0x00010000
|
||||
for rec in record.FeatureTableSubstitution.SubstitutionRecord:
|
||||
table.FeatureList.FeatureRecord[rec.FeatureIndex].Feature = rec.Feature
|
||||
table.FeatureList.FeatureRecord[rec.FeatureIndex].Feature = deepcopy(rec.Feature)
|
||||
# Set variations only once
|
||||
featureVariationApplied = True
|
||||
|
||||
|
@ -1539,9 +1539,10 @@ class InstantiateFeatureVariationsTest(object):
|
||||
"location, appliedSubs, expectedRecords",
|
||||
[
|
||||
({"wght": 0}, {}, [({"cntr": (0.75, 1.0)}, {"uni0041": "uni0061"})]),
|
||||
# Buggy. See: https://github.com/fonttools/fonttools/issues/2737
|
||||
(
|
||||
{"wght": -1.0},
|
||||
{},
|
||||
{"uni0061": "uni0041"},
|
||||
[
|
||||
({"cntr": (0, 0.25)}, {"uni0061": "uni0041"}),
|
||||
({"cntr": (0.75, 1.0)}, {"uni0041": "uni0061"}),
|
||||
@ -1597,6 +1598,16 @@ class InstantiateFeatureVariationsTest(object):
|
||||
),
|
||||
],
|
||||
),
|
||||
(
|
||||
{"cntr": (.8, .9, 1.0)},
|
||||
{"uni0041": "uni0061"},
|
||||
[
|
||||
(
|
||||
{"wght": (0.20886, 1.0)},
|
||||
{"uni0024": "uni0024.nostroke", "uni0041": "uni0061"},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_partial_instance(self, location, appliedSubs, expectedRecords):
|
||||
|
Loading…
x
Reference in New Issue
Block a user