How to use the svglib.svglib.NodeTracker 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_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 / svglib / svglib.py View on Github external
def get_shape_from_node(node):
            for child in node.getchildren():
                if node_name(child) == 'path':
                    group = self.shape_converter.convertShape('path', NodeTracker(child))
                    return group.contents[-1]
                elif node_name(child) == 'use':
                    grp = self.renderUse(NodeTracker(child))
                    return get_shape_from_group(grp)
                elif node_name(child) == 'rect':
                    return self.shape_converter.convertRect(NodeTracker(child))
                else:
                    return get_shape_from_node(child)
github deeplook / svglib / svglib / svglib.py View on Github external
def renderSvg(self, node, outermost=False):
        _saved_preserve_space = self.shape_converter.preserve_space
        self.shape_converter.preserve_space = node.getAttribute("{%s}space" % XML_NS) == 'preserve'

        # Rendering all definition nodes first.
        svg_ns = node.nsmap.get(None)
        for def_node in node.iterdescendants('{%s}defs' % svg_ns if svg_ns else 'defs'):
            self.renderG(NodeTracker(def_node))

        group = Group()
        for child in node.getchildren():
            self.renderNode(child, group)
        self.shape_converter.preserve_space = _saved_preserve_space

        # Translating
        if not outermost:
            x, y = self.shape_converter.convert_length_attrs(node, "x", "y")
            if x or y:
                group.translate(x or 0, y or 0)

        # Scaling
        view_box = self.get_box(node)
        if not view_box and outermost:
            # Apply only the 'reverse' y-scaling (PDF 0,0 is bottom left)
github deeplook / svglib / svglib / svglib.py View on Github external
def get_shape_from_node(node):
            for child in node.getchildren():
                if node_name(child) == 'path':
                    group = self.shape_converter.convertShape('path', NodeTracker(child))
                    return group.contents[-1]
                elif node_name(child) == 'use':
                    grp = self.renderUse(NodeTracker(child))
                    return get_shape_from_group(grp)
                elif node_name(child) == 'rect':
                    return self.shape_converter.convertRect(NodeTracker(child))
                else:
                    return get_shape_from_node(child)
github deeplook / svglib / svglib / svglib.py View on Github external
def get_shape_from_node(node):
            for child in node.getchildren():
                if node_name(child) == 'path':
                    group = self.shape_converter.convertShape('path', NodeTracker(child))
                    return group.contents[-1]
                elif node_name(child) == 'use':
                    grp = self.renderUse(NodeTracker(child))
                    return get_shape_from_group(grp)
                elif node_name(child) == 'rect':
                    return self.shape_converter.convertRect(NodeTracker(child))
                else:
                    return get_shape_from_node(child)
github deeplook / svglib / svglib / svglib.py View on Github external
def render(self, svg_node):
        node = NodeTracker(svg_node)
        view_box = self.get_box(node, default_box=True)
        # Knowing the main box is useful for percentage units
        self.attrConverter.set_box(view_box)

        main_group = self.renderSvg(node, outermost=True)
        for xlink in self.waiting_use_nodes.keys():
            logger.debug("Ignoring unavailable object width ID '%s'." % xlink)

        main_group.translate(0 - view_box.x, -view_box.height - view_box.y)

        width, height = self.shape_converter.convert_length_attrs(
            svg_node, "width", "height", defaults=(view_box.width, view_box.height)
        )
        drawing = Drawing(width, height)
        drawing.add(main_group)
        return drawing