Skip to content

Commit

Permalink
Fix issue with fontra source name
Browse files Browse the repository at this point in the history
  • Loading branch information
ollimeier committed Feb 4, 2025
1 parent b00dd76 commit 2f99a3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/fontra_glyphs/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
convertMatchesToTuples,
getAssociatedMasterId,
getLocationFromSources,
getSourceNameWithLayerName,
matchTreeFont,
)

Expand Down Expand Up @@ -289,7 +290,9 @@ async def getGlyph(self, glyphName: str) -> VariableGlyph | None:
braceLocation = self._getBraceLayerLocation(gsLayer)
smartLocation = self._getSmartLocation(gsLayer, localAxesByName)
masterName = self.gsFont.masters[gsLayer.associatedMasterId].name
if braceLocation or smartLocation:
if gsLayer.userData["xyz.fontra.source-name"]:
sourceName = gsLayer.userData["xyz.fontra.source-name"]
elif braceLocation or smartLocation:
sourceName = f"{masterName} / {gsLayer.name}"
else:
sourceName = gsLayer.name or masterName
Expand Down Expand Up @@ -777,6 +780,9 @@ def variableGlyphToGSGlyph(variableGlyph, gsGlyph):
gsLayer.layerId = layerName
gsLayer.isSpecialLayer = True

sourceName = getSourceNameWithLayerName(variableGlyph.sources, layerName)
gsLayer.userData["xyz.fontra.source-name"] = sourceName

location = getLocationFromSources(variableGlyph.sources, layerName)
gsLocation = [
location[axis.name.lower()]
Expand Down
6 changes: 6 additions & 0 deletions src/fontra_glyphs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ def getLocationFromSources(sources, layerName):
return {k.lower(): v for k, v in s.location.items()}


def getSourceNameWithLayerName(sources, layerName):
for source in sources:
if source.layerName == layerName:
return source.name


def getAssociatedMasterId(gsFont, gsLocation):
# Best guess for associatedMasterId
closestMasterID = gsFont.masters[0].id # default first master.
Expand Down

0 comments on commit 2f99a3a

Please sign in to comment.