-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for linear gradients #62
Comments
I've been working on gradients the last two nights, actually. Prawn does support gradients, but very badly. The co-ordinates you pass the fill_gradient method are absolute co-ordinates on the page, and not affected by any scaling, translation or rotation that's done in user space. That's just how PDF works, although there are two options to get them into user space: XForm objects (apparently, I have not confirmed but the spec leads me to believe that's possible), and using a shading drawing instruction instead of stroke/fill. The latter wouldn't give individual control over stroke and fill colors, so although some kludge might be able to be done using clips and drawing the stroke separately from the fill maybe. To make it even harder, SVG allows (and by default accepts) x/y coordinates between 0 and 100% which are mapped to the bounding box of the shape being drawn, and PDF does not. To support SVG gradients, I'd have to work out the bounding box for every shape that's able to be drawn. Not impossible, but not trivial, and definitely requiring a substantial rewrite. And although PDF does support multi-stage gradients like SVG, prawn doesn't. I've seen a nice implementation of shading with opacity in nodejs-images-to-pdf, so again, possible, but work required. In short: a lot more investigation needs to be done, let alone code. I'll do it as I find time, but not promising anything here! |
Wow! The devil is always in the details, isn't it? Hopefully, PDF will reveal some secrets that you can tap into. I'll try to grab some interest in this issue to see if it helps uncover more research. I'll try to help in anyway I can. |
Progress update: I've prototyped a fix to prawn so it will render gradients correctly. See prawnpdf/prawn#891. Waiting to see whether I get any comments about my approach before submitting a PR. With that fixed, it'll be easier to implement them in prawn-svg. Is going to be a pain having to calculate the bounding box for everything prawn-svg can draw, though! |
Fantastic! Thanks for the update. I'm following the progress with great anticipation. |
Hey @mojavelinux, I haven't dealt with the new prawn maintainers before. Are they likely to respond to the issue, or should I just go ahead with the PR? |
@mogest The new maintainers, and in particular Evan, are quite responsive and willing to learn what is necessary to address issues in Prawn. I'd recommend moving forward with the PR as that seems to get the conversation focused on the scale of the change. I'm really excited about these improvements because it's refreshing part of the code that seems to have gone dormant. |
Basic support implemented in 5c7fb8a! I'll wait until Prawn 2.0.3 gets released (assuming the second PR gets accepted before then) and then I'll release a new prawn-svg. |
I'm really excited about this! It's going to open a lot of doors for document authors. I'm very grateful for your contributions to Prawn. Thanks! |
Just an update: we're waiting on prawnpdf/prawn#902 to go in and be released before this feature can go live. |
According to the prawns changelog this should be possible to implement by now? All your pull requests have been merged? |
@v3rmin, yeah, the PR that was required was merged on May 14, but there hasn't been a release since March 😞 |
@mogest Prawn has been updated to 2.2.2 now - any chance of this progressing now we're a few versions further? 🤞 |
Ooo, yes, looks like it. Let me play. |
Very happy, at long last, to bring gradients to prawn-svg 😄 🎉 🎈 🎈 🎉 |
…s to be mapped in SVG - see mogest/prawn-svg#94 - also resolves asciidoctor#741; see mogest/prawn-svg#91 - also resolves asciidoctor#228; see mogest/prawn-svg#62
…ped in SVG (PR #796) - see mogest/prawn-svg#94 - also resolves #741; see mogest/prawn-svg#91 - also resolves #228; see mogest/prawn-svg#62
Add support for the linear gradient fill.
Many diagramming tools output shapes using linear gradients. In order for these diagrams to look right in the PDF, prawn-svg will need to apply the requested linear gradients. I'm sure there are many other use cases for linear gradients, but this one seems to come up the most.
Here's one such example:
https://github.com/openEHR/spec-publish-asciidoc/blob/22f7f71115cfe1e826b6baf1f99ba127cd4be735/docs/AOM2/uml_diagrams/AOM-archetype.svg
Prawn does support linear gradients, so it should be possible in theory to delegate to prawn to handle this type of fill.
The text was updated successfully, but these errors were encountered: