1from __future__ import print_function, division, absolute_import 2from fontTools.misc.py23 import * 3from fontTools.pens.boundsPen import BoundsPen, ControlBoundsPen 4import unittest 5 6 7def draw_(pen): 8 pen.moveTo((0, 0)) 9 pen.lineTo((0, 100)) 10 pen.qCurveTo((50, 75), (60, 50), (50, 25), (0, 0)) 11 pen.curveTo((-50, 25), (-60, 50), (-50, 75), (0, 100)) 12 pen.closePath() 13 14 15def bounds_(pen): 16 return " ".join(["%.0f" % c for c in pen.bounds]) 17 18 19class BoundsPenTest(unittest.TestCase): 20 def test_draw(self): 21 pen = BoundsPen(None) 22 draw_(pen) 23 self.assertEqual("-55 0 58 100", bounds_(pen)) 24 25 def test_empty(self): 26 pen = BoundsPen(None) 27 self.assertEqual(None, pen.bounds) 28 29 def test_curve(self): 30 pen = BoundsPen(None) 31 pen.moveTo((0, 0)) 32 pen.curveTo((20, 10), (90, 40), (0, 0)) 33 self.assertEqual("0 0 45 20", bounds_(pen)) 34 35 def test_quadraticCurve(self): 36 pen = BoundsPen(None) 37 pen.moveTo((0, 0)) 38 pen.qCurveTo((6, 6), (10, 0)) 39 self.assertEqual("0 0 10 3", bounds_(pen)) 40 41 42class ControlBoundsPenTest(unittest.TestCase): 43 def test_draw(self): 44 pen = ControlBoundsPen(None) 45 draw_(pen) 46 self.assertEqual("-55 0 60 100", bounds_(pen)) 47 48 def test_empty(self): 49 pen = ControlBoundsPen(None) 50 self.assertEqual(None, pen.bounds) 51 52 def test_curve(self): 53 pen = ControlBoundsPen(None) 54 pen.moveTo((0, 0)) 55 pen.curveTo((20, 10), (90, 40), (0, 0)) 56 self.assertEqual("0 0 90 40", bounds_(pen)) 57 58 def test_quadraticCurve(self): 59 pen = ControlBoundsPen(None) 60 pen.moveTo((0, 0)) 61 pen.qCurveTo((6, 6), (10, 0)) 62 self.assertEqual("0 0 10 6", bounds_(pen)) 63 64 def test_singlePoint(self): 65 pen = ControlBoundsPen(None) 66 pen.moveTo((-5, 10)) 67 self.assertEqual("-5 10 -5 10", bounds_(pen)) 68 69 def test_ignoreSinglePoint(self): 70 pen = ControlBoundsPen(None, ignoreSinglePoints=True) 71 pen.moveTo((0, 10)) 72 self.assertEqual(None, pen.bounds) 73 74 75if __name__ == '__main__': 76 import sys 77 sys.exit(unittest.main()) 78