How can I force Red Hat OpenJDK 8 to render fonts as clearly as AdoptOpenJDK and Oracle JDK on Windows?

JKD :

Our users run our Java GUI app on their Windows desktops, and we're planning a switch from Oracle Java 8 to OpenJDK 8. But we've found that different OpenJDK builds are inconsistent in the quality of the font rendering, with Oracle and AdoptOpenJDK being equivalent but Red Hat severely lacking.

The following screenshot shows a simple Java AWT/Swing program on Windows on the three different JDKs:

  • Oracle 1.8.0_201-b26
  • AdoptOpenJDK 1.8.0_202-b08
  • Red Hat 1.8.0_201-2-redhat-b09

Windows Java Default Font on each JDK - Oracle, AdoptOpenJDK, Red Hat

There's some problem with the rendering in the Red Hat JDK, because every character is distorted.

The program is just displaying a Swing JLabel with the command-line-specified Dialog/bold/12 font (which each JDK maps to the Windows OS Arial font):

    $ cat fontname.groovy
    import javax.swing.*
    import java.awt.Font
    import sun.font.*

    styles=[bold:Font.BOLD,italic:Font.ITALIC,plain:Font.PLAIN]
    SwingUtilities.invokeLater({
     l = new JLabel("${args}: ${System.getProperty('java.runtime.name')} ${System.getProperty('java.runtime.version')}")
     l.setFont(new Font(args[0],styles[args[1]],Integer.valueOf(args[2])))
     f = new JFrame()
     f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
     f.getContentPane().setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10))
     f.getContentPane().add(l)
     f.pack()
     f.setVisible(true)
     logicalFont = l.getGraphics().getFont()
     print(logicalFont)
     physicalFont = FontManagerFactory.getInstance().findFont2D( logicalFont.getName(), 0, FontManager.NO_FALLBACK )
     print(physicalFont)
    })

The additional screenshot below shows the same font on 3 Swing PLAFs available on this Windows system and shows that the appearance under Red Hat OpenJDK is consistent for each PLAF (set via system property option "-Dswing.defaultlaf="):

  • Default Look and Feel (javax.swing.plaf.metal.MetalLookAndFeel)
  • Windows Look and Feel (com.sun.java.swing.plaf.windows.WindowsLookAndFeel)
  • Nimbus Look and Feel (javax.swing.plaf.nimbus.NimbusLookAndFeel)

Windows Java Default Font on multiple Swing PLAFs and JDKs

Does anyone know why the Red Hat OpenJDK build would render fonts in a way that's so different? Is it possibly some additional JDK configuration or setup that the Red Hat OpenJDK might require?

Update - the workaround in alexkasko's answer (thank you!) of setting environment variable FREETYPE_PROPERTIES does correct the font issue, as of OpenJDK version 1.8.0_201-2-redhat-b09:

Windows Java Default Font with/without FREETYPE_PROPERTIES

alexkasko :

This is a regression in Red Hat build caused by the FreeType update to 2.8. AdoptOpenJDK jdk8 build uses older FreeType 2.5.3. This is going to be fixed in Red Hat builds, meanwhile the old behaviour can be re-enabled using environment variable:

FREETYPE_PROPERTIES=truetype:interpreter-version=35

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=105058&siteId=1