2019-03-12 19:44:33 +00:00
|
|
|
from __future__ import print_function, division, absolute_import
|
|
|
|
from fontTools.misc.py23 import *
|
2019-03-29 13:00:27 +00:00
|
|
|
from fontTools import ttLib
|
|
|
|
from fontTools.ttLib.tables import _f_v_a_r
|
2019-04-16 18:14:05 +01:00
|
|
|
from fontTools.ttLib.tables.TupleVariation import TupleVariation
|
2019-03-21 15:30:48 +00:00
|
|
|
from fontTools.varLib import instancer
|
2019-03-25 13:19:38 +00:00
|
|
|
from fontTools.varLib.mvar import MVAR_ENTRIES
|
2019-03-28 19:32:05 +00:00
|
|
|
from fontTools.varLib import builder
|
2019-03-12 19:44:33 +00:00
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
TESTDATA = os.path.join(os.path.dirname(__file__), "data")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def varfont():
|
2019-03-29 13:00:27 +00:00
|
|
|
f = ttLib.TTFont()
|
2019-03-12 19:44:33 +00:00
|
|
|
f.importXML(os.path.join(TESTDATA, "PartialInstancerTest-VF.ttx"))
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2019-04-15 18:39:49 +01:00
|
|
|
@pytest.fixture(params=[True, False], ids=["optimize", "no-optimize"])
|
|
|
|
def optimize(request):
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
2019-04-16 18:14:05 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def fvarAxes():
|
|
|
|
wght = _f_v_a_r.Axis()
|
|
|
|
wght.axisTag = Tag("wght")
|
|
|
|
wght.minValue = 100
|
|
|
|
wght.defaultValue = 400
|
|
|
|
wght.maxValue = 900
|
|
|
|
wdth = _f_v_a_r.Axis()
|
|
|
|
wdth.axisTag = Tag("wdth")
|
|
|
|
wdth.minValue = 70
|
|
|
|
wdth.defaultValue = 100
|
|
|
|
wdth.maxValue = 100
|
|
|
|
return [wght, wdth]
|
|
|
|
|
|
|
|
|
2019-03-12 19:44:33 +00:00
|
|
|
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": [
|
2019-04-04 14:02:22 +01:00
|
|
|
(34, 229),
|
|
|
|
(34, 309),
|
|
|
|
(265, 309),
|
|
|
|
(265, 229),
|
2019-03-12 19:44:33 +00:00
|
|
|
(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",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2019-04-01 11:03:45 +01:00
|
|
|
def test_pin_and_drop_axis(self, varfont, glyph_name, location, expected, optimize):
|
|
|
|
instancer.instantiateGvar(varfont, location, optimize=optimize)
|
2019-03-12 19:44:33 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
2019-03-25 11:09:46 +00:00
|
|
|
|
2019-04-15 18:39:49 +01:00
|
|
|
def test_full_instance(self, varfont, optimize):
|
|
|
|
instancer.instantiateGvar(
|
|
|
|
varfont, {"wght": 0.0, "wdth": -0.5}, optimize=optimize
|
|
|
|
)
|
2019-04-01 11:03:45 +01:00
|
|
|
|
|
|
|
assert _get_coordinates(varfont, "hyphen") == [
|
2019-04-04 14:02:22 +01:00
|
|
|
(34, 229),
|
|
|
|
(34, 309),
|
|
|
|
(265, 309),
|
|
|
|
(265, 229),
|
2019-04-01 11:03:45 +01:00
|
|
|
(0, 0),
|
|
|
|
(298, 0),
|
|
|
|
(0, 1000),
|
|
|
|
(0, 0),
|
|
|
|
]
|
|
|
|
|
|
|
|
assert "gvar" not in varfont
|
|
|
|
|
2019-03-25 11:09:46 +00:00
|
|
|
|
|
|
|
class InstantiateCvarTest(object):
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"location, expected",
|
|
|
|
[
|
|
|
|
pytest.param({"wght": -1.0}, [500, -400, 150, 250], id="wght=-1.0"),
|
|
|
|
pytest.param({"wdth": -1.0}, [500, -400, 180, 200], id="wdth=-1.0"),
|
|
|
|
pytest.param({"wght": -0.5}, [500, -400, 165, 250], id="wght=-0.5"),
|
2019-03-25 12:22:42 +00:00
|
|
|
pytest.param({"wdth": -0.3}, [500, -400, 180, 235], id="wdth=-0.3"),
|
2019-03-25 11:09:46 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_pin_and_drop_axis(self, varfont, location, expected):
|
|
|
|
instancer.instantiateCvar(varfont, location)
|
|
|
|
|
|
|
|
assert list(varfont["cvt "].values) == expected
|
|
|
|
|
2019-04-01 11:03:45 +01:00
|
|
|
# check that the pinned axis has been dropped from cvar
|
2019-03-25 11:09:46 +00:00
|
|
|
pinned_axes = location.keys()
|
|
|
|
assert not any(
|
|
|
|
axis in t.axes for t in varfont["cvar"].variations for axis in pinned_axes
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_full_instance(self, varfont):
|
|
|
|
instancer.instantiateCvar(varfont, {"wght": -0.5, "wdth": -0.5})
|
|
|
|
|
|
|
|
assert list(varfont["cvt "].values) == [500, -400, 165, 225]
|
|
|
|
|
|
|
|
assert "cvar" not in varfont
|
2019-03-25 13:19:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class InstantiateMvarTest(object):
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"location, expected",
|
|
|
|
[
|
|
|
|
pytest.param(
|
2019-04-15 18:45:46 +01:00
|
|
|
{"wght": 1.0},
|
|
|
|
{"strs": 100, "undo": -200, "unds": 150, "xhgt": 530},
|
|
|
|
id="wght=1.0",
|
2019-03-25 13:19:38 +00:00
|
|
|
),
|
|
|
|
pytest.param(
|
2019-04-15 18:45:46 +01:00
|
|
|
{"wght": 0.5},
|
|
|
|
{"strs": 75, "undo": -150, "unds": 100, "xhgt": 515},
|
|
|
|
id="wght=0.5",
|
2019-03-25 13:19:38 +00:00
|
|
|
),
|
|
|
|
pytest.param(
|
2019-04-15 18:45:46 +01:00
|
|
|
{"wght": 0.0},
|
|
|
|
{"strs": 50, "undo": -100, "unds": 50, "xhgt": 500},
|
|
|
|
id="wght=0.0",
|
2019-03-25 13:19:38 +00:00
|
|
|
),
|
|
|
|
pytest.param(
|
2019-04-15 18:45:46 +01:00
|
|
|
{"wdth": -1.0},
|
|
|
|
{"strs": 20, "undo": -100, "unds": 50, "xhgt": 500},
|
|
|
|
id="wdth=-1.0",
|
2019-03-25 13:19:38 +00:00
|
|
|
),
|
|
|
|
pytest.param(
|
2019-04-15 18:45:46 +01:00
|
|
|
{"wdth": -0.5},
|
|
|
|
{"strs": 35, "undo": -100, "unds": 50, "xhgt": 500},
|
|
|
|
id="wdth=-0.5",
|
2019-03-25 13:19:38 +00:00
|
|
|
),
|
|
|
|
pytest.param(
|
2019-04-15 18:45:46 +01:00
|
|
|
{"wdth": 0.0},
|
|
|
|
{"strs": 50, "undo": -100, "unds": 50, "xhgt": 500},
|
|
|
|
id="wdth=0.0",
|
2019-03-25 13:19:38 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_pin_and_drop_axis(self, varfont, location, expected):
|
|
|
|
mvar = varfont["MVAR"].table
|
2019-04-15 18:45:46 +01:00
|
|
|
# initially we have two VarData: the first contains deltas associated with 3
|
|
|
|
# regions: 1 with only wght, 1 with only wdth, and 1 with both wght and wdth
|
|
|
|
assert len(mvar.VarStore.VarData) == 2
|
2019-03-26 18:40:03 +00:00
|
|
|
assert mvar.VarStore.VarRegionList.RegionCount == 3
|
2019-03-25 13:19:38 +00:00
|
|
|
assert mvar.VarStore.VarData[0].VarRegionCount == 3
|
|
|
|
assert all(len(item) == 3 for item in mvar.VarStore.VarData[0].Item)
|
2019-04-15 18:45:46 +01:00
|
|
|
# The second VarData has deltas associated only with 1 region (wght only).
|
|
|
|
assert mvar.VarStore.VarData[1].VarRegionCount == 1
|
|
|
|
assert all(len(item) == 1 for item in mvar.VarStore.VarData[1].Item)
|
2019-03-25 13:19:38 +00:00
|
|
|
|
|
|
|
instancer.instantiateMvar(varfont, location)
|
|
|
|
|
|
|
|
for mvar_tag, expected_value in expected.items():
|
|
|
|
table_tag, item_name = MVAR_ENTRIES[mvar_tag]
|
|
|
|
assert getattr(varfont[table_tag], item_name) == expected_value
|
|
|
|
|
|
|
|
# check that the pinned axis does not influence any of the remaining regions
|
|
|
|
# in MVAR VarStore
|
|
|
|
pinned_axes = location.keys()
|
|
|
|
fvar = varfont["fvar"]
|
|
|
|
assert all(
|
2019-03-25 13:41:41 +00:00
|
|
|
peak == 0
|
2019-03-25 13:19:38 +00:00
|
|
|
for region in mvar.VarStore.VarRegionList.Region
|
2019-03-25 13:41:41 +00:00
|
|
|
for axis, (start, peak, end) in region.get_support(fvar.axes).items()
|
2019-03-25 13:19:38 +00:00
|
|
|
if axis in pinned_axes
|
|
|
|
)
|
|
|
|
|
2019-03-26 18:40:03 +00:00
|
|
|
# check that regions and accompanying deltas have been dropped
|
|
|
|
num_regions_left = len(mvar.VarStore.VarRegionList.Region)
|
|
|
|
assert num_regions_left < 3
|
|
|
|
assert mvar.VarStore.VarRegionList.RegionCount == num_regions_left
|
|
|
|
assert mvar.VarStore.VarData[0].VarRegionCount == num_regions_left
|
2019-04-15 18:45:46 +01:00
|
|
|
# VarData subtables have been merged
|
|
|
|
assert len(mvar.VarStore.VarData) == 1
|
2019-03-25 13:19:38 +00:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"location, expected",
|
|
|
|
[
|
|
|
|
pytest.param(
|
|
|
|
{"wght": 1.0, "wdth": 0.0},
|
|
|
|
{"strs": 100, "undo": -200, "unds": 150},
|
|
|
|
id="wght=1.0,wdth=0.0",
|
|
|
|
),
|
|
|
|
pytest.param(
|
|
|
|
{"wght": 0.0, "wdth": -1.0},
|
|
|
|
{"strs": 20, "undo": -100, "unds": 50},
|
|
|
|
id="wght=0.0,wdth=-1.0",
|
|
|
|
),
|
|
|
|
pytest.param(
|
|
|
|
{"wght": 0.5, "wdth": -0.5},
|
|
|
|
{"strs": 55, "undo": -145, "unds": 95},
|
|
|
|
id="wght=0.5,wdth=-0.5",
|
|
|
|
),
|
|
|
|
pytest.param(
|
|
|
|
{"wght": 1.0, "wdth": -1.0},
|
|
|
|
{"strs": 50, "undo": -180, "unds": 130},
|
|
|
|
id="wght=0.5,wdth=-0.5",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_full_instance(self, varfont, location, expected):
|
|
|
|
instancer.instantiateMvar(varfont, location)
|
|
|
|
|
|
|
|
for mvar_tag, expected_value in expected.items():
|
|
|
|
table_tag, item_name = MVAR_ENTRIES[mvar_tag]
|
|
|
|
assert getattr(varfont[table_tag], item_name) == expected_value
|
|
|
|
|
|
|
|
assert "MVAR" not in varfont
|
2019-03-28 19:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class InstantiateItemVariationStoreTest(object):
|
2019-04-16 18:14:05 +01:00
|
|
|
def test_VarRegion_get_support(self):
|
2019-03-28 19:32:05 +00:00
|
|
|
axisOrder = ["wght", "wdth", "opsz"]
|
|
|
|
regionAxes = {"wdth": (-1.0, -1.0, 0.0), "wght": (0.0, 1.0, 1.0)}
|
|
|
|
region = builder.buildVarRegion(regionAxes, axisOrder)
|
|
|
|
|
2019-04-16 18:14:05 +01:00
|
|
|
assert len(region.VarRegionAxis) == 3
|
|
|
|
assert region.VarRegionAxis[2].PeakCoord == 0
|
2019-03-28 19:32:05 +00:00
|
|
|
|
2019-04-16 18:14:05 +01:00
|
|
|
fvarAxes = [SimpleNamespace(axisTag=axisTag) for axisTag in axisOrder]
|
2019-03-29 13:00:27 +00:00
|
|
|
|
2019-04-16 18:14:05 +01:00
|
|
|
assert region.get_support(fvarAxes) == regionAxes
|
2019-03-29 13:00:27 +00:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def varStore(self):
|
|
|
|
return builder.buildVarStore(
|
|
|
|
builder.buildVarRegionList(
|
|
|
|
[
|
|
|
|
{"wght": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0, 0.5, 1.0)},
|
|
|
|
{"wght": (0.5, 1.0, 1.0)},
|
|
|
|
{"wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0, 0.5, 1.0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0.5, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
],
|
|
|
|
["wght", "wdth"],
|
|
|
|
),
|
|
|
|
[
|
|
|
|
builder.buildVarData([0, 1, 2], [[100, 100, 100], [100, 100, 100]]),
|
|
|
|
builder.buildVarData(
|
|
|
|
[3, 4, 5, 6], [[100, 100, 100, 100], [100, 100, 100, 100]]
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2019-04-15 18:45:46 +01:00
|
|
|
"location, expected_deltas, num_regions",
|
2019-03-29 13:00:27 +00:00
|
|
|
[
|
2019-04-16 18:14:05 +01:00
|
|
|
({"wght": 0}, [[0, 0], [0, 0]], 1),
|
|
|
|
({"wght": 0.25}, [[50, 50], [0, 0]], 1),
|
|
|
|
({"wdth": 0}, [[0, 0], [0, 0]], 3),
|
|
|
|
({"wdth": -0.75}, [[0, 0], [75, 75]], 3),
|
|
|
|
({"wght": 0, "wdth": 0}, [[0, 0], [0, 0]], 0),
|
|
|
|
({"wght": 0.25, "wdth": 0}, [[50, 50], [0, 0]], 0),
|
|
|
|
({"wght": 0, "wdth": -0.75}, [[0, 0], [75, 75]], 0),
|
2019-03-29 13:00:27 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_instantiate_default_deltas(
|
2019-04-15 18:45:46 +01:00
|
|
|
self, varStore, fvarAxes, location, expected_deltas, num_regions
|
2019-03-29 13:00:27 +00:00
|
|
|
):
|
2019-04-15 18:45:46 +01:00
|
|
|
defaultDeltas, _ = instancer.instantiateItemVariationStore(
|
2019-03-29 13:00:27 +00:00
|
|
|
varStore, fvarAxes, location
|
|
|
|
)
|
|
|
|
|
2019-04-17 19:20:26 +01:00
|
|
|
defaultDeltaArray = []
|
|
|
|
for varidx, delta in sorted(defaultDeltas.items()):
|
|
|
|
major, minor = varidx >> 16, varidx & 0xFFFF
|
|
|
|
if major == len(defaultDeltaArray):
|
|
|
|
defaultDeltaArray.append([])
|
|
|
|
assert len(defaultDeltaArray[major]) == minor
|
|
|
|
defaultDeltaArray[major].append(delta)
|
|
|
|
|
|
|
|
assert defaultDeltaArray == expected_deltas
|
2019-03-29 13:00:27 +00:00
|
|
|
assert varStore.VarRegionList.RegionCount == num_regions
|
2019-04-16 18:14:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TupleVarStoreAdapterTest(object):
|
|
|
|
def test_instantiate(self):
|
|
|
|
regions = [
|
|
|
|
{"wght": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0.0, 1.0, 1.0)},
|
|
|
|
{"wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
]
|
|
|
|
axisOrder = ["wght", "wdth"]
|
|
|
|
tupleVarData = [
|
|
|
|
[
|
|
|
|
TupleVariation({"wght": (-1.0, -1.0, 0)}, [10, 70]),
|
|
|
|
TupleVariation({"wght": (0.0, 1.0, 1.0)}, [30, 90]),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)}, [-40, -100]
|
|
|
|
),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (0, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)}, [-60, -120]
|
|
|
|
),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
TupleVariation({"wdth": (-1.0, -1.0, 0)}, [5, 45]),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)}, [-15, -55]
|
|
|
|
),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (0, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)}, [-35, -75]
|
|
|
|
),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
adapter = instancer._TupleVarStoreAdapter(
|
|
|
|
regions, axisOrder, tupleVarData, itemCounts=[2, 2]
|
|
|
|
)
|
|
|
|
|
|
|
|
defaultDeltaArray = adapter.instantiate({"wght": 0.5})
|
|
|
|
|
|
|
|
assert defaultDeltaArray == [[15, 45], [0, 0]]
|
|
|
|
assert adapter.regions == [{"wdth": (-1.0, -1.0, 0)}]
|
|
|
|
assert adapter.tupleVarData == [
|
|
|
|
[TupleVariation({"wdth": (-1.0, -1.0, 0)}, [-30, -60])],
|
|
|
|
[TupleVariation({"wdth": (-1.0, -1.0, 0)}, [-12, 8])],
|
|
|
|
]
|
|
|
|
|
|
|
|
def test_dropAxes(self):
|
|
|
|
regions = [
|
|
|
|
{"wght": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0.0, 1.0, 1.0)},
|
|
|
|
{"wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"opsz": (0.0, 1.0, 1.0)},
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0, 0.5, 1.0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0.5, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
]
|
|
|
|
axisOrder = ["wght", "wdth", "opsz"]
|
|
|
|
adapter = instancer._TupleVarStoreAdapter(regions, axisOrder, [], itemCounts=[])
|
|
|
|
|
|
|
|
adapter.dropAxes({"wdth"})
|
|
|
|
|
|
|
|
assert adapter.regions == [
|
|
|
|
{"wght": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0.0, 1.0, 1.0)},
|
|
|
|
{"opsz": (0.0, 1.0, 1.0)},
|
|
|
|
{"wght": (0.0, 0.5, 1.0)},
|
|
|
|
{"wght": (0.5, 1.0, 1.0)},
|
|
|
|
]
|
|
|
|
|
|
|
|
adapter.dropAxes({"wght", "opsz"})
|
|
|
|
|
|
|
|
assert adapter.regions == []
|
|
|
|
|
|
|
|
def test_roundtrip(self, fvarAxes):
|
|
|
|
regions = [
|
|
|
|
{"wght": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0, 0.5, 1.0)},
|
|
|
|
{"wght": (0.5, 1.0, 1.0)},
|
|
|
|
{"wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0, 0.5, 1.0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
{"wght": (0.5, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)},
|
|
|
|
]
|
|
|
|
axisOrder = [axis.axisTag for axis in fvarAxes]
|
|
|
|
|
|
|
|
itemVarStore = builder.buildVarStore(
|
|
|
|
builder.buildVarRegionList(regions, axisOrder),
|
|
|
|
[
|
|
|
|
builder.buildVarData(
|
|
|
|
[0, 1, 2, 4, 5, 6],
|
|
|
|
[[10, -20, 30, -40, 50, -60], [70, -80, 90, -100, 110, -120]],
|
|
|
|
),
|
|
|
|
builder.buildVarData(
|
|
|
|
[3, 4, 5, 6], [[5, -15, 25, -35], [45, -55, 65, -75]]
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
adapter = instancer._TupleVarStoreAdapter.fromItemVarStore(
|
|
|
|
itemVarStore, fvarAxes
|
|
|
|
)
|
|
|
|
|
|
|
|
assert adapter.tupleVarData == [
|
|
|
|
[
|
|
|
|
TupleVariation({"wght": (-1.0, -1.0, 0)}, [10, 70]),
|
|
|
|
TupleVariation({"wght": (0, 0.5, 1.0)}, [-20, -80]),
|
|
|
|
TupleVariation({"wght": (0.5, 1.0, 1.0)}, [30, 90]),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)}, [-40, -100]
|
|
|
|
),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (0, 0.5, 1.0), "wdth": (-1.0, -1.0, 0)}, [50, 110]
|
|
|
|
),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (0.5, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)}, [-60, -120]
|
|
|
|
),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
TupleVariation({"wdth": (-1.0, -1.0, 0)}, [5, 45]),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (-1.0, -1.0, 0), "wdth": (-1.0, -1.0, 0)}, [-15, -55]
|
|
|
|
),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (0, 0.5, 1.0), "wdth": (-1.0, -1.0, 0)}, [25, 65]
|
|
|
|
),
|
|
|
|
TupleVariation(
|
|
|
|
{"wght": (0.5, 1.0, 1.0), "wdth": (-1.0, -1.0, 0)}, [-35, -75]
|
|
|
|
),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
assert adapter.itemCounts == [data.ItemCount for data in itemVarStore.VarData]
|
|
|
|
assert adapter.regions == regions
|
|
|
|
assert adapter.axisOrder == axisOrder
|
|
|
|
|
|
|
|
itemVarStore2 = adapter.asItemVarStore()
|
|
|
|
|
|
|
|
assert [
|
|
|
|
reg.get_support(fvarAxes)
|
|
|
|
for reg in itemVarStore2.VarRegionList.Region
|
|
|
|
] == regions
|
|
|
|
|
|
|
|
assert itemVarStore2.VarDataCount == 2
|
|
|
|
assert itemVarStore2.VarData[0].VarRegionIndex == [0, 1, 2, 4, 5, 6]
|
|
|
|
assert itemVarStore2.VarData[0].Item == [
|
|
|
|
[10, -20, 30, -40, 50, -60],
|
|
|
|
[70, -80, 90, -100, 110, -120],
|
|
|
|
]
|
|
|
|
assert itemVarStore2.VarData[1].VarRegionIndex == [3, 4, 5, 6]
|
|
|
|
assert itemVarStore2.VarData[1].Item == [[5, -15, 25, -35], [45, -55, 65, -75]]
|