[ttGlyphSet_test] Test CFF2 variations
This commit is contained in:
parent
f5a1d0ba10
commit
b3d6868516
BIN
Tests/ttLib/data/I.otf
Normal file
BIN
Tests/ttLib/data/I.otf
Normal file
Binary file not shown.
@ -6,82 +6,116 @@ 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",
|
||||
"fontfile, location, expected",
|
||||
[
|
||||
(
|
||||
"I.ttf",
|
||||
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", ()),
|
||||
],
|
||||
),
|
||||
(
|
||||
"I.ttf",
|
||||
{},
|
||||
[
|
||||
('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},
|
||||
"I.ttf",
|
||||
{"wght": 100},
|
||||
[
|
||||
('moveTo', ((175, 0),)),
|
||||
('lineTo', ((271, 0),)),
|
||||
('lineTo', ((271, 1456),)),
|
||||
('lineTo', ((175, 1456),)),
|
||||
('closePath', ())
|
||||
]
|
||||
("moveTo", ((175, 0),)),
|
||||
("lineTo", ((271, 0),)),
|
||||
("lineTo", ((271, 1456),)),
|
||||
("lineTo", ((175, 1456),)),
|
||||
("closePath", ()),
|
||||
],
|
||||
),
|
||||
(
|
||||
{'wght': 1000},
|
||||
"I.ttf",
|
||||
{"wght": 1000},
|
||||
[
|
||||
('moveTo', ((128, 0),)),
|
||||
('lineTo', ((550, 0),)),
|
||||
('lineTo', ((550, 1456),)),
|
||||
('lineTo', ((128, 1456),)),
|
||||
('closePath', ())
|
||||
]
|
||||
("moveTo", ((128, 0),)),
|
||||
("lineTo", ((550, 0),)),
|
||||
("lineTo", ((550, 1456),)),
|
||||
("lineTo", ((128, 1456),)),
|
||||
("closePath", ()),
|
||||
],
|
||||
),
|
||||
(
|
||||
{'wght': 1000, 'wdth': 25},
|
||||
"I.ttf",
|
||||
{"wght": 1000, "wdth": 25},
|
||||
[
|
||||
('moveTo', ((140, 0),)),
|
||||
('lineTo', ((553, 0),)),
|
||||
('lineTo', ((553, 1456),)),
|
||||
('lineTo', ((140, 1456),)),
|
||||
('closePath', ())
|
||||
]
|
||||
("moveTo", ((140, 0),)),
|
||||
("lineTo", ((553, 0),)),
|
||||
("lineTo", ((553, 1456),)),
|
||||
("lineTo", ((140, 1456),)),
|
||||
("closePath", ()),
|
||||
],
|
||||
),
|
||||
(
|
||||
{'wght': 1000, 'wdth': 50},
|
||||
"I.ttf",
|
||||
{"wght": 1000, "wdth": 50},
|
||||
[
|
||||
('moveTo', ((136, 0),)),
|
||||
('lineTo', ((552, 0),)),
|
||||
('lineTo', ((552, 1456),)),
|
||||
('lineTo', ((136, 1456),)),
|
||||
('closePath', ())
|
||||
]
|
||||
("moveTo", ((136, 0),)),
|
||||
("lineTo", ((552, 0),)),
|
||||
("lineTo", ((552, 1456),)),
|
||||
("lineTo", ((136, 1456),)),
|
||||
("closePath", ()),
|
||||
],
|
||||
),
|
||||
]
|
||||
(
|
||||
"I.otf",
|
||||
{"wght": 1000},
|
||||
[
|
||||
("moveTo", ((179, 74),)),
|
||||
("lineTo", ((28, 59),)),
|
||||
("lineTo", ((28, 0),)),
|
||||
("lineTo", ((367, 0),)),
|
||||
("lineTo", ((367, 59),)),
|
||||
("lineTo", ((212, 74),)),
|
||||
("lineTo", ((179, 74),)),
|
||||
("closePath", ()),
|
||||
("moveTo", ((179, 578),)),
|
||||
("lineTo", ((212, 578),)),
|
||||
("lineTo", ((367, 593),)),
|
||||
("lineTo", ((367, 652),)),
|
||||
("lineTo", ((28, 652),)),
|
||||
("lineTo", ((28, 593),)),
|
||||
("lineTo", ((179, 578),)),
|
||||
("closePath", ()),
|
||||
("moveTo", ((98, 310),)),
|
||||
("curveTo", ((98, 205), (98, 101), (95, 0))),
|
||||
("lineTo", ((299, 0),)),
|
||||
("curveTo", ((296, 103), (296, 207), (296, 311))),
|
||||
("lineTo", ((296, 342),)),
|
||||
("curveTo", ((296, 447), (296, 551), (299, 652))),
|
||||
("lineTo", ((95, 652),)),
|
||||
("curveTo", ((98, 549), (98, 445), (98, 342))),
|
||||
("lineTo", ((98, 310),)),
|
||||
("closePath", ()),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_glyphset(
|
||||
self, location, expected
|
||||
):
|
||||
# TODO: also test loading CFF-flavored fonts
|
||||
font = TTFont(self.getpath("I.ttf"))
|
||||
def test_glyphset(self, fontfile, location, expected):
|
||||
font = TTFont(self.getpath(fontfile))
|
||||
glyphset = font.getGlyphSet(location=location)
|
||||
|
||||
assert isinstance(glyphset, ttGlyphSet._TTGlyphSet)
|
||||
@ -96,17 +130,22 @@ class TTGlyphSetTest(object):
|
||||
assert len(glyphset) == 2
|
||||
|
||||
pen = RecordingPen()
|
||||
glyph = glyphset['I']
|
||||
glyph = glyphset["I"]
|
||||
|
||||
assert glyphset.get("foobar") is None
|
||||
|
||||
assert isinstance(glyph, ttGlyphSet._TTGlyph)
|
||||
is_glyf = fontfile.endswith(".ttf")
|
||||
if location:
|
||||
assert isinstance(glyph, ttGlyphSet._TTVarGlyphGlyf)
|
||||
glyphType = (
|
||||
ttGlyphSet._TTVarGlyphGlyf if is_glyf else ttGlyphSet._TTVarGlyphCFF
|
||||
)
|
||||
else:
|
||||
assert isinstance(glyph, ttGlyphSet._TTGlyphGlyf)
|
||||
glyphType = ttGlyphSet._TTGlyphGlyf if is_glyf else ttGlyphSet._TTGlyphCFF
|
||||
assert isinstance(glyph, glyphType)
|
||||
|
||||
glyph.draw(pen)
|
||||
actual = pen.value
|
||||
|
||||
print(actual)
|
||||
assert actual == expected, (location, actual, expected)
|
||||
|
Loading…
x
Reference in New Issue
Block a user