3

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):

// 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?

Windows Java Default Font with/without FREETYPE_PROPERTIES

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
JKD
  • 103
  • 7
  • Check your font server; the jdk fonts are ttf (or they work with ttf). – Elliott Frisch Apr 19 '19 at 21:00
  • Thanks. I'm 99% certain each of the 3 JDKs is rendering the same font from the same exact TTF file. The physical font the program logs is always `** TrueType Font: Family=Arial Name=Arial style=0 fileName=C:\Windows\Fonts\ARIAL.TTF` – JKD Apr 19 '19 at 21:04
  • Correct. On redhat, you need to configure the [font server](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/desktop_migration_and_administration_guide/configure-fonts). This is (mostly) unrelated to Java. – Elliott Frisch Apr 19 '19 at 21:06
  • I haven't tried the same experiment on a Red Hat Enterprise Linux server, but I have tried it on an Ubuntu Linux desktop with Ubuntu's OpenJDK 8 package, and the font rendering looks nice (default font on that OS happens to be DejaVu Sans, specifically `** TrueType Font: Family=DejaVu Sans Name=DejaVu Sans style=0 fileName=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf`). So the poor appearance is specific to the Windows OS JDK builds, and specific to Red Hat's flavor of those builds. – JKD Apr 19 '19 at 21:11
  • Do the fonts render as you expect under *any* of the available PLAFs? – Andrew Thompson Apr 20 '19 at 09:52
  • @AndrewThompson - I did a similar non-Swing experiment with similar font rendering results - a java.awt.Frame subclass overriding paint(Graphics) to draw a text string - so I was thinking it's not tied to Swing and its PLAFs. But I'll give other PLAFs a try and update with my results. Thanks! – JKD Apr 22 '19 at 12:25
  • @AndrewThompson - I edited my post with a screenshot of different PLAFs on Windows, all with the same font appearance. Under Oracle JDK, the font is consistently good across all the PLAFs. Under Red Hat OpenJDK, the font is consistently distorted across all the PLAFs. Whatever is not working, it's not tied to a specific PLAF. – JKD Apr 22 '19 at 13:10

1 Answers1

3

This is a regression in the Red Hat build caused by the FreeType update to 2.8. The AdoptOpenJDK Java 8 build uses the older FreeType 2.5.3.

Until Red Hat fixes it, the old behaviour can be re-enabled by setting the interpretor-version property of the TrueType driver to version 35, which can be done with an environment variable:

FREETYPE_PROPERTIES="truetype:interpreter-version=35"
Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
alexkasko
  • 4,855
  • 1
  • 26
  • 31
  • 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. (Originally I had added this note to the question itself, as an update, but it was removed from my question recently. Noting the version I successfully tested with the workaround still seems helpful, so I moved it to this comment. The screenshot from my successful test is still in the question itself, which is a little confusing since the note explaining it has been removed.) – JKD Feb 02 '23 at 18:25