svgpathtools: SVG Groups are ignored. Especially transformations acting on the paths inside the group.
Example in an SVG created in Inkscape:
<g id=“g3450-3” transform=“matrix(-1e-4,-1,1,-1e-4,670.77002,132.92999)”> <path inkscape:connector-curvature=“0” d=“m 28.35,0 c 0,15.65621 -12.69107,28.3485 -28.34728,28.35” style=“fill:none;stroke:#000000;stroke-width:0.72000003;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none” id=“path3452-8” /> </g>
The group transformation is ignored when calling svgpathtools.svg2paths()
.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 8
- Comments: 41 (26 by maintainers)
Commits related to this issue
- Fixed #16 Groups are now taken into account during parsing and transform attributes of groups are applied to the paths before they are returned. — committed to alphanoob1337/svgpathtools by alphanoob1337 7 years ago
I’d like to add this functionality. I probably won’t get to this in the near future though.
Here’s how to do this (in case some helpful awesome person wants to make a pull-request): You can quite easily take an affine transformation of lines, quadratics, and cubics by simply transforming the coefficients. E.g.,
This should work (I didn’t test it, but just wanted to give the idea) for everything but paths containing Arc objects. Arc objects shouldn’t be too hard to deal with either (see Arc.rotated() and Arc.translated()). … it might be nice to just add a Path.transformed() method to deal with affine transformations in general.
Yes, with “expected behaviour” I was referring to how Inkscape handles SVG group transformations. I see Inkscape as the de facto reference implementation of the SVG standard, but that is a personal opinion and in this case there is no conflict with the W3C standard. For some projects rendering is irrelevant (i.e. I was using svgpathtools for the optimization of SVG files for laser cutters). Even for most projects where rendering matters, tatarizes approach will match the expected result or will be very close to it.