From dafce3ff4676ee2e7bbacb26d0f1ddabd90db5fd Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 25 May 2021 12:30:35 +0100 Subject: [PATCH 1/2] instancer_test: add test with PairPos ValueRecord with XAdvDevice but no XAdvance this currently raises AttributeError in MutatorMerger.merge for ValueRecord table, because the latter assumes that whenever one of the Device tables are present the respective non-device values are also present, but they may be omitted (and it should default to 0 when missing) --- .../data/PartialInstancerTest4-VF.ttx | 463 ++++++++++++++++++ Tests/varLib/instancer/instancer_test.py | 24 + 2 files changed, 487 insertions(+) create mode 100644 Tests/varLib/instancer/data/PartialInstancerTest4-VF.ttx diff --git a/Tests/varLib/instancer/data/PartialInstancerTest4-VF.ttx b/Tests/varLib/instancer/data/PartialInstancerTest4-VF.ttx new file mode 100644 index 000000000..8d445b019 --- /dev/null +++ b/Tests/varLib/instancer/data/PartialInstancerTest4-VF.ttx @@ -0,0 +1,463 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Weight + + + Regular + + + Bold + + + New Font + + + Regular + + + 1.000;NONE;NewFont-Regular + + + New Font Regular + + + Version 1.000 + + + NewFont-Regular + + + Weight + + + Regular + + + Bold + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wght + 0x0 + 400.0 + 400.0 + 700.0 + 256 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/instancer/instancer_test.py b/Tests/varLib/instancer/instancer_test.py index cb7e8547a..90048c181 100644 --- a/Tests/varLib/instancer/instancer_test.py +++ b/Tests/varLib/instancer/instancer_test.py @@ -936,6 +936,30 @@ class InstantiateOTLTest(object): assert not hasattr(valueRec1, "XAdvDevice") assert valueRec1.XAdvance == v2 + def test_GPOS_ValueRecord_XAdvDevice_wtihout_XAdvance(self): + # Test VF contains a PairPos adjustment in which the default instance + # has no XAdvance but there are deltas in XAdvDevice (VariationIndex). + vf = ttLib.TTFont() + vf.importXML(os.path.join(TESTDATA, "PartialInstancerTest4-VF.ttx")) + pairPos = vf["GPOS"].table.LookupList.Lookup[0].SubTable[0] + assert pairPos.ValueFormat1 == 0x40 + valueRec1 = pairPos.PairSet[0].PairValueRecord[0].Value1 + assert not hasattr(valueRec1, "XAdvance") + assert valueRec1.XAdvDevice.DeltaFormat == 0x8000 + outer = valueRec1.XAdvDevice.StartSize + inner = valueRec1.XAdvDevice.EndSize + assert vf["GDEF"].table.VarStore.VarData[outer].Item[inner] == [-50] + + # check that MutatorMerger for ValueRecord doesn't raise AttributeError + # when XAdvDevice is present but there's no corresponding XAdvance. + instancer.instantiateOTL(vf, {"wght": 0.5}) + + pairPos = vf["GPOS"].table.LookupList.Lookup[0].SubTable[0] + assert pairPos.ValueFormat1 == 0x4 + valueRec1 = pairPos.PairSet[0].PairValueRecord[0].Value1 + assert not hasattr(valueRec1, "XAdvDevice") + assert valueRec1.XAdvance == -25 + class InstantiateAvarTest(object): @pytest.mark.parametrize("location", [{"wght": 0.0}, {"wdth": 0.0}]) From b8ce99962c96a5cbe2fa319e92cb4889f8045162 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 25 May 2021 12:36:17 +0100 Subject: [PATCH 2/2] [merger] make getattr(valueRecord, *) default to 0 if it has Device tables but corresponding value is not set Fixes https://github.com/fonttools/fonttools/pull/2323 --- Lib/fontTools/varLib/merger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/fontTools/varLib/merger.py b/Lib/fontTools/varLib/merger.py index 77d2ea7ef..888b52c26 100644 --- a/Lib/fontTools/varLib/merger.py +++ b/Lib/fontTools/varLib/merger.py @@ -993,7 +993,7 @@ def merge(merger, self, lst): varidx = (dev.StartSize << 16) + dev.EndSize delta = otRound(instancer[varidx]) - setattr(self, name, getattr(self, name) + delta) + setattr(self, name, getattr(self, name, 0) + delta) #