Example #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)
Example #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)
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_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 #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #10
0
def add_group(document, tx, ty, text_content, transform=None, rotate=None):
    root = document.document_element

    group = document.create_element_ns(Element.SVG_NAMESPACE_URI, 'g')
    root.append(group)
    css_style = group.style
    css_style['font-family'] = 'DejaVu Sans'
    css_style['font-size'] = '36'
    transform_list = SVGTransformList([
        SVGTransform(SVGTransform.SVG_TRANSFORM_TRANSLATE, tx, ty),
    ])
    group.transform = transform_list

    rect = document.create_element_ns(Element.SVG_NAMESPACE_URI, 'rect')
    group.append(rect)
    css_style = rect.style
    css_style['fill'] = 'none'
    css_style['stroke'] = 'red'
    css_style['stroke-width'] = '1'
    css_style['stroke-dasharray'] = '2'

    circle = document.create_element_ns(Element.SVG_NAMESPACE_URI, 'circle')
    group.append(circle)
    css_style = circle.style
    css_style['fill'] = 'red'
    circle.attributes['r'] = '2'

    text = document.create_element_ns(Element.SVG_NAMESPACE_URI, 'text')
    group.append(text)
    css_style = text.style
    css_style['fill'] = 'skyblue'
    text.text_content = text_content
    if transform is not None:
        text.attributes['transform'] = transform
    if rotate is not None:
        text.attributes['rotate'] = rotate

    legend = document.create_element_ns(Element.SVG_NAMESPACE_URI, 'text')
    group.append(legend)
    css_style = legend.style
    css_style['font-size'] = '12'
    legend.text_content = 'transform: "{}", rotate: "{}"'.format(
        transform if transform is not None else '',
        rotate if rotate is not None else '')

    path = document.create_element_ns(Element.SVG_NAMESPACE_URI, 'path')
    group.append(path)
    css_style = path.style
    css_style['fill'] = 'none'
    css_style['stroke'] = 'blue'
    css_style['stroke-width'] = '1'
    path_data = text.get_path_data()
    if transform is not None:
        transform_list = SVGTransformList.parse(transform)
        matrix = transform_list.matrix
        path_data = PathParser.transform(path_data, matrix)
    path.set_path_data(path_data)

    bbox = path.get_bbox()
    rect.attributes['x'] = str(bbox.x)
    rect.attributes['y'] = str(bbox.y)
    rect.attributes['width'] = str(bbox.width)
    rect.attributes['height'] = str(bbox.height)
    legend.attributes['x'] = str(bbox.right + 10)

    return bbox