tooling: fixes a performance issue with componentReferences

This commit is contained in:
Rasmus Andersson 2021-03-24 13:26:53 -07:00
parent 079ce6cd54
commit 4c9d8fc1c0

View file

@ -29,9 +29,10 @@ class FontBuilder:
# decompose some glyphs # decompose some glyphs
glyphNamesToDecompose = set() glyphNamesToDecompose = set()
componentReferences = set(ufo.componentReferences)
for g in ufo: for g in ufo:
directives = findGlyphDirectives(g.note) directives = findGlyphDirectives(g.note)
if self._shouldDecomposeGlyph(ufo, g, directives): if self._shouldDecomposeGlyph(g, directives, componentReferences):
glyphNamesToDecompose.add(g.name) glyphNamesToDecompose.add(g.name)
self._decompose([ufo], glyphNamesToDecompose) self._decompose([ufo], glyphNamesToDecompose)
@ -106,12 +107,12 @@ class FontBuilder:
log.info('Decomposing %d glyphs', len(glyphNamesToDecompose)) log.info('Decomposing %d glyphs', len(glyphNamesToDecompose))
decomposeGlyphs(ufos, glyphNamesToDecompose) decomposeGlyphs(ufos, glyphNamesToDecompose)
def _shouldDecomposeGlyph(self, ufo, g, directives): def _shouldDecomposeGlyph(self, g, directives, componentReferences):
# Note: Used for building both static and variable fonts # Note: Used for building both static and variable fonts
if 'decompose' in directives: if 'decompose' in directives:
return True return True
if g.components: if g.components:
if g.name in ufo.componentReferences: if g.name in componentReferences:
# This means that the glyph... # This means that the glyph...
# a) has component instances and # a) has component instances and
# b) is itself a component used by other glyphs as instances. # b) is itself a component used by other glyphs as instances.
@ -157,9 +158,10 @@ class FontBuilder:
# Note: ufo is of type defcon.objects.font.Font # Note: ufo is of type defcon.objects.font.Font
# update font version # update font version
updateFontVersion(ufo, dummy=False, isVF=True) updateFontVersion(ufo, dummy=False, isVF=True)
componentReferences = set(ufo.componentReferences)
for g in ufo: for g in ufo:
directives = findGlyphDirectives(g.note) directives = findGlyphDirectives(g.note)
if self._shouldDecomposeGlyph(ufo, g, directives): if self._shouldDecomposeGlyph(g, directives, componentReferences):
glyphNamesToDecompose.add(g.name) glyphNamesToDecompose.add(g.name)
if 'removeoverlap' in directives: if 'removeoverlap' in directives:
if g.components and len(g.components) > 0: if g.components and len(g.components) > 0: