1 from __future__ import print_function, division, absolute_import 2 from fontTools.misc.py23 import * 3 from fontTools.pens.perimeterPen import PerimeterPen 4 import unittest 5 6 def draw1_(pen): 7 pen.moveTo( (254, 360) ) 8 pen.lineTo( (771, 367) ) 9 pen.curveTo( (800, 393), (808, 399), (819, 412) ) 10 pen.curveTo( (818, 388), (774, 138), (489, 145) ) 11 pen.curveTo( (188, 145), (200, 398), (200, 421) ) 12 pen.curveTo( (209, 409), (220, 394), (254, 360) ) 13 pen.closePath() 14 15 def draw2_(pen): 16 pen.moveTo( (254, 360) ) 17 pen.curveTo( (220, 394), (209, 409), (200, 421) ) 18 pen.curveTo( (200, 398), (188, 145), (489, 145) ) 19 pen.curveTo( (774, 138), (818, 388), (819, 412) ) 20 pen.curveTo( (808, 399), (800, 393), (771, 367) ) 21 pen.closePath() 22 23 def draw3_(pen): 24 pen.moveTo( (771, 367) ) 25 pen.curveTo( (800, 393), (808, 399), (819, 412) ) 26 pen.curveTo( (818, 388), (774, 138), (489, 145) ) 27 pen.curveTo( (188, 145), (200, 398), (200, 421) ) 28 pen.curveTo( (209, 409), (220, 394), (254, 360) ) 29 pen.closePath() 30 31 def draw4_(pen): 32 pen.moveTo( (771, 367) ) 33 pen.lineTo( (254, 360) ) 34 pen.curveTo( (220, 394), (209, 409), (200, 421) ) 35 pen.curveTo( (200, 398), (188, 145), (489, 145) ) 36 pen.curveTo( (774, 138), (818, 388), (819, 412) ) 37 pen.curveTo( (808, 399), (800, 393), (771, 367) ) 38 pen.closePath() 39 40 def draw5_(pen): 41 pen.moveTo( (254, 360) ) 42 pen.lineTo( (771, 367) ) 43 pen.qCurveTo( (793, 386), (802, 394) ) 44 pen.qCurveTo( (811, 402), (819, 412) ) 45 pen.qCurveTo( (819, 406), (814, 383.5) ) 46 pen.qCurveTo( (809, 361), (796, 330.5) ) 47 pen.qCurveTo( (783, 300), (760.5, 266.5) ) 48 pen.qCurveTo( (738, 233), (701, 205.5) ) 49 pen.qCurveTo( (664, 178), (612, 160.5) ) 50 pen.qCurveTo( (560, 143), (489, 145) ) 51 pen.qCurveTo( (414, 145), (363, 164) ) 52 pen.qCurveTo( (312, 183), (280, 211.5) ) 53 pen.qCurveTo( (248, 240), (231.5, 274.5) ) 54 pen.qCurveTo( (215, 309), (208, 339.5) ) 55 pen.qCurveTo( (201, 370), (200.5, 392.5) ) 56 pen.qCurveTo( (200, 415), (200, 421) ) 57 pen.qCurveTo( (207, 412), (217.5, 399) ) 58 pen.qCurveTo( (228, 386), (254, 360) ) 59 pen.closePath() 60 61 def draw6_(pen): 62 pen.moveTo( (254, 360) ) 63 pen.qCurveTo( (228, 386), (217.5, 399) ) 64 pen.qCurveTo( (207, 412), (200, 421) ) 65 pen.qCurveTo( (200, 415), (200.5, 392.5) ) 66 pen.qCurveTo( (201, 370), (208, 339.5) ) 67 pen.qCurveTo( (215, 309), (231.5, 274.5) ) 68 pen.qCurveTo( (248, 240), (280, 211.5) ) 69 pen.qCurveTo( (312, 183), (363, 164) ) 70 pen.qCurveTo( (414, 145), (489, 145) ) 71 pen.qCurveTo( (560, 143), (612, 160.5) ) 72 pen.qCurveTo( (664, 178), (701, 205.5) ) 73 pen.qCurveTo( (738, 233), (760.5, 266.5) ) 74 pen.qCurveTo( (783, 300), (796, 330.5) ) 75 pen.qCurveTo( (809, 361), (814, 383.5) ) 76 pen.qCurveTo( (819, 406), (819, 412) ) 77 pen.qCurveTo( (811, 402), (802, 394) ) 78 pen.qCurveTo( (793, 386), (771, 367) ) 79 pen.closePath() 80 81 def draw7_(pen): 82 pen.moveTo( (771, 367) ) 83 pen.qCurveTo( (793, 386), (802, 394) ) 84 pen.qCurveTo( (811, 402), (819, 412) ) 85 pen.qCurveTo( (819, 406), (814, 383.5) ) 86 pen.qCurveTo( (809, 361), (796, 330.5) ) 87 pen.qCurveTo( (783, 300), (760.5, 266.5) ) 88 pen.qCurveTo( (738, 233), (701, 205.5) ) 89 pen.qCurveTo( (664, 178), (612, 160.5) ) 90 pen.qCurveTo( (560, 143), (489, 145) ) 91 pen.qCurveTo( (414, 145), (363, 164) ) 92 pen.qCurveTo( (312, 183), (280, 211.5) ) 93 pen.qCurveTo( (248, 240), (231.5, 274.5) ) 94 pen.qCurveTo( (215, 309), (208, 339.5) ) 95 pen.qCurveTo( (201, 370), (200.5, 392.5) ) 96 pen.qCurveTo( (200, 415), (200, 421) ) 97 pen.qCurveTo( (207, 412), (217.5, 399) ) 98 pen.qCurveTo( (228, 386), (254, 360) ) 99 pen.closePath() 100 101 def draw8_(pen): 102 pen.moveTo( (771, 367) ) 103 pen.lineTo( (254, 360) ) 104 pen.qCurveTo( (228, 386), (217.5, 399) ) 105 pen.qCurveTo( (207, 412), (200, 421) ) 106 pen.qCurveTo( (200, 415), (200.5, 392.5) ) 107 pen.qCurveTo( (201, 370), (208, 339.5) ) 108 pen.qCurveTo( (215, 309), (231.5, 274.5) ) 109 pen.qCurveTo( (248, 240), (280, 211.5) ) 110 pen.qCurveTo( (312, 183), (363, 164) ) 111 pen.qCurveTo( (414, 145), (489, 145) ) 112 pen.qCurveTo( (560, 143), (612, 160.5) ) 113 pen.qCurveTo( (664, 178), (701, 205.5) ) 114 pen.qCurveTo( (738, 233), (760.5, 266.5) ) 115 pen.qCurveTo( (783, 300), (796, 330.5) ) 116 pen.qCurveTo( (809, 361), (814, 383.5) ) 117 pen.qCurveTo( (819, 406), (819, 412) ) 118 pen.qCurveTo( (811, 402), (802, 394) ) 119 pen.qCurveTo( (793, 386), (771, 367) ) 120 pen.closePath() 121 122 123 class PerimeterPenTest(unittest.TestCase): 124 def test_PScontour_clockwise_line_first(self): 125 pen = PerimeterPen(None) 126 draw1_(pen) 127 self.assertEqual(1589, round(pen.value)) 128 129 def test_PScontour_counterclockwise_line_last(self): 130 pen = PerimeterPen(None) 131 draw2_(pen) 132 self.assertEqual(1589, round(pen.value)) 133 134 def test_PScontour_clockwise_line_last(self): 135 pen = PerimeterPen(None) 136 draw3_(pen) 137 self.assertEqual(1589, round(pen.value)) 138 139 def test_PScontour_counterclockwise_line_first(self): 140 pen = PerimeterPen(None) 141 draw4_(pen) 142 self.assertEqual(1589, round(pen.value)) 143 144 def test_TTcontour_clockwise_line_first(self): 145 pen = PerimeterPen(None) 146 draw5_(pen) 147 self.assertEqual(1589, round(pen.value)) 148 149 def test_TTcontour_counterclockwise_line_last(self): 150 pen = PerimeterPen(None) 151 draw6_(pen) 152 self.assertEqual(1589, round(pen.value)) 153 154 def test_TTcontour_clockwise_line_last(self): 155 pen = PerimeterPen(None) 156 draw7_(pen) 157 self.assertEqual(1589, round(pen.value)) 158 159 def test_TTcontour_counterclockwise_line_first(self): 160 pen = PerimeterPen(None) 161 draw8_(pen) 162 self.assertEqual(1589, round(pen.value)) 163 164 165 if __name__ == '__main__': 166 import sys 167 sys.exit(unittest.main()) 168