Skip to content

RadialGradientPaint incorrect focal point location and transition direction #44

@bblocher

Description

@bblocher

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.
marble-red

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);
}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions