diff --git a/src/fontra_compile/builder.py b/src/fontra_compile/builder.py index a8598a7..5b35e80 100644 --- a/src/fontra_compile/builder.py +++ b/src/fontra_compile/builder.py @@ -46,6 +46,7 @@ async def setup(self): self.defaultLocation = {k: v[1] for k, v in self.globalAxisDict.items()} self.cachedSourceGlyphs = {} + self.cachedComponentBaseInfo = {} self.glyphs = {} self.cmap = {} @@ -231,7 +232,7 @@ async def collectComponentInfo(self, glyph): attrName: [] for attrName in VAR_COMPONENT_TRANSFORM_MAPPING }, location={axisName: [] for axisName in axisNames}, - **await self.setupComponentBaseInfo(compo.name), + **await self.getComponentBaseInfo(compo.name), ) for compo, axisNames in zip( firstSourceGlyph.components, allComponentAxisNames @@ -297,6 +298,13 @@ async def collectComponentInfo(self, glyph): return components + async def getComponentBaseInfo(self, baseGlyphName): + baseInfo = self.cachedComponentBaseInfo.get(baseGlyphName) + if baseInfo is None: + baseInfo = await self.setupComponentBaseInfo(baseGlyphName) + self.cachedComponentBaseInfo[baseGlyphName] = baseInfo + return baseInfo + async def setupComponentBaseInfo(self, baseGlyphName): # Ideally we need the full "made of" graph, so we can normalize # nested var composites, but then again, our local axis name -> fvar tag name