IBM Support

How To Add Fonts To the IBM Technology for Java (J9) JDKs on the IBM i

Troubleshooting


Problem

This document discusses where to obtain some standard fonts and how to add them to the IBM Technology for Java (J9) JDKs on the IBM i.

Environment

IBM i; IBM i Java Development Kit (JDK)

Resolving The Problem

Some client applications that use Java's Abstract Windows Toolkit (AWT) might require the addition of custom fonts in order for the output text to display properly. This document will discuss where to obtain some of the standard fonts and how to add them to the IBM Technology for Java (J9) JDKs.

Resolution 1)  We first suggest to verify if ADDITIONAL FONTS have been installed to the IBMi OS.   
DSPSFWRSC
Resource                              
   ID          Option  Feature  Description
5770SS1   43       5050    Additional Fonts  
 

TrueType and OpenType fonts are expected to be found in one of two integrated file system directories:

  • /QIBM/ProdData/OS400/Fonts/TTFonts for IBM supplied fonts.
  • /QIBM/UserData/OS400/Fonts/TTFonts for user fonts.

You can specify additional directories for user fonts by using environment variable QIBM_FONT_RESOURCES_PATH. One or more directories, separated by a colon, can be specified.

Example resolve of sql java call: java.lang.Error: Probable fatal error: No physical fonts found...when using GENERATE_SPREADSHEET for an xlsx or xls file.
 
Example search for Option 43 on install image.


Resolution 2)  Many of the standard fonts used today within Windows can be found in the C:\WINDOWS\Fonts directory, including the Arial, Courier New, and Times New Roman fonts.  In the Windows default font directory, you find the fonts are listed as True Type Font (TTF) files. TrueType is an outline font standard, which is a common format for fonts on the Mac operating system and Windows operating systems.

Included below is a listing of a few standard fonts available through the Windows operating system:
Arial C:\WINDOWS\Fonts\arial.ttf
Arial Bold C:\WINDOWS\Fonts\arialbd.ttf
Arial Bold Italic C:\WINDOWS\Fonts\arialbi.ttf
Courier New C:\WINDOWS\Fonts\cour.ttf
Courier New Bold C:\WINDOWS\Fonts\courbd.ttf
Courier New Bold Italic C:\WINDOWS\Fonts\courbi.ttf
Times New Roman C:\WINDOWS\Fonts\times.ttf
Times New Roman Bold C:\WINDOWS\Fonts\timesbd.ttf
Times New Roman Bold Italic C:\WINDOWS\Fonts\timesbi.ttf

Default IBM Technology for Java (J9) JDK font directories

JV1 Option 17 - JDK 8.0 64 bit
/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit/jre/lib/fonts
JV1 Option 16 - JDK 8.0 32 bit
/QOpenSys/QIBM/ProdData/JavaVM/jdk80/32bit/jre/lib/fonts
JV1 Option 15 - JDK 7.0 64 bit
/QOpenSys/QIBM/ProdData/JavaVM/jdk70/64bit/jre/lib/fonts
JV1 Option 14 - JDK 7.0 32 bit
/QOpenSys/QIBM/ProdData/JavaVM/jdk70/32bit/jre/lib/fonts

Beginning with IBM JDK 11, fonts are no longer shipped with the JDK and must be supplied by the operating system or an external source.  As a result, the fonts in the Bigelow & Holmes Lucida family (Lucida Sans, Lucida Bright, and Lucida Typewriter) are no longer available to applications from the JDK.  Clients can use either JVM option to append or prepend fonts to the JVM process.
-Dsun.java2d.fontpath=append:<pathto>/myfonts
or
-Dsun.java2d.fontpath=prepend:<pathto>/myfonts 
Example: To add IBM JDK 8.0 fonts back into JDK 11, add this JVM option when invoking your Java program.
-Dsun.java2d.fontpath=append:/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit/jre/lib/fonts
For IBM JDK 8.0 and earlier, use these steps to add custom fonts to the IBM Technology for Java JDKs:
1. Locate the custom TrueType Font (TTF) file(s).
The default Windows font location is C:\WINDOWS\Fonts.
2. Copy/FTP the custom TTF file(s) to the IBM i Integrated File System (IFS).
Note: You can copy the files to the IBM i IFS using FTP, a mapped network drive, or IBM i Navigator.

The target IBM i IFS location can either be an existing, user specified directory, or the default JDK font directory. You should refer to the section above entitled Default IBM Technology for Java (J9) JDK font directories to obtain the default JDK font directory. Important Note: IBM highly recommends the use of a custom font directory. This allows the client a more granular use of the custom font(s). Adding the TTF file to a default JDK font directory will automatically make the font available only for the specified JDK.

User specified directory example:
MKDIR DIR('/fonts')

The TTF files would then be copied into the /fonts directory. Example: /fonts/arial.ttf, /fonts/cour.ttf, /fonts/times.ttf

If you decide to only use the default JDK font directory, you should skip to Step 4. If you would like to use a custom font directory, you should proceed to Step 3.
3. Add the JAVA_FONTS environment variable to specify the custom font directory(ies).

Qshell/PASE

export JAVA_FONTS=/fonts
export JAVA_FONTS=/fonts:/fonts2

System-wide - IBM i

ADDENVVAR ENVVAR(JAVA_FONTS) VALUE('/fonts:/fonts2') LEVEL(*SYS)
Note: This will load the fonts in the specified directories for all JVMs on the system.

ADDENVVAR ENVVAR(JAVA_FONTS) VALUE('/fonts') LEVEL(*JOB)
4. The IBM Technology for Java JDK(s) will now use the custom font(s) added to the default JDK font directory and/or in the directory(ies) specified on the JAVA_FONTS environment variable.
 

Sample Java Source (ListAvailableFonts.java) for Listing Available Fonts
 
import java.awt.GraphicsEnvironment;

public class ListAvailableFonts {

   public static void main(String[] args) {
      String fonts[] =
      GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

      for ( int i = 0; i < fonts.length; i++ ) {
         System.out.println(fonts[i]);
      }
   }

}

When calling the above program on the IBM i, use the JVM argument -Djava.awt.headless=true

Example:
STRQSH
javac ListAvailableFonts.java
java -Djava.awt.headless=true ListAvailableFonts

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CH5AAM","label":"Java Development Kit"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.2.0;7.3.0;7.4.0;7.5.0"}]

Historical Number

622714229

Document Information

Modified date:
04 December 2024

UID

nas8N1011186