1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
import fontTools.designspaceLib
import fontTools.ttLib
import pytest
import ufo2ft
import statmake.cli
from . import testutil
def test_cli_stylespace_in_designspace(datadir, tmp_path):
varfont = empty_varfont(datadir / "Test_Wght_Upright.designspace")
varfont.save(tmp_path / "varfont.ttf")
statmake.cli.main(
[
"-m",
str(datadir / "TestInlineStylespace.designspace"),
str(tmp_path / "varfont.ttf"),
]
)
font = fontTools.ttLib.TTFont(tmp_path / "varfont.ttf")
v = testutil.dump_axis_values(font, font["STAT"].table.AxisValueArray.AxisValue)
assert v == TEST_WGHT_UPRIGHT_STAT_DUMP
def test_cli_designspace_stylespace_external(datadir, tmp_path):
varfont = empty_varfont(datadir / "Test_Wght_Upright.designspace")
varfont.save(tmp_path / "varfont.ttf")
statmake.cli.main(
[
"-m",
str(datadir / "TestExternalStylespace.designspace"),
str(tmp_path / "varfont.ttf"),
]
)
font = fontTools.ttLib.TTFont(tmp_path / "varfont.ttf")
v = testutil.dump_axis_values(font, font["STAT"].table.AxisValueArray.AxisValue)
assert v == TEST_WGHT_UPRIGHT_STAT_DUMP
def test_cli_stylespace_external(datadir, tmp_path):
varfont = empty_varfont(datadir / "Test_Wght_Upright.designspace")
varfont.save(tmp_path / "varfont.ttf")
statmake.cli.main(
[
"-m",
str(datadir / "Test_Wght_Upright.designspace"),
"--stylespace",
str(datadir / "Test.stylespace"),
str(tmp_path / "varfont.ttf"),
]
)
font = fontTools.ttLib.TTFont(tmp_path / "varfont.ttf")
v = testutil.dump_axis_values(font, font["STAT"].table.AxisValueArray.AxisValue)
assert v == TEST_WGHT_UPRIGHT_STAT_DUMP
def test_cli_stylespace_in_broken_designspace(datadir, tmp_path):
with pytest.raises(SystemExit):
statmake.cli.main(
[
"-m",
str(datadir / "Test_Wght_Upright.designspace"),
str(tmp_path / "varfont.ttf"),
]
)
def empty_varfont(designspace_path):
designspace = fontTools.designspaceLib.DesignSpaceDocument.fromfile(
designspace_path
)
for source in designspace.sources:
source.font = testutil.empty_UFO(source.styleName)
ufo2ft.compileInterpolatableTTFsFromDS(designspace, inplace=True)
varfont, _, _ = fontTools.varLib.build(designspace)
return varfont
TEST_WGHT_UPRIGHT_STAT_DUMP = [
{"Format": 1, "Name": {"en": "XLight"}, "Flags": 0, "AxisIndex": 0, "Value": 200.0},
{"Format": 1, "Name": {"en": "Light"}, "Flags": 0, "AxisIndex": 0, "Value": 300.0},
{
"Format": 3,
"Name": {"en": "Regular"},
"Flags": 2,
"AxisIndex": 0,
"Value": 400.0,
"LinkedValue": 700.0,
},
{
"Format": 1,
"Name": {"en": "Semi Bold"},
"Flags": 0,
"AxisIndex": 0,
"Value": 600.0,
},
{"Format": 1, "Name": {"en": "Bold"}, "Flags": 0, "AxisIndex": 0, "Value": 700.0},
{
"Format": 2,
"Name": {"en": "Black"},
"Flags": 0,
"AxisIndex": 0,
"NominalValue": 900.0,
"RangeMinValue": 701.0,
"RangeMaxValue": 900.0,
},
{
"Format": 3,
"Name": {"en": "Upright"},
"Flags": 2,
"AxisIndex": 1,
"Value": 0.0,
"LinkedValue": 1.0,
},
]
|