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