mathandy / svgpathtools

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

SVG file with transform leads to inconsistency between viewBox and path coordinates #189

Open g3grau opened 2 years ago

g3grau commented 2 years ago

I'm trying to read SVG files which were created with potrace using a scaling parameter -u 10. This results in a SVG with a transform group (translation 0, 0, scale 0.1, -0.1). I figured out that the path coordinates are all 10x larger than expected from reading the viewBox in svg_attributes, thus I wanted to get at least the information if a scale transform has been defined in the file. I could not find a way to extract this using the API and ended in an ugly index-search for "scale(" and the following ")" in str(svgpathtools.Document(file)) to get these numbers. Is there a more elegant way to get this transform info? I thought it might be a "group" since it's in a g tag, but I couldn't get Document(file).contains_group or get_group to work.

I have seen a fork which attempts to "flatten" the transform, but I think this has not been merged. Would it be an alternative to transform the viewBox instead of the paths and add translate/scale items to svg_attributes?

bcwhite-code commented 1 year ago

I'm seeing this, too. The SVG has

<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)">

Inkscape reports the coordinates as 0,0 to 1000,1000 but the segments returned by this library are in the range of 90.8, -4793.8 to 9901.1, 5028.2.