Merge pull request #1782 from anthrotype/subset-feature-vars-remap-indices
[subset] remap FeatureVariations SubstitutionRecord.FeatureIndex
This commit is contained in:
commit
3b9a94d659
@ -1307,6 +1307,9 @@ def subset_features(self, feature_indices):
|
||||
self.ensureDecompiled()
|
||||
self.SubstitutionRecord = [r for r in self.SubstitutionRecord
|
||||
if r.FeatureIndex in feature_indices]
|
||||
# remap feature indices
|
||||
for r in self.SubstitutionRecord:
|
||||
r.FeatureIndex = feature_indices.index(r.FeatureIndex)
|
||||
self.SubstitutionCount = len(self.SubstitutionRecord)
|
||||
return bool(self.SubstitutionCount)
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
import io
|
||||
from fontTools.misc.py23 import *
|
||||
from fontTools import subset
|
||||
from fontTools.fontBuilder import FontBuilder
|
||||
from fontTools.ttLib import TTFont, newTable
|
||||
from fontTools.misc.loggingTools import CapturingLogHandler
|
||||
import difflib
|
||||
@ -728,5 +730,43 @@ class SubsetTest(unittest.TestCase):
|
||||
self.assertEqual(ttf.flavor, None)
|
||||
|
||||
|
||||
def test_subset_feature_variations():
|
||||
fb = FontBuilder(unitsPerEm=100)
|
||||
fb.setupGlyphOrder([".notdef", "f", "f_f", "dollar", "dollar.rvrn"])
|
||||
fb.setupCharacterMap({ord("f"): "f", ord("$"): "dollar"})
|
||||
fb.setupNameTable({"familyName": "TestFeatureVars", "styleName": "Regular"})
|
||||
fb.setupPost()
|
||||
fb.setupFvar(axes=[("wght", 100, 400, 900, "Weight")], instances=[])
|
||||
fb.addOpenTypeFeatures("""\
|
||||
feature dlig {
|
||||
sub f f by f_f;
|
||||
} dlig;
|
||||
""")
|
||||
fb.addFeatureVariations(
|
||||
[([{"wght": (0.20886, 1.0)}], {"dollar": "dollar.rvrn"})],
|
||||
featureTag="rvrn"
|
||||
)
|
||||
buf = io.BytesIO()
|
||||
fb.save(buf)
|
||||
buf.seek(0)
|
||||
|
||||
font = TTFont(buf)
|
||||
|
||||
options = subset.Options()
|
||||
subsetter = subset.Subsetter(options)
|
||||
subsetter.populate(unicodes=[ord("f"), ord("$")])
|
||||
subsetter.subset(font)
|
||||
|
||||
featureTags = {
|
||||
r.FeatureTag for r in font["GSUB"].table.FeatureList.FeatureRecord
|
||||
}
|
||||
# 'dlig' is discretionary so it is dropped by default
|
||||
assert "dlig" not in featureTags
|
||||
assert "f_f" not in font.getGlyphOrder()
|
||||
# 'rvrn' is required so it is kept by default
|
||||
assert "rvrn" in featureTags
|
||||
assert "dollar.rvrn" in font.getGlyphOrder()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(unittest.main())
|
||||
|
Loading…
x
Reference in New Issue
Block a user