Skip to content

Instantly share code, notes, and snippets.

@mbr
Created April 29, 2013 11:24
Show Gist options
  • Save mbr/5481042 to your computer and use it in GitHub Desktop.
Save mbr/5481042 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="744.09448" height="1052.3622">
<text x="102.67084" y="521.4234" id="text3079" xml:space="preserve"
style="font-size:84.10165405px;font-style:normal;font-variant:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;opacity:0.5;fill:#000000;fill-opacity:1;stroke:none;font-family:Times New Roman;-inkscape-font-specification:Times New Roman"><tspan
x="102.67084" y="521.4234" >This <tspan style="font-style:italic">breaks</tspan>.</tspan></text>
</svg>
@mbr
Copy link
Author

mbr commented Apr 29, 2013

This will break with cairosvg 0.5 with the following error:

Traceback (most recent call last):
  File "/home/marc/.virtualenvs/svglue/bin/cairosvg", line 25, in <module>
    cairosvg.main()
  File "/home/marc/.virtualenvs/svglue/lib/python2.7/site-packages/cairosvg/__init__.py", line 92, in main
    SURFACES[output_format.upper()].convert(**kwargs)
  File "/home/marc/.virtualenvs/svglue/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 79, in convert
    cls(tree, output, dpi).finish()
  File "/home/marc/.virtualenvs/svglue/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 128, in __init__
    self.draw_root(tree)
  File "/home/marc/.virtualenvs/svglue/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 353, in draw_root
    self.draw(node)
  File "/home/marc/.virtualenvs/svglue/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 315, in draw
    self.draw(child, stroke_and_fill)
  File "/home/marc/.virtualenvs/svglue/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 327, in draw
    self.context.paint_with_alpha(opacity)
cairo.Error: Context.pop_group without matching Context.push_group

The issue seems to be with the nested tspan elements. Removing the inner causes it to work correctly.

The image is valid SVG: http://validator.w3.org/check?uri=https%3A%2F%2Fgist.github.com%2Fmbr%2F5481042%2Fraw%2F06f0c1d802081f47a60dcddf4b78c90d77524096%2Fbroken.svg&charset=%28detect+automatically%29&doctype=Inline&group=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment