Improve the selection of shading logic for linear gradients#65
Conversation
|
Wow, nice. I just released pdfbox-graphics2d version 0.46 and 3.0.4 with your other fix. I'll have to take a look here. |
|
Yeah, that looks fine now... I was fooled by the macOS preview app - that stopped to correctly render transparency years ago... Acrobat correctly displays the now working transparencies. Thank you very much! Lets see if somebody finds another way to break that heuristic. But for now, I'm happy that you found a solution! |
|
I've just released version 0.47 and 3.0.5 with your fix. |
|
Thank you. For me there are two remaining questions:
|
|
Hmm, Batik is in "security-fixes-only" maintenance mode. Good luck to get that in... even bugfixes are not merged, so likely no chance for new features. But you might try anyway. Maybe I should try at some point to see if https://github.com/css4j/echosvg would work with this library. This fork at least tries to maintain the whole thing. |
|
Thumbs up for @css4j/echosvg . I was adding or updating SVG output to an app of mine a year ago. After a bit of wrangling with the maintainer, I got a nice clean archive I could use that produced output as good or better than Batik, but the jar was same size or smaller and I could rely on an active developer managing the project. |



@rototor in the other PR you pointed at the Tux example, which motivated me to take a look at that.
I have no deep understanding about the vector mathematics involved here, but i believe Tux is not painted perfectly, because linearGradientObjectBoundingBoxShading was just called in too many cases, even on gradients that were explicitly set to userSpaceOnUse in the svg.
When deactivating the code branch for objectBoundingBox, Tux was already painting perfectly in PDF. But of course that broke the test for long-gradient.svg.
So i believe the main problem is, that we are using a heuristic to select the proper shading procedure. Unfortunately the explicit information about the gradientUnits is not available anymore. (The last time i see it explicitly in the stack is in method org.apache.batik.bridge.SVGLinearGradientElementBridge#buildGradient)
So in this PR i propose to fine tune the heuristic by detecting if the coordinate system used is in the range 0 to 1. All common examples use this range because it kind of makes sense for objectBoundingBox.
I would be happy to hear what others think about this, because it sounds like a naive idea. But nothing better came to my mind while thinking about the problem.