From 689daf78e95c53452a702025b74593ab81172d29 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Thu, 31 Aug 2023 16:15:32 +0200 Subject: [PATCH 1/3] Only write classic components if _all_ components in _all_ layers are classic --- src/fontra/backends/designspace.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/fontra/backends/designspace.py b/src/fontra/backends/designspace.py index 943f84302..a66f92f20 100644 --- a/src/fontra/backends/designspace.py +++ b/src/fontra/backends/designspace.py @@ -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(): @@ -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 @@ -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(): From b93a9cb6b129f7775b42876c4b3a3592cafcb64b Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Thu, 31 Aug 2023 16:23:52 +0200 Subject: [PATCH 2/3] Flatten loop over all components --- src/fontra/backends/designspace.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/fontra/backends/designspace.py b/src/fontra/backends/designspace.py index a66f92f20..02754a347 100644 --- a/src/fontra/backends/designspace.py +++ b/src/fontra/backends/designspace.py @@ -282,13 +282,11 @@ 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 - ) + compo.location + or compo.transformation.tCenterX + or compo.transformation.tCenterY for layer in glyph.layers.values() + for compo in layer.glyph.components ) modTimes = set() From 05855ef6bf1c140c067581c262de9978fbe7d042 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Thu, 31 Aug 2023 16:25:29 +0200 Subject: [PATCH 3/3] Adjust comments --- src/fontra/backends/designspace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fontra/backends/designspace.py b/src/fontra/backends/designspace.py index 02754a347..b8d0f2927 100644 --- a/src/fontra/backends/designspace.py +++ b/src/fontra/backends/designspace.py @@ -762,13 +762,13 @@ def populateUFOLayerGlyph( variableComponents = [] for component in staticGlyph.components: if component.location or forceVariableComponents: - # It's a variable component + # 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()),