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

clipPath ignored with PNG rendering #292

Open
victorbnl opened this issue Aug 26, 2021 · 15 comments
Open

clipPath ignored with PNG rendering #292

victorbnl opened this issue Aug 26, 2021 · 15 comments

Comments

@victorbnl
Copy link
Contributor

victorbnl commented Aug 26, 2021

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
Copy link
Collaborator

claudep commented Aug 26, 2021

@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
Copy link
Contributor Author

Even using a path it doesn't work

@claudep
Copy link
Collaborator

claudep commented Aug 26, 2021

Are you really sure? It worked for me.

@victorbnl
Copy link
Contributor Author

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

@victorbnl
Copy link
Contributor Author

Maybe you have a dev version or anything?

@claudep
Copy link
Collaborator

claudep commented Aug 26, 2021

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
Copy link
Contributor Author

I'll test on Linux

@victorbnl
Copy link
Contributor Author

The issues is still there for me on Linux

@victorbnl
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Collaborator

claudep commented Aug 27, 2021

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

@claudep
Copy link
Collaborator

claudep commented Aug 27, 2021

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
Copy link
Contributor Author

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
Copy link
Contributor

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.

@victorbnl victorbnl changed the title clipPath ignored clipPath ignored with PNG rendering Aug 29, 2021
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

3 participants