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

Ensure that the glyphMap has loaded before doing any glyph requests #122

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
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