From d0de0e273d343553be19edf21e144df70b9661c5 Mon Sep 17 00:00:00 2001 From: Jany Belluz Date: Tue, 15 Mar 2022 14:20:56 +0000 Subject: [PATCH 1/3] Disable the GPOS optimization while building the VF masters --- Lib/ufo2ft/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Lib/ufo2ft/__init__.py b/Lib/ufo2ft/__init__.py index c80757ed8..696f6a5a6 100644 --- a/Lib/ufo2ft/__init__.py +++ b/Lib/ufo2ft/__init__.py @@ -1,7 +1,9 @@ import logging from enum import IntEnum +import os from fontTools import varLib +from fontTools.otlLib.optimize.gpos import GPOS_COMPACT_MODE_ENV_KEY from ufo2ft.constants import SPARSE_OTF_MASTER_TABLES, SPARSE_TTF_MASTER_TABLES from ufo2ft.featureCompiler import ( @@ -537,6 +539,9 @@ def compileVariableTTF(designSpaceDoc, **kwargs): excludeVariationTables = kwargs.pop("excludeVariationTables") optimizeGvar = kwargs.pop("optimizeGvar") + # Disable GPOS compaction while building masters because the compaction + # will be undone anyway by varLib merge and then done again on the VF + gpos_compact_value = os.environ.pop(GPOS_COMPACT_MODE_ENV_KEY, None) ttfDesignSpace = compileInterpolatableTTFsFromDS( designSpaceDoc, **{ @@ -548,6 +553,8 @@ def compileVariableTTF(designSpaceDoc, **kwargs): ), }, ) + if gpos_compact_value is not None: + os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value logger.info("Building variable TTF font") @@ -596,6 +603,9 @@ def compileVariableCFF2(designSpaceDoc, **kwargs): excludeVariationTables = kwargs.pop("excludeVariationTables") + # Disable GPOS compaction while building masters because the compaction + # will be undone anyway by varLib merge and then done again on the VF + gpos_compact_value = os.environ.pop(GPOS_COMPACT_MODE_ENV_KEY, None) otfDesignSpace = compileInterpolatableOTFsFromDS( designSpaceDoc, **{ @@ -607,6 +617,8 @@ def compileVariableCFF2(designSpaceDoc, **kwargs): ), }, ) + if gpos_compact_value is not None: + os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value logger.info("Building variable CFF2 font") From 1c887c9d0c81a6360a49f33295900c426d2577f2 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Wed, 16 Mar 2022 16:07:52 +0000 Subject: [PATCH 2/3] Restore env var even if exception occurs --- Lib/ufo2ft/__init__.py | 66 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/Lib/ufo2ft/__init__.py b/Lib/ufo2ft/__init__.py index 696f6a5a6..ae781b292 100644 --- a/Lib/ufo2ft/__init__.py +++ b/Lib/ufo2ft/__init__.py @@ -539,22 +539,25 @@ def compileVariableTTF(designSpaceDoc, **kwargs): excludeVariationTables = kwargs.pop("excludeVariationTables") optimizeGvar = kwargs.pop("optimizeGvar") - # Disable GPOS compaction while building masters because the compaction - # will be undone anyway by varLib merge and then done again on the VF + # FIXME: Hack until we get a fontTools config module. Disable GPOS + # compaction while building masters because the compaction will be undone + # anyway by varLib merge and then done again on the VF gpos_compact_value = os.environ.pop(GPOS_COMPACT_MODE_ENV_KEY, None) - ttfDesignSpace = compileInterpolatableTTFsFromDS( - designSpaceDoc, - **{ - **kwargs, - **dict( - useProductionNames=False, # will rename glyphs after varfont is built - # No need to post-process intermediate fonts. - postProcessorClass=None, - ), - }, - ) - if gpos_compact_value is not None: - os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value + try: + ttfDesignSpace = compileInterpolatableTTFsFromDS( + designSpaceDoc, + **{ + **kwargs, + **dict( + useProductionNames=False, # will rename glyphs after varfont is built + # No need to post-process intermediate fonts. + postProcessorClass=None, + ), + }, + ) + finally: + if gpos_compact_value is not None: + os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value logger.info("Building variable TTF font") @@ -603,22 +606,25 @@ def compileVariableCFF2(designSpaceDoc, **kwargs): excludeVariationTables = kwargs.pop("excludeVariationTables") - # Disable GPOS compaction while building masters because the compaction - # will be undone anyway by varLib merge and then done again on the VF + # FIXME: Hack until we get a fontTools config module. Disable GPOS + # compaction while building masters because the compaction will be undone + # anyway by varLib merge and then done again on the VF gpos_compact_value = os.environ.pop(GPOS_COMPACT_MODE_ENV_KEY, None) - otfDesignSpace = compileInterpolatableOTFsFromDS( - designSpaceDoc, - **{ - **kwargs, - **dict( - useProductionNames=False, # will rename glyphs after varfont is built - # No need to post-process intermediate fonts. - postProcessorClass=None, - ), - }, - ) - if gpos_compact_value is not None: - os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value + try: + otfDesignSpace = compileInterpolatableOTFsFromDS( + designSpaceDoc, + **{ + **kwargs, + **dict( + useProductionNames=False, # will rename glyphs after varfont is built + # No need to post-process intermediate fonts. + postProcessorClass=None, + ), + }, + ) + finally: + if gpos_compact_value is not None: + os.environ[GPOS_COMPACT_MODE_ENV_KEY] = gpos_compact_value logger.info("Building variable CFF2 font") From d9f08b361b0e3b6e62c7f36020e01e5009eabfa5 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Wed, 16 Mar 2022 16:39:46 +0000 Subject: [PATCH 3/3] Fix lint --- Lib/ufo2ft/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ufo2ft/__init__.py b/Lib/ufo2ft/__init__.py index ae781b292..9bd77f0db 100644 --- a/Lib/ufo2ft/__init__.py +++ b/Lib/ufo2ft/__init__.py @@ -1,6 +1,6 @@ import logging -from enum import IntEnum import os +from enum import IntEnum from fontTools import varLib from fontTools.otlLib.optimize.gpos import GPOS_COMPACT_MODE_ENV_KEY