From 8ed77926826fc68d07194929da1a9a2821ae535c Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Wed, 23 Sep 2020 10:10:38 +0100 Subject: [PATCH 1/4] Only stash lookup location if buildLookups_ has cooperated Fixes #2065 --- Lib/fontTools/feaLib/builder.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index f8b6a33b0..f71a77310 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -707,9 +707,10 @@ class Builder(object): continue for ix in lookup_indices: - self.lookup_locations[tag][str(ix)] = self.lookup_locations[tag][ - str(ix) - ]._replace(feature=key) + if str(ix) in self.lookup_locations[tag]: + self.lookup_locations[tag][str(ix)] = self.lookup_locations[tag][ + str(ix) + ]._replace(feature=key) feature_key = (feature_tag, lookup_indices) feature_index = feature_indices.get(feature_key) From b992e2837473497e9168153db602862dcc2787f9 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Thu, 8 Oct 2020 14:21:42 +0200 Subject: [PATCH 2/4] [varLib] Add designspace lib key for custom feavar feature tag (#2080) * Add designspace lib key to specify a custom feature tag for feature variations, as discussed in #2079 * Added comment for the lib key * if the lib key is present, the 'processing' flag should be ignored completely --- Lib/fontTools/varLib/__init__.py | 18 +- .../data/FeatureVarsCustomTag.designspace | 77 ++++++++ .../test_results/FeatureVarsCustomTag.ttx | 180 ++++++++++++++++++ Tests/varLib/varLib_test.py | 12 ++ 4 files changed, 281 insertions(+), 6 deletions(-) create mode 100644 Tests/varLib/data/FeatureVarsCustomTag.designspace create mode 100644 Tests/varLib/data/test_results/FeatureVarsCustomTag.ttx diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index e491ce239..95cd9b6e9 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -43,6 +43,10 @@ from .errors import VarLibError, VarLibValidationError log = logging.getLogger("fontTools.varLib") +# This is a lib key for the designspace document. The value should be +# an OpenType feature tag, to be used as the FeatureVariations feature. +# If present, the DesignSpace flag is ignored. +FEAVAR_FEATURETAG_LIB_KEY = "com.github.fonttools.varLib.featureVarsFeatureTag" # # Creation routines @@ -629,7 +633,7 @@ def _merge_OTL(font, model, master_fonts, axisTags): font['GPOS'].table.remap_device_varidxes(varidx_map) -def _add_GSUB_feature_variations(font, axes, internal_axis_supports, rules, rulesProcessingLast): +def _add_GSUB_feature_variations(font, axes, internal_axis_supports, rules, featureTag): def normalize(name, value): return models.normalizeLocation( @@ -664,10 +668,6 @@ def _add_GSUB_feature_variations(font, axes, internal_axis_supports, rules, rule conditional_subs.append((region, subs)) - if rulesProcessingLast: - featureTag = 'rclt' - else: - featureTag = 'rvrn' addFeatureVariations(font, conditional_subs, featureTag) @@ -682,6 +682,7 @@ _DesignSpaceData = namedtuple( "instances", "rules", "rulesProcessingLast", + "lib", ], ) @@ -811,6 +812,7 @@ def load_designspace(designspace): instances, ds.rules, ds.rulesProcessingLast, + ds.lib, ) @@ -917,7 +919,11 @@ def build(designspace, master_finder=lambda s:s, exclude=[], optimize=True): if 'cvar' not in exclude and 'glyf' in vf: _merge_TTHinting(vf, model, master_fonts) if 'GSUB' not in exclude and ds.rules: - _add_GSUB_feature_variations(vf, ds.axes, ds.internal_axis_supports, ds.rules, ds.rulesProcessingLast) + featureTag = ds.lib.get( + FEAVAR_FEATURETAG_LIB_KEY, + "rclt" if ds.rulesProcessingLast else "rvrn" + ) + _add_GSUB_feature_variations(vf, ds.axes, ds.internal_axis_supports, ds.rules, featureTag) if 'CFF2' not in exclude and ('CFF ' in vf or 'CFF2' in vf): _add_CFF2(vf, model, master_fonts) if "post" in vf: diff --git a/Tests/varLib/data/FeatureVarsCustomTag.designspace b/Tests/varLib/data/FeatureVarsCustomTag.designspace new file mode 100644 index 000000000..45b06f30c --- /dev/null +++ b/Tests/varLib/data/FeatureVarsCustomTag.designspace @@ -0,0 +1,77 @@ + + + + + + Contrast + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.github.fonttools.varLib.featureVarsFeatureTag + calt + + + diff --git a/Tests/varLib/data/test_results/FeatureVarsCustomTag.ttx b/Tests/varLib/data/test_results/FeatureVarsCustomTag.ttx new file mode 100644 index 000000000..f50ef785a --- /dev/null +++ b/Tests/varLib/data/test_results/FeatureVarsCustomTag.ttx @@ -0,0 +1,180 @@ + + + + + + + + wght + 0x0 + 0.0 + 368.0 + 1000.0 + 256 + + + + + cntr + 0x0 + 0.0 + 0.0 + 100.0 + 257 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/varLib_test.py b/Tests/varLib/varLib_test.py index 42e04bd9c..dfc10c34f 100644 --- a/Tests/varLib/varLib_test.py +++ b/Tests/varLib/varLib_test.py @@ -221,6 +221,18 @@ class BuildTest(unittest.TestCase): save_before_dump=True, ) + def test_varlib_build_feature_variations_custom_tag(self): + """Designspace file contains element, used to build + GSUB FeatureVariations table. + """ + self._run_varlib_build_test( + designspace_name="FeatureVarsCustomTag", + font_name="TestFamily", + tables=["fvar", "GSUB"], + expected_ttx_name="FeatureVarsCustomTag", + save_before_dump=True, + ) + def test_varlib_build_feature_variations_whole_range(self): """Designspace file contains element specifying the entire design space, used to build GSUB FeatureVariations table. From 16e058fe9742024d77681ad9151b04abec51a2b6 Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Fri, 9 Oct 2020 09:33:47 +0200 Subject: [PATCH 3/4] Test for 0xFFFF, not 0xFFF, fixes #2073 --- Lib/fontTools/varLib/varStore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/fontTools/varLib/varStore.py b/Lib/fontTools/varLib/varStore.py index 3d9566a1c..b28d2a657 100644 --- a/Lib/fontTools/varLib/varStore.py +++ b/Lib/fontTools/varLib/varStore.py @@ -68,7 +68,7 @@ class OnlineVarStoreBuilder(object): self._outer = varDataIdx self._data = self._store.VarData[varDataIdx] self._cache = self._varDataCaches[key] - if len(self._data.Item) == 0xFFF: + if len(self._data.Item) == 0xFFFF: # This is full. Need new one. varDataIdx = None From 0c9cb3a87806f5d51f1508d353bc6c389ec2eee2 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sun, 18 Oct 2020 11:21:49 +0100 Subject: [PATCH 4/4] Warn developer if subclass needs upgrading --- Lib/fontTools/feaLib/builder.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index f71a77310..6baaeeb24 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -30,6 +30,7 @@ from fontTools.otlLib.error import OpenTypeLibError from collections import defaultdict import itertools import logging +import warnings log = logging.getLogger(__name__) @@ -707,10 +708,13 @@ class Builder(object): continue for ix in lookup_indices: - if str(ix) in self.lookup_locations[tag]: + try: self.lookup_locations[tag][str(ix)] = self.lookup_locations[tag][ str(ix) ]._replace(feature=key) + except KeyError: + warnings.warn("feaLib.Builder subclass needs upgrading to " + "stash debug information. See fonttools#2065.") feature_key = (feature_tag, lookup_indices) feature_index = feature_indices.get(feature_key)