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
|
from fontTools.ttLib import TTFont
from fontTools.ttLib import ttGlyphSet
from fontTools.pens.recordingPen import RecordingPen
import os
import pytest
class TTGlyphSetTest(object):
@staticmethod
def getpath(testfile):
path = os.path.dirname(__file__)
return os.path.join(path, "data", testfile)
@pytest.mark.parametrize(
"location, expected",
[
(
None,
[
('moveTo', ((175, 0),)),
('lineTo', ((367, 0),)),
('lineTo', ((367, 1456),)),
('lineTo', ((175, 1456),)),
('closePath', ())
]
),
(
{},
[
('moveTo', ((175, 0),)),
('lineTo', ((367, 0),)),
('lineTo', ((367, 1456),)),
('lineTo', ((175, 1456),)),
('closePath', ())
]
),
(
{'wght': 100},
[
('moveTo', ((175, 0),)),
('lineTo', ((271, 0),)),
('lineTo', ((271, 1456),)),
('lineTo', ((175, 1456),)),
('closePath', ())
]
),
(
{'wght': 1000},
[
('moveTo', ((128, 0),)),
('lineTo', ((550, 0),)),
('lineTo', ((550, 1456),)),
('lineTo', ((128, 1456),)),
('closePath', ())
]
),
(
{'wght': 1000, 'wdth': 25},
[
('moveTo', ((140, 0),)),
('lineTo', ((553, 0),)),
('lineTo', ((553, 1456),)),
('lineTo', ((140, 1456),)),
('closePath', ())
]
),
(
{'wght': 1000, 'wdth': 50},
[
('moveTo', ((136, 0),)),
('lineTo', ((552, 0),)),
('lineTo', ((552, 1456),)),
('lineTo', ((136, 1456),)),
('closePath', ())
]
),
]
)
def test_glyphset(
self, location, expected
):
# TODO: also test loading CFF-flavored fonts
font = TTFont(self.getpath("I.ttf"))
glyphset = font.getGlyphSet(location=location)
assert isinstance(glyphset, ttGlyphSet._TTGlyphSet)
if location:
assert isinstance(glyphset, ttGlyphSet._TTVarGlyphSet)
assert list(glyphset.keys()) == [".notdef", "I"]
assert "I" in glyphset
assert glyphset.has_key("I") # we should really get rid of this...
assert len(glyphset) == 2
pen = RecordingPen()
glyph = glyphset['I']
assert glyphset.get("foobar") is None
assert isinstance(glyph, ttGlyphSet._TTGlyph)
if location:
assert isinstance(glyph, ttGlyphSet._TTVarGlyphGlyf)
else:
assert isinstance(glyph, ttGlyphSet._TTGlyphGlyf)
glyph.draw(pen)
actual = pen.value
assert actual == expected, (location, actual, expected)
|