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 with linearGradient using matrix gradientTransform is not rendered correctly #1601

Closed
jelle-eastground opened this issue Mar 18, 2022 · 4 comments · Fixed by #1771
Closed
Labels
bug Existing features not working as expected

Comments

@jelle-eastground
Copy link

jelle-eastground commented Mar 18, 2022

Using the new way of SVG rendering (v53+), a matrix gradientTransform gradient is no longer working. Is this something WeasyPrint could support again in the near future?
test_gradient

@liZe liZe added the bug Existing features not working as expected label Mar 18, 2022
@liZe
Copy link
Member

liZe commented Mar 19, 2022

Hello!

There’s a problem about translations in gradientTransform, here’s a simple example:

<svg viewBox="0 0 800 800" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <linearGradient id="gradient" gradientTransform="translate(1, 0)">
      <stop offset="0" stop-color="blue" />
      <stop offset="1" stop-color="yellow"/>
    </linearGradient>
  </defs>
  <rect width="800" height="800" fill="url(#gradient)"/>
</svg>

Is this something WeasyPrint could support again in the near future?

That’s a good question. The current code drawing gradients is broken in many ways, because testing gradients is hard and there are so many different features. I tried to find a quick fix but the problem seems to be deep in the way we handle gradientUnits and gradientTransform.

If someone is interested in SVG gradients and in the PDF specification (does someone like this even exist?), we’d be happy to get some help about this.

@jelle-eastground
Copy link
Author

Maybe off-topic, but why did you (had to) decide to stop using CairoSVG? I think it is very unfortunate, as I had no issues at all in the past few years when WeasyPrint still used CairoSVG. Maybe it is possible to use the implementation of CairoSVG regarding gradients as a reference to implement something new?

@liZe
Copy link
Member

liZe commented Apr 5, 2022

Maybe off-topic, but why did you (had to) decide to stop using CairoSVG?

Everything is explained in this article.

I think it is very unfortunate, as I had no issues at all in the past few years when WeasyPrint still used CairoSVG.

We’re really sorry for you. We tried hard to keep the same features and renderings, but it was obvious that we were about to face bugs like this one.

Maybe it is possible to use the implementation of CairoSVG regarding gradients as a reference to implement something new?

We actually reused CairoSVG’s code to handle SVGs in the new version of WeasyPrint. But of course, we had to change many things as pydyf is a low-level library while Cairo is more high-level. Handling gradients is one of the areas where we had to rewrite almost everything because of very different APIs, fixing some bugs like #790, but creating new ones like this one.

@jelle-eastground
Copy link
Author

Thank you for your quick reply and clear explanation. Cairo wasn't an optimal solution for the long term, as I understand it. Well, let's hope one day all SVG features are back again :). Besides this I use WeasyPrint a lot and it works very well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants