From aeff093f489b6ee5dd7fa21c687c7f1498ef0ce8 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Sat, 2 Dec 2023 15:25:26 +0100 Subject: [PATCH] Support writing lib to designspace and .fontra, make copyFont() copy lib --- src/fontra/backends/copy.py | 1 + src/fontra/backends/designspace.py | 6 +++++- src/fontra/backends/fontra.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/fontra/backends/copy.py b/src/fontra/backends/copy.py index 725738032..2fb66d57e 100644 --- a/src/fontra/backends/copy.py +++ b/src/fontra/backends/copy.py @@ -14,6 +14,7 @@ async def copyFont( sourceBackend, destBackend, *, glyphNames=None, numTasks=1, progressInterval=0 ): await destBackend.putGlobalAxes(await sourceBackend.getGlobalAxes()) + await destBackend.putFontLib(await sourceBackend.getFontLib()) glyphMap = await sourceBackend.getGlyphMap() glyphNamesInFont = set(glyphMap) glyphNamesToCopy = sorted( diff --git a/src/fontra/backends/designspace.py b/src/fontra/backends/designspace.py index b80723bde..e6ffb6e60 100644 --- a/src/fontra/backends/designspace.py +++ b/src/fontra/backends/designspace.py @@ -561,7 +561,11 @@ async def getUnitsPerEm(self): return self.defaultFontInfo.unitsPerEm async def getFontLib(self): - return self.dsDoc.lib + return deepcopy(self.dsDoc.lib) + + async def putFontLib(self, lib): + self.dsDoc.lib = deepcopy(lib) + self.dsDoc.write(self.dsDoc.path) async def watchExternalChanges(self): ufoPaths = sorted(set(self.ufoLayers.iterAttrs("path"))) diff --git a/src/fontra/backends/fontra.py b/src/fontra/backends/fontra.py index 76e361ef3..d6333e945 100644 --- a/src/fontra/backends/fontra.py +++ b/src/fontra/backends/fontra.py @@ -96,7 +96,11 @@ async def putGlobalAxes(self, axes): self._scheduler.schedule(self._writeFontData) async def getFontLib(self): - return {} + return deepcopy(self.fontData.lib) + + async def putFontLib(self, lib): + self.fontData.lib = deepcopy(lib) + self._scheduler.schedule(self._writeFontData) def _readGlyphInfo(self): with open(self.glyphInfoPath, "r", encoding="utf-8") as file: