Example #1
0
 def test_cubic02_01_path05_bbox(self):
     # See also: cubic02_01.html
     d = 'm600,500 c0,-150 300,150 300,0'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(600, bbox.x, places=places)
     self.assertAlmostEqual(456.699, bbox.y, places=places)
     self.assertAlmostEqual(300, bbox.width, places=places)
     self.assertAlmostEqual(86.603, bbox.height, places=places)
Example #2
0
 def test_cubic02_01_path02_bbox(self):
     # See also: cubic02_01.html
     d = 'm100,500 c-75,-100 375,-100 300,0'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(91.534, bbox.x, places=places)
     self.assertAlmostEqual(425, bbox.y, places=places)
     self.assertAlmostEqual(316.933, bbox.width, places=places)
     self.assertAlmostEqual(75, bbox.height, places=places)
Example #3
0
 def test_cubic02_path06_transform(self):
     # See also: cubic02.html
     d = 'M600,800 C625,700 725,700 750,800 S875,900 900,800'
     path_data = PathParser.parse(d)
     matrix = DOMMatrix()
     matrix.translate_self(-50, 50)
     transformed = PathParser.transform(path_data, matrix)
     d2 = PathParser.tostring(transformed)
     expected = 'M550,850 C575,750 675,750 700,850 S825,950 850,850'
     self.assertEqual(expected, d2)
Example #4
0
 def test_cubic02_path06_bbox(self):
     # See also: cubic02.html
     d = 'M600,800 C625,700 725,700 750,800 S875,900 900,800'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(600, bbox.x, places=places)
     self.assertAlmostEqual(725, bbox.y, places=places)
     self.assertAlmostEqual(300, bbox.width, places=places)
     self.assertAlmostEqual(150, bbox.height, places=places)
Example #5
0
 def test_cubic02_01_path06_bbox(self):
     # See also: cubic02_01.html
     d = 'm600,800 c25,-100 125,-100 150,0 s125,100 150,0'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(600, bbox.x, places=places)
     self.assertAlmostEqual(725, bbox.y, places=places)
     self.assertAlmostEqual(300, bbox.width, places=places)
     self.assertAlmostEqual(150, bbox.height, places=places)
Example #6
0
 def test_cubic03_path04_bbox(self):
     # See also: cubic03.html
     d = 'm575,200 c20,100 50,100 70,0 20,-100 55,-100 75,0'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(575, bbox.x, places=places)
     self.assertAlmostEqual(125, bbox.y, places=places)
     self.assertAlmostEqual(145, bbox.width, places=places)
     self.assertAlmostEqual(150, bbox.height, places=places)
Example #7
0
 def test_cubic02_path03_transform(self):
     # See also: cubic02.html
     d = 'M100,800 C175,700 325,700 400,800'
     path_data = PathParser.parse(d)
     matrix = DOMMatrix()
     matrix.translate_self(-50, 50)
     transformed = PathParser.transform(path_data, matrix)
     d2 = PathParser.tostring(transformed)
     expected = 'M50,850 C125,750 275,750 350,850'
     self.assertEqual(expected, d2)
Example #8
0
 def test_quad01_path01_transform(self):
     # See also: quad01.html
     d = 'M200,300 Q400,50 600,300 T1000,300'
     path_data = PathParser.parse(d)
     matrix = DOMMatrix()
     matrix.translate_self(-50, 50)
     transformed = PathParser.transform(path_data, matrix)
     d2 = PathParser.tostring(transformed)
     expected = 'M150,350 Q350,100 550,350 T950,350'
     self.assertEqual(expected, d2)
Example #9
0
 def test_cubic02_path05_transform(self):
     # See also: cubic02.html
     d = 'M600,500 C600,350 900,650 900,500'
     path_data = PathParser.parse(d)
     matrix = DOMMatrix()
     matrix.translate_self(-50, 50)
     transformed = PathParser.transform(path_data, matrix)
     d2 = PathParser.tostring(transformed)
     expected = 'M550,550 C550,400 850,700 850,550'
     self.assertEqual(expected, d2)
Example #10
0
 def test_quad01_path02_bbox(self):
     # See also: quad01.html
     d = 'M200,300 Q400,50 600,300'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(200, bbox.x, places=places)
     self.assertAlmostEqual(175, bbox.y, places=places)
     self.assertAlmostEqual(400, bbox.width, places=places)
     self.assertAlmostEqual(125, bbox.height, places=places)
Example #11
0
 def test_quad01_path01_normalize(self):
     # See also: quad01.html
     d = 'M200,300 Q400,50 600,300 T1000,300'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     d = PathParser.tostring(normalized)
     expected = "M200,300" \
                " C333.333,133.333 466.667,133.333 600,300" \
                " 733.333,466.667 866.667,466.667 1000,300"
     self.assertEqual(expected, d)
Example #12
0
 def test_cubic01_path01_transform(self):
     # See also: cubic01.html
     d = 'M100,200 C100,100 250,100 250,200 S400,300 400,200'
     path_data = PathParser.parse(d)
     matrix = DOMMatrix()
     matrix.translate_self(-50, 50)
     transformed = PathParser.transform(path_data, matrix)
     d2 = PathParser.tostring(transformed)
     expected = 'M50,250 C50,150 200,150 200,250 S350,350 350,250'
     self.assertEqual(expected, d2)
Example #13
0
 def test_cubic03_path02_bbox(self):
     # See also: cubic03.html
     d = 'M175,200 C195,300 225,300 245,200 265,100 300,100 320,200'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(175, bbox.x, places=places)
     self.assertAlmostEqual(125, bbox.y, places=places)
     self.assertAlmostEqual(145, bbox.width, places=places)
     self.assertAlmostEqual(150, bbox.height, places=places)
Example #14
0
 def test_arcs02_path04_bearing(self):
     # See also: arcs02.html
     # same as 'transform="rotate(90 125 75)"'
     d = 'M 125,75 B90 a100,50 0 1,1 100,50'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = \
         "M125,75 C152.614,75 175,119.772 175,175" \
         " 175,230.228 152.614,275 125,275 97.386,275 75,230.228 75,175"
     self.assertEqual(expected, exp)
Example #15
0
 def test_arcs02_path03_bearing(self):
     # See also: arcs02.html
     # same as 'transform="rotate(90 125 75)"'
     d = 'M 125,75 B90 a100,50 0 1,0 100,50'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = \
         "M125,75 C125,19.772 102.614,-25 75,-25" \
         " 47.386,-25 25,19.772 25,75 25,130.228 47.386,175 75,175"
     self.assertEqual(expected, exp)
Example #16
0
 def test_arcs02_path02_normalize(self):
     # See also: arcs02.html
     # x_axis_rotation: 0
     # large_arc_flag: 0
     # sweep_flag: 1
     d = 'M 125,75 a100,50 0 0,1 100,50'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = 'M125,75 C180.228,75 225,97.386 225,125'
     self.assertEqual(expected, exp)
Example #17
0
 def test_arcs02_path01_normalize(self):
     # See also: arcs02.html
     # x_axis_rotation: 0
     # large_arc_flag: 0
     # sweep_flag: 0
     d = 'M125,75 a100,50 0 0 0 100,50'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = 'M125,75 C125,102.614 169.772,125 225,125'
     self.assertEqual(expected, exp)
Example #18
0
 def test_quad02_path03_normalize(self):
     # See also: quad02.html
     d = 'm200,300 q200,-250 400,0 t400,0 400,0'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     d = PathParser.tostring(normalized)
     expected = "M200,300" \
                " C333.333,133.333 466.667,133.333 600,300" \
                " 733.333,466.667 866.667,466.667 1000,300" \
                " 1133.333,133.333 1266.667,133.333 1400,300"
     self.assertEqual(expected, d)
Example #19
0
 def test_ellipse01_path21_normalize(self):
     # See also: ellipse01.html
     d = 'M93.969,-85.505 A100,250 0 0 1 70.711,176.777'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = \
         "M93.969,-85.505" \
         " C96.024,-107.64 104.802,-23.844 97.457,56.022" \
         " 90.111,135.889 67.575,201.684 70.711,176.777"
     self.assertEqual(expected, exp)
Example #20
0
 def test_cubic03_path01_bbox(self):
     # See also: cubic03.html
     d = "M100,200" \
         " C120,100 155,100 175,200 S225,300 245,200 300,100 320,200"
     path_data = PathParser.parse(d)
     path_data = PathParser.normalize(path_data)
     bbox = PathParser.get_bbox(path_data)
     self.assertAlmostEqual(100, bbox.x, places=places)
     self.assertAlmostEqual(125, bbox.y, places=places)
     self.assertAlmostEqual(220, bbox.width, places=places)
     self.assertAlmostEqual(150, bbox.height, places=places)
Example #21
0
    def test_lineto_abs_normalize(self):
        path_data = list()
        path_data.append(SVGPathSegment('M', 100, 100))
        path_data.append(SVGPathSegment('L', 300, 100))
        path_data.append(SVGPathSegment('L', 200, 300))
        path_data.append(SVGPathSegment('z'))

        normalized = PathParser.normalize(path_data)
        d = PathParser.tostring(normalized)
        expected = 'M100,100 L300,100 200,300 Z'
        self.assertEqual(expected, d)
Example #22
0
    def test_horizontal_lineto_rel_length(self):
        path_data = list()
        path_data.append(SVGPathSegment('m', 100, 50))
        path_data.append(SVGPathSegment('h', -100))
        d = PathParser.tostring(path_data)
        expected = 'm100,50 h-100'
        self.assertEqual(expected, d)

        n = PathParser.get_total_length(path_data)
        expected = 100
        self.assertAlmostEqual(expected, n)
Example #23
0
 def test_arcs01_path06_length(self):
     # See also: arcs01.html
     # (cx,cy)=(945.586, 226.768)
     # s=(950, 175)
     # e=(50, -25)
     d = 'M950,175 a25,100 +30 0,1 50,-25'
     path_data = PathParser.parse(d)
     n = PathParser.get_total_length(path_data)
     # expected = 71.29801177978516  # firefox
     expected = 71.29816436767578
     self.assertAlmostEqual(expected, n, places=places)
Example #24
0
 def test_path_transform02(self):
     # See also: svg.svg
     # Mm Aa Hh Zz
     d = 'M-27-5a7,7,0,1,0,0,10h54a7,7,0,1,0,0-10z'
     path_data = PathParser.parse(d)
     matrix = DOMMatrix()
     matrix.rotate_self(rot_z=90)
     transformed = PathParser.transform(path_data, matrix)
     exp = PathParser.tostring(transformed)
     expected = 'M5,-27 A7,7 0 1 0 -5,-27 L-5,27 A7,7 0 1 0 5,27 Z'
     self.assertEqual(expected, exp)
Example #25
0
 def test_horizontal_lineto_rel_bbox(self):
     path_data = list()
     path_data.append(SVGPathSegment('m', 100, 50))
     path_data.append(SVGPathSegment('h', -100))
     normalized = PathParser.normalize(path_data)
     # "M100,50 L0,50"
     bbox = PathParser.get_bbox(normalized)
     self.assertAlmostEqual(0, bbox.x, places=places)
     self.assertAlmostEqual(50, bbox.y, places=places)
     self.assertAlmostEqual(100, bbox.width, places=places)
     self.assertAlmostEqual(0, bbox.height, places=places)
Example #26
0
 def test_path_normalize_negative01(self):
     # cx=0 cy=0 r=100
     # large_arc_flag=0, sweep_flag=1
     # angle: 30 to -30
     d = "M86.60254037844388,-49.99999999999999" \
         " A100,100 0 0 1 86.60254037844386,50.000000000000014"
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = 'M86.603,-50 C104.466,-19.06 104.466,19.06 86.603,50'
     self.assertEqual(expected, exp)
Example #27
0
 def test_ellipse01_path33_normalize(self):
     # See also: ellipse01.html
     d = 'M-85.505,93.969 A250,100 0 0 0 176.777,70.711'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = \
         "M-85.505,93.969" \
         " C-107.64,96.024 -23.844,104.802 56.022,97.457" \
         " 135.889,90.111 201.684,67.575 176.777,70.711"
     self.assertEqual(expected, exp)
Example #28
0
 def test_ellipse01_path31_normalize(self):
     # See also: ellipse01.html
     d = 'M85.505,-93.969 A250,100 0 0 0 -176.777,-70.711'
     path_data = PathParser.parse(d)
     normalized = PathParser.normalize(path_data)
     exp = PathParser.tostring(normalized)
     expected = \
         "M85.505,-93.969" \
         " C107.64,-96.024 23.844,-104.802 -56.022,-97.457" \
         " -135.889,-90.111 -201.684,-67.575 -176.777,-70.711"
     self.assertEqual(expected, exp)
Example #29
0
 def test_path_transform03(self):
     # See also: svg.svg
     # Mm Aa Hh Zz
     d = 'M-27-5a7,7,0,1,0,0,10h54a7,7,0,1,0,0-10z'
     path_data = PathParser.parse(d)
     matrix = DOMMatrix()
     matrix.rotate_self(rot_z=135)
     transformed = PathParser.transform(path_data, matrix)
     exp = PathParser.tostring(transformed)
     expected = "M22.627,-15.556 A7,7 0 1 0 15.556,-22.627 L-22.627,15.556" \
                " A7,7 0 1 0 -15.556,22.627 Z"
     self.assertEqual(expected, exp)
Example #30
0
 def test_arcs01_path03_length(self):
     # See also: arcs01.html
     d = "M600,350 l 50,-25 " \
         "a25,25  -30 0,1 50,-25 l 50,-25 " \
         "a25,50  -30 0,1 50,-25 l 50,-25 " \
         "a25,75  -30 0,1 50,-25 l 50,-25 " \
         "a25,100 -30 0,1 50,-25 l 50,-25"
     path_data = PathParser.parse(d)
     n = PathParser.get_total_length(path_data)
     expected = 928.3827514648438
     # expected = 928.4309692382812
     self.assertAlmostEqual(expected, n, places=places)