zopefoundation/z3c.rml — pull request #2 by kylemacfarlane (2013-03-06 00:40:30+00:00)
Title: SVG support

I've tried to add SVG support to the ``image`` and ``imageAndFlowables`` tags.

The ReportLab source mentions a package called ``svglib`` that has a function called ``svg2rlg`` that converts an SVG to a ReportLab ``Drawing`` object. I didn't have much luck with that and it only drew <10% of the paths in my SVGs. However, I found another package confusingly also called ``svg2rlg`` that does the same job and performs much better.

Originally (my patch at Launchpad) I was just creating a ``Drawing`` object and passing it around. This created perfect quality images but it slowed down rendering significantly and each unique drawing added about a megabyte to the file size. I also never really got it working well with ``imageAndFlowables``.

To improve on that I now convert the drawing to a PIL ``Image`` and pass that around just like a regular image. The big problem is that in the conversion from ``Drawing`` to ``Image`` stroke width can often get messed up and become too thick. I think this is maybe down to how scaling is done but you can avoid it by editing the SVGs you want to insert. You also lose any transparency and get a white background. Basically you no longer really have a vector graphic but instead a 300 DPI bitmap that is automatically scaled to the correct size with little quality loss.