You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found a bug where the focal point is always centered regardless of what it's set to, but it does affect the transition of the gradient. The gradient also appears to paint in the incorrect direction (Bottom/Right to Top Left), instead of (Top/Left to Bottom/Right) but I believe that's because the focal point logic is incorrect.
Here is an example of an svg that renders correctly in chrome, inkscape, etc.
Here is an example of that same image rendered using pdfbox graphics2d example.pdf
` private void example(Graphics2D g2d, int x, int y, int diameter) {
var cRestore = g2d.getComposite();
var tRestore = g2d.getTransform();
g2d.translate(x, y);
g2d.setColor(Color.RED);
g2d.fillOval(0, 0, diameter, diameter);
// Setup radial gradient
Point2D center = new Point2D.Float(diameter / 2, diameter / 2);
float radius = diameter / 2;
Point2D focus = new Point2D.Float((int) (diameter * .3), (int) (diameter * .3));
float[] dist = {0.0f, .75f, 1f};
Color c = Color.WHITE;
Color transparent = new Color(c.getRed(), c.getGreen(), c.getBlue(), 0);
Color[] colors = {c, transparent, Color.BLACK};
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2d.setPaint(p);
g2d.fillOval(0, 0, diameter, diameter);
g2d.setComposite(cRestore);
g2d.setTransform(tRestore);
}`
The text was updated successfully, but these errors were encountered:
No idea why, but I got no notification for this issue ...
There are two bugs. The focial point is wrong but also the transparency mask is off, see #37. I was able to fix the focial point, but regarding the transparency issue I have to find some free time to deeper investigate this, as this stuff is rather tricky...
In PDF you don't have transparent colors, i.e. something like rgba(255,0,0,0.5) for some halve transparent red is not possible in PDF. You have to created some mask (i.e. a bitmap or a form (PDF command stream) with drawing instructions) which represents the alpha channel you want. And then you perform your paint/draw operation but set the transparency mask in the PDF extended graphics state before drawing. For solid colors you can set a special transparency value in the extended graphics state. But this is not possible for gradients. There you have to create a mask which resembles that alpha. And something is wrong with the matrix transforms of the mask. If you like to investigate that deeper you are welcome. But I can not estimate at the moment when I will time for that.
I've found a bug where the focal point is always centered regardless of what it's set to, but it does affect the transition of the gradient. The gradient also appears to paint in the incorrect direction (Bottom/Right to Top Left), instead of (Top/Left to Bottom/Right) but I believe that's because the focal point logic is incorrect.
Here is an example of an svg that renders correctly in chrome, inkscape, etc.
Here is an example of that same image rendered using pdfbox graphics2d
example.pdf
` private void example(Graphics2D g2d, int x, int y, int diameter) {
The text was updated successfully, but these errors were encountered: