Skip to content

SVGGraphics2D: drawRect and fillRect misaligned compared to Graphics2D #24

@markustw

Description

@markustw

In Graphics2D drawing a filled rectangle with a 1-pixel border shows a correctly filled rectangle, applying the same code with SVGGraphics2D results in a misalignment of the border and the filled rectangle:

SVGGraphics2D graphics = new SVGGraphics2D(40, 40);
graphics.drawRect(10, 10, 20, 10); // 1- pixel border
graphics.setColor(Color.BLUE);
graphics.fillRect(11, 11, 19, 9);

The method drawRect of Graphics2D internally draws four lines to get a rectangle, it seems in SVG the x,y starting-coordinate of lines is not the top-left corner but the middle of the lines which causes the misaligment.
Unfortunately the class SVGGraphics2D is final so no easy workaround can be implemented.

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