diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index f8b6a33b0..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,9 +708,13 @@ class Builder(object): continue for ix in lookup_indices: - self.lookup_locations[tag][str(ix)] = self.lookup_locations[tag][ - str(ix) - ]._replace(feature=key) + 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) 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/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 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.