Skip to content

Commit

Permalink
Merge pull request #765 from googlefonts/better-classic-components
Browse files Browse the repository at this point in the history
[designspace] Only write classic components if _all_ components in _all_ layers are classic
  • Loading branch information
justvanrossum authored Aug 31, 2023
2 parents f1cee17 + 05855ef commit 65da81a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/fontra/backends/designspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ async def putGlyph(self, glyphName, glyph, unicodes):

revLayerNameMapping = reverseSparseDict(layerNameMapping)

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

modTimes = set()
usedLayers = set()
for layerName, layer in glyph.layers.items():
Expand All @@ -297,7 +305,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,21 +750,25 @@ 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:
# It's a variable component
if component.location or forceVariableComponents:
# Store as a variable component
varCoDict = {"base": component.name, "location": component.location}
if component.transformation != DecomposedTransform():
varCoDict["transformation"] = asdict(component.transformation)
variableComponents.append(varCoDict)
else:
# It's a regular component
# Store as a regular component
pen.addComponent(
component.name,
cleanupTransform(component.transformation.toTransform()),
Expand Down

0 comments on commit 65da81a

Please sign in to comment.