[ttGlyphPen_test] Exercise preserveTopology

This commit is contained in:
Behdad Esfahbod 2023-02-22 07:51:44 -07:00
parent 7580fc7e24
commit bbdee18f67

View File

@ -597,7 +597,7 @@ class TTGlyphPointPenTest(TTGlyphPenTestBase):
class CubicGlyfTest: class CubicGlyfTest:
def test_cubic(self): def test_cubic_simple(self):
spen = TTGlyphPen(None) spen = TTGlyphPen(None)
spen.moveTo((0, 0)) spen.moveTo((0, 0))
spen.curveTo((0, 1), (1, 1), (1, 0)) spen.curveTo((0, 1), (1, 1), (1, 0))
@ -605,7 +605,7 @@ class CubicGlyfTest:
ppen = TTGlyphPointPen(None) ppen = TTGlyphPointPen(None)
ppen.beginPath() ppen.beginPath()
ppen.addPoint((0, 0), "move") ppen.addPoint((0, 0), "line")
ppen.addPoint((0, 1)) ppen.addPoint((0, 1))
ppen.addPoint((1, 1)) ppen.addPoint((1, 1))
ppen.addPoint((1, 0), "curve") ppen.addPoint((1, 0), "curve")
@ -613,7 +613,7 @@ class CubicGlyfTest:
for pen in (spen, ppen): for pen in (spen, ppen):
glyph = pen.glyph(preserveTopology=False) glyph = pen.glyph()
for i in range(2): for i in range(2):
@ -638,6 +638,96 @@ class CubicGlyfTest:
("closePath", ()), ("closePath", ()),
] ]
def test_cubic_topology(self):
for preserveTopology in (False, True):
spen = TTGlyphPen(None)
spen.moveTo((0, 0))
spen.curveTo((0, 1), (1, 2), (2, 2))
spen.curveTo((3, 2), (4, 1), (4, 0))
spen.closePath()
ppen = TTGlyphPointPen(None)
ppen.beginPath()
ppen.addPoint((0, 0), "line")
ppen.addPoint((0, 1))
ppen.addPoint((1, 2))
ppen.addPoint((2, 2), "curve")
ppen.addPoint((3, 2))
ppen.addPoint((4, 1))
ppen.addPoint((4, 0), "curve")
ppen.endPath()
expected_coordinates = (
[
(0, 0),
(0, 1),
(1, 2),
(2, 2),
(3, 2),
(4, 1),
(4, 0),
]
if preserveTopology
else [
(0, 0),
(0, 1),
(1, 2),
(3, 2),
(4, 1),
(4, 0),
]
)
expected_flags = (
[
0x01,
0x80,
0x80,
0x01,
0x80,
0x80,
0x01,
]
if preserveTopology
else [
0x01,
0x80,
0x80,
0x80,
0x80,
0x01,
]
)
for pen in (spen, ppen):
glyph = pen.glyph(preserveTopology=preserveTopology)
assert list(glyph.coordinates) == expected_coordinates
assert list(glyph.flags) == expected_flags
rpen = RecordingPen()
glyph.draw(rpen, None)
assert rpen.value == [
("moveTo", ((0, 0),)),
(
"curveTo",
(
(0, 1),
(1, 2),
(2, 2),
),
),
(
"curveTo",
(
(3, 2),
(4, 1),
(4, 0),
),
),
("closePath", ()),
]
class _TestGlyph(object): class _TestGlyph(object):
def __init__(self, glyph): def __init__(self, glyph):