The Font of All Knowledge About Java and Fonts
Here's everything you need to know about fonts in the JDK.
Join the DZone community and get the full member experience.Join For Free
Around the middle of the 15th century, Johannes Gutenberg introduced the metal movable-type printing press. I think it would be easy to argue that this was one of the most significant inventions in history for enabling widespread access to information; something, today, we take very much for granted. The metal type pieces of Gutenberg’s press led to the development of both typography and fonts. Although the basic character shapes are the same, fonts allow us to render the same fundamental alphabet in different ways. The use of styles like bold and italics can further be used to highlight or emphasise parts of text. Although we no longer use metal type pieces, we still use fonts for text displayed on the screen for our applications and rely on font rendering to do this for us.
Java has always aimed to be as cross-platform as possible, leading to the famous “write once, run anywhere” slogan. Aside from the low-level fundamentals such as bytecodes and the JVM, this extends to how a graphical application looks on the screen.
Desktop operating systems all provide a range of fonts that can be used by applications to display text. However, there is no standard to ensure that the same fonts are supported across all possible platforms. To solve this problem, the Oracle JDK included a simple set of physical fonts; the idea being that, if you used only those fonts, your application text would look the same wherever you ran it. The fonts that were included were from the Lucida design family:
One of the changes made in JDK 11 was the removal of these fonts. As part of the convergence of the Oracle JDK with the OpenJDK, the Oracle JDK also no longer uses the T2K rendering engine (described in the JDK 11 Migration Guide) that it had in the past.
The JDK now relies purely on the fonts available on the host platform and supports both TrueType and PostScript Type 1 fonts.
There are also five logical fonts:
These are simply names that are guaranteed to exist on all platforms but map to underlying operating system fonts, which may differ from one platform to another and so may not render in the same way.
When migrating graphical applications from JDK 8 (or earlier) to JDK 11, the availability of physical fonts is something that you may need to check to ensure that the way your applications appear on the screen correctly.
To determine what fonts are supported on a given platform and available to a Java application is straightforward. An array of font names can be retrieved using the
String fonts = GraphicsEnvironment .getLocalGraphicsEnvironment() .getAvailableFontFamilyNames();
Azul’s Zulu JDK is built only from the OpenJDK source, so it does not include the physical fonts. For users who do require these fonts we have provided a separate download, the Zulu Commercial Compatibilty Kit (ZCCK). We have been doing this for JDK 6, 7, and 8 (download link) and now have a version available for JDK 11 (download link).
The four fonts that are included in the ZCCK are shown below:
The good news is that if you want to migrate to JDK 11 and continue to use the default physical fonts, then Zulu will be your choice of Java runtime.
Published at DZone with permission of Simon Ritter, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.