aboutsummaryrefslogtreecommitdiff
path: root/Tests/pens/pointPen_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/pens/pointPen_test.py')
-rw-r--r--Tests/pens/pointPen_test.py253
1 files changed, 144 insertions, 109 deletions
diff --git a/Tests/pens/pointPen_test.py b/Tests/pens/pointPen_test.py
index a9201780..e811826f 100644
--- a/Tests/pens/pointPen_test.py
+++ b/Tests/pens/pointPen_test.py
@@ -1,12 +1,16 @@
import unittest
from fontTools.pens.basePen import AbstractPen
-from fontTools.pens.pointPen import AbstractPointPen, PointToSegmentPen, \
- SegmentToPointPen, GuessSmoothPointPen, ReverseContourPointPen
+from fontTools.pens.pointPen import (
+ AbstractPointPen,
+ PointToSegmentPen,
+ SegmentToPointPen,
+ GuessSmoothPointPen,
+ ReverseContourPointPen,
+)
class _TestSegmentPen(AbstractPen):
-
def __init__(self):
self._commands = []
@@ -49,7 +53,6 @@ def _reprKwargs(kwargs):
class _TestPointPen(AbstractPointPen):
-
def __init__(self):
self._commands = []
@@ -63,8 +66,9 @@ class _TestPointPen(AbstractPointPen):
items.extend(_reprKwargs(kwargs))
self._commands.append("beginPath(%s)" % ", ".join(items))
- def addPoint(self, pt, segmentType=None, smooth=False, name=None,
- identifier=None, **kwargs):
+ def addPoint(
+ self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
+ ):
items = ["%s" % (pt,)]
if segmentType is not None:
items.append("segmentType='%s'" % segmentType)
@@ -89,7 +93,6 @@ class _TestPointPen(AbstractPointPen):
class PointToSegmentPenTest(unittest.TestCase):
-
def test_open(self):
pen = _TestSegmentPen()
ppen = PointToSegmentPen(pen)
@@ -123,7 +126,7 @@ class PointToSegmentPenTest(unittest.TestCase):
def test_quad(self):
pen = _TestSegmentPen()
ppen = PointToSegmentPen(pen)
- ppen.beginPath(identifier='foo')
+ ppen.beginPath(identifier="foo")
ppen.addPoint((10, 10), "line")
ppen.addPoint((10, 40))
ppen.addPoint((40, 40))
@@ -150,9 +153,11 @@ class PointToSegmentPenTest(unittest.TestCase):
ppen.addPoint((20, 20))
ppen.addPoint((20, 40), "curve")
ppen.endPath()
- self.assertEqual("beginPath() addPoint((10, 10), segmentType='line') addPoint((10, 20)) "
- "addPoint((20, 20)) addPoint((20, 40), segmentType='curve') endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((10, 10), segmentType='line') addPoint((10, 20)) "
+ "addPoint((20, 20)) addPoint((20, 40), segmentType='curve') endPath()",
+ repr(tpen),
+ )
def test_closed_outputImpliedClosingLine(self):
tpen = _TestSegmentPen()
@@ -168,7 +173,7 @@ class PointToSegmentPenTest(unittest.TestCase):
"20 20 lineto "
"10 10 lineto " # explicit closing line
"closepath",
- repr(tpen)
+ repr(tpen),
)
def test_closed_line_overlapping_start_end_points(self):
@@ -193,7 +198,7 @@ class PointToSegmentPenTest(unittest.TestCase):
"0 651 lineto "
"0 651 lineto "
"closepath",
- repr(tpen)
+ repr(tpen),
)
def test_roundTrip2(self):
@@ -212,19 +217,19 @@ class PointToSegmentPenTest(unittest.TestCase):
"addPoint((0, 101), segmentType='line') "
"addPoint((0, 651), segmentType='line') "
"endPath()",
- repr(tpen)
+ repr(tpen),
)
class TestSegmentToPointPen(unittest.TestCase):
-
def test_move(self):
tpen = _TestPointPen()
pen = SegmentToPointPen(tpen)
pen.moveTo((10, 10))
pen.endPath()
- self.assertEqual("beginPath() addPoint((10, 10), segmentType='move') endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((10, 10), segmentType='move') endPath()", repr(tpen)
+ )
def test_poly(self):
tpen = _TestPointPen()
@@ -233,10 +238,12 @@ class TestSegmentToPointPen(unittest.TestCase):
pen.lineTo((10, 20))
pen.lineTo((20, 20))
pen.closePath()
- self.assertEqual("beginPath() addPoint((10, 10), segmentType='line') "
- "addPoint((10, 20), segmentType='line') "
- "addPoint((20, 20), segmentType='line') endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((10, 10), segmentType='line') "
+ "addPoint((10, 20), segmentType='line') "
+ "addPoint((20, 20), segmentType='line') endPath()",
+ repr(tpen),
+ )
def test_cubic(self):
tpen = _TestPointPen()
@@ -244,9 +251,12 @@ class TestSegmentToPointPen(unittest.TestCase):
pen.moveTo((10, 10))
pen.curveTo((10, 20), (20, 20), (20, 10))
pen.closePath()
- self.assertEqual("beginPath() addPoint((10, 10), segmentType='line') "
- "addPoint((10, 20)) addPoint((20, 20)) addPoint((20, 10), "
- "segmentType='curve') endPath()", repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((10, 10), segmentType='line') "
+ "addPoint((10, 20)) addPoint((20, 20)) addPoint((20, 10), "
+ "segmentType='curve') endPath()",
+ repr(tpen),
+ )
def test_quad(self):
tpen = _TestPointPen()
@@ -254,19 +264,23 @@ class TestSegmentToPointPen(unittest.TestCase):
pen.moveTo((10, 10))
pen.qCurveTo((10, 20), (20, 20), (20, 10))
pen.closePath()
- self.assertEqual("beginPath() addPoint((10, 10), segmentType='line') "
- "addPoint((10, 20)) addPoint((20, 20)) "
- "addPoint((20, 10), segmentType='qcurve') endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((10, 10), segmentType='line') "
+ "addPoint((10, 20)) addPoint((20, 20)) "
+ "addPoint((20, 10), segmentType='qcurve') endPath()",
+ repr(tpen),
+ )
def test_quad2(self):
tpen = _TestPointPen()
pen = SegmentToPointPen(tpen)
pen.qCurveTo((10, 20), (20, 20), (20, 10), (10, 10), None)
pen.closePath()
- self.assertEqual("beginPath() addPoint((10, 20)) addPoint((20, 20)) "
- "addPoint((20, 10)) addPoint((10, 10)) endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((10, 20)) addPoint((20, 20)) "
+ "addPoint((20, 10)) addPoint((10, 10)) endPath()",
+ repr(tpen),
+ )
def test_roundTrip1(self):
spen = _TestSegmentPen()
@@ -282,31 +296,34 @@ class TestSegmentToPointPen(unittest.TestCase):
pen = SegmentToPointPen(PointToSegmentPen(spen))
pen.qCurveTo((10, 20), (20, 20), (20, 10), (10, 10), None)
pen.closePath()
- pen.addComponent('base', [1, 0, 0, 1, 0, 0])
- self.assertEqual("10 20 20 20 20 10 10 10 None qcurveto closepath "
- "'base' [1, 0, 0, 1, 0, 0] addcomponent",
- repr(spen))
+ pen.addComponent("base", [1, 0, 0, 1, 0, 0])
+ self.assertEqual(
+ "10 20 20 20 20 10 10 10 None qcurveto closepath "
+ "'base' [1, 0, 0, 1, 0, 0] addcomponent",
+ repr(spen),
+ )
class TestGuessSmoothPointPen(unittest.TestCase):
-
def test_guessSmooth_exact(self):
tpen = _TestPointPen()
pen = GuessSmoothPointPen(tpen)
pen.beginPath(identifier="foo")
pen.addPoint((0, 100), segmentType="curve")
pen.addPoint((0, 200))
- pen.addPoint((400, 200), identifier='bar')
+ pen.addPoint((400, 200), identifier="bar")
pen.addPoint((400, 100), segmentType="curve")
pen.addPoint((400, 0))
pen.addPoint((0, 0))
pen.endPath()
- self.assertEqual("beginPath(identifier='foo') "
- "addPoint((0, 100), segmentType='curve', smooth=True) "
- "addPoint((0, 200)) addPoint((400, 200), identifier='bar') "
- "addPoint((400, 100), segmentType='curve', smooth=True) "
- "addPoint((400, 0)) addPoint((0, 0)) endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath(identifier='foo') "
+ "addPoint((0, 100), segmentType='curve', smooth=True) "
+ "addPoint((0, 200)) addPoint((400, 200), identifier='bar') "
+ "addPoint((400, 100), segmentType='curve', smooth=True) "
+ "addPoint((400, 0)) addPoint((0, 0)) endPath()",
+ repr(tpen),
+ )
def test_guessSmooth_almost(self):
tpen = _TestPointPen()
@@ -319,11 +336,13 @@ class TestGuessSmoothPointPen(unittest.TestCase):
pen.addPoint((400, 0))
pen.addPoint((0, 0))
pen.endPath()
- self.assertEqual("beginPath() addPoint((0, 100), segmentType='curve', smooth=True) "
- "addPoint((1, 200)) addPoint((395, 200)) "
- "addPoint((400, 100), segmentType='curve', smooth=True) "
- "addPoint((400, 0)) addPoint((0, 0)) endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((0, 100), segmentType='curve', smooth=True) "
+ "addPoint((1, 200)) addPoint((395, 200)) "
+ "addPoint((400, 100), segmentType='curve', smooth=True) "
+ "addPoint((400, 0)) addPoint((0, 0)) endPath()",
+ repr(tpen),
+ )
def test_guessSmooth_tangent(self):
tpen = _TestPointPen()
@@ -335,24 +354,26 @@ class TestGuessSmoothPointPen(unittest.TestCase):
pen.addPoint((300, 200))
pen.addPoint((400, 200), segmentType="curve")
pen.endPath()
- self.assertEqual("beginPath() addPoint((0, 0), segmentType='move') "
- "addPoint((0, 100), segmentType='line', smooth=True) "
- "addPoint((3, 200)) addPoint((300, 200)) "
- "addPoint((400, 200), segmentType='curve') endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() addPoint((0, 0), segmentType='move') "
+ "addPoint((0, 100), segmentType='line', smooth=True) "
+ "addPoint((3, 200)) addPoint((300, 200)) "
+ "addPoint((400, 200), segmentType='curve') endPath()",
+ repr(tpen),
+ )
-class TestReverseContourPointPen(unittest.TestCase):
+class TestReverseContourPointPen(unittest.TestCase):
def test_singlePoint(self):
tpen = _TestPointPen()
pen = ReverseContourPointPen(tpen)
pen.beginPath()
pen.addPoint((0, 0), segmentType="move")
pen.endPath()
- self.assertEqual("beginPath() "
- "addPoint((0, 0), segmentType='move') "
- "endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() " "addPoint((0, 0), segmentType='move') " "endPath()",
+ repr(tpen),
+ )
def test_line(self):
tpen = _TestPointPen()
@@ -361,11 +382,13 @@ class TestReverseContourPointPen(unittest.TestCase):
pen.addPoint((0, 0), segmentType="move")
pen.addPoint((0, 100), segmentType="line")
pen.endPath()
- self.assertEqual("beginPath() "
- "addPoint((0, 100), segmentType='move') "
- "addPoint((0, 0), segmentType='line') "
- "endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() "
+ "addPoint((0, 100), segmentType='move') "
+ "addPoint((0, 0), segmentType='line') "
+ "endPath()",
+ repr(tpen),
+ )
def test_triangle(self):
tpen = _TestPointPen()
@@ -375,12 +398,14 @@ class TestReverseContourPointPen(unittest.TestCase):
pen.addPoint((0, 100), segmentType="line")
pen.addPoint((100, 100), segmentType="line")
pen.endPath()
- self.assertEqual("beginPath() "
- "addPoint((0, 0), segmentType='line') "
- "addPoint((100, 100), segmentType='line') "
- "addPoint((0, 100), segmentType='line') "
- "endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() "
+ "addPoint((0, 0), segmentType='line') "
+ "addPoint((100, 100), segmentType='line') "
+ "addPoint((0, 100), segmentType='line') "
+ "endPath()",
+ repr(tpen),
+ )
def test_cubicOpen(self):
tpen = _TestPointPen()
@@ -391,13 +416,15 @@ class TestReverseContourPointPen(unittest.TestCase):
pen.addPoint((100, 200))
pen.addPoint((200, 200), segmentType="curve")
pen.endPath()
- self.assertEqual("beginPath() "
- "addPoint((200, 200), segmentType='move') "
- "addPoint((100, 200)) "
- "addPoint((0, 100)) "
- "addPoint((0, 0), segmentType='curve') "
- "endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() "
+ "addPoint((200, 200), segmentType='move') "
+ "addPoint((100, 200)) "
+ "addPoint((0, 100)) "
+ "addPoint((0, 0), segmentType='curve') "
+ "endPath()",
+ repr(tpen),
+ )
def test_quadOpen(self):
tpen = _TestPointPen()
@@ -408,13 +435,15 @@ class TestReverseContourPointPen(unittest.TestCase):
pen.addPoint((100, 200))
pen.addPoint((200, 200), segmentType="qcurve")
pen.endPath()
- self.assertEqual("beginPath() "
- "addPoint((200, 200), segmentType='move') "
- "addPoint((100, 200)) "
- "addPoint((0, 100)) "
- "addPoint((0, 0), segmentType='qcurve') "
- "endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() "
+ "addPoint((200, 200), segmentType='move') "
+ "addPoint((100, 200)) "
+ "addPoint((0, 100)) "
+ "addPoint((0, 0), segmentType='qcurve') "
+ "endPath()",
+ repr(tpen),
+ )
def test_cubicClosed(self):
tpen = _TestPointPen()
@@ -425,13 +454,15 @@ class TestReverseContourPointPen(unittest.TestCase):
pen.addPoint((100, 200))
pen.addPoint((200, 200), segmentType="curve")
pen.endPath()
- self.assertEqual("beginPath() "
- "addPoint((0, 0), segmentType='curve') "
- "addPoint((200, 200), segmentType='line') "
- "addPoint((100, 200)) "
- "addPoint((0, 100)) "
- "endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() "
+ "addPoint((0, 0), segmentType='curve') "
+ "addPoint((200, 200), segmentType='line') "
+ "addPoint((100, 200)) "
+ "addPoint((0, 100)) "
+ "endPath()",
+ repr(tpen),
+ )
def test_quadClosedOffCurveStart(self):
tpen = _TestPointPen()
@@ -442,32 +473,36 @@ class TestReverseContourPointPen(unittest.TestCase):
pen.addPoint((0, 0), segmentType="line")
pen.addPoint((0, 100))
pen.endPath()
- self.assertEqual("beginPath() "
- "addPoint((100, 200)) "
- "addPoint((0, 100)) "
- "addPoint((0, 0), segmentType='qcurve') "
- "addPoint((200, 200), segmentType='line') "
- "endPath()",
- repr(tpen))
+ self.assertEqual(
+ "beginPath() "
+ "addPoint((100, 200)) "
+ "addPoint((0, 100)) "
+ "addPoint((0, 0), segmentType='qcurve') "
+ "addPoint((200, 200), segmentType='line') "
+ "endPath()",
+ repr(tpen),
+ )
def test_quadNoOnCurve(self):
tpen = _TestPointPen()
pen = ReverseContourPointPen(tpen)
- pen.beginPath(identifier='bar')
+ pen.beginPath(identifier="bar")
pen.addPoint((0, 0))
- pen.addPoint((0, 100), identifier='foo', arbitrary='foo')
+ pen.addPoint((0, 100), identifier="foo", arbitrary="foo")
pen.addPoint((100, 200), arbitrary=123)
pen.addPoint((200, 200))
pen.endPath()
- pen.addComponent("base", [1, 0, 0, 1, 0, 0], identifier='foo')
- self.assertEqual("beginPath(identifier='bar') "
- "addPoint((0, 0)) "
- "addPoint((200, 200)) "
- "addPoint((100, 200), arbitrary=123) "
- "addPoint((0, 100), identifier='foo', arbitrary='foo') "
- "endPath() "
- "addComponent('base', [1, 0, 0, 1, 0, 0], identifier='foo')",
- repr(tpen))
+ pen.addComponent("base", [1, 0, 0, 1, 0, 0], identifier="foo")
+ self.assertEqual(
+ "beginPath(identifier='bar') "
+ "addPoint((0, 0)) "
+ "addPoint((200, 200)) "
+ "addPoint((100, 200), arbitrary=123) "
+ "addPoint((0, 100), identifier='foo', arbitrary='foo') "
+ "endPath() "
+ "addComponent('base', [1, 0, 0, 1, 0, 0], identifier='foo')",
+ repr(tpen),
+ )
def test_closed_line_overlapping_start_end_points(self):
# Test case from https://github.com/googlefonts/fontmake/issues/572
@@ -486,5 +521,5 @@ class TestReverseContourPointPen(unittest.TestCase):
"addPoint((0, 101), segmentType='line') "
"addPoint((0, 101), segmentType='line') "
"endPath()",
- repr(tpen)
+ repr(tpen),
)