How to use the svgis.dom.ns function in svgis

To help you get started, we’ve selected a few svgis 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 fitnr / svgis / tests / test_style.py View on Github external
def testPartialStyleName(self):
        doc = ElementTree.fromstring(self.svg).find('./' + dom.ns('g'))
        ruleset = style._parse_css(self.css1)

        dom.apply_rule(doc, ruleset.rules[0])
        svg = ElementTree.tostring(doc, encoding='utf-8').decode('utf-8')
        self.assertNotIn('orange', svg)

        inlined = style.inline(self.svg, self.css1)
        self.assertNotIn('orange', inlined)
github fitnr / svgis / svgis / style.py View on Github external
* ``.class``
    * ``tag``
    * ``tag.class``
    * ``#layer .class``
    * ``#layer tag``

    Args:
        svg (string): An SVG document.
        css (string): CSS to use, instead of the CSS in the
github fitnr / svgis / svgis / style.py View on Github external
root, ext = os.path.splitext(style)

    if ext == '.css' or root == '/dev/stdin':
        with open(style) as f:
            style = _uncomment(f.read())

    try:
        svg = ElementTree.parse(svgfile).getroot()
    except IOError:
        try:
            svg = ElementTree.fromstring(svgfile)
        except UnicodeDecodeError:
            svg = ElementTree.fromstring(svgfile.encode('utf-8'))

    if svg.find(dom.ns('defs')) is not None:
        defs = svg.find(dom.ns('defs'))

    else:
        defs = ElementTree.Element(dom.ns('defs'))
        svg.insert(0, defs)

    if defs.find(dom.ns('style')) is not None:
        style_element = defs.find(dom.ns('style'))

        if not replace:
            # Append CSS.
            style = (style_element.text or '') + ' ' + style

        style_element.text = ''

    else:
        style_element = ElementTree.Element(dom.ns('style'))
github fitnr / svgis / svgis / style.py View on Github external
else:
        defs = ElementTree.Element(dom.ns('defs'))
        svg.insert(0, defs)

    if defs.find(dom.ns('style')) is not None:
        style_element = defs.find(dom.ns('style'))

        if not replace:
            # Append CSS.
            style = (style_element.text or '') + ' ' + style

        style_element.text = ''

    else:
        style_element = ElementTree.Element(dom.ns('style'))
        defs.append(style_element)

    style_element.append(dom.cdata(style))

    return ElementTree.tostring(svg, encoding='utf-8').decode('utf-8')
github fitnr / svgis / svgis / style.py View on Github external
svg = ElementTree.parse(svgfile).getroot()
    except IOError:
        try:
            svg = ElementTree.fromstring(svgfile)
        except UnicodeDecodeError:
            svg = ElementTree.fromstring(svgfile.encode('utf-8'))

    if svg.find(dom.ns('defs')) is not None:
        defs = svg.find(dom.ns('defs'))

    else:
        defs = ElementTree.Element(dom.ns('defs'))
        svg.insert(0, defs)

    if defs.find(dom.ns('style')) is not None:
        style_element = defs.find(dom.ns('style'))

        if not replace:
            # Append CSS.
            style = (style_element.text or '') + ' ' + style

        style_element.text = ''

    else:
        style_element = ElementTree.Element(dom.ns('style'))
        defs.append(style_element)

    style_element.append(dom.cdata(style))

    return ElementTree.tostring(svg, encoding='utf-8').decode('utf-8')
github fitnr / svgis / svgis / style.py View on Github external
with open(style) as f:
            style = _uncomment(f.read())

    try:
        svg = ElementTree.parse(svgfile).getroot()
    except IOError:
        try:
            svg = ElementTree.fromstring(svgfile)
        except UnicodeDecodeError:
            svg = ElementTree.fromstring(svgfile.encode('utf-8'))

    if svg.find(dom.ns('defs')) is not None:
        defs = svg.find(dom.ns('defs'))

    else:
        defs = ElementTree.Element(dom.ns('defs'))
        svg.insert(0, defs)

    if defs.find(dom.ns('style')) is not None:
        style_element = defs.find(dom.ns('style'))

        if not replace:
            # Append CSS.
            style = (style_element.text or '') + ' ' + style

        style_element.text = ''

    else:
        style_element = ElementTree.Element(dom.ns('style'))
        defs.append(style_element)

    style_element.append(dom.cdata(style))
github fitnr / svgis / svgis / style.py View on Github external
def rescale(svgfile, factor):
    _register()
    svg = ElementTree.parse(svgfile)
    scalar = 'scale({})'.format(factor)
    g = svg.getroot().find(dom.ns('g'))
    g.attrib['transform'] = (g.attrib.get('transform') + ' ' + scalar).strip()
    return ElementTree.tostring(svg.getroot(), encoding='utf-8').decode('utf-8')