How to use svglib - 10 common examples

To help you get started, we’ve selected a few svglib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deeplook / svglib / tests / test_basic.py View on Github external
mapping = (
            ("red", colors.red),
            ("#ff0000", colors.red),
            ("#ff000055", colors.Color(1, 0, 0, 1/3.0)),
            ("#f00", colors.red),
            ("#f00f", colors.red),
            ("rgb(100%,50%,10%)", colors.Color(1, 1.0/255 * 128, 1.0/255 * 26, 1)),
            ("rgb(255, 0, 0)", colors.red),
            ("rgba(255, 255, 128, .5)", colors.Color(1, 1, 1.0/255 * 128, .5)),
            ("fuchsia", colors.Color(1, 0, 1, 1)),
            ("slategrey", colors.HexColor(0x708090)),
            ("transparent", colors.Color(0, 0, 0, 0)),
            ("whatever", None),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertColor, mapping)
        assert len(failed) == 0
github deeplook / svglib / tests / test_basic.py View on Github external
def test_1(self):
        "Test color attribute conversion to CMYK"

        mapping = (
            ("red", force_cmyk(colors.red)),
            ("#ff0000", force_cmyk(colors.red)),
            ("#f00", force_cmyk(colors.red)),
            ("rgb(100%,0%,0%)", force_cmyk(colors.red)),
            ("rgb(255, 0, 0)", force_cmyk(colors.red)),
            ("rgb(0,255, 0)", force_cmyk(colors.Color(0, 1, 0))),
            ("rgb(0, 0, 255)", force_cmyk(colors.Color(0, 0, 1))),
        )
        ac = svglib.Svg2RlgAttributeConverter(color_converter=force_cmyk)
        failed = _testit(ac.convertColor, mapping)
        assert len(failed) == 0
github deeplook / svglib / tests / test_basic.py View on Github external
def test_0(self):
        "Test length list attribute conversion."

        mapping = (
            (" 5cm 5in", [5*cm, 5*inch]),
            (" 5, 5", [5, 5]),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertLengthList, mapping)
        assert len(failed) == 0
github deeplook / svglib / tests / test_basic.py View on Github external
def test_0(self):
        "Test multi-attribute conversion."

        mapping = (
            ("fill: black; stroke: yellow",
                {"fill": "black", "stroke": "yellow"}),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.parseMultiAttributes, mapping)
        assert len(failed) == 0
github deeplook / svglib / tests / test_basic.py View on Github external
"3.502-1.865 3.918-.773.201-1.488.127-2.659-.281-1.438-.502-1.684-.494-2.405.058"
             "-1.618 1.239-3.869 1.355-5.894.299z",
                ['m', [246.026, 120.178], 'c', [-0.558, -0.295, -1.186, -0.768, -1.395, -1.054],
                 'c', [-0.314, -0.438, -0.132, -0.456, 1.163, -0.104],
                 'c', [2.318, 0.629, 3.814, 0.383, 5.298, -0.873],
                 'l', [1.308, -1.103], 'l', [1.54, 0.784],
                 'c', [0.848, 0.428, 1.748, 0.725, 2.008, 0.656],
                 'c', [0.667, -0.176, 2.05, -1.95, 2.005, -2.564],
                 'c', [-0.054, -0.759, 0.587, -0.568, 0.896, 0.264],
                 'c', [0.615, 1.631, -0.281, 3.502, -1.865, 3.918],
                 'c', [-0.773, 0.201, -1.488, 0.127, -2.659, -0.281],
                 'c', [-1.438, -0.502, -1.684, -0.494, -2.405, 0.058],
                 'c', [-1.618, 1.239, -3.869, 1.355, -5.894, 0.299],
                 'z', []]),
        )
        failed = _testit(utils.normalise_svg_path, mapping)
        assert len(failed) == 0
github deeplook / svglib / tests / test_basic.py View on Github external
def test_css_stylesheet(self):
        drawing = svglib.svg2rlg(io.StringIO(textwrap.dedent(u'''\
            
            <svg xml:space="preserve" height="267" width="777">
              <defs>
                <style type="text/css">
                #p1 { fill:rgb(255,0,0); }
                #p2 { fill:rgb(255,0,0); }
                .paths { stroke-width:1.5; }
                </style>
              </defs>
              <g id="g1">
                <path d="M 0,-100 V 0 H 50" class="paths" id="p1"></path>
                <path d="M 0,100 V 0 H 50" style="fill: #000000" class="paths other" id="p2"></path>
              </g>
            </svg>
        ''')))
        main_group = drawing.contents[0]
github deeplook / svglib / tests / test_basic.py View on Github external
def test_use(self, drawing_source=None):
        drawing = svglib.svg2rlg(io.StringIO(textwrap.dedent(drawing_source or '''\
            
            <svg viewBox="0 0 100 30" height="3cm" width="10cm" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1">
              <defs>
                  <rect height="10" width="60" id="MyRect"></rect>
              </defs>
              <rect stroke-width=".2" stroke="blue" fill="none" height="29.8" width="99.8" y=".1" x=".1"></rect>
              
              
            </svg>
        ''')))
        main_group = drawing.contents[0]
        # First Rect
github deeplook / svglib / tests / test_basic.py View on Github external
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(
            '
github deeplook / svglib / tests / test_basic.py View on Github external
def test_filling(self):
        converter = svglib.Svg2RlgShapeConverter(None)
        node = svglib.NodeTracker(etree.XML(
            '
github deeplook / svglib / tests / test_basic.py View on Github external
def test_elliptical_arc(self):
        converter = svglib.Svg2RlgShapeConverter(None)
        node = svglib.NodeTracker(etree.XML(
            '