diff --git a/src/fontra_rcjk/backend_fs.py b/src/fontra_rcjk/backend_fs.py index 9d2b713..18b2423 100644 --- a/src/fontra_rcjk/backend_fs.py +++ b/src/fontra_rcjk/backend_fs.py @@ -261,15 +261,10 @@ async def getCustomData(self) -> dict[str, Any]: customDataPath = self.path / FONTLIB_FILENAME if customDataPath.is_file(): customData = json.loads(customDataPath.read_text(encoding="utf-8")) - return customData | standardCustomDataItems + return deepcopy(standardCustomDataItems) | customData async def putCustomData(self, customData: dict[str, Any]) -> None: customDataPath = self.path / FONTLIB_FILENAME - customData = { - k: v - for k, v in customData.items() - if k not in standardCustomDataItems or standardCustomDataItems[k] != v - } customDataPath.write_text(json.dumps(customData, indent=2), encoding="utf-8") async def watchExternalChanges( diff --git a/src/fontra_rcjk/backend_mysql.py b/src/fontra_rcjk/backend_mysql.py index 400e9f7..89f7d7e 100644 --- a/src/fontra_rcjk/backend_mysql.py +++ b/src/fontra_rcjk/backend_mysql.py @@ -131,7 +131,7 @@ async def taskFunc(): "features", "" ) self._tempFontItemsCache["customData"] = ( - font_data["data"].get("fontlib", {}) | standardCustomDataItems + standardCustomDataItems | font_data["data"].get("fontlib", {}) ) self._tempFontItemsCache.updateTimeOut() del self._getMiscFontItemsTask @@ -220,7 +220,7 @@ async def getCustomData(self) -> dict[str, Any]: if customData is None: await self._getMiscFontItems() customData = self._tempFontItemsCache["customData"] - return customData + return deepcopy(customData) async def putCustomData(self, customData: dict[str, Any]) -> None: await self._getMiscFontItems() diff --git a/src/fontra_rcjk/base.py b/src/fontra_rcjk/base.py index edc413b..a3b186e 100644 --- a/src/fontra_rcjk/base.py +++ b/src/fontra_rcjk/base.py @@ -521,28 +521,28 @@ def makeSafeLayerName(layerName): "fontra.sourceStatusFieldDefinitions": [ { "label": "In progress", - "color": (1.0, 0.0, 0.0, 1.0), + "color": [1.0, 0.0, 0.0, 1.0], "value": 0, "isDefault": True, }, { "label": "Checking-1", - "color": (1.0, 0.5, 0.0, 1.0), + "color": [1.0, 0.5, 0.0, 1.0], "value": 1, }, { "label": "Checking-2", - "color": (1.0, 1.0, 0.0, 1.0), + "color": [1.0, 1.0, 0.0, 1.0], "value": 2, }, { "label": "Checking-3", - "color": (0.0, 0.5, 1.0, 1.0), + "color": [0.0, 0.5, 1.0, 1.0], "value": 3, }, { "label": "Validated", - "color": (0.0, 1.0, 0.5, 1.0), + "color": [0.0, 1.0, 0.5, 1.0], "value": 4, }, ] diff --git a/tests/test_font.py b/tests/test_font.py index 62e7e72..e9e64a6 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -1,4 +1,5 @@ import contextlib +import json import pathlib import shutil from importlib.metadata import entry_points @@ -20,7 +21,7 @@ unstructure, ) -from fontra_rcjk.base import makeSafeLayerName +from fontra_rcjk.base import makeSafeLayerName, standardCustomDataItems dataDir = pathlib.Path(__file__).resolve().parent / "data" @@ -1086,3 +1087,33 @@ async def test_read_write_glyph_customData(writableTestFont): async with contextlib.aclosing(reopenedFont): reopenedGlyph = await reopenedFont.getGlyph(glyphName) assert glyph == reopenedGlyph + + +async def test_statusFieldDefinitions(writableTestFont): + customData = await writableTestFont.getCustomData() + statusDefinitions = customData["fontra.sourceStatusFieldDefinitions"] + assert ( + standardCustomDataItems["fontra.sourceStatusFieldDefinitions"] + == statusDefinitions + ) + newStatusDef = { + "color": [0, 0, 0, 1], + "label": "Rejected", + "value": 5, + } + statusDefinitions.append(newStatusDef) + + editedCustomData = customData | { + "fontra.sourceStatusFieldDefinitions": statusDefinitions + } + await writableTestFont.putCustomData(editedCustomData) + + newCustomData = await writableTestFont.getCustomData() + newStatusDefinitions = newCustomData["fontra.sourceStatusFieldDefinitions"] + + assert newStatusDefinitions[5] == newStatusDef + + fontLibPath = writableTestFont.path / "fontLib.json" + fontLib = json.loads(fontLibPath.read_text()) + + assert editedCustomData == fontLib