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