From 126a2d9c38722e7396bd03a49efef1cce4a3c103 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 12 Mar 2019 19:44:33 +0000 Subject: [PATCH] Add partialInstancer_test.py and PartialInstancerTest-VF.ttx Currently tests the instantiateGvar function only. The test font contains two axes and a single glyph. I shall make add more complexity later. --- Tests/varLib/data/PartialInstancerTest-VF.ttx | 915 ++++++++++++++++++ Tests/varLib/partialInstancer_test.py | 92 ++ 2 files changed, 1007 insertions(+) create mode 100644 Tests/varLib/data/PartialInstancerTest-VF.ttx create mode 100644 Tests/varLib/partialInstancer_test.py diff --git a/Tests/varLib/data/PartialInstancerTest-VF.ttx b/Tests/varLib/data/PartialInstancerTest-VF.ttx new file mode 100644 index 000000000..98fec4168 --- /dev/null +++ b/Tests/varLib/data/PartialInstancerTest-VF.ttx @@ -0,0 +1,915 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Weight + + + Width + + + Thin + + + ExtraLight + + + Light + + + Regular + + + Medium + + + SemiBold + + + Bold + + + ExtraBold + + + Black + + + SemiCondensed Thin + + + SemiCondensed ExtraLight + + + SemiCondensed Light + + + SemiCondensed + + + SemiCondensed Medium + + + SemiCondensed SemiBold + + + SemiCondensed Bold + + + SemiCondensed ExtraBold + + + SemiCondensed Black + + + Condensed Thin + + + Condensed ExtraLight + + + Condensed Light + + + Condensed + + + Condensed Medium + + + Condensed SemiBold + + + Condensed Bold + + + Condensed ExtraBold + + + Condensed Black + + + ExtraCondensed Thin + + + ExtraCondensed ExtraLight + + + ExtraCondensed Light + + + ExtraCondensed + + + ExtraCondensed Medium + + + ExtraCondensed SemiBold + + + ExtraCondensed Bold + + + ExtraCondensed ExtraBold + + + ExtraCondensed Black + + + Copyright 2015 Google Inc. All Rights Reserved. + + + Test Variable Font + + + Regular + + + 2.001;GOOG;TestVariableFont-Regular + + + Test Variable Font Regular + + + Version 2.001 + + + TestVariableFont-Regular + + + Noto is a trademark of Google Inc. + + + Monotype Imaging Inc. + + + Monotype Design Team + + + http://www.google.com/get/noto/ + + + http://www.monotype.com/studio + + + Weight + + + Width + + + Thin + + + ExtraLight + + + Light + + + Regular + + + Medium + + + SemiBold + + + Bold + + + ExtraBold + + + Black + + + SemiCondensed Thin + + + SemiCondensed ExtraLight + + + SemiCondensed Light + + + SemiCondensed + + + SemiCondensed Medium + + + SemiCondensed SemiBold + + + SemiCondensed Bold + + + SemiCondensed ExtraBold + + + SemiCondensed Black + + + Condensed Thin + + + Condensed ExtraLight + + + Condensed Light + + + Condensed + + + Condensed Medium + + + Condensed SemiBold + + + Condensed Bold + + + Condensed ExtraBold + + + Condensed Black + + + ExtraCondensed Thin + + + ExtraCondensed ExtraLight + + + ExtraCondensed Light + + + ExtraCondensed + + + ExtraCondensed Medium + + + ExtraCondensed SemiBold + + + ExtraCondensed Bold + + + ExtraCondensed ExtraBold + + + ExtraCondensed Black + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wght + 0x0 + 100.0 + 400.0 + 900.0 + 256 + + + + + wdth + 0x0 + 70.0 + 100.0 + 100.0 + 257 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/varLib/partialInstancer_test.py b/Tests/varLib/partialInstancer_test.py new file mode 100644 index 000000000..d251b7c3e --- /dev/null +++ b/Tests/varLib/partialInstancer_test.py @@ -0,0 +1,92 @@ +from __future__ import print_function, division, absolute_import +from fontTools.misc.py23 import * +from fontTools.ttLib import TTFont +from fontTools.varLib import partialInstancer as pi +import os +import pytest + + +TESTDATA = os.path.join(os.path.dirname(__file__), "data") + + +@pytest.fixture +def varfont(): + f = TTFont() + f.importXML(os.path.join(TESTDATA, "PartialInstancerTest-VF.ttx")) + return f + + +def _get_coordinates(varfont, glyphname): + # converts GlyphCoordinates to a list of (x, y) tuples, so that pytest's + # assert will give us a nicer diff + return list(varfont["glyf"].getCoordinates(glyphname, varfont)) + + +class InstantiateGvarTest(object): + @pytest.mark.parametrize("glyph_name", ["hyphen"]) + @pytest.mark.parametrize( + "location, expected", + [ + pytest.param( + {"wdth": -1.0}, + { + "hyphen": [ + (27, 229), + (27, 310), + (247, 310), + (247, 229), + (0, 0), + (274, 0), + (0, 1000), + (0, 0), + ] + }, + id="wdth=-1.0", + ), + pytest.param( + {"wdth": -0.5}, + { + "hyphen": [ + (33.5, 229), + (33.5, 308.5), + (264.5, 308.5), + (264.5, 229), + (0, 0), + (298, 0), + (0, 1000), + (0, 0), + ] + }, + id="wdth=-0.5", + ), + # an axis pinned at the default normalized location (0.0) means + # the default glyf outline stays the same + pytest.param( + {"wdth": 0.0}, + { + "hyphen": [ + (40, 229), + (40, 307), + (282, 307), + (282, 229), + (0, 0), + (322, 0), + (0, 1000), + (0, 0), + ] + }, + id="wdth=0.0", + ), + ], + ) + def test_pin_and_drop_axis(self, varfont, glyph_name, location, expected): + pi.instantiateGvar(varfont, location) + + assert _get_coordinates(varfont, glyph_name) == expected[glyph_name] + + # check that the pinned axis has been dropped from gvar + assert not any( + "wdth" in t.axes + for tuples in varfont["gvar"].variations.values() + for t in tuples + )