How to use the svglib.svglib function in svglib

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
def test_filling(self):
        converter = svglib.Svg2RlgShapeConverter(None)
        node = svglib.NodeTracker(etree.XML(
            '
github deeplook / svglib / tests / test_samples.py View on Github external
def test_png_in_svg(self):
        path = join(TEST_ROOT, "samples", "others", "png_in_svg.svg")
        drawing = svglib.svg2rlg(path)
        result = renderPDF.drawToString(drawing)
        # If the PNG image is really included, the size is over 7k.
        assert len(result) > 7000
github deeplook / svglib / tests / test_basic.py View on Github external
def test_fillopacity(self):
        """
        The fill-opacity property set the alpha of the color.
        """
        drawing = svglib.svg2rlg(io.StringIO(textwrap.dedent(u'''\
            
            <svg height="480" width="660" xmlns="http://www.w3.org/2000/svg" version="1.1">
                <polygon fill-opacity="0" stroke-width="5.5" stroke="#0038b8" points="0,-29.14 -25.23, 14.57 25.23, 14.57" id="triangle"></polygon>
            </svg>
        ''')))
        assert drawing.contents[0].contents[0].fillColor == colors.Color(0, 0, 0, 0)
github deeplook / svglib / svglib / utils.py View on Github external
'dirname': dirname(path) or '.',
        'basename': basename(path),
        'base': basename(splitext(path)[0]),
        'ext': splitext(path)[1],
        'now': datetime.now(),
        'format': _format
    }
    out_pattern = outputPat or '%(dirname)s/%(base)s.%(format)s'
    # allow classic %%(name)s notation
    out_path = out_pattern % file_info
    # allow also newer {name} notation
    out_path = out_path.format(**file_info)

    # generate a drawing from the SVG file
    try:
        drawing = svglib.svg2rlg(path)
    except:
        print('Rendering failed.')
        raise

    # save drawing into a new file
    if drawing:
        fmt = file_info['format'].upper()
        if fmt == 'PDF':
            renderPDF.drawToFile(drawing, out_path, showBoundary=0)
        elif fmt == 'EPS':
            renderPS.drawToFile(drawing, out_path, showBoundary=0)
        elif fmt in 'JPG JPEG PNG BMP PPM GIF PCT PICT TIFF TIFFP TIFFL TIF TIFF1'.split(): # PY SVG
            renderPM.drawToFile(drawing, out_path, fmt=fmt)