From 2a1e6a1fd56d2c175d8ca594a6b8449760e0c855 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sat, 20 Apr 2019 19:24:30 +0100 Subject: [PATCH] instancer_test: test instancing HVAR table Aldo added AdvWidthMap to PartialInstancer-VF.ttx test font --- Tests/varLib/data/PartialInstancerTest-VF.ttx | 18 +++--- Tests/varLib/instancer_test.py | 56 +++++++++++++++++++ 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/Tests/varLib/data/PartialInstancerTest-VF.ttx b/Tests/varLib/data/PartialInstancerTest-VF.ttx index 30d00b96b..712e2c94a 100644 --- a/Tests/varLib/data/PartialInstancerTest-VF.ttx +++ b/Tests/varLib/data/PartialInstancerTest-VF.ttx @@ -1,5 +1,5 @@ - + @@ -12,12 +12,12 @@ - + - + @@ -570,7 +570,7 @@ - + @@ -578,11 +578,15 @@ - - - + + + + + + + diff --git a/Tests/varLib/instancer_test.py b/Tests/varLib/instancer_test.py index aa5c1177a..99e4b6db7 100644 --- a/Tests/varLib/instancer_test.py +++ b/Tests/varLib/instancer_test.py @@ -277,6 +277,62 @@ class InstantiateMVARTest(object): assert "MVAR" not in varfont +class InstantiateHVARTest(object): + # the 'expectedDeltas' below refer to the VarData item deltas for the "hyphen" + # glyph in the PartialInstancerTest-VF.ttx test font, that are left after + # partial instancing + @pytest.mark.parametrize( + "location, expectedRegions, expectedDeltas", + [ + ({"wght": -1.0}, [{"wdth": (-1.0, -1.0, 0)}], [-59]), + ({"wght": 0}, [{"wdth": (-1.0, -1.0, 0)}], [-48]), + ({"wght": 1.0}, [{"wdth": (-1.0, -1.0, 0)}], [7]), + ( + {"wdth": -1.0}, + [ + {"wght": (-1.0, -1.0, 0.0)}, + {"wght": (0.0, 0.61, 1.0)}, + {"wght": (0.61, 1.0, 1.0)}, + ], + [-11, 31, 51], + ), + ({"wdth": 0}, [{"wght": (0.61, 1.0, 1.0)}], [-4]), + ], + ) + def test_partial_instance( + self, varfont, fvarAxes, location, expectedRegions, expectedDeltas + ): + instancer.instantiateHVAR(varfont, location) + + assert "HVAR" in varfont + hvar = varfont["HVAR"].table + varStore = hvar.VarStore + + regions = varStore.VarRegionList.Region + assert [reg.get_support(fvarAxes) for reg in regions] == expectedRegions + + assert len(varStore.VarData) == 1 + assert varStore.VarData[0].ItemCount == 2 + + assert hvar.AdvWidthMap is not None + advWithMap = hvar.AdvWidthMap.mapping + + assert advWithMap[".notdef"] == advWithMap["space"] + varIdx = advWithMap[".notdef"] + # these glyphs have no metrics variations in the test font + assert varStore.VarData[varIdx >> 16].Item[varIdx & 0xFFFF] == ( + [0] * varStore.VarData[0].VarRegionCount + ) + + varIdx = advWithMap["hyphen"] + assert varStore.VarData[varIdx >> 16].Item[varIdx & 0xFFFF] == expectedDeltas + + def test_full_instance(self, varfont): + instancer.instantiateHVAR(varfont, {"wght": 0, "wdth": 0}) + + assert "HVAR" not in varfont + + class InstantiateItemVariationStoreTest(object): def test_VarRegion_get_support(self): axisOrder = ["wght", "wdth", "opsz"]