Skip to content

Commit

Permalink
Merge pull request #122 from googlefonts/issue111
Browse files Browse the repository at this point in the history
Ensure that the glyphMap has loaded before doing any glyph requests
  • Loading branch information
justvanrossum authored Nov 6, 2023
2 parents 5f02cad + ec8e8ef commit bc0b0f2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/fontra_rcjk/backend_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ def close(self):
self._tempFontItemsCache.cancel()

async def getGlyphMap(self):
if self._glyphMap is None:
self._glyphMap, self._rcjkGlyphInfo = await self._getGlyphMap()
await self._ensureGlyphMap()
return dict(self._glyphMap)

async def _getGlyphMap(self):
async def _ensureGlyphMap(self):
if self._glyphMap is not None:
return
rcjkGlyphInfo = {}
glyphMap = {}
response = await self.client.glif_list(self.fontUID)
for typeCode, typeName in _glyphTypes:
for glyphInfo in response["data"][typeName]:
glyphMap[glyphInfo["name"]] = _unicodesFromGlyphInfo(glyphInfo)
rcjkGlyphInfo[glyphInfo["name"]] = (typeCode, glyphInfo["id"])
return glyphMap, rcjkGlyphInfo
self._glyphMap = glyphMap
self._rcjkGlyphInfo = rcjkGlyphInfo

async def _getMiscFontItems(self):
if not hasattr(self, "_getMiscFontItemsTask"):
Expand Down Expand Up @@ -113,7 +115,8 @@ async def getFontLib(self):
return fontLib

async def getGlyph(self, glyphName):
if self._glyphMap is not None and glyphName not in self._glyphMap:
await self._ensureGlyphMap()
if glyphName not in self._glyphMap:
return None
layerGlyphs = await self._getLayerGlyphs(glyphName)
return buildVariableGlyphFromLayerGlyphs(layerGlyphs)
Expand Down Expand Up @@ -152,6 +155,7 @@ def _populateGlyphCache(self, glyphName, glyphData):
self._populateGlyphCache(subGlyphName, subGlyphData)

async def putGlyph(self, glyphName, glyph, unicodes):
await self._ensureGlyphMap()
logger.info(f"Start writing {glyphName}")
self._writingChanges += 1
try:
Expand Down Expand Up @@ -256,6 +260,7 @@ async def _newGlyph(self, glyphName, unicodes):
self._glyphTimeStamps[glyphName] = getUpdatedTimeStamp(response["data"])

async def deleteGlyph(self, glyphName):
await self._ensureGlyphMap()
if glyphName not in self._rcjkGlyphInfo:
raise KeyError(f"Glyph '{glyphName}' does not exist")

Expand Down Expand Up @@ -283,6 +288,7 @@ async def _callGlyphMethod(self, glyphName, methodName, *args, **kwargs):
return await method(self.fontUID, glyphID, *args, **kwargs)

async def watchExternalChanges(self):
await self._ensureGlyphMap()
errorDelay = 30
while True:
try:
Expand Down

0 comments on commit bc0b0f2

Please sign in to comment.