From 10d544d6a451616f6dfdb6ec284aadc1f8d86e0d Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 17 Oct 2019 19:03:30 +0100 Subject: [PATCH] instancer_test: update tests for instantiateSTAT new behavior And add tests for limiting STAT's axis ranges. --- .../varLib/data/PartialInstancerTest2-VF.ttx | 133 +++++++++++++++--- ...tialInstancerTest2-VF-instance-100,100.ttx | 64 ++++++++- ...ialInstancerTest2-VF-instance-100,62.5.ttx | 64 ++++++++- ...tialInstancerTest2-VF-instance-400,100.ttx | 59 +++++++- ...ialInstancerTest2-VF-instance-400,62.5.ttx | 65 ++++++++- ...tialInstancerTest2-VF-instance-900,100.ttx | 64 ++++++++- ...ialInstancerTest2-VF-instance-900,62.5.ttx | 64 ++++++++- Tests/varLib/instancer_test.py | 115 ++++++++++++--- 8 files changed, 578 insertions(+), 50 deletions(-) diff --git a/Tests/varLib/data/PartialInstancerTest2-VF.ttx b/Tests/varLib/data/PartialInstancerTest2-VF.ttx index 0f19bde35..ca9231d87 100644 --- a/Tests/varLib/data/PartialInstancerTest2-VF.ttx +++ b/Tests/varLib/data/PartialInstancerTest2-VF.ttx @@ -1,5 +1,5 @@ - + @@ -14,16 +14,16 @@ - + - - - - - + + + + + @@ -36,10 +36,10 @@ - - - - + + + + @@ -55,10 +55,10 @@ - - - - + + + + @@ -66,8 +66,8 @@ - - + + @@ -107,8 +107,8 @@ - - + + @@ -1037,15 +1037,104 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,100.ttx b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,100.ttx index c64049fed..56b5623f8 100644 --- a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,100.ttx +++ b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,100.ttx @@ -14,12 +14,12 @@ - + - + @@ -238,6 +238,18 @@ + + Weight + + + Width + + + Thin + + + Regular + Copyright 2015 Google Inc. All Rights Reserved. @@ -283,6 +295,18 @@ http://scripts.sil.org/OFL + + Weight + + + Width + + + Thin + + + Regular + @@ -481,4 +505,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,62.5.ttx b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,62.5.ttx index 87d0c65c7..d220e1563 100644 --- a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,62.5.ttx +++ b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-100,62.5.ttx @@ -14,12 +14,12 @@ - + - + @@ -238,6 +238,18 @@ + + Weight + + + Width + + + Thin + + + ExtraCondensed + Copyright 2015 Google Inc. All Rights Reserved. @@ -283,6 +295,18 @@ http://scripts.sil.org/OFL + + Weight + + + Width + + + Thin + + + ExtraCondensed + @@ -481,4 +505,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,100.ttx b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,100.ttx index fc64365eb..b71369e8c 100644 --- a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,100.ttx +++ b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,100.ttx @@ -14,12 +14,12 @@ - + - + @@ -238,6 +238,15 @@ + + Weight + + + Width + + + Regular + Copyright 2015 Google Inc. All Rights Reserved. @@ -283,6 +292,15 @@ http://scripts.sil.org/OFL + + Weight + + + Width + + + Regular + @@ -481,4 +499,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,62.5.ttx b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,62.5.ttx index 9b40106fe..9db3e8625 100644 --- a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,62.5.ttx +++ b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-400,62.5.ttx @@ -14,12 +14,12 @@ - + - + @@ -238,6 +238,18 @@ + + Weight + + + Width + + + Regular + + + ExtraCondensed + Copyright 2015 Google Inc. All Rights Reserved. @@ -283,6 +295,18 @@ http://scripts.sil.org/OFL + + Weight + + + Width + + + Regular + + + ExtraCondensed + @@ -481,4 +505,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,100.ttx b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,100.ttx index 8f8517960..6ae729b19 100644 --- a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,100.ttx +++ b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,100.ttx @@ -14,12 +14,12 @@ - + - + @@ -238,6 +238,18 @@ + + Weight + + + Width + + + Regular + + + Black + Copyright 2015 Google Inc. All Rights Reserved. @@ -283,6 +295,18 @@ http://scripts.sil.org/OFL + + Weight + + + Width + + + Regular + + + Black + @@ -481,4 +505,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,62.5.ttx b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,62.5.ttx index bc8c7e9a6..7c923e415 100644 --- a/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,62.5.ttx +++ b/Tests/varLib/data/test_results/PartialInstancerTest2-VF-instance-900,62.5.ttx @@ -14,12 +14,12 @@ - + - + @@ -238,6 +238,18 @@ + + Weight + + + Width + + + Black + + + ExtraCondensed + Copyright 2015 Google Inc. All Rights Reserved. @@ -283,6 +295,18 @@ http://scripts.sil.org/OFL + + Weight + + + Width + + + Black + + + ExtraCondensed + @@ -481,4 +505,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/instancer_test.py b/Tests/varLib/instancer_test.py index 84a1b9795..c1779240d 100644 --- a/Tests/varLib/instancer_test.py +++ b/Tests/varLib/instancer_test.py @@ -1189,7 +1189,7 @@ class InstantiateSTATTest(object): @pytest.mark.parametrize( "location, expected", [ - ({"wght": 400}, ["Condensed", "Upright"]), + ({"wght": 400}, ["Regular", "Condensed", "Upright"]), ({"wdth": 100}, ["Thin", "Regular", "Black", "Upright"]), ], ) @@ -1199,7 +1199,7 @@ class InstantiateSTATTest(object): stat = varfont["STAT"].table designAxes = {a.AxisTag for a in stat.DesignAxisRecord.Axis} - assert designAxes == {"wght", "wdth", "ital"}.difference(location) + assert designAxes == {"wght", "wdth", "ital"} name = varfont["name"] valueNames = [] @@ -1209,7 +1209,23 @@ class InstantiateSTATTest(object): assert valueNames == expected - def test_skip_empty_table(self, varfont): + def test_skip_table_no_axis_value_array(self, varfont): + varfont["STAT"].table.AxisValueArray = None + + instancer.instantiateSTAT(varfont, {"wght": 100}) + + assert len(varfont["STAT"].table.DesignAxisRecord.Axis) == 3 + assert varfont["STAT"].table.AxisValueArray is None + + def test_skip_table_axis_value_array_empty(self, varfont): + varfont["STAT"].table.AxisValueArray.AxisValue = [] + + instancer.instantiateSTAT(varfont, {"wght": 100}) + + assert len(varfont["STAT"].table.DesignAxisRecord.Axis) == 3 + assert not varfont["STAT"].table.AxisValueArray.AxisValue + + def test_skip_table_no_design_axes(self, varfont): stat = otTables.STAT() stat.Version = 0x00010001 stat.populateDefaults() @@ -1221,21 +1237,88 @@ class InstantiateSTATTest(object): assert not varfont["STAT"].table.DesignAxisRecord - def test_drop_table(self, varfont): - stat = otTables.STAT() - stat.Version = 0x00010001 - stat.populateDefaults() - stat.DesignAxisRecord = otTables.AxisRecordArray() - axis = otTables.AxisRecord() - axis.AxisTag = "wght" - axis.AxisNameID = 0 - axis.AxisOrdering = 0 - stat.DesignAxisRecord.Axis = [axis] - varfont["STAT"].table = stat + @staticmethod + def get_STAT_axis_values(stat): + axes = stat.DesignAxisRecord.Axis + result = [] + for axisValue in stat.AxisValueArray.AxisValue: + if axisValue.Format == 1: + result.append((axes[axisValue.AxisIndex].AxisTag, axisValue.Value)) + elif axisValue.Format == 3: + result.append( + ( + axes[axisValue.AxisIndex].AxisTag, + (axisValue.Value, axisValue.LinkedValue), + ) + ) + elif axisValue.Format == 2: + result.append( + ( + axes[axisValue.AxisIndex].AxisTag, + ( + axisValue.RangeMinValue, + axisValue.NominalValue, + axisValue.RangeMaxValue, + ), + ) + ) + elif axisValue.Format == 4: + result.append( + tuple( + (axes[rec.AxisIndex].AxisTag, rec.Value) + for rec in axisValue.AxisValueRecord + ) + ) + else: + raise AssertionError(axisValue.Format) + return result - instancer.instantiateSTAT(varfont, {"wght": 100}) + def test_limit_axes(self, varfont2): + instancer.instantiateSTAT(varfont2, {"wght": (400, 500), "wdth": (75, 100)}) - assert "STAT" not in varfont + assert len(varfont2["STAT"].table.AxisValueArray.AxisValue) == 5 + assert self.get_STAT_axis_values(varfont2["STAT"].table) == [ + ("wght", (400.0, 700.0)), + ("wght", 500.0), + ("wdth", (93.75, 100.0, 100.0)), + ("wdth", (81.25, 87.5, 93.75)), + ("wdth", (68.75, 75.0, 81.25)), + ] + + def test_limit_axis_value_format_4(self, varfont2): + stat = varfont2["STAT"].table + + axisValue = otTables.AxisValue() + axisValue.Format = 4 + axisValue.AxisValueRecord = [] + for tag, value in (("wght", 575), ("wdth", 90)): + rec = otTables.AxisValueRecord() + rec.AxisIndex = next( + i for i, a in enumerate(stat.DesignAxisRecord.Axis) if a.AxisTag == tag + ) + rec.Value = value + axisValue.AxisValueRecord.append(rec) + stat.AxisValueArray.AxisValue.append(axisValue) + + instancer.instantiateSTAT(varfont2, {"wght": (100, 600)}) + + assert axisValue in varfont2["STAT"].table.AxisValueArray.AxisValue + + instancer.instantiateSTAT(varfont2, {"wdth": (62.5, 87.5)}) + + assert axisValue not in varfont2["STAT"].table.AxisValueArray.AxisValue + + def test_unknown_axis_value_format(self, varfont2, caplog): + stat = varfont2["STAT"].table + axisValue = otTables.AxisValue() + axisValue.Format = 5 + stat.AxisValueArray.AxisValue.append(axisValue) + + with caplog.at_level(logging.WARNING, logger="fontTools.varLib.instancer"): + instancer.instantiateSTAT(varfont2, {"wght": 400}) + + assert "Unknown AxisValue table format (5)" in caplog.text + assert axisValue in varfont2["STAT"].table.AxisValueArray.AxisValue def test_pruningUnusedNames(varfont):