Skip to content
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

Closed
mojavelinux opened this issue Jun 24, 2015 · 14 comments
Closed

Add support for linear gradients #62

mojavelinux opened this issue Jun 24, 2015 · 14 comments

Comments

@mojavelinux
Copy link
Contributor

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.

@mogest
Copy link
Owner

mogest commented Jun 25, 2015

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!

@mojavelinux
Copy link
Contributor Author

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.

@mogest
Copy link
Owner

mogest commented Jul 5, 2015

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!

@mojavelinux
Copy link
Contributor Author

Fantastic! Thanks for the update. I'm following the progress with great anticipation.

@mogest
Copy link
Owner

mogest commented Jul 8, 2015

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?

@mojavelinux
Copy link
Contributor Author

@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.

@mogest
Copy link
Owner

mogest commented Aug 15, 2015

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.

@mojavelinux
Copy link
Contributor Author

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!

@mogest
Copy link
Owner

mogest commented Apr 24, 2016

Just an update: we're waiting on prawnpdf/prawn#902 to go in and be released before this feature can go live.

@v3rmin
Copy link

v3rmin commented Nov 23, 2016

According to the prawns changelog this should be possible to implement by now? All your pull requests have been merged?

@mogest
Copy link
Owner

mogest commented Nov 23, 2016

@v3rmin, yeah, the PR that was required was merged on May 14, but there hasn't been a release since March 😞

@ghost
Copy link

ghost commented Mar 27, 2017

@mogest Prawn has been updated to 2.2.2 now - any chance of this progressing now we're a few versions further? 🤞

@mogest
Copy link
Owner

mogest commented Mar 31, 2017

Ooo, yes, looks like it. Let me play.

@mogest mogest closed this as completed in cfa7a47 Mar 31, 2017
@mogest
Copy link
Owner

mogest commented Mar 31, 2017

Very happy, at long last, to bring gradients to prawn-svg 😄 🎉 🎈 🎈 🎉

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Apr 1, 2017
mojavelinux added a commit to asciidoctor/asciidoctor-pdf that referenced this issue Apr 1, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants