def test_cubic_bezier_shorthand(self):
     # If there is no previous command or if the previous command was not
     # an C, c, S or s, assume the first control point is coincident with
     # the current point.
     converter = svglib.Svg2RlgShapeConverter(None)
     node = svglib.NodeTracker(
         etree.XML(
             '<path d="M3,4c-0.5-0.25-1.3-0.77-1.3-1.8h2.5s0.04,0.46,0.04,1.48z"/>'
         ))
     path = converter.convertPath(node).contents[0]
     assert path.operators == [
         _MOVETO, _CURVETO, _LINETO, _CURVETO, _CLOSEPATH
     ]
     assert path.points == [
         3.0,
         4.0,
         2.5,
         3.75,
         1.7,
         3.23,
         1.7,
         2.2,
         4.2,
         2.2,
         4.2,
         2.2,
         4.24,
         2.66,
         4.24,
         3.68,
     ]
Exemple #2
0
 def test_stroke(self):
     converter = svglib.Svg2RlgShapeConverter(None)
     node = etree.XML('<path d="m0,6.5h27m0,5H0" stroke="#FFF" stroke-opacity="0.5"/>')
     path = Path()
     converter.applyStyleOnShape(path, node)
     assert path.strokeColor == colors.white
     assert path.strokeOpacity == 0.5
     assert path.strokeWidth == 1
 def test_translate_only_x(self):
     """
     When the second translate value is missing, 0 is assumed.
     """
     group = Group()
     converter = svglib.Svg2RlgShapeConverter(None)
     transform = "translate(10)"
     converter.applyTransformOnGroup(transform, group)
     assert group.transform == (1, 0, 0, 1, 10, 0)
 def test_rx_ry(self):
     converter = svglib.Svg2RlgShapeConverter(None)
     node = svglib.NodeTracker(
         etree.XML(
             '<rect rx="10" ry="4" width="10" height="3" x="0" y="0"/>'))
     rect = converter.convertRect(node)
     # rx/ry cannot be more than half the rect lengths.
     assert rect.rx == 5
     assert rect.ry == 1.5
Exemple #5
0
 def test_elliptical_arc(self):
     converter = svglib.Svg2RlgShapeConverter(None)
     node = svglib.NodeTracker(etree.XML(
         '<path d="M334.500000 0.000000 A185.000000 185.000000 0 0 1 334.500000 0.000000 '
         'L334.500000 185.000000 A0.000000 0.000000 0 0 0 334.500000 185.000000 z"/>'
     ))
     # First elliptical arc with identical start/end points, ignored
     path = converter.convertPath(node).contents[0]
     assert path.points == [334.5, 0.0, 334.5, 185.0, 334.5, 185.0]
 def test_relative_move_after_closepath(self):
     """
     A relative subpath is relative to the point *after* the previous
     closePath op (which is not recorded in path.points).
     """
     converter = svglib.Svg2RlgShapeConverter(None)
     node = svglib.NodeTracker(
         etree.XML('<path d="M0 0,0 1,1 1z m-1-1 0 1 1 0z"/>'))
     # last point of this path should be 0 0
     path = converter.convertPath(node).contents[0]
     assert path.points[-2:] == [0, 0]
Exemple #7
0
 def test_unclosed_paths(self):
     converter = svglib.Svg2RlgShapeConverter(None)
     node = svglib.NodeTracker(etree.XML('<path d="M0,0 4.5,3 0,6M4.5,3H9" id="W"/>'))
     group = converter.convertPath(node)
     assert len(group.contents) == 2
     closed_path = group.contents[0]
     unclosed_path = group.contents[1]
     assert len(closed_path.points) == len(unclosed_path.points)
     assert closed_path.operators == [
         _MOVETO, _LINETO, _LINETO, _CLOSEPATH, _MOVETO, _LINETO, _CLOSEPATH]
     assert unclosed_path.operators == [
         _MOVETO, _LINETO, _LINETO, _MOVETO, _LINETO]
Exemple #8
0
 def test_strokewidth_0(self):
     """
     When strokeWidth = 0, we force strokeColor to None to avoid the stroke
     to be displayed.
     """
     converter = svglib.Svg2RlgShapeConverter(None)
     node = svglib.NodeTracker(etree.XML(
         '<rect style="stroke: rgb(100, 84, 0); fill: rgb(255, 255, 255); '
         'fill-opacity: 1; stroke-width: 0;" width="135" height="86" x="10" y="10"/>'
     ))
     rect = converter.convertShape('rect', node)
     assert rect.strokeColor is None
    def test_filling(self):
        converter = svglib.Svg2RlgShapeConverter(None)
        node = svglib.NodeTracker(
            etree.XML('<polyline fill="none" stroke="#000000" '
                      'points="10,50,35,150,60,50,85,150,110,50,135,150" />'))
        polyline = converter.convertPolyline(node)
        assert isinstance(polyline, PolyLine)

        # svglib simulates polyline filling by a fake polygon.
        node = svglib.NodeTracker(
            etree.XML('<polyline fill="#fff" stroke="#000000" '
                      'points="10,50,35,150,60,50,85,150,110,50,135,150" />'))
        group = converter.convertPolyline(node)
        assert isinstance(group.contents[0], Polygon)
        assert group.contents[0].fillColor == colors.white
        assert isinstance(group.contents[1], PolyLine)
 def test_fillrule(self):
     converter = svglib.Svg2RlgShapeConverter(None)
     node = etree.XML('<polygon fill-rule="evenodd"/>')
     poly = Polygon()
     converter.applyStyleOnShape(poly, node)
     assert poly._fillRule == FILL_EVEN_ODD
 def test_empty_path(self):
     converter = svglib.Svg2RlgShapeConverter(None)
     node = svglib.NodeTracker(etree.XML('<path id="W"/>'))
     group = converter.convertPath(node)
     assert group is None