diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index 1e9e13148..2b7aafa66 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -2633,58 +2633,68 @@ def closure_glyphs(self, s): @_add_method(ttLib.getTableClass("VARC")) def subset_glyphs(self, s): indices = self.table.Coverage.subset(s.glyphs) - # TODO Subset MultiVarStore - self.table.VarCompositeGlyphs.glyphs = _list_subset( - self.table.VarCompositeGlyphs.glyphs, indices + self.table.VarCompositeGlyphs.VarCompositeGlyph = _list_subset( + self.table.VarCompositeGlyphs.VarCompositeGlyph, indices ) - return bool(self.table.VarCompositeGlyphs.glyphs) + return bool(self.table.VarCompositeGlyphs.VarCompositeGlyph) @_add_method(ttLib.getTableClass("VARC")) def closure_glyphs(self, s): - if self.table.VarCompositeGlyphs: - allGlyphs = { - glyphName: glyph - for glyphName, glyph in zip( - self.table.Coverage.glyphs, self.table.VarCompositeGlyphs.glyphs - ) - } + if self.table.VarCompositeGlyphs is None: + return - glyphs = s.glyphs - new = set(s.glyphs) - while new: - oldNew = new - new = set() - for glyphName in oldNew: - glyph = allGlyphs.get(glyphName) - if glyph is None: - continue - for comp in glyph.components: - name = comp.glyphName - if name not in glyphs: - glyphs.add(name) - new.add(name) + allGlyphs = { + glyphName: glyph + for glyphName, glyph in zip( + self.table.Coverage.glyphs, self.table.VarCompositeGlyphs.VarCompositeGlyph + ) + } + + glyphs = s.glyphs + covered = set() + new = set(glyphs) + while new: + oldNew = new + new = set() + for glyphName in oldNew: + if glyphName in covered: + continue + glyph = allGlyphs.get(glyphName) + if glyph is None: + continue + for comp in glyph.components: + name = comp.glyphName + glyphs.add(name) + if name not in covered: + new.add(name) @_add_method(ttLib.getTableClass("VARC")) def prune_post_subset(self, font, options): table = self.table - if not hasattr(table, "MultiVarStore"): - return True - store = table.MultiVarStore + if store is not None: + usedVarIdxes = set() + table.collect_varidxes(usedVarIdxes) + varidx_map = store.subset_varidxes(usedVarIdxes) + table.remap_varidxes(varidx_map) - usedVarIdxes = set() - - # Collect. - table.collect_varidxes(usedVarIdxes) - - # Subset. - varidx_map = store.subset_varidxes(usedVarIdxes) - - # Map. - table.remap_varidxes(varidx_map) + axisIndicesList = table.AxisIndicesList.Item + if axisIndicesList is not None: + usedIndices = set() + for glyph in table.VarCompositeGlyphs.VarCompositeGlyph: + for comp in glyph.components: + if comp.axisIndicesIndex is not None: + usedIndices.add(comp.axisIndicesIndex) + usedIndices = sorted(usedIndices) + table.AxisIndicesList.Item = _list_subset(axisIndicesList, usedIndices) + mapping = {old: new for new, old in enumerate(usedIndices)} + for glyph in table.VarCompositeGlyphs.VarCompositeGlyph: + for comp in glyph.components: + if comp.axisIndicesIndex is not None: + comp.axisIndicesIndex = mapping[comp.axisIndicesIndex] return True diff --git a/Lib/fontTools/varLib/multiVarStore.py b/Lib/fontTools/varLib/multiVarStore.py index c29899746..f24a6e6f7 100644 --- a/Lib/fontTools/varLib/multiVarStore.py +++ b/Lib/fontTools/varLib/multiVarStore.py @@ -236,16 +236,16 @@ ot.MultiVarStore.get_supports = MultiVarStore_get_supports def VARC_collect_varidxes(self, varidxes): - for glyph in self.VarCompositeGlyphs.glyphs: + for glyph in self.VarCompositeGlyphs.VarCompositeGlyph: for component in glyph.components: - varidxes.add(component.locationVarIndex) + varidxes.add(component.axisValuesVarIndex) varidxes.add(component.transformVarIndex) def VARC_remap_varidxes(self, varidxes_map): - for glyph in self.VarCompositeGlyphs.glyphs: + for glyph in self.VarCompositeGlyphs.VarCompositeGlyph: for component in glyph.components: - component.locationVarIndex = varidxes_map[component.locationVarIndex] + component.axisValuesVarIndex = varidxes_map[component.axisValuesVarIndex] component.transformVarIndex = varidxes_map[component.transformVarIndex] diff --git a/Tests/ttLib/data/varc-6868.ttf b/Tests/ttLib/data/varc-6868.ttf index 71d94e042..62e071c17 100644 Binary files a/Tests/ttLib/data/varc-6868.ttf and b/Tests/ttLib/data/varc-6868.ttf differ diff --git a/Tests/ttLib/data/varc-ac00-ac01.ttf b/Tests/ttLib/data/varc-ac00-ac01.ttf index cfe10a044..c011395a8 100644 Binary files a/Tests/ttLib/data/varc-ac00-ac01.ttf and b/Tests/ttLib/data/varc-ac00-ac01.ttf differ