Open ClementWalter opened 2 years ago
Yeah, I'm surprised no one has commented on this before (as far as I recall). If you make a PR and include a unit test to check order is preserved, I'll merge it in.
What's motivates including an @wraps
decorator?
Are you interested in making a pull request for this @ClementWalter? Otherwise, I'll likely make one myself.
@stjohn909 I actually did implement a solution for this. For now it is housed in the preserve-order branch.
I want to merge this branch in. First, svgpathtools
needs of a test set of SVGs to test changes like this against.
@mathandy Sorry I deleted my earlier comment, I'm kind of new at this and realized my ordering issue is with the path list returned in _flattenedpaths() in document.py.
Would an acceptable test SVG be something with a known layer order and examples of nested transforms?
@stjohn909 that's part of what I'm looking for.
If you take care of that part, I'll take care of a minimal implementation of the rest and we can get this merged in. The "rest" being to gather a set of SVG's that I can just check to make sure the same path data is being returned -- this is a bigger test issue related to more than just #165. If you have any examples you'd like me to include, please attach them here. In the near future I'll make a directory to store such pull requests and create an issue or request in the documentation for people to add any SVGs they want included by pull-request.
I made my own version of the order-preserving svg2paths function, based on @mathandy's code. https://github.com/olivier-roche/svgpathtools/commit/09b1669fdcc3f632e04a985a329dd4157b8a6a0f
The changes I made are:
'path': True
to include_dictdoc.getElementsByTagName('*')
instead of doc.documentElement.childNodes
, to include not only direct children of the root XML element, but all the ancestors.
This problem drove me crazy: the
svg2paths
function parses first thepath
and then add at the end depending on the options the other elements.However, ordering of the elements in svg is not random but bears meaning.
For now I have rewritten the function like this:
If you want I can make a PR.