Beispiel #1
0
 def test_cubic02_path01_transform(self):
     # See also: cubic02.html
     d = 'M100,200 C100,100 400,100 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 350,150 350,250'
     self.assertEqual(expected, d2)
Beispiel #2
0
 def test_quad02_path03_transform(self):
     # See also: quad01.html
     d = 'm200,300 q200,-250 400,0 t400,0 400,0'
     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 1350,350'
     self.assertEqual(expected, d2)
Beispiel #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)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
 def test_cubic03_path01_transform(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)
     matrix = DOMMatrix()
     matrix.translate_self(-50, 50)
     transformed = PathParser.transform(path_data, matrix)
     d2 = PathParser.tostring(transformed)
     expected = \
         "M50,250 C70,150 105,150 125,250 S175,350 195,250 250,150 270,250"
     self.assertEqual(expected, d2)
Beispiel #8
0
    def test_bearing01_transform02(self):
        # See also: bearing01.html
        d = 'M150,10 B36 h47 b72 h47 b72 h47 b72 h47 Z'
        path_data = PathParser.parse(d)

        matrix = DOMMatrix()
        matrix = matrix.flip_y()
        transformed = PathParser.transform(path_data, matrix)
        d = PathParser.tostring(transformed)
        expected = \
            "M150,-10 L188.023799,-37.625907 173.5,-82.325563" \
            " 126.5,-82.325563 111.976201,-37.625907 Z"
        self.assertEqual(expected, d)
Beispiel #9
0
    def test_bearing01_transform01(self):
        # See also: bearing01.html
        d = 'M150,10 B36 h47 b72 h47 b72 h47 b72 h47 Z'
        path_data = PathParser.parse(d)

        matrix = DOMMatrix()
        matrix.translate_self(10, 10)
        transformed = PathParser.transform(path_data, matrix)
        d = PathParser.tostring(transformed)
        expected = \
            "M160,20 L198.023799,47.625907 183.5,92.325563 136.5,92.325563" \
            " 121.976201,47.625907 Z"
        self.assertEqual(expected, d)
Beispiel #10
0
    def test_transform_set_matrix(self):
        t = SVGTransform(SVGTransform.SVG_TRANSFORM_MATRIX, 1, 2, 3, 4, 5, 6)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_MATRIX, t.type)
        self.assertEqual('matrix(1, 2, 3, 4, 5, 6)', t.tostring())
        self.assertTrue(DOMMatrix([1, 2, 3, 4, 5, 6]) == t.matrix)
        self.assertTrue((np.array([[1, 3, 0, 5], [2, 4, 0, 6], [0, 0, 1, 0],
                                   [0, 0, 0, 1]]) == t.matrix.matrix).all())

        t = SVGTransform()
        matrix = DOMMatrix([-1, 1.2, 3, -1.4, 5, 1.6])
        t.set_matrix(matrix)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_MATRIX, t.type)
        self.assertEqual('matrix(-1, 1.2, 3, -1.4, 5, 1.6)', t.tostring())
        self.assertTrue(DOMMatrix([-1, 1.2, 3, -1.4, 5, 1.6]) == t.matrix)
        self.assertEqual(0, t.angle)

        t = SVGTransform()
        matrix = DOMMatrix(is2d=False)
        self.assertFalse(matrix.is2d)
        # t.set_matrix(matrix)
        self.assertRaises(ValueError, lambda: t.set_matrix(matrix))
Beispiel #11
0
    def test_transform_list_consolidate(self):
        # See also: RotateScale.html
        transform_list = SVGTransformList.parse('translate(50,30) rotate(30)')
        self.assertEqual(2, len(transform_list))

        t = transform_list.consolidate()
        self.assertEqual(1, len(transform_list))
        self.assertEqual(transform_list[0], t)
        m = DOMMatrix([
            0.8660254037844387, 0.49999999999999994, -0.49999999999999994,
            0.8660254037844387, 50, 30
        ])
        self.assertEqual(SVGTransform.SVG_TRANSFORM_MATRIX, t.type)
        self.assertTrue(t.matrix == m)
Beispiel #12
0
    def test_transform_set_skew_y(self):
        a = 190.0001
        m = DOMMatrix()
        m.skew_y_self(a)

        t = SVGTransform(SVGTransform.SVG_TRANSFORM_SKEWY, a)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_SKEWY, t.type)
        self.assertEqual('skewY(190)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(a, t.angle)

        a = -120.4567
        m = DOMMatrix()
        m.skew_y_self(a)

        t = SVGTransform()
        t.set_skew_y(a)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_SKEWY, t.type)
        self.assertEqual('skewY(-120.457)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(a, t.angle)
Beispiel #13
0
    def test_transform_set_scale(self):
        sx = 1.5
        sy = 1.5
        m = DOMMatrix()
        m.scale_self(sx, sy)

        t = SVGTransform(SVGTransform.SVG_TRANSFORM_SCALE, sx, sy)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_SCALE, t.type)
        self.assertEqual('scale(1.5)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(0, t.angle)

        sy = -0
        m = DOMMatrix()
        m.scale_self(sx, sy)

        t = SVGTransform()
        t.set_scale(sx, sy)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_SCALE, t.type)
        self.assertEqual('scale(1.5, 0)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(0, t.angle)
Beispiel #14
0
    def test_transform_set_translate(self):
        tx = 100
        ty = -100
        m = DOMMatrix()
        m.translate_self(tx, ty)

        t = SVGTransform(SVGTransform.SVG_TRANSFORM_TRANSLATE, tx, ty)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_TRANSLATE, t.type)
        self.assertEqual('translate(100, -100)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(0, t.angle)

        tx = -1.5
        ty = -0
        m = DOMMatrix()
        m.translate_self(tx, ty)

        t = SVGTransform()
        t.set_translate(tx, ty)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_TRANSLATE, t.type)
        self.assertEqual('translate(-1.5)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(0, t.angle)
Beispiel #15
0
    def test_transform_set_rotate(self):
        r = -30
        cx = 24
        cy = 16
        m = DOMMatrix()
        m.translate_self(cx, cy)
        m.rotate_self(rot_z=r)
        m.translate_self(-cx, -cy)

        t = SVGTransform(SVGTransform.SVG_TRANSFORM_ROTATE, r, cx, cy)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_ROTATE, t.type)
        self.assertEqual('rotate(-30, 24, 16)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(r, t.angle)

        cx = 12.3456
        cy = -0
        m = DOMMatrix()
        m.translate_self(cx, cy)
        m.rotate_self(rot_z=r)
        m.translate_self(-cx, -cy)

        t = SVGTransform()
        t.set_rotate(r, cx, cy)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_ROTATE, t.type)
        self.assertEqual('rotate(-30, 12.346, 0)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(r, t.angle)

        cx = -0
        cy = -0
        m = DOMMatrix()
        m.rotate_self(rot_z=r)

        t = SVGTransform()
        t.set_rotate(r, cx, cy)
        self.assertEqual(SVGTransform.SVG_TRANSFORM_ROTATE, t.type)
        self.assertEqual('rotate(-30)', t.tostring())
        self.assertTrue(m == t.matrix)
        self.assertEqual(r, t.angle)