Skip to content

Commit

Permalink
Fix assumption that source 0 is the default source
Browse files Browse the repository at this point in the history
  • Loading branch information
justvanrossum committed Apr 22, 2024
1 parent b98cdb1 commit b4a7d7d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/fontra_compile/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ class ComponentInfo:
baseAxisTags: dict
isVariableComponent: bool = False
flags: int = 0
defaultSourceIndex: int = 0

def addTransformationToComponent(self, compo, storeBuilder):
compo.transform = DecomposedTransform(
**{k: v[0] for k, v in self.transform.items()}
**{k: v[self.defaultSourceIndex] for k, v in self.transform.items()}
)

if not self.flags & VarComponentFlags.TRANSFORM_HAS_VARIATION:
Expand Down Expand Up @@ -99,6 +100,7 @@ def addLocationToComponent(self, compo, axisIndicesMapping, axisTags, storeBuild
return

assert self.location

location = sorted(mapDictKeys(self.location, self.baseAxisTags).items())
axisIndices = tuple(axisTags.index(k) for k, v in location)
axisIndicesIndex = axisIndicesMapping.get(axisIndices)
Expand All @@ -107,7 +109,7 @@ def addLocationToComponent(self, compo, axisIndicesMapping, axisTags, storeBuild
axisIndicesMapping[axisIndices] = axisIndicesIndex

compo.axisIndicesIndex = axisIndicesIndex
compo.axisValues = [v[0] for k, v in location]
compo.axisValues = [v[self.defaultSourceIndex] for k, v in location]

if self.flags & VarComponentFlags.AXIS_VALUES_HAVE_VARIATION:
locationValues = [[fl2fi(v, 14) for v in values] for k, values in location]
Expand Down Expand Up @@ -221,7 +223,8 @@ async def prepareOneGlyph(self, glyphName: str) -> GlyphInfo:
defaultGlyph.path.drawPoints(ttGlyphPen)
ttGlyph = ttGlyphPen.glyph()

componentInfo = await self.collectComponentInfo(glyph)
defaultSourceIndex = model.reverseMapping[0]
componentInfo = await self.collectComponentInfo(glyph, defaultSourceIndex)

return GlyphInfo(
glyph=ttGlyph,
Expand All @@ -232,7 +235,9 @@ async def prepareOneGlyph(self, glyphName: str) -> GlyphInfo:
model=model,
)

async def collectComponentInfo(self, glyph: VariableGlyph) -> list[ComponentInfo]:
async def collectComponentInfo(
self, glyph: VariableGlyph, defaultSourceIndex: int
) -> list[ComponentInfo]:
glyphSources = filterActiveSources(glyph.sources)
sourceGlyphs = [glyph.layers[source.layerName].glyph for source in glyphSources]

Expand All @@ -253,6 +258,7 @@ async def collectComponentInfo(self, glyph: VariableGlyph) -> list[ComponentInfo
transform={attrName: [] for attrName in VAR_TRANSFORM_MAPPING},
location={axisName: [] for axisName in axisNames},
**await self.getComponentBaseInfo(compo.name),
defaultSourceIndex=defaultSourceIndex,
)
for compo, axisNames in zip(
firstSourceGlyph.components, allComponentAxisNames
Expand Down

0 comments on commit b4a7d7d

Please sign in to comment.