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] Fix non default local source UFO choice when reading #774

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
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
28 changes: 21 additions & 7 deletions src/fontra/backends/designspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async def getGlyph(self, glyphName):
localDS = ufoGlyph.lib.get(GLYPH_DESIGNSPACE_LIB_KEY)
if localDS is not None:
axes, localSources = self._unpackLocalDesignSpace(
localDS, ufoLayer.path, ufoLayer.name
localDS, ufoLayer.name
)
sources.extend(localSources)
sourceNameMapping = ufoGlyph.lib.get(SOURCE_NAME_MAPPING_LIB_KEY, {})
Expand All @@ -247,7 +247,7 @@ async def getGlyph(self, glyphName):

return VariableGlyph(glyphName, axes=axes, sources=sources, layers=layers)

def _unpackLocalDesignSpace(self, dsDict, ufoPath, defaultLayerName):
def _unpackLocalDesignSpace(self, dsDict, defaultLayerName):
axes = [
LocalAxis(
name=axis["name"],
Expand All @@ -257,14 +257,26 @@ def _unpackLocalDesignSpace(self, dsDict, ufoPath, defaultLayerName):
)
for axis in dsDict["axes"]
]
localAxisNames = {axis.name for axis in axes}

sources = []
for source in dsDict.get("sources", ()):
ufoLayerName = source.get("layername", defaultLayerName)
sourceName = source.get(
"name",
ufoLayerName if ufoLayerName != defaultLayerName else "<default>",
)

sourceLocation = {**self.defaultLocation, **source["location"]}
globalLocation = getGlobalPortionOfLocation(sourceLocation, localAxisNames)
dsSource = self.dsSources.findItem(
locationTuple=tuplifyLocation(globalLocation)
)
assert dsSource is not None
ufoPath = dsSource.layer.path

ufoLayer = self.ufoLayers.findItem(path=ufoPath, name=ufoLayerName)
assert ufoLayer is not None
sources.append(
Source(
name=sourceName,
Expand Down Expand Up @@ -373,11 +385,7 @@ async def putGlyph(self, glyphName, glyph, unicodes):

def _prepareUFOSourceLayer(self, source, localAxisNames, revLayerNameMapping):
sourceLocation = {**self.defaultLocation, **source.location}
globalLocation = {
name: value
for name, value in sourceLocation.items()
if name not in localAxisNames
}
globalLocation = getGlobalPortionOfLocation(sourceLocation, localAxisNames)

dsSource = self.dsSources.findItem(
locationTuple=tuplifyLocation(globalLocation)
Expand Down Expand Up @@ -928,3 +936,9 @@ def glyphHasVariableComponents(glyph):
for layer in glyph.layers.values()
for compo in layer.glyph.components
)


def getGlobalPortionOfLocation(location, localAxisNames):
return {
name: value for name, value in location.items() if name not in localAxisNames
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>varcotest2</key>
<string>varcotest2.glif</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version='1.0' encoding='UTF-8'?>
<glyph name="varcotest2" format="2">
<advance width="500"/>
<unicode hex="E001"/>
<outline>
<contour>
<point x="70" y="278" type="line"/>
<point x="452" y="278" type="line"/>
<point x="522" y="278" type="line"/>
<point x="522" y="380" type="line"/>
<point x="522" y="664" type="line"/>
<point x="204" y="664" type="line"/>
<point x="204" y="588" type="line"/>
<point x="70" y="588" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
<string>background</string>
<string>glyphs.background</string>
</array>
<array>
<string>weight=850,flip=100</string>
<string>glyphs.weight=850,flip=100</string>
</array>
</array>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,24 @@
<integer>100</integer>
</dict>
</dict>
<dict>
<key>layername</key>
<string>weight=850,flip=100</string>
<key>location</key>
<dict>
<key>flip</key>
<integer>100</integer>
<key>weight</key>
<integer>850</integer>
</dict>
</dict>
</array>
</dict>
<key>xyz.fontra.layer-names</key>
<dict>
<key>MutatorSansBoldCondensed/weight=850,flip=100</key>
<string>weight=850,flip=100</string>
</dict>
</dict>
</lib>
</glyph>
38 changes: 38 additions & 0 deletions test-py/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@
"location": {"flip": 0, "flop": 100},
"name": "varco_flop",
},
{
"name": "weight=850,flip=100",
"layerName": "weight=850,flip=100",
"location": {"flip": 100, "weight": 850},
"inactive": False,
"customData": {},
},
],
"layers": {
"MutatorSansLightCondensed/foreground": {
Expand Down Expand Up @@ -529,6 +536,37 @@
"xAdvance": 500,
},
},
"weight=850,flip=100": {
"glyph": {
"path": {
"coordinates": [
70,
278,
452,
278,
522,
278,
522,
380,
522,
664,
204,
664,
204,
588,
70,
588,
],
"pointTypes": [0, 0, 0, 0, 0, 0, 0, 0],
"contourInfo": [{"endPoint": 7, "isClosed": True}],
},
"components": [],
"xAdvance": 500,
"yAdvance": None,
"verticalOrigin": None,
},
"customData": {},
},
},
},
),
Expand Down