From 279b26242c5d635c89fb44eeb6784ad0ec58f46f Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Mon, 21 Oct 2024 09:35:36 +0200 Subject: [PATCH] Add flag to add minimal gasp table --- src/fontra_compile/compile_fontmake_action.py | 21 +++++++++++++++++++ tests/data/MutatorSans-fontmake.ttx | 4 ++++ tests/test_workflow.py | 1 + 3 files changed, 26 insertions(+) diff --git a/src/fontra_compile/compile_fontmake_action.py b/src/fontra_compile/compile_fontmake_action.py index 9fd5c05..0e3493b 100644 --- a/src/fontra_compile/compile_fontmake_action.py +++ b/src/fontra_compile/compile_fontmake_action.py @@ -25,6 +25,7 @@ class CompileFontMakeAction: destination: str options: dict[str, str] = field(default_factory=dict) setOverlapSimpleFlag: bool = False + addMinimalGaspTable: bool = False ufoTempDir: str | None = None input: ReadableFontBackend | None = field(init=False, default=None) @@ -81,6 +82,9 @@ async def process( addInstances(sourcePath) addGlyphOrder(sourcePath) + if self.addMinimalGaspTable: + addMinimalGaspTable(sourcePath) + extraArguments = [] for option, value in self.options.items(): extraArguments.append(f"--{option}") @@ -176,3 +180,20 @@ def addGlyphOrder(designspacePath): glyphSet = ufo.getGlyphSet() lib["public.glyphOrder"] = sorted(glyphSet.keys(), key=_glyphSortKeyFunc) ufo.writeLib(lib) + + +class UFOFontInfo: + pass + + +def addMinimalGaspTable(designspacePath): + backend = getFileSystemBackend(designspacePath) + dsDoc = backend.dsDoc + defaultSource = dsDoc.findDefault() + ufo = UFOReaderWriter(defaultSource.path) + fontInfo = UFOFontInfo() + ufo.readInfo(fontInfo) + fontInfo.openTypeGaspRangeRecords = [ + {"rangeMaxPPEM": 0xFFFF, "rangeGaspBehavior": [0, 1, 2, 3]} + ] + ufo.writeInfo(fontInfo) diff --git a/tests/data/MutatorSans-fontmake.ttx b/tests/data/MutatorSans-fontmake.ttx index fb78446..98dd314 100644 --- a/tests/data/MutatorSans-fontmake.ttx +++ b/tests/data/MutatorSans-fontmake.ttx @@ -1829,6 +1829,10 @@ + + + + diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 5994cd3..ba93e6a 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -95,6 +95,7 @@ async def processGlyph(self, glyph: VariableGlyph) -> VariableGlyph: options: flatten-components: # no value destination: "output-fontmake.ttf" + addMinimalGaspTable: true """, "MutatorSans-fontmake.ttx", ),