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