From 73e7aad1c3e83d7c2e80eb9ce2ca6c97da248215 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Wed, 15 Mar 2023 16:18:47 +0000 Subject: [PATCH] Guard against missing avar entries --- Lib/fontTools/feaLib/builder.py | 3 ++- Tests/feaLib/builder_test.py | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index bee3711fb..0aa7a819c 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -1596,7 +1596,8 @@ class Builder(object): mapping = self.font["avar"].segments value = { axis: tuple( - piecewiseLinearMap(v, mapping[axis]) for v in condition_range + piecewiseLinearMap(v, mapping[axis]) if axis in mapping else v + for v in condition_range ) for axis, condition_range in value.items() } diff --git a/Tests/feaLib/builder_test.py b/Tests/feaLib/builder_test.py index 885e82384..abf4965b1 100644 --- a/Tests/feaLib/builder_test.py +++ b/Tests/feaLib/builder_test.py @@ -988,6 +988,7 @@ class BuilderTest(unittest.TestCase): conditionset test { wght 600 1000; + wdth 150 200; } test; variation rlig test { @@ -998,33 +999,40 @@ class BuilderTest(unittest.TestCase): def make_mock_vf(): font = makeTTFont() font["name"] = newTable("name") - addFvar(font, [("wght", 0, 0, 1000, "Weight")], []) + addFvar( + font, + [("wght", 0, 0, 1000, "Weight"), ("wdth", 100, 100, 200, "Width")], + [], + ) del font["name"] return font # Without `avar`: font = make_mock_vf() addOpenTypeFeaturesFromString(font, features) - assert ( + condition_table = ( font.tables["GSUB"] .table.FeatureVariations.FeatureVariationRecord[0] - .ConditionSet.ConditionTable[0] - .FilterRangeMinValue - == 0.6 # user-space 600 + .ConditionSet.ConditionTable ) + # user-space wdth=150 and wght=600: + assert condition_table[0].FilterRangeMinValue == 0.5 + assert condition_table[1].FilterRangeMinValue == 0.6 - # With `avar`, shifting the positive midpoint 0.5 a bit to the right: + # With `avar`, shifting the wght axis' positive midpoint 0.5 a bit to + # the right, but leaving the wdth axis alone: font = make_mock_vf() font["avar"] = newTable("avar") font["avar"].segments = {"wght": {-1.0: -1.0, 0.0: 0.0, 0.5: 0.625, 1.0: 1.0}} addOpenTypeFeaturesFromString(font, features) - assert ( + condition_table = ( font.tables["GSUB"] .table.FeatureVariations.FeatureVariationRecord[0] - .ConditionSet.ConditionTable[0] - .FilterRangeMinValue - == 0.7 # user-space 600 shifted to the right, + .ConditionSet.ConditionTable ) + # user-space wdth=150 as before and wght=600 shifted to the right: + assert condition_table[0].FilterRangeMinValue == 0.5 + assert condition_table[1].FilterRangeMinValue == 0.7 def generate_feature_file_test(name):