[VARC] Update subsetting

This commit is contained in:
Behdad Esfahbod 2023-12-20 12:12:42 -07:00
parent 735859f929
commit a7ca67ada8
4 changed files with 52 additions and 42 deletions

View File

@ -2633,58 +2633,68 @@ def closure_glyphs(self, s):
@_add_method(ttLib.getTableClass("VARC")) @_add_method(ttLib.getTableClass("VARC"))
def subset_glyphs(self, s): def subset_glyphs(self, s):
indices = self.table.Coverage.subset(s.glyphs) indices = self.table.Coverage.subset(s.glyphs)
# TODO Subset MultiVarStore self.table.VarCompositeGlyphs.VarCompositeGlyph = _list_subset(
self.table.VarCompositeGlyphs.glyphs = _list_subset( self.table.VarCompositeGlyphs.VarCompositeGlyph, indices
self.table.VarCompositeGlyphs.glyphs, indices
) )
return bool(self.table.VarCompositeGlyphs.glyphs) return bool(self.table.VarCompositeGlyphs.VarCompositeGlyph)
@_add_method(ttLib.getTableClass("VARC")) @_add_method(ttLib.getTableClass("VARC"))
def closure_glyphs(self, s): def closure_glyphs(self, s):
if self.table.VarCompositeGlyphs: if self.table.VarCompositeGlyphs is None:
allGlyphs = { return
glyphName: glyph
for glyphName, glyph in zip(
self.table.Coverage.glyphs, self.table.VarCompositeGlyphs.glyphs
)
}
glyphs = s.glyphs allGlyphs = {
new = set(s.glyphs) glyphName: glyph
while new: for glyphName, glyph in zip(
oldNew = new self.table.Coverage.glyphs, self.table.VarCompositeGlyphs.VarCompositeGlyph
new = set() )
for glyphName in oldNew: }
glyph = allGlyphs.get(glyphName)
if glyph is None: glyphs = s.glyphs
continue covered = set()
for comp in glyph.components: new = set(glyphs)
name = comp.glyphName while new:
if name not in glyphs: oldNew = new
glyphs.add(name) new = set()
new.add(name) 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")) @_add_method(ttLib.getTableClass("VARC"))
def prune_post_subset(self, font, options): def prune_post_subset(self, font, options):
table = self.table table = self.table
if not hasattr(table, "MultiVarStore"):
return True
store = table.MultiVarStore 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() axisIndicesList = table.AxisIndicesList.Item
if axisIndicesList is not None:
# Collect. usedIndices = set()
table.collect_varidxes(usedVarIdxes) for glyph in table.VarCompositeGlyphs.VarCompositeGlyph:
for comp in glyph.components:
# Subset. if comp.axisIndicesIndex is not None:
varidx_map = store.subset_varidxes(usedVarIdxes) usedIndices.add(comp.axisIndicesIndex)
usedIndices = sorted(usedIndices)
# Map. table.AxisIndicesList.Item = _list_subset(axisIndicesList, usedIndices)
table.remap_varidxes(varidx_map) 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 return True

View File

@ -236,16 +236,16 @@ ot.MultiVarStore.get_supports = MultiVarStore_get_supports
def VARC_collect_varidxes(self, varidxes): def VARC_collect_varidxes(self, varidxes):
for glyph in self.VarCompositeGlyphs.glyphs: for glyph in self.VarCompositeGlyphs.VarCompositeGlyph:
for component in glyph.components: for component in glyph.components:
varidxes.add(component.locationVarIndex) varidxes.add(component.axisValuesVarIndex)
varidxes.add(component.transformVarIndex) varidxes.add(component.transformVarIndex)
def VARC_remap_varidxes(self, varidxes_map): def VARC_remap_varidxes(self, varidxes_map):
for glyph in self.VarCompositeGlyphs.glyphs: for glyph in self.VarCompositeGlyphs.VarCompositeGlyph:
for component in glyph.components: for component in glyph.components:
component.locationVarIndex = varidxes_map[component.locationVarIndex] component.axisValuesVarIndex = varidxes_map[component.axisValuesVarIndex]
component.transformVarIndex = varidxes_map[component.transformVarIndex] component.transformVarIndex = varidxes_map[component.transformVarIndex]

Binary file not shown.

Binary file not shown.