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
2 changes: 1 addition & 1 deletion src/fontra_rcjk/backend_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ 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 standardCustomDataItems | customData

async def putCustomData(self, customData: dict[str, Any]) -> None:
customDataPath = self.path / FONTLIB_FILENAME
Expand Down
26 changes: 25 additions & 1 deletion tests/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 +1086,27 @@ 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.get("fontra.sourceStatusFieldDefinitions")
assert (
standardCustomDataItems.get("fontra.sourceStatusFieldDefinitions")
== statusDefinitions
)
newStatusDef = {
"color": [0, 0, 0, 1],
"label": "Rejected",
"value": 5,
}
statusDefinitionsCopy = statusDefinitions.copy()
statusDefinitionsCopy.append(newStatusDef)

await writableTestFont.putCustomData(
{"fontra.sourceStatusFieldDefinitions": statusDefinitionsCopy}
)
newCustomData = await writableTestFont.getCustomData()
newStatusDefinitions = newCustomData.get("fontra.sourceStatusFieldDefinitions")

assert newStatusDefinitions[5] == newStatusDef
Loading