-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVG parsing issue, tries to convert "c" to float #450
Comments
Thanks for reporting this. After having a quick look, I think the issue comes from this part of the SVG path: If you remove the
With added whitespaces, the following is a valid SVG path string: But with the original string, our parser doesn't know how to parse I don't what the fix should be exactly... I checked how Firefox renders this SVG path, and it draws the arc like this: We should find a way to adapt our parser in order to have |
The SVG 1.1 spec does not seem to mention how the parser should behave if there are not enough parameters provided to the I think we could adapt our parser so that |
The specs say:
but are unfortunately not very specific about which ones are to be considered actually superfluous.
Possibly, but I think there's another mechanism at play here. I guess for testing purposes you just did a random split to arrive at this:
Turns out the correct solution is slightly different:
The arguments 4 (large-arc-flag) and 5 (sweep-flag) for an arc are flags, which means they can each only be one of |
Nice! Well spotted @gmischler :) @preshtildeath: are you interested on working on a PR to fix this, or not necessarily? |
Not necessarily! That sounds like regex, which makes me nervous haha. This conversation has been very enlightening, I'll definitely be fiddling around some more with my project. Thank you both! |
Alright, thank you for your answer @preshtildeath 😊 I may give @gmischler suggestion a try when I have some time, but anyone else is free to grab it and submit a PR! |
You might find some inspiration in svg.path. Their approach of type checking and parsing path arguments looks quite helpful. |
In #453 I tried to use |
I didn't actually want to suggest adding another dependency, I just liked their way of parametrizing the parameter parsing. |
No, but that would be a wise idea. |
I have merged #453 that fixes this bug. That PR didn't make it in v2.5.5, but it will be included in the next |
Trying to add an SVG to an empty PDF using (essentially) the code from the example at: https://pyfpdf.github.io/fpdf2/SVG.html
Could be a strange SVG, main reason I'm making it into a PDF is because Photoshop doesn't open it correctly, despite it rendering fine in Chrome and Edge.
Environment
Windows 10 Pro version 21H1
Python 3.10.4
fpdf2 version 2.5.4, also checked the latest master branch
Error details
Full traceback is as follows:
The offending SVG:
If it's something I could do to "fix" the SVG before throwing it at fpdf2, I'd love to hear some ideas. Thanks for all the work you all do!
The text was updated successfully, but these errors were encountered: