From 6d915fc81691965323d0a9c8c41b9eec1e846d65 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 14 May 2024 11:57:49 -0600 Subject: [PATCH] [instancer/CFF2] Add test --- Lib/fontTools/varLib/instancer/__init__.py | 6 +- .../instancer/data/CFF2Instancer-VF.ttx | 729 ++++++++++++++++++ Tests/varLib/instancer/instancer_test.py | 44 ++ 3 files changed, 775 insertions(+), 4 deletions(-) create mode 100644 Tests/varLib/instancer/data/CFF2Instancer-VF.ttx diff --git a/Lib/fontTools/varLib/instancer/__init__.py b/Lib/fontTools/varLib/instancer/__init__.py index bc6b25867..0bdb494b9 100644 --- a/Lib/fontTools/varLib/instancer/__init__.py +++ b/Lib/fontTools/varLib/instancer/__init__.py @@ -588,10 +588,6 @@ def instantiateCFF2( cff.desubroutinize() - assert ( - varStore is topDict.CharStrings.varStore.otVarStore - ) # Who knows why it's in two places?! - def getNumRegions(vsindex): return varStore.VarData[vsindex if vsindex is not None else 0].VarRegionCount @@ -1182,6 +1178,8 @@ def instantiateItemVariationStore(itemVarStore, fvarAxes, axisLimits): newItemVarStore = tupleVarStore.asItemVarStore() itemVarStore.VarRegionList = newItemVarStore.VarRegionList + if not hasattr(itemVarStore, "VarDataCount"): # Happens fromXML + itemVarStore.VarDataCount = len(newItemVarStore.VarData) assert itemVarStore.VarDataCount == newItemVarStore.VarDataCount itemVarStore.VarData = newItemVarStore.VarData diff --git a/Tests/varLib/instancer/data/CFF2Instancer-VF.ttx b/Tests/varLib/instancer/data/CFF2Instancer-VF.ttx new file mode 100644 index 000000000..c140f2f37 --- /dev/null +++ b/Tests/varLib/instancer/data/CFF2Instancer-VF.ttx @@ -0,0 +1,729 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + © 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. + + + Noto Sans SC + + + Regular + + + 2.004;ADBO;NotoSansSC-Thin;ADOBE + + + Noto Sans SC + + + Version 2.004;hotconv 1.0.118;makeotfexe 2.5.65603 + + + NotoSansSC-Thin + + + Regular + + + Thin + + + Light + + + DemiLight + + + Regular + + + Medium + + + Bold + + + Black + + + Weight + + + Thin + + + NotoSansSC-Thin + + + Light + + + NotoSansSC-Light + + + DemiLight + + + NotoSansSC-DemiLight + + + Regular + + + NotoSansSC-Regular + + + Medium + + + NotoSansSC-Medium + + + Bold + + + NotoSansSC-Bold + + + Black + + + NotoSansSC-Black + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 44 256 6 -29 2 blend + rmoveto + 239 35 -239 44 90 -44 3 blend + hlineto + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wght + 0x0 + 100.0 + 100.0 + 900.0 + 265 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/instancer/instancer_test.py b/Tests/varLib/instancer/instancer_test.py index 3dfbf448f..190f42ce1 100644 --- a/Tests/varLib/instancer/instancer_test.py +++ b/Tests/varLib/instancer/instancer_test.py @@ -63,6 +63,50 @@ def _get_coordinates(varfont, glyphname): ) +class InstantiateCFF2Test(object): + @pytest.mark.parametrize( + "location, expected", + [ + ( + {}, + [ + 44, + 256, + 6, + -29, + 2, + "blend", + "rmoveto", + 239, + 35, + -239, + 44, + 90, + -44, + 3, + "blend", + "hlineto", + ], + ), + ({"wght": 0}, [44, 256, "rmoveto", 239, 35, -239, "hlineto"]), + ({"wght": 0.5}, [47, 242, "rmoveto", 261, 80, -261, "hlineto"]), + ({"wght": 1}, [50, 227, "rmoveto", 283, 125, -283, "hlineto"]), + ], + ) + def test_pin_and_drop_axis(self, varfont, location, expected): + + varfont = ttLib.TTFont() + varfont.importXML(os.path.join(TESTDATA, "CFF2Instancer-VF.ttx")) + + location = instancer.NormalizedAxisLimits(location) + + instancer.instantiateCFF2(varfont, location) + instancer.instantiateHVAR(varfont, location) + + program = varfont["CFF2"].cff.topDictIndex[0].CharStrings.values()[1].program + assert program == expected + + class InstantiateGvarTest(object): @pytest.mark.parametrize("glyph_name", ["hyphen"]) @pytest.mark.parametrize(