From 45a8fcefc24b2d08c706d50688485f36ec69d212 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Fri, 15 May 2020 17:27:15 +0100 Subject: [PATCH] [varLib] Allow feature variations to be active across the entire space (#1957) * Allow feature variations to be active across the entire space * Add test with empty condition set * Skip initial box instead of removing it * Correct comment --- Lib/fontTools/varLib/featureVars.py | 5 +- .../data/FeatureVarsWholeRange.designspace | 34 +++++++++ .../FeatureVarsWholeRangeEmpty.designspace | 33 ++++++++ .../test_results/FeatureVarsWholeRange.ttx | 75 +++++++++++++++++++ Tests/varLib/varLib_test.py | 24 ++++++ 5 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 Tests/varLib/data/FeatureVarsWholeRange.designspace create mode 100644 Tests/varLib/data/FeatureVarsWholeRangeEmpty.designspace create mode 100644 Tests/varLib/data/test_results/FeatureVarsWholeRange.ttx diff --git a/Lib/fontTools/varLib/featureVars.py b/Lib/fontTools/varLib/featureVars.py index dab9a0b1c..76e8cc4af 100644 --- a/Lib/fontTools/varLib/featureVars.py +++ b/Lib/fontTools/varLib/featureVars.py @@ -82,6 +82,7 @@ def overlayFeatureVariations(conditionalSubstitutions): ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}), ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}), ... ([{"wdth": (0.5, 1.0)}], {"cent": "cent.rvrn"}), + ... ([{"wght": (0.5, 1.0), "wdth": (-1, 1.0)}], {"dollar": "dollar.rvrn"}), ... ] >>> from pprint import pprint >>> pprint(overlayFeatureVariations(condSubst)) @@ -136,12 +137,14 @@ def overlayFeatureVariations(conditionalSubstitutions): remainder = hashdict(remainder) newMap[remainder] = newMap.get(remainder, 0) | rank boxMap = newMap - del boxMap[hashdict()] # Generate output items = [] for box,rank in sorted(boxMap.items(), key=(lambda BoxAndRank: -popCount(BoxAndRank[1]))): + # Skip any box that doesn't have any substitution. + if rank == 0: + continue substsList = [] i = 0 while rank: diff --git a/Tests/varLib/data/FeatureVarsWholeRange.designspace b/Tests/varLib/data/FeatureVarsWholeRange.designspace new file mode 100644 index 000000000..2d8802cfe --- /dev/null +++ b/Tests/varLib/data/FeatureVarsWholeRange.designspace @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/FeatureVarsWholeRangeEmpty.designspace b/Tests/varLib/data/FeatureVarsWholeRangeEmpty.designspace new file mode 100644 index 000000000..a692daa62 --- /dev/null +++ b/Tests/varLib/data/FeatureVarsWholeRangeEmpty.designspace @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/FeatureVarsWholeRange.ttx b/Tests/varLib/data/test_results/FeatureVarsWholeRange.ttx new file mode 100644 index 000000000..8e098b9bd --- /dev/null +++ b/Tests/varLib/data/test_results/FeatureVarsWholeRange.ttx @@ -0,0 +1,75 @@ + + + + + + + + wght + 0x0 + 0.0 + 368.0 + 1000.0 + 256 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/varLib_test.py b/Tests/varLib/varLib_test.py index 2c95784ac..5d36d6871 100644 --- a/Tests/varLib/varLib_test.py +++ b/Tests/varLib/varLib_test.py @@ -218,6 +218,30 @@ class BuildTest(unittest.TestCase): 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. + """ + self._run_varlib_build_test( + designspace_name="FeatureVarsWholeRange", + font_name="TestFamily", + tables=["fvar", "GSUB"], + expected_ttx_name="FeatureVarsWholeRange", + save_before_dump=True, + ) + + def test_varlib_build_feature_variations_whole_range_empty(self): + """Designspace file contains element without a condition, specifying + the entire design space, used to build GSUB FeatureVariations table. + """ + self._run_varlib_build_test( + designspace_name="FeatureVarsWholeRangeEmpty", + font_name="TestFamily", + tables=["fvar", "GSUB"], + expected_ttx_name="FeatureVarsWholeRange", + save_before_dump=True, + ) + def test_varlib_build_feature_variations_with_existing_rclt(self): """Designspace file contains element, used to build GSUB FeatureVariations table. is specified to do its OT processing