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)
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)
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)
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)
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)
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)
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)
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)