diff --git a/src/fontra/backends/designspace.py b/src/fontra/backends/designspace.py index f9ea2a4400..80aadb635c 100644 --- a/src/fontra/backends/designspace.py +++ b/src/fontra/backends/designspace.py @@ -178,9 +178,12 @@ def updateGlyphSetContents(self, glyphSet): for glyphName, fileName in glyphSet.contents.items(): glifFileNames[fileName] = glyphName - async def getGlyphMap(self): + async def getGlyphMap(self) -> dict[str, list[int]]: return dict(self.glyphMap) + async def putGlyphMap(self, value: dict[str, list[int]]) -> None: + pass + async def getGlyph(self, glyphName: str) -> VariableGlyph | None: if glyphName not in self.glyphMap: return None @@ -538,7 +541,7 @@ async def deleteGlyph(self, glyphName): del self.glyphMap[glyphName] self.savedGlyphModificationTimes[glyphName] = None - async def getGlobalAxes(self): + async def getGlobalAxes(self) -> list[GlobalAxis | GlobalDiscreteAxis]: return self.axes async def putGlobalAxes(self, axes): @@ -561,10 +564,20 @@ async def putGlobalAxes(self, axes): self.updateAxisInfo() self.loadUFOLayers() - async def getUnitsPerEm(self): + async def getUnitsPerEm(self) -> int: return self.defaultFontInfo.unitsPerEm - async def getCustomData(self): + async def putUnitsPerEm(self, value: int) -> None: + del self.defaultFontInfo + ufoPaths = sorted(set(self.ufoLayers.iterAttrs("path"))) + for ufoPath in ufoPaths: + reader = self.ufoManager.getReader(ufoPath) + info = UFOFontInfo() + reader.readInfo(info) + info.unitsPerEm = value + reader.writeInfo(info) + + async def getCustomData(self) -> dict[str, Any]: return deepcopy(self.dsDoc.lib) async def putCustomData(self, lib): diff --git a/src/fontra/backends/fontra.py b/src/fontra/backends/fontra.py index 45cf845ebd..4d772694b6 100644 --- a/src/fontra/backends/fontra.py +++ b/src/fontra/backends/fontra.py @@ -7,9 +7,16 @@ from copy import deepcopy from dataclasses import dataclass, field from os import PathLike -from typing import Callable - -from fontra.core.classes import Font, VariableGlyph, structure, unstructure +from typing import Any, Callable + +from fontra.core.classes import ( + Font, + GlobalAxis, + GlobalDiscreteAxis, + VariableGlyph, + structure, + unstructure, +) from fontra.core.protocols import WritableFontBackend from .filenames import stringToFileName @@ -66,16 +73,19 @@ def close(self): def flush(self): self._scheduler.flush() - async def getUnitsPerEm(self): + async def getUnitsPerEm(self) -> int: return self.fontData.unitsPerEm async def putUnitsPerEm(self, unitsPerEm): self.fontData.unitsPerEm = unitsPerEm self._scheduler.schedule(self._writeFontData) - async def getGlyphMap(self): + async def getGlyphMap(self) -> dict[str, list[int]]: return dict(self.glyphMap) + async def putGlyphMap(self, value: dict[str, list[int]]) -> None: + pass + async def getGlyph(self, glyphName: str) -> VariableGlyph | None: try: jsonSource = self.getGlyphData(glyphName) @@ -95,14 +105,14 @@ async def putGlyph( async def deleteGlyph(self, glyphName): self.glyphMap.pop(glyphName, None) - async def getGlobalAxes(self): + async def getGlobalAxes(self) -> list[GlobalAxis | GlobalDiscreteAxis]: return deepcopy(self.fontData.axes) async def putGlobalAxes(self, axes): self.fontData.axes = deepcopy(axes) self._scheduler.schedule(self._writeFontData) - async def getCustomData(self): + async def getCustomData(self) -> dict[str, Any]: return deepcopy(self.fontData.customData) async def putCustomData(self, customData): diff --git a/src/fontra/backends/opentype.py b/src/fontra/backends/opentype.py index ff748a700f..ea02b2b243 100644 --- a/src/fontra/backends/opentype.py +++ b/src/fontra/backends/opentype.py @@ -1,4 +1,5 @@ from os import PathLike +from typing import Any from fontTools.misc.psCharStrings import SimpleT2Decompiler from fontTools.pens.pointPen import GuessSmoothPointPen @@ -6,7 +7,14 @@ from fontra.core.protocols import ReadableFontBackend -from ..core.classes import GlobalAxis, Layer, Source, StaticGlyph, VariableGlyph +from ..core.classes import ( + GlobalAxis, + GlobalDiscreteAxis, + Layer, + Source, + StaticGlyph, + VariableGlyph, +) from ..core.path import PackedPath, PackedPathPointPen @@ -39,7 +47,7 @@ def __init__(self, *, path): def close(self): self.font.close() - async def getGlyphMap(self): + async def getGlyphMap(self) -> dict[str, list[int]]: return self.glyphMap async def getGlyph(self, glyphName: str) -> VariableGlyph | None: @@ -100,13 +108,13 @@ def _getGlyphVariationLocations(self, glyphName): } return [dict(loc) for loc in sorted(locations)] - async def getGlobalAxes(self): + async def getGlobalAxes(self) -> list[GlobalAxis | GlobalDiscreteAxis]: return self.globalAxes - async def getUnitsPerEm(self): + async def getUnitsPerEm(self) -> int: return self.font["head"].unitsPerEm - async def getCustomData(self): + async def getCustomData(self) -> dict[str, Any]: return {}