deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
311 stars 80 forks source link

clipPath ignored with PNG rendering #292

Open victorbnl opened 2 years ago

victorbnl commented 2 years ago

The SVG I have

bildo

svg source

The PNG it produces

bildo

Additionnal context

OS: Windows 10 / Arch Linux (this happens on both) svglib: 1.1.0 reportlab: 3.6.1

claudep commented 2 years ago

@replabrobin, can you confirm that ReportLab only support Path-like clip paths? Is there anything that would prevent using a circle as a clip path, like in this example image?

victorbnl commented 2 years ago

Even using a path it doesn't work

claudep commented 2 years ago

Are you really sure? It worked for me.

victorbnl commented 2 years ago

I tested again and yep, I still get the image of the first post, without masks

victorbnl commented 2 years ago

Maybe you have a dev version or anything?

claudep commented 2 years ago

No, even when reverting code to 1.1.0, it still works. I have no Windows to test, but I don't see this would make a difference.

victorbnl commented 2 years ago

I'll test on Linux

victorbnl commented 2 years ago

The issues is still there for me on Linux

victorbnl commented 2 years ago

Here are the debug logs

DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Unused attrs: path ['class']
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Unused attrs: path ['class']
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Unused attrs: image ['__rules_applied', '{http://www.w3.org/1999/xlink}href']
DEBUG:svglib.svglib:Unused attrs: g ['__rules_applied']
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Exception during applyStyleOnShape
DEBUG:svglib.svglib:Unused attrs: image ['__rules_applied', '{http://www.w3.org/1999/xlink}href']
DEBUG:svglib.svglib:Unused attrs: g ['__rules_applied']
DEBUG:PIL.PngImagePlugin:STREAM b'IHDR' 16 13
DEBUG:PIL.PngImagePlugin:STREAM b'IDAT' 41 41578
DEBUG:PIL.PngImagePlugin:STREAM b'IHDR' 16 13
DEBUG:PIL.PngImagePlugin:STREAM b'IDAT' 41 65536
replabrobin commented 2 years ago

Claude, so far as I can tell PDF supports clipping with paths and in canvas.py we use a path to create ellipse/circle So at least in principle it ought to be possible to mask using a circle. Unfortunately the canvas api doesn't make this terribly easy as the canvas circle/ellipse methods don't return the created path and don't have a render mode to allow easier specification of the rendering. On the other hand one can create the path with path.ellipse(....) and then just use canvas.clipPath on the result

victorbnl commented 2 years ago

With PDF, path clips work, but circle ones don't. And for PNG both don't work. So what we need to figure out is why path clips don't work in PNG

claudep commented 2 years ago

Ah sorry, indeed I only tested PDF rendering. I admit I don't care so much for PNG (not in my use cases).

claudep commented 2 years ago

On the other hand one can create the path with path.ellipse(....) and then just use canvas.clipPath on the result

Thanks for this tip. I think we should able to support at least Circles with that trick.

victorbnl commented 2 years ago

Ah sorry, indeed I only tested PDF rendering. I admit I don't care so much for PNG (not in my use cases).

So, with PNG, does the issue also happen on your device?

replabrobin commented 2 years ago

Hi Victor, unfortunately the renderPM/PDF/PS/SVG csnvasses sre all slightly different.from the original pdfgen/canvas.py code. The shapes.path class does allow isClipPath to be set so if png is not obeying the setting then presumably we will have to mess with the renderPM canvas/renderer classes to amke it work.