Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[designspace] Only write classic components if _all_ components in _all_ layers are classic #765

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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