[instancer.featureVars] Fix deficiency in L4 instancing
See discussion on the issue. I think I got this right. Fixes https://github.com/fonttools/fonttools/issues/2737
This commit is contained in:
parent
1b6f4fb858
commit
392706949c
@ -1,4 +1,5 @@
|
||||
|
||||
from fontTools.ttLib.tables import otTables as ot
|
||||
from fontTools.varLib.models import normalizeValue
|
||||
from copy import deepcopy
|
||||
import logging
|
||||
@ -117,6 +118,7 @@ def _instantiateFeatureVariations(table, fvarAxes, axisLimits):
|
||||
featureVariationApplied = False
|
||||
uniqueRecords = set()
|
||||
newRecords = []
|
||||
defaultsSubsts = None
|
||||
|
||||
for i, record in enumerate(table.FeatureVariations.FeatureVariationRecord):
|
||||
applies, shouldKeep, universal = _instantiateFeatureVariationRecord(
|
||||
@ -128,7 +130,10 @@ def _instantiateFeatureVariations(table, fvarAxes, axisLimits):
|
||||
|
||||
if applies and not featureVariationApplied:
|
||||
assert record.FeatureTableSubstitution.Version == 0x00010000
|
||||
for rec in record.FeatureTableSubstitution.SubstitutionRecord:
|
||||
defaultsSubsts = deepcopy(record.FeatureTableSubstitution)
|
||||
for default,rec in zip(defaultsSubsts.SubstitutionRecord,
|
||||
record.FeatureTableSubstitution.SubstitutionRecord):
|
||||
default.Feature = deepcopy(table.FeatureList.FeatureRecord[rec.FeatureIndex].Feature)
|
||||
table.FeatureList.FeatureRecord[rec.FeatureIndex].Feature = deepcopy(
|
||||
rec.Feature
|
||||
)
|
||||
@ -139,6 +144,16 @@ def _instantiateFeatureVariations(table, fvarAxes, axisLimits):
|
||||
if universal:
|
||||
break
|
||||
|
||||
# Insert a catch-all record to reinstate the old features if necessary
|
||||
if featureVariationApplied and newRecords and not universal:
|
||||
defaultRecord = ot.FeatureVariationRecord()
|
||||
defaultRecord.ConditionSet = ot.ConditionSet()
|
||||
defaultRecord.ConditionSet.ConditionTable = []
|
||||
defaultRecord.ConditionSet.ConditionCount = 0
|
||||
defaultRecord.FeatureTableSubstitution = defaultsSubsts
|
||||
|
||||
newRecords.append(defaultRecord)
|
||||
|
||||
if newRecords:
|
||||
table.FeatureVariations.FeatureVariationRecord = newRecords
|
||||
table.FeatureVariations.FeatureVariationCount = len(newRecords)
|
||||
|
@ -1588,13 +1588,13 @@ 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"}),
|
||||
({}, {}),
|
||||
],
|
||||
),
|
||||
(
|
||||
@ -1604,7 +1604,8 @@ class InstantiateFeatureVariationsTest(object):
|
||||
(
|
||||
{"cntr": (0.75, 1.0)},
|
||||
{"uni0024": "uni0024.nostroke", "uni0041": "uni0061"},
|
||||
)
|
||||
),
|
||||
({}, {})
|
||||
],
|
||||
),
|
||||
(
|
||||
@ -1622,7 +1623,8 @@ class InstantiateFeatureVariationsTest(object):
|
||||
(
|
||||
{"wght": (0.20886, 1.0)},
|
||||
{"uni0024": "uni0024.nostroke", "uni0041": "uni0061"},
|
||||
)
|
||||
),
|
||||
({}, {})
|
||||
],
|
||||
),
|
||||
(
|
||||
|
Loading…
x
Reference in New Issue
Block a user