From a9783a5112a76bb47b1898a75077fd52021985d6 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Mon, 18 Mar 2024 14:54:33 +0100 Subject: [PATCH] Implement reading/writing font info and sources --- src/fontra_rcjk/backend_mysql.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fontra_rcjk/backend_mysql.py b/src/fontra_rcjk/backend_mysql.py index e24b35d..c7c7dd4 100644 --- a/src/fontra_rcjk/backend_mysql.py +++ b/src/fontra_rcjk/backend_mysql.py @@ -9,6 +9,7 @@ from typing import Any, Awaitable, Callable from fontra.core.classes import ( + Font, FontInfo, GlobalAxis, GlobalDiscreteAxis, @@ -135,7 +136,7 @@ async def taskFunc(): self._getMiscFontItemsTask = asyncio.create_task(taskFunc()) await self._getMiscFontItemsTask - async def _getDesignspace(self): + async def _getDesignspace(self) -> Font: await self._getMiscFontItems() designspace = self._tempFontItemsCache["designspace"] self._updateDefaultLocation(designspace) @@ -146,23 +147,28 @@ def _updateDefaultLocation(self, designspace): self._defaultLocation = mapLocationFromUserToSource(userLoc, designspace.axes) async def getFontInfo(self) -> FontInfo: - return FontInfo() + designspace = await self._getDesignspace() + return deepcopy(designspace.fontInfo) async def putFontInfo(self, fontInfo: FontInfo): - pass + designspace = await self._getDesignspace() + designspace.fontInfo = deepcopy(fontInfo) + await self._writeDesignspace(designspace) async def getSources(self) -> dict[str, GlobalSource]: - return {} + designspace = await self._getDesignspace() + return deepcopy(designspace.sources) async def putSources(self, sources: dict[str, GlobalSource]) -> None: - pass + designspace = await self._getDesignspace() + designspace.sources = deepcopy(sources) + await self._writeDesignspace(designspace) async def getGlobalAxes(self) -> list[GlobalAxis | GlobalDiscreteAxis]: designspace = await self._getDesignspace() return deepcopy(designspace.axes) async def putGlobalAxes(self, axes: list[GlobalAxis | GlobalDiscreteAxis]) -> None: - await self._getMiscFontItems() designspace = await self._getDesignspace() designspace.axes = deepcopy(axes) self._updateDefaultLocation(designspace)