Skip to content

Commit

Permalink
Only write classic components if _all_ components in _all_ layers are…
Browse files Browse the repository at this point in the history
… classic
  • Loading branch information
justvanrossum committed Aug 31, 2023
1 parent f1cee17 commit 689daf7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/fontra/backends/designspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ async def putGlyph(self, glyphName, glyph, unicodes):

revLayerNameMapping = reverseSparseDict(layerNameMapping)

haveVariableComponents = any(
any(
compo.location
or compo.transformation.tCenterX
or compo.transformation.tCenterY
for compo in layer.glyph.components
)
for layer in glyph.layers.values()
)

modTimes = set()
usedLayers = set()
for layerName, layer in glyph.layers.items():
Expand All @@ -297,7 +307,9 @@ async def putGlyph(self, glyphName, glyph, unicodes):
else:
layerGlyph = readGlyphOrCreate(glyphSet, glyphName, unicodes)

drawPointsFunc = populateUFOLayerGlyph(layerGlyph, layer.glyph)
drawPointsFunc = populateUFOLayerGlyph(
layerGlyph, layer.glyph, haveVariableComponents
)
glyphSet.writeGlyph(glyphName, layerGlyph, drawPointsFunc=drawPointsFunc)
if writeGlyphSetContents:
# FIXME: this is inefficient if we write many glyphs
Expand Down Expand Up @@ -740,14 +752,18 @@ def readGlyphOrCreate(
return layerGlyph


def populateUFOLayerGlyph(layerGlyph: UFOGlyph, staticGlyph: StaticGlyph) -> None:
def populateUFOLayerGlyph(
layerGlyph: UFOGlyph,
staticGlyph: StaticGlyph,
forceVariableComponents: bool = False,
) -> None:
pen = RecordingPointPen()
layerGlyph.width = staticGlyph.xAdvance
layerGlyph.height = staticGlyph.yAdvance
staticGlyph.path.drawPoints(pen)
variableComponents = []
for component in staticGlyph.components:
if component.location:
if component.location or forceVariableComponents:
# It's a variable component
varCoDict = {"base": component.name, "location": component.location}
if component.transformation != DecomposedTransform():
Expand Down

0 comments on commit 689daf7

Please sign in to comment.