jfree / jfreechart

A 2D chart library for Java applications (JavaFX, Swing or server-side).
http://www.jfree.org/jfreechart/
GNU Lesser General Public License v2.1
1.22k stars 461 forks source link

Legend Text Vertical Offset with DPI Scaling > 100% #196

Open lynnskii opened 3 years ago

lynnskii commented 3 years ago

I've noticed that legend item text is not centered with the lines/symbols when DPI scaling is greater than 100%. (OpenJDK 11 on Windows 10).

Here is an example at 125% and 100%: LegendTextOffset

Here is another image where I added code to draw the bounding boxes around the legend line/shape and the text label. The shape is properly centered at both 125% and 100% scaling, but the text is not. LegendBounds

I'm not sure if it has to do with calculating bounds/offsets with a scaled Graphics2D object. I could tweak the text position by adjusting the y-offset value in TextBlock.draw(Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle), but I haven't found a generic way to address it or what other consequences it might have.

lynnskii commented 3 years ago

Doing some more testing, it appears it may not be a DPI scaling issue, but rather a JRE difference. My 100% tests were using Oracle's Java 8 on Windows 10, but my 125% tests were using AdoptOpenJDK 11. I think the OpenJDK may be using a different font rendering package because the legend text wasn't center aligned at 100% scaling either.