From 4441fd023c1bc3649d765041c726aac690e8b4aa Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 23 Jun 2022 18:19:45 +0100 Subject: [PATCH 1/3] disable COLR layer reuse for interpolatable masters when building variable fonts To successfully merge multiple master COLR tables into a variable COLR with varLib (https://github.com/fonttools/fonttools/pull/2660) the master must have the same structure, number of color glyphs, total number of paints, etc. So we want to disable layer reuse optimization performed by fontTools.colorLib.buildCOLR when building each interpolatable COLR masters (otherwise we might end up with different PaintColrLayers or LayerList count between masters). I also added a colrLayerReuse parameter to compile* methods to force disabling this altogether, in case it might be useful for debugging or speeding up builds. This is set to True by default for all compile* methods, except for compileInterpolatable* Requires https://github.com/fonttools/fonttools/pull/2660 --- Lib/ufo2ft/__init__.py | 7 +++++++ Lib/ufo2ft/outlineCompiler.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Lib/ufo2ft/__init__.py b/Lib/ufo2ft/__init__.py index a3b1c5160..4295caaaf 100644 --- a/Lib/ufo2ft/__init__.py +++ b/Lib/ufo2ft/__init__.py @@ -98,6 +98,7 @@ def call_postprocessor(otf, ufo, glyphSet, *, postProcessorClass, **kwargs): skipExportGlyphs=None, debugFeatureFile=None, notdefGlyph=None, + colrLayerReuse=True, ) compileOTF_args = { @@ -258,6 +259,7 @@ def compileTTF(ufo, **kwargs): reverseDirection=True, flattenComponents=False, layerNames=None, + colrLayerReuse=False, ), } @@ -392,6 +394,7 @@ def compileInterpolatableTTFsFromDS(designSpaceDoc, **kwargs): featureCompilerClass=None, roundTolerance=None, optimizeCFF=CFFOptimization.NONE, + colrLayerReuse=False, ), } @@ -582,6 +585,7 @@ def compileVariableTTFs(designSpaceDoc: DesignSpaceDocument, **kwargs): optimizeGvar = kwargs.pop("optimizeGvar") excludeVariationTables = kwargs.pop("excludeVariationTables") variableFontNames = kwargs.pop("variableFontNames") + colrLayerReuse = kwargs.pop("colrLayerReuse") # Pop inplace because we'll make a copy at this level so deeper functions # don't need to worry @@ -603,6 +607,7 @@ def compileVariableTTFs(designSpaceDoc: DesignSpaceDocument, **kwargs): exclude=excludeVariationTables, optimize=optimizeGvar, skip_vf=lambda vf_name: variableFontNames and vf_name not in variableFontNames, + colr_layer_reuse=colrLayerReuse, ) for vfName, varfont in list(vfNameToTTFont.items()): @@ -692,6 +697,7 @@ def compileVariableCFF2s(designSpaceDoc, **kwargs): excludeVariationTables = kwargs.pop("excludeVariationTables") optimizeCFF = CFFOptimization(kwargs.pop("optimizeCFF")) variableFontNames = kwargs.pop("variableFontNames") + colrLayerReuse = kwargs.pop("colrLayerReuse") # Pop inplace because we'll make a copy at this level so deeper functions # don't need to worry @@ -716,6 +722,7 @@ def compileVariableCFF2s(designSpaceDoc, **kwargs): # https://github.com/fonttools/fonttools/pull/1979 optimize=optimizeCFF >= CFFOptimization.SPECIALIZE, skip_vf=lambda vf_name: variableFontNames and vf_name not in variableFontNames, + colr_layer_reuse=colrLayerReuse, ) for vfName, varfont in list(vfNameToTTFont.items()): diff --git a/Lib/ufo2ft/outlineCompiler.py b/Lib/ufo2ft/outlineCompiler.py index 722220a74..424f70689 100644 --- a/Lib/ufo2ft/outlineCompiler.py +++ b/Lib/ufo2ft/outlineCompiler.py @@ -94,7 +94,13 @@ class BaseOutlineCompiler: ) def __init__( - self, font, glyphSet=None, glyphOrder=None, tables=None, notdefGlyph=None + self, + font, + glyphSet=None, + glyphOrder=None, + tables=None, + notdefGlyph=None, + colrLayerReuse=True, ): self.ufo = font # use the previously filtered glyphSet, if any @@ -110,6 +116,7 @@ def __init__( self.unicodeToGlyphNameMapping = self.makeUnicodeToGlyphNameMapping() if tables is not None: self.tables = tables + self.colrLayerReuse = colrLayerReuse # cached values defined later on self._glyphBoundingBoxes = None self._fontBoundingBox = None @@ -967,6 +974,7 @@ def setupTable_COLR(self): layerInfo, glyphMap=glyphMap, clipBoxes=clipBoxes, + allowLayerReuse=self.colrLayerReuse, ) def setupTable_CPAL(self): From 3321ca6e52f0ccaf41aae3b7aa82ad6413a24dd7 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Wed, 6 Jul 2022 12:07:21 +0100 Subject: [PATCH 2/3] require fonttools 4.34 with variable COLR support --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index c4113ed14..0abfb0ff0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -fonttools[lxml,ufo]==4.33.3 +fonttools[lxml,ufo]==4.34.0 defcon==0.10.0 cu2qu==1.6.7.post1 compreffor==0.5.1.post1 diff --git a/setup.py b/setup.py index 968d88aab..d8d998204 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup_requires=pytest_runner + wheel + ["setuptools_scm"], tests_require=["pytest>=2.8"], install_requires=[ - "fonttools[ufo]>=4.33.3", + "fonttools[ufo]>=4.34.0", "cu2qu>=1.6.7", "cffsubr>=0.2.8", "booleanOperations>=0.9.0", From c57e29a971a99b0783a48c26483b85120596f83d Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Wed, 6 Jul 2022 12:11:37 +0100 Subject: [PATCH 3/3] markFeatureWriter.py: mute flake8 B023 --- Lib/ufo2ft/featureWriters/markFeatureWriter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ufo2ft/featureWriters/markFeatureWriter.py b/Lib/ufo2ft/featureWriters/markFeatureWriter.py index 473541e48..6e4154d08 100644 --- a/Lib/ufo2ft/featureWriters/markFeatureWriter.py +++ b/Lib/ufo2ft/featureWriters/markFeatureWriter.py @@ -559,7 +559,7 @@ def _groupAttachments(self, attachments): # We keep the NamedAnchor if the markClass is allowed in the # current lookup. def include(anchor): - return anchor.markClass.name in markClasses + return anchor.markClass.name in markClasses # noqa: B023 filteredAttachment = attachment.filter(include) if filteredAttachment: