Skip to content

Commit

Permalink
Work around layername issues on case-insensitive file systems
Browse files Browse the repository at this point in the history
  • Loading branch information
justvanrossum committed Nov 28, 2023
1 parent 4eb5d6a commit 1b73b6a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/fontra_rcjk/backend_fs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import os
import pathlib

Expand All @@ -16,6 +17,8 @@
unpackAxes,
)

logger = logging.getLogger(__name__)

glyphSetNames = ["characterGlyph", "deepComponent", "atomicElement"]


Expand Down Expand Up @@ -118,11 +121,48 @@ def _populateGlyphCache(self, glyphName):
layerGlyphs = {}
for layerName, glifData in layerGLIFData:
layerGlyphs[layerName] = GLIFGlyph.fromGLIFData(glifData)

layerGlyphs = self._fudgeLayerNames(glyphName, layerGlyphs)

self._tempGlyphCache[glyphName] = layerGlyphs

for compoName in layerGlyphs["foreground"].getComponentNames():
self._populateGlyphCache(compoName)

def _fudgeLayerNames(self, glyphName, layerGlyphs):
usedLayerNames = set()
for varData in layerGlyphs["foreground"].lib.get("robocjk.variationGlyphs", []):
layerName = varData.get("layerName")
if layerName:
usedLayerNames.add(layerName)
missingLayerNames = usedLayerNames - set(layerGlyphs)

if not missingLayerNames:
return layerGlyphs

if len(usedLayerNames) != len(
{layerName.casefold() for layerName in usedLayerNames}
):
logger.warn(
f"Possible layer name conflict on case-insensitive file system ({glyphName})"
)
return layerGlyphs

renameMap = {}
availableLayerNames = {
layerName.casefold(): layerName for layerName in layerGlyphs
}
for missingLayerName in missingLayerNames:
folded = missingLayerName.casefold()
fudged = availableLayerNames.get(folded)
if fudged:
renameMap[fudged] = missingLayerName
if renameMap:
logger.warn(f"fudging layer names for {glyphName}: {renameMap}")
layerGlyphs = {renameMap.get(k, k): v for k, v in layerGlyphs.items()}

return layerGlyphs

def _getLayerGLIFData(self, glyphName):
for gs, _ in self._iterGlyphSets():
if glyphName in gs:
Expand Down

0 comments on commit 1b73b6a

Please sign in to comment.