mathandy / svgpathtools

A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.
MIT License
557 stars 142 forks source link

`Document` adds "svg:" prefixes to all tags #182

Open mathandy opened 2 years ago

mathandy commented 2 years ago

To make matters worse, Document.add_path() adds the path without the prefix, causing the path to not render in chrome. Here's an example, which includes a little hack at the end as a workaround.

from svgpathtools import Document, Path, polygon

doc = Document('test.svg')

xmin, xmax, ymin, ymax = Path(*[seg for path in doc.paths() for seg in path]).bbox()
box = polygon(xmin+ymin*1j, xmax+ymin*1j, xmax+ymax*1j, xmin+ymax*1j)

doc.add_path(box, attribs={'stroke':"red", 'stroke-width':'0.1', 'fill': 'none'})

doc.save('test2.svg')

# fix for issue #182
with open('test2.svg') as f:
    txt = f.read().replace('<path', '<svg:path')
with open('test2.svg', 'w') as f:
    f.write(txt)

testing