Currently tests the instantiateGvar function only. The test font contains two axes and a single glyph. I shall make add more complexity later.
93 lines
2.7 KiB
Python
93 lines
2.7 KiB
Python
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
|
|
)
|