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

Add support for user editable status definitions #184

Merged
merged 9 commits into from
May 29, 2024
7 changes: 1 addition & 6 deletions src/fontra_rcjk/backend_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/fontra_rcjk/backend_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/fontra_rcjk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]
Expand Down
33 changes: 32 additions & 1 deletion tests/test_font.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import json
import pathlib
import shutil
from importlib.metadata import entry_points
Expand All @@ -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"

Expand Down Expand Up @@ -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
Loading