From c7092ec43b979c4d4a41caaf67c56b1b4b317c39 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Wed, 6 Mar 2024 16:16:34 +0100 Subject: [PATCH 1/8] refactoring unicode to codePoint --- src/fontra_rcjk/backend_fs.py | 24 ++++++++++++------------ src/fontra_rcjk/backend_mysql.py | 28 ++++++++++++++-------------- src/fontra_rcjk/base.py | 6 +++--- tests/test_font.py | 4 ++-- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/fontra_rcjk/backend_fs.py b/src/fontra_rcjk/backend_fs.py index b19949f..ce7bc1d 100644 --- a/src/fontra_rcjk/backend_fs.py +++ b/src/fontra_rcjk/backend_fs.py @@ -9,7 +9,7 @@ import watchfiles from fontra.backends.designspace import cleanupWatchFilesChanges -from fontra.backends.ufo_utils import extractGlyphNameAndUnicodes +from fontra.backends.ufo_utils import extractGlyphNameAndCodePoints from fontra.core.classes import ( GlobalAxis, GlobalDiscreteAxis, @@ -78,11 +78,11 @@ def __init__(self, path: PathLike, *, create: bool = False): self._glyphMap: dict[str, list[int]] = {} for gs, hasEncoding in self._iterGlyphSets(): glyphMap = gs.getGlyphMap(not hasEncoding) - for glyphName, unicodes in glyphMap.items(): + for glyphName, codePoints in glyphMap.items(): assert glyphName not in self._glyphMap if not hasEncoding: - assert not unicodes - self._glyphMap[glyphName] = unicodes + assert not codePoints + self._glyphMap[glyphName] = codePoints self._recentlyWrittenPaths: dict[str, Any] = {} self._tempGlyphCache = TimedCache() @@ -184,7 +184,7 @@ def _getLayerGLIFData(self, glyphName): return None async def putGlyph( - self, glyphName: str, glyph: VariableGlyph, unicodes: list[int] + self, glyphName: str, glyph: VariableGlyph, codePoints: list[int] ) -> None: if glyphName not in self._glyphMap: existingLayerGlyphs = {} @@ -194,11 +194,11 @@ async def putGlyph( axis.name: axis.defaultValue for axis in glyph.axes } layerGlyphs = buildLayerGlyphsFromVariableGlyph( - glyphName, glyph, unicodes, localDefaultLocation, existingLayerGlyphs + glyphName, glyph, codePoints, localDefaultLocation, existingLayerGlyphs ) glyphSet = self.getGlyphSetForGlyph(glyphName) glyphSet.putGlyphLayerData(glyphName, layerGlyphs.items()) - self._glyphMap[glyphName] = unicodes + self._glyphMap[glyphName] = codePoints self._tempGlyphCache[glyphName] = layerGlyphs async def deleteGlyph(self, glyphName): @@ -276,17 +276,17 @@ def setupLayers(self): if glifPaths: self.layers[layerDir.name] = glifPaths - def getGlyphMap(self, ignoreUnicodes=False): + def getGlyphMap(self, ignoreCodePoints=False): if self.glyphMap is None: glyphMap = {} for path in self.path.glob("*.glif"): with open(path, "rb") as f: # assuming all unicodes are in the first 1024 bytes of the file data = f.read(1024) - glyphName, unicodes = extractGlyphNameAndUnicodes(data, path.name) - if ignoreUnicodes: - unicodes = [] - glyphMap[glyphName] = unicodes + glyphName, codePoints = extractGlyphNameAndCodePoints(data, path.name) + if ignoreCodePoints: + codePoints = [] + glyphMap[glyphName] = codePoints self.contents[glyphName] = path self.glifFileNames[path.name] = glyphName self.glyphMap = glyphMap diff --git a/src/fontra_rcjk/backend_mysql.py b/src/fontra_rcjk/backend_mysql.py index c82798e..5492847 100644 --- a/src/fontra_rcjk/backend_mysql.py +++ b/src/fontra_rcjk/backend_mysql.py @@ -105,7 +105,7 @@ async def _ensureGlyphMapTask(self) -> None: self._lastPolledForChanges = response["server_datetime"] for typeCode, typeName in _glyphTypes: for glyphInfo in response["data"][typeName]: - glyphMap[glyphInfo["name"]] = _unicodesFromGlyphInfo(glyphInfo) + glyphMap[glyphInfo["name"]] = _codePointsFromGlyphInfo(glyphInfo) rcjkGlyphInfo[glyphInfo["name"]] = RCJKGlyphInfo( typeCode, glyphInfo["id"], getUpdatedTimeStamp(glyphInfo) ) @@ -272,12 +272,12 @@ async def putGlyph( logger.info(f"Done writing {glyphName}") async def _putGlyph( - self, glyphName: str, glyph: VariableGlyph, unicodes: list[int] + self, glyphName: str, glyph: VariableGlyph, codePoints: list[int] ) -> None: defaultLocation = await self.getDefaultLocation() if glyphName not in self._rcjkGlyphInfo: - await self._newGlyph(glyphName, unicodes) + await self._newGlyph(glyphName, codePoints) existingLayerGlyphs = {} else: existingLayerGlyphs = await self._getLayerGlyphs(glyphName) @@ -285,10 +285,10 @@ async def _putGlyph( existingLayerData = {k: v.asGLIFData() for k, v in existingLayerGlyphs.items()} layerGlyphs = buildLayerGlyphsFromVariableGlyph( - glyphName, glyph, unicodes, defaultLocation, existingLayerGlyphs + glyphName, glyph, codePoints, defaultLocation, existingLayerGlyphs ) - self._glyphMap[glyphName] = unicodes + self._glyphMap[glyphName] = codePoints lockResponse = await self._callGlyphMethod(glyphName, "lock", return_data=False) @@ -342,7 +342,7 @@ async def _putGlyph( self._rcjkGlyphInfo[glyphName].updated = timeStamp self._writeGlyphToCacheDir(glyphName, glyph) - async def _newGlyph(self, glyphName: str, unicodes: list[int]) -> None: + async def _newGlyph(self, glyphName: str, codePoints: list[int]) -> None: # In _newGlyph() we create a new character glyph in the database. # _putGlyph will immediately overwrite it with the real glyph data, # with a lock acquired. Our dummy glyph has to have a glyph name, but @@ -351,14 +351,14 @@ async def _newGlyph(self, glyphName: str, unicodes: list[int]) -> None: logger.info(f"Creating new glyph '{glyphName}'") dummyGlyph = GLIFGlyph() dummyGlyph.name = glyphName - dummyGlyph.unicodes = unicodes + dummyGlyph.codePoints = codePoints dummyGlyph.width = 314 # arbitrary positive value xmlData = dummyGlyph.asGLIFData() response = await self.client.character_glyph_create( self.fontUID, xmlData, return_data=False ) glyphID = response["data"]["id"] - self._glyphMap[glyphName] = unicodes + self._glyphMap[glyphName] = codePoints timeStamp = getUpdatedTimeStamp(response["data"]) self._rcjkGlyphInfo[glyphName] = RCJKGlyphInfo("CG", glyphID, timeStamp) self._glyphTimeStamps[glyphName] = timeStamp @@ -491,10 +491,10 @@ async def _pollOnceForChanges(self) -> tuple[Any, Any]: typeCode, glyphInfo["id"], glyphUpdatedAt ) - unicodes = _unicodesFromGlyphInfo(glyphInfo) - if unicodes != self._glyphMap.get(glyphName): - self._glyphMap[glyphName] = unicodes - glyphMapUpdates[glyphName] = unicodes + codePoints = _codePointsFromGlyphInfo(glyphInfo) + if codePoints != self._glyphMap.get(glyphName): + self._glyphMap[glyphName] = codePoints + glyphMapUpdates[glyphName] = codePoints glyphNames.add(glyphName) self._glyphCache.pop(glyphName, None) @@ -509,8 +509,8 @@ async def _pollOnceForChanges(self) -> tuple[Any, Any]: return externalChange, reloadPattern -def _unicodesFromGlyphInfo(glyphInfo: dict) -> list[int]: - return glyphInfo.get("unicodes", []) +def _codePointsFromGlyphInfo(glyphInfo: dict) -> list[int]: + return glyphInfo.get("codePoints", []) def getUpdatedTimeStamp(info: dict) -> str: diff --git a/src/fontra_rcjk/base.py b/src/fontra_rcjk/base.py index ea68f63..3e29111 100644 --- a/src/fontra_rcjk/base.py +++ b/src/fontra_rcjk/base.py @@ -28,7 +28,7 @@ class GLIFGlyph: def __init__(self): self.name = None # Must be set to a string before we can write GLIF data - self.unicodes = [] + self.codePoints = [] self.width = 0 self.path = None self.lib = {} @@ -254,7 +254,7 @@ def convertTransformation(rcjkTransformation): def buildLayerGlyphsFromVariableGlyph( - glyphName, glyph, unicodes, defaultLocation, existingLayerGlyphs + glyphName, glyph, codePoints, defaultLocation, existingLayerGlyphs ): fontraLayerNameMapping = {} defaultLayerName = None @@ -284,7 +284,7 @@ def buildLayerGlyphsFromVariableGlyph( fontraLayerNameMapping[safeLayerName] = layerName layerGlyphs[layerName] = layerGlyph - layerGlyphs[layerName].unicodes = unicodes + layerGlyphs[layerName].unicodes = codePoints defaultGlyph = layerGlyphs["foreground"] if glyph.axes: diff --git a/tests/test_font.py b/tests/test_font.py index 6be65e7..f3adca0 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -389,8 +389,8 @@ async def test_getGlyphMap(backendName, numGlyphs, testMapping): with contextlib.closing(font): glyphMap = await font.getGlyphMap() assert numGlyphs == len(glyphMap) - for glyphName, unicodes in testMapping.items(): - assert glyphMap[glyphName] == unicodes + for glyphName, codePoints in testMapping.items(): + assert glyphMap[glyphName] == codePoints @pytest.mark.asyncio From 3434f452b132d1c4da7f93a5014d4549e8f84dd9 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Wed, 6 Mar 2024 16:22:47 +0100 Subject: [PATCH 2/8] change back attribute name: "unicodes" --- src/fontra_rcjk/backend_mysql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontra_rcjk/backend_mysql.py b/src/fontra_rcjk/backend_mysql.py index 5492847..ed6968a 100644 --- a/src/fontra_rcjk/backend_mysql.py +++ b/src/fontra_rcjk/backend_mysql.py @@ -510,7 +510,7 @@ async def _pollOnceForChanges(self) -> tuple[Any, Any]: def _codePointsFromGlyphInfo(glyphInfo: dict) -> list[int]: - return glyphInfo.get("codePoints", []) + return glyphInfo.get("unicodes", []) def getUpdatedTimeStamp(info: dict) -> str: From 77eb2739002c7cdb733d671df47a2bf19ed3c574 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Wed, 6 Mar 2024 16:26:55 +0100 Subject: [PATCH 3/8] redo unicodes for GLIFGlyph --- src/fontra_rcjk/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontra_rcjk/base.py b/src/fontra_rcjk/base.py index 3e29111..4318efc 100644 --- a/src/fontra_rcjk/base.py +++ b/src/fontra_rcjk/base.py @@ -28,7 +28,7 @@ class GLIFGlyph: def __init__(self): self.name = None # Must be set to a string before we can write GLIF data - self.codePoints = [] + self.unicodes = [] self.width = 0 self.path = None self.lib = {} From f1a7ac6ca20fb5971fdaebe487e19f9a8f71ac30 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Wed, 6 Mar 2024 17:02:04 +0100 Subject: [PATCH 4/8] Extend README --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index a178a3a..1db5712 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # fontra-rcjk Fontra plug-in with [django-robocjk](https://github.com/googlefonts/django-robo-cjk) support and .rcjk file format support + + +# How to test code changes made in fontra which effects fontra-rjck +Let's imagine you have made some changes within fontra, which will have an impakt to fontra-rcjk as well, eg. code refactoring. But the the new code is not merged, yet, because we need to test it first. +The challanging part is, that we cannot add a specific branch to requirements-dev.txt sadly. + +1. Go to your local fontra folder/repo +2. Checkout the needed fontra branch into your current venv +2. Go to you fontra-rcjk folder/repo +3. Install the required fontra branch via: `pip install -e ../fontra/` +4. Run `pytest` + +Please keep in mind the *_fs backend has some unit tests. The mysql one does not, so we need to be super careful there. + + +# How to run a rcjk project + +1. Start fontra like this: `fontra rcjk robocjk.black-foundry.com` +2. Open the `http://localhost:8000/` +3. Then use your robocjk login credentials to log in. +4. Click a project. From 4b1e55cfd73da302354966727969755bd77863da Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Wed, 6 Mar 2024 17:03:49 +0100 Subject: [PATCH 5/8] Fixing typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1db5712..ca0bdc8 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ Fontra plug-in with [django-robocjk](https://github.com/googlefonts/django-robo- # How to test code changes made in fontra which effects fontra-rjck -Let's imagine you have made some changes within fontra, which will have an impakt to fontra-rcjk as well, eg. code refactoring. But the the new code is not merged, yet, because we need to test it first. -The challanging part is, that we cannot add a specific branch to requirements-dev.txt sadly. +Let's imagine you have made some changes within fontra, which may have an impact to fontra-rcjk as well, eg. code refactoring. But the new code is not merged, yet, because we need to test it first. +The challenging part is, that we cannot add a specific branch to requirements-dev.txt, sadly. 1. Go to your local fontra folder/repo 2. Checkout the needed fontra branch into your current venv From 3430efc8d889b7714fc021a4ec1c6169b4d365d6 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Wed, 6 Mar 2024 17:07:28 +0100 Subject: [PATCH 6/8] removing 'the' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca0bdc8..ab71f47 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,6 @@ Please keep in mind the *_fs backend has some unit tests. The mysql one does not # How to run a rcjk project 1. Start fontra like this: `fontra rcjk robocjk.black-foundry.com` -2. Open the `http://localhost:8000/` +2. Open `http://localhost:8000/` 3. Then use your robocjk login credentials to log in. 4. Click a project. From b2ffbe78708ea94d4ae798d74e4b408428d0e85c Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Fri, 8 Mar 2024 08:32:17 +0100 Subject: [PATCH 7/8] Fix attr name --- src/fontra_rcjk/backend_mysql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontra_rcjk/backend_mysql.py b/src/fontra_rcjk/backend_mysql.py index ed6968a..2e69f6a 100644 --- a/src/fontra_rcjk/backend_mysql.py +++ b/src/fontra_rcjk/backend_mysql.py @@ -351,7 +351,7 @@ async def _newGlyph(self, glyphName: str, codePoints: list[int]) -> None: logger.info(f"Creating new glyph '{glyphName}'") dummyGlyph = GLIFGlyph() dummyGlyph.name = glyphName - dummyGlyph.codePoints = codePoints + dummyGlyph.unicodes = codePoints dummyGlyph.width = 314 # arbitrary positive value xmlData = dummyGlyph.asGLIFData() response = await self.client.character_glyph_create( From ed783495addb64a096c7f55d37acb48be8b299b4 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Fri, 8 Mar 2024 09:32:13 +0100 Subject: [PATCH 8/8] Removing changes to readme --- README.md | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/README.md b/README.md index ab71f47..a178a3a 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,2 @@ # fontra-rcjk Fontra plug-in with [django-robocjk](https://github.com/googlefonts/django-robo-cjk) support and .rcjk file format support - - -# How to test code changes made in fontra which effects fontra-rjck -Let's imagine you have made some changes within fontra, which may have an impact to fontra-rcjk as well, eg. code refactoring. But the new code is not merged, yet, because we need to test it first. -The challenging part is, that we cannot add a specific branch to requirements-dev.txt, sadly. - -1. Go to your local fontra folder/repo -2. Checkout the needed fontra branch into your current venv -2. Go to you fontra-rcjk folder/repo -3. Install the required fontra branch via: `pip install -e ../fontra/` -4. Run `pytest` - -Please keep in mind the *_fs backend has some unit tests. The mysql one does not, so we need to be super careful there. - - -# How to run a rcjk project - -1. Start fontra like this: `fontra rcjk robocjk.black-foundry.com` -2. Open `http://localhost:8000/` -3. Then use your robocjk login credentials to log in. -4. Click a project.