Skip to content

Commit

Permalink
Slight refactor: make _newUFOLayer also create the wrapper object
Browse files Browse the repository at this point in the history
  • Loading branch information
justvanrossum committed Sep 3, 2023
1 parent a0d35df commit 6fa4901
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/fontra/backends/designspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,8 @@ def _prepareUFOLayer(self, source, localAxisNames, revLayerNameMapping):

if ufoLayer is None:
ufoPath = dsSource.layer.path
ufoLayerName = self._newUFOLayer(ufoPath, source.layerName)
ufoLayer = UFOLayer(
manager=self.ufoManager,
path=ufoPath,
name=ufoLayerName,
)
self.ufoLayers.append(ufoLayer)
ufoLayer = self._newUFOLayer(ufoPath, source.layerName)
ufoLayerName = ufoLayer.name
else:
ufoLayerName = ufoLayer.name
normalizedSourceName = source.name
Expand Down Expand Up @@ -442,6 +437,13 @@ def _createDSSource(self, source, globalLocation):
reader.writeLayerContents()
ufoLayerName = reader.getDefaultLayerName()
assert os.path.isdir(ufoPath)

ufoLayer = UFOLayer(
manager=manager,
path=ufoPath,
name=ufoLayerName,
)
self.ufoLayers.append(ufoLayer)
else:
# Create a new layer in the appropriate existing UFO
atPole = {**self.defaultLocation, **atPole}
Expand All @@ -452,7 +454,8 @@ def _createDSSource(self, source, globalLocation):
poleDSSource = self.defaultDSSource
assert poleDSSource is not None
ufoPath = poleDSSource.layer.path
ufoLayerName = self._newUFOLayer(poleDSSource.layer.path, source.layerName)
ufoLayer = self._newUFOLayer(poleDSSource.layer.path, source.layerName)
ufoLayerName = ufoLayer.name

self.dsDoc.addSourceDescriptor(
styleName=source.name,
Expand All @@ -462,30 +465,31 @@ def _createDSSource(self, source, globalLocation):
)
self.dsDoc.write(self.dsDoc.path)

ufoLayer = UFOLayer(
manager=manager,
path=ufoPath,
name=ufoLayerName,
)

dsSource = DSSource(
name=source.name,
layer=ufoLayer,
location=globalLocation,
)
self.dsSources.append(dsSource)
self.ufoLayers.append(ufoLayer)

return dsSource

def _newUFOLayer(self, path, suggestedLayerName):
reader = self.ufoManager.getReader(path)
def _newUFOLayer(self, ufoPath, suggestedLayerName):
reader = self.ufoManager.getReader(ufoPath)
makeUniqueName = uniqueNameMaker(reader.getLayerNames())
ufoLayerName = makeUniqueName(suggestedLayerName)
# Create the new UFO layer now
_ = self.ufoManager.getGlyphSet(path, ufoLayerName)
_ = self.ufoManager.getGlyphSet(ufoPath, ufoLayerName)
reader.writeLayerContents()
return ufoLayerName

ufoLayer = UFOLayer(
manager=self.ufoManager,
path=ufoPath,
name=ufoLayerName,
)
self.ufoLayers.append(ufoLayer)

return ufoLayer

async def getGlobalAxes(self):
return self.axes
Expand Down

0 comments on commit 6fa4901

Please sign in to comment.