From 4c9d8fc1c0407ed27f2a10bc6c8302321662820e Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Wed, 24 Mar 2021 13:26:53 -0700 Subject: tooling: fixes a performance issue with componentReferences --- misc/fontbuildlib/builder.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'misc/fontbuildlib') diff --git a/misc/fontbuildlib/builder.py b/misc/fontbuildlib/builder.py index 2989734da..b0510ceb9 100644 --- a/misc/fontbuildlib/builder.py +++ b/misc/fontbuildlib/builder.py @@ -29,9 +29,10 @@ class FontBuilder: # decompose some glyphs glyphNamesToDecompose = set() + componentReferences = set(ufo.componentReferences) for g in ufo: directives = findGlyphDirectives(g.note) - if self._shouldDecomposeGlyph(ufo, g, directives): + if self._shouldDecomposeGlyph(g, directives, componentReferences): glyphNamesToDecompose.add(g.name) self._decompose([ufo], glyphNamesToDecompose) @@ -106,12 +107,12 @@ class FontBuilder: log.info('Decomposing %d glyphs', len(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 if 'decompose' in directives: return True if g.components: - if g.name in ufo.componentReferences: + if g.name in componentReferences: # This means that the glyph... # a) has component instances and # 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 # update font version updateFontVersion(ufo, dummy=False, isVF=True) + componentReferences = set(ufo.componentReferences) for g in ufo: directives = findGlyphDirectives(g.note) - if self._shouldDecomposeGlyph(ufo, g, directives): + if self._shouldDecomposeGlyph(g, directives, componentReferences): glyphNamesToDecompose.add(g.name) if 'removeoverlap' in directives: if g.components and len(g.components) > 0: -- cgit v1.2.3