2

I'm experimenting with different fonts for a Swing UI and I've noticed a strange effect when switching from Oracle JDK 8 to OpenJDK 16. Using two versions of the Lato font (the version 1 available from Google Fonts, and the version 2 available from latofonts.com), there is a significant difference in the position of the baseline with the version 2 on OpenJDK.

Here is an example with Oracle JDK 8:

Font rendering with Oracle JDK 8

And an example with OpenJDK 16:

Font Rendering with OpenJDK 16

On Oracle JDK 8 the baseline is the same for both fonts, but on OpenJDK 16 the Lato 2 baseline is higher. The text is no longer vertically centered relatively to the checkbox and to the text field.

I don't understand why this happens. Is this a bug in the JDK? Or an issue with the font file? I've opened both fonts in FontForge and they look quite similar.

I'm aware the font rasterizer used by OpenJDK (FreeType) is different from the one in the Oracle JDK 8 (T2K). I also know that the Lato 2 font could be shifted by deriving the font with an AffineTransform but that sounds like a dubious hack.

Emmanuel Bourg
  • 9,601
  • 3
  • 48
  • 76
  • 1
    Perhaps related? https://stackoverflow.com/questions/61565649/calibri-font-when-in-html-text-moves-to-the-bottom-part-of-the-component . Maybe not. – George Z. Jun 29 '21 at 14:32
  • Thank you for the reference, there is indeed the same issue with the Calibri font. Looking at the font metrics, Lato 1 has a leading of 0 at all font sizes, and Lato 2 has a leading of 20% relatively to the size. – Emmanuel Bourg Jun 29 '21 at 16:36
  • I still use to this day the accepted answer of my question. Maybe you could try something similar. And my other answer in the same question uses hacky reflection. I doubt if it will work in Java 16. – George Z. Jun 29 '21 at 16:42
  • 1
    Likely related to https://bugs.openjdk.java.net/browse/JDK-8251836 – Emmanuel Bourg Jun 30 '21 at 07:12

0 Answers0