Adding Fonts to the Java Runtime

This document explains how to add Asian and other language fonts to the Java Runtime JDK 1.1. More specifically, this document covers the JDK 1.1 special feature for adding these fonts to the Java Runtime. It is very likely that this feature will change in future JDK releases.

At this time, this document describes how to install Japanese, Korean, Chinese, and Traditional Chinese fonts to your system.

If the core Java Runtime includes support only for Latin-1 fonts, then the Runtime requires only one file. All other files can be in the optional I18n package.

The JDK 1.1 release for Win32 platforms supports TrueType fonts. JDK 1.1 for Solaris supports outline fonts that can be handled by an X11 server, such as F3, Type1, and TrueType.

Using the File

You must work with the file to add fonts to the Java Runtime. The file is platform- specific. It indicates the fonts that a particular platform uses for its Java virtual fonts. Fonts are grouped by types or classes. Currently, the Java Runtime supports the following classes of fonts:

There are several files that come bundled with the JDK 1.1. You can find these files in the directory ../lib that is beneath the directory where Java is installed. These files contain standard font environment information. The explanations that follow assume that the readers of this document are working in an English environment. In an English environment, you use the file with no suffix on its file name, as follows:
However, if your environment is Japanese, Korean, Chinese, or Traditional Chinese, then you must use the file that corresponds to your particular environment. These files can be identified by the country or locale suffix that is appended to the file name, as follows:<locale>
where locale is one of:




Select the file with the suffix for the particular font that you are interested in. Thus, for Traditional Chinese, you would access the file

Adding Asian Fonts to the Java Runtime

There are two steps you must take to use Asian fonts, such as the Japanese font, on an English environment platform.

Step 1: Install the Font

First, you must install the Japanese, Korean, Chinese, or Traditional Chinese font to your system. For Windows platform users, Microsoft delivers these Asian fonts free with the NT4.0 installation CD. Or, you can download these fonts from the Microsoft World Wide Web home page. Solaris users must contact SunSoft to request the Asian outline fonts for Solaris environments.

Step 2: Copy the Font

Once you have installed the fonts on your system, copy the font description that you are interested in to The easiest way to add one Asian font is to rename the<locale> file to be the new file. The locale symbol represents the font name that you are interested in. No editing is required when you replace with<locale> because<locale> is a superset of These are the locale symbols that specify the different font properties files:

Locale Symbols for Fonts
Font Name Symbol
Japanese ja
Korean ko
Chinese zh
Traditional Chinese zh_TW

Thus, to use the the Korean font, you copy or rename to

Using Multiple Fonts in the Runtime

It is possible to use more than one Asian font in your runtime. To do this, you must edit the file. This section describes the edits you need to make to the file to use multiple Asian fonts. The file defines certain information about the fonts for your platform. This includes aliases, such as:


It also includes descriptions for the fonts. The descriptions differ between the Win32 and Solaris platforms. Our examples use serif fonts to illustrate how fonts are specified and converted, if necessary. However, the same entries apply to other types of fonts. In general, there are entries in the font properties file that specify the fonts you want to use. These entries have the following format:
   <virtual font name>.<index number> = <platform font name>, attributes
The virtual font name is the name of the font as recognized by the Java Runtime. The platform font name is the actual name of the font on your platform. For example, Dialog and Serif are Java font names, while Times and Helvetica are the native font names on a Win32 or Solaris platform. The index number specifies the order of searching for matching font glyphs, with zero the highest priority.

Specifying Fonts on Win32 Platform

There are three default serif fonts available on an English language Win32 platform. These fonts are:

In addition, the descriptions for these serif fonts in the file are as follows:

serif.0=Times New Roman,ANSI_CHARSET



These three lines together indicate the indexes for the three serif fonts that are available on this platform. Each line indicates one serif font, followed by up to three arguments for that font.

The numbers (0, 1, and 2) that appear after the word serif, such as serif.0, indicate the order in which the font glyphs are searched for a corresponding match with the Unicode, or Java string encoding, codepoint. Thus, if serif.0 and serif.1 both have the glyph that corresponds to the same Unicode codepoint, then the glyph for serif.0 will be used.

The first argument is the face name of the Win32 native font. Each line names a particular font. For example, the line for serif.0 names the font Times New Roman, while the line for serif.2 names the font Symbol.

The second argument takes the form *_CHARSET. In our example, it is either ANSI_CHARSET or SYMBOL_CHARSET. This argument indicates the charset entry of the corresponding font in Win32. (See the Win32 API document for more details.)

The third argument, if present, is NEED_CONVERTED. This argument indicates that the corresponding platform font cannot be accessed with Unicode. When this argument is present, the Java Runtime needs to convert the Unicode string to this font index before attempting to use the glyph for the font. Fonts that have this NEED_CONVERTED argument must have a corresponding fontcharset entry, which indicates the charset converter to use to convert the Unicode string.

In our example, both serif.1 and serif.2 have the NEED_CONVERTED argument. Both have fontcharset entries in the file, as follows:


The fontcharset entry for serif.1 indicates that, to draw the WingDings glyph, the Unicode string should be converted using the converter. (Recall that the file has already established the font for serif.1 as WingDings.)

The specification for the charset converter is described later in the section ÒThe Charset Converter.Ó

Win32 Font Files

The current Win32 JDK build provides the following font properties files:






If you need a different font from what is provided, then you must create your own font properties file.

Specifying Fonts on Solaris Platform

The Solaris file uses a different format for specifying fonts than the Win32 version. The Solaris version uses fixed-width, rather than proportional, platform fonts. For example, the serif font on an English Solaris platform consists of the following fixed-width fonts:


serif.1=-urw-itc zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-





These lines from the Solaris file indicate the indexes for serif fonts with different styles. For example, the font whose face name is serif and whose style is plain consists of serif.plain.0, serif.1, and serif.2. In addition, these lines indicate that the serif font with the style italic consists of serif.italic.0, serif.1, and serif.2.

Currently, the index of Solaris (X11) font is not a Unicode index. Because it is not Unicode, the font always needs to be converted. Each entry must have a corresponding fontcharset entry to indicate how it should be converted, as follows: 



For example, the line: 

indicates that all serif.0 fonts, regardless of whether the type is plain (serif.plain.0), bold (serif.bold.0), italics (serif.italic.0), or bold and italics (serif.bolditalic.0), will be converted using the converter.

Solaris Font Files

The current Solaris JDK build provides the following font properties files:















If you need a different font from what is provided, then you must create your own font properties file.

The Charset Converter

The charset converter converts Unicode, or Java string encoding, to the index of the font. For font drawing, the JDK 1.1 Runtime uses the charset converter that is the subclass of

To add your own font to your JDK 1.1 Runtime, you need to create a charset converter and specify it in the file.

The following example illustrates how to add your own platform font to the Java serif font. In this example, your font contains 256 glyphs, which are indexed 0 - 0xff. Your fontŐs glyphs correspond to Unicode 0xe000 - 0xe0ff. This example is divided into two steps. First, you create your fontcharset converter class. Second, you specify your font name and converter class name in the file file.

Step 1. Create fontcharset Converter

This is the Java code for creating the fontcharset converter.

package mypkg.converter;

public class CharToByteMyfont extends {

 * This method indicates the range this font covers.
public boolean canConvert(char ch) {
   if (ch >= 0xe000 && ch <= 0xe0ff) {
       return true;
   return false;

 * This method converts the unicode to this font index.
public int convert(char[] input, int inStart, int inEnd,
                   byte[] output, int outStart, int outEnd)
                   throws ConversionBufferFullException;
   int outIndex = outStart; 
   for (int i = inStart; i < inEnd; i++) {
        char ch = input[i];

        if (ch >= 0xe000 && ch <= 0xe0ff) {
            if (outIndex >= outEnd) 
            throw new ConversionBufferFullException();
            output[outIndex++] = (byte)(ch - 0xe000);
   return outIndex - outStart;
 * This method indicates the charset name for this font.
public String toString() {
   return "Myfont";

Step 2. Add Font and Converter to Properties File

You must first set the font name in the file file. Do this by adding an index entry for the font. For example, for a serif font, add a line that designates the serif font followed by the next sequential index number in the file. The Java Runtime requires that the index numbers for any one font be continuous.

Thus, to add a serif font to our previous example file, you would insert the following line:

serif.3=<your own font name>
The index number must be the next highest index number in the properties file. In our example file, we have already used serif.0, serif.1, and serif.2. Therefore, the new serif font must be serif.3. Had we used a number that was discontinuous, such as serif.5, the Java Runtime would not use that entry.

Next, you must define the converter for this font. This requires a fontcharset entry for the new font, in this case, serif.3. The following line is the fontcharset entry that uses the converter created in the Java code example:

You must also ensure that your new converter is visible to the Java Runtime. To ensure that the Java Runtime can see your converter, your java application classpath must include the class path to the converter. In our example, we must be sure that the class mypkg.converter.CharToByteMyfont is visible to the Java Runtime. The simplest way to do this is to put this class under your $JDK_HOME/classes/myown/package directory.