Skip to content

Commit 8852905

Browse files
Merge pull request #120 from googlefonts/fix-layer-name-bug
Fix long standing layer name bug
2 parents da40da8 + 8ded7f5 commit 8852905

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/fontra_rcjk/base.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def buildVariableGlyphFromLayerGlyphs(layerGlyphs):
128128
if defaultComponents:
129129
layers["foreground"].glyph.components += defaultComponents
130130

131-
fontraLayerNameMapping = defaultGlyph.lib.get("fontra.layerNames", {})
131+
fontraLayerNameMapping = dict(defaultGlyph.lib.get("fontra.layerNames", {}))
132132

133133
dcNames = [c.name for c in defaultComponents]
134134

@@ -171,6 +171,10 @@ def buildVariableGlyphFromLayerGlyphs(layerGlyphs):
171171
# We'll delete it to make sure we don't reuse its data
172172
layers.pop(layerName, None)
173173

174+
fontraLayerNameMapping[layerName] = varDict.get(
175+
"fontraLayerName"
176+
) or fontraLayerNameMapping.get(layerName, layerName)
177+
174178
syntheticLayerNames.add(layerName)
175179

176180
xAdvance = defaultGlyph.width
@@ -314,11 +318,14 @@ def buildLayerGlyphsFromVariableGlyph(
314318

315319
if layerGlyph.hasOutlineOrClassicComponents():
316320
safeLayerName = makeSafeLayerName(source.layerName)
321+
varDict["layerName"] = safeLayerName
317322
if safeLayerName != source.layerName:
318323
fontraLayerNameMapping[safeLayerName] = source.layerName
319-
varDict["layerName"] = safeLayerName
324+
varDict["fontraLayerName"] = source.layerName
320325
else:
321326
varDict["layerName"] = "" # Mimic RoboCJK
327+
if source.layerName != source.name:
328+
varDict["fontraLayerName"] = source.layerName
322329
# This is a "virtual" layer: all info will go to defaultGlyph.lib,
323330
# and no "true" layer will be written
324331
del layerGlyphs[source.layerName]
@@ -331,14 +338,14 @@ def buildLayerGlyphsFromVariableGlyph(
331338
defaultGlyph.lib.pop("robocjk.variationGlyphs", None)
332339

333340
if fontraLayerNameMapping:
334-
defaultGlyph.lib["fontra.layerNames"] = fontraLayerNameMapping
335341
rcjkLayerNameMapping = {v: k for k, v in fontraLayerNameMapping.items()}
336342
layerGlyphs = {
337343
rcjkLayerNameMapping.get(layerName, layerName): layerGlyph
338344
for layerName, layerGlyph in layerGlyphs.items()
339345
}
340-
else:
341-
defaultGlyph.lib.pop("fontra.layerNames", None)
346+
347+
# Get rid of legacy data
348+
defaultGlyph.lib.pop("fontra.layerNames", None)
342349

343350
return layerGlyphs
344351

tests/test_font.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,6 @@ async def test_write_roundtrip(writableTestFont, glyphName):
741741
" </outline>",
742742
" <lib>",
743743
" <dict>",
744-
" <key>fontra.layerNames</key>",
745-
" <dict>",
746-
" <key>boooo_oooold.75e003ed2da2</key>",
747-
" <string>boooo/oooold</string>",
748-
" <key>boooo_ooooldboooo_ooooldboooo_ooooldb.360a3fdd78e6</key>",
749-
" <string>boooo/ooooldboooo/ooooldboooo/ooooldboooo/ooooldboooo/oooold</string>",
750-
" </dict>",
751744
" <key>robocjk.status</key>",
752745
" <integer>0</integer>",
753746
" <key>robocjk.variationGlyphs</key>",
@@ -768,6 +761,8 @@ async def test_write_roundtrip(writableTestFont, glyphName):
768761
" <integer>0</integer>",
769762
" </dict>",
770763
" <dict>",
764+
" <key>fontraLayerName</key>",
765+
" <string>boooo/oooold</string>",
771766
" <key>layerName</key>",
772767
" <string>boooo_oooold.75e003ed2da2</string>",
773768
" <key>location</key>",
@@ -780,6 +775,8 @@ async def test_write_roundtrip(writableTestFont, glyphName):
780775
" <integer>0</integer>",
781776
" </dict>",
782777
" <dict>",
778+
" <key>fontraLayerName</key>",
779+
" <string>boooo/ooooldboooo/ooooldboooo/ooooldboooo/ooooldboooo/oooold</string>",
783780
" <key>layerName</key>",
784781
" <string>boooo_ooooldboooo_ooooldboooo_ooooldb.360a3fdd78e6</string>",
785782
" <key>location</key>",

0 commit comments

Comments
 (0)