Skip to content
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 would not parse #71

Closed
SchwarzMarek opened this issue Feb 2, 2017 · 3 comments
Closed

svg would not parse #71

SchwarzMarek opened this issue Feb 2, 2017 · 3 comments

Comments

@SchwarzMarek
Copy link

Hello,
I have an svg produced by matplotlib and I would like to read it with svg2rlg.
I'm able to read different svgs, but this one eludes me.

When reading, I end up with error:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/IPython/core/interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
d = svg2rlg(a)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 1029, in svg2rlg
drawing = svgRenderer.render(svg)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 362, in render
main_group = self.renderNode(svg_node)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 383, in renderNode
item = self.renderSvg(n)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 473, in renderSvg
self.renderNode(child, group)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 392, in renderNode
item = self.renderG(n, clipping=clipping)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 483, in renderG
item = self.renderNode(child, parent=gr)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 392, in renderNode
item = self.renderG(n, clipping=clipping)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 483, in renderG
item = self.renderNode(child, parent=gr)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 392, in renderNode
item = self.renderG(n, clipping=clipping)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 483, in renderG
item = self.renderNode(child, parent=gr)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 386, in renderNode
item = self.renderG(n)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 483, in renderG
item = self.renderNode(child, parent=gr)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 405, in renderNode
item = self.shape_converter.convertShape(name, n, clipping)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 560, in convertShape
shape = getattr(self, method_name)(node)
File "/usr/local/lib/python3.4/dist-packages/svglib/svglib.py", line 870, in convertPath
if path.operators[-1] != _CLOSEPATH:
IndexError: list index out of range

I've traced it to the line 233 (debugger:convertPath>node>sourceline which I believe to be the line when error happen) (line: " id="BitstreamVeraSans-Roman-6e"/>)
What I do not understand is, that it appears to successfully parsed very similar path before this line.
I've tried to search for unsupported statements, but I'm not such well familiar with svg, so i was unable to determine what style-list is.

Python is 3.4, svglib is 0.80 and reportlab is 3.3.0

Please ignore my issue, if the svg is not supported. Or if some preprocessing can be done, point me please to violating attribute.

Thanks
Best regards
Marek

I'm including the svg file as a text below:

<style type="text/css"> *{stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:100000;} </style>
@claudep
Copy link
Collaborator

claudep commented Feb 2, 2017

Did you forget joining the SVG?

@SchwarzMarek
Copy link
Author

Sorry,
I've pasted it, as I could not attach svg directly, but something went wrong.
I've genereted new svg, now the error is occuring at line 161.
I hope the file reaches You now.

dist_fig.zip

Best regards
Marek

@claudep
Copy link
Collaborator

claudep commented Feb 2, 2017

Thanks, got it. The issue is that empty paths make svglib crash. I'll prepare a patch.

deeplook added a commit that referenced this issue Feb 3, 2017
Fixes #71 -- Prevent crash with empty paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants