6 Font Configuration Files

The Java Platform defines five logical font names that every implementation must support: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These logical font names are mapped to physical fonts in implementation dependent ways.

One way the Oracle JDK maps logical font names to physical fonts is by using font configuration files. There may be several files to support different mappings depending on the host operating system version. The files are distributed with the JDK installation. You can edit or create your own font configuration files to adjust the mappings to your particular system setup, however these must be placed in conf/fonts, and are subject to implementation notes discussed below.

Font configuration files come in two formats: a properties format and a binary format. The properties format is described in detail in this document and can be used for user-defined configurations. The binary format is undocumented and used only for the JDK's predefined configurations; the corresponding files in properties format are available for reference as files with the .properties.src extension.

Supported Platforms

Font configuration files are implementation dependent. Not all implementations of the Java Platform use them, and the format and content vary between different runtime environments as well as between releases. The macOS implementation does not use font configuration files, as the mapping is hard coded in the source and cannot be changed in any way.

The Oracle JDK supports font configuration files on the host operating system as follows:
  • For Windows, font configuration files are required.

  • For macOS, font configuration files are unsupported.

  • For Linux and Solaris: the Oracle JDK is moving away from providing custom font configuration files on Linux platforms, as they are difficult to keep up to date across distributions and versions. A distribution that has control over the fonts on the system can continue to provide this custom file. If the JRE finds a custom file that exactly matches the distribution and version it will use it. If no exact match is found, the JRE dynamically creates the file at runtime. These generated files are placed in a location determined by the implementation. They should be considered implementation internal: they are not user editable and do not follow the syntax as described in this specification.

Loading Font Configuration Files

The JDK places any files that it provides in $JDKHOME/lib. Do not modify that location. Instead, put any updates or custom versions of the configuration files in $JDKHOME/conf/fonts.

On platforms that support font configuration files, the runtime will look first in $JDKHOME/conf/fonts. In other words, a user-supplied file is preferred if it is a match.

The font configuration file for a host operating system is located as follows:

  • JavaHome - the JDK directory, as given by the java.home system property.
  • OS - a string identifying an operating system variant:
    • For Windows, empty.
    • For Solaris, empty.
    • For Linux, "RedHat", "SuSE", etc.
  • Version - a string identifying the operating system version.

The runtime uses the first of the following files it finds:

JavaHome/lib/fontconfig.OS.Version.properties
JavaHome/lib/fontconfig.OS.Version.bfc
JavaHome/lib/fontconfig.OS.properties
JavaHome/lib/fontconfig.OS.bfc
JavaHome/lib/fontconfig.Version.properties
JavaHome/lib/fontconfig.Version.bfc
JavaHome/lib/fontconfig.properties
JavaHome/lib/fontconfig.bfc

Files with a .properties suffix are assumed to be properties files as specified by the Properties class and are loaded through that class. Files without this suffix are assumed to be in binary format.

Names Used in Font Configuration Files

Throughout the font configuration files, a number of different names are used:

  • LogicalFontName - one of the five logical font names: serif, sansserif, monospaced, dialog, and dialoginput. In font configuration files, these names are always in lowercase.
  • StyleName - one of the four standard font styles: plain, bold, italic, and bolditalic. Again, these names are always in lowercase.
  • PlatformFontName - the name of a physical font, in a format typically used on the platform:
    • On Windows, a font face name, such as "Courier New" or "\uad74\ub9bc".
    • On Solaris and Linux, an xlfd name, such as "-monotype-times new roman-regular-r---*-%d-*-*-p-*-iso8859-1". Note that "%d" is used for the font size - the actual font size is filled in at runtime.
  • CharacterSubsetName - a name for a subset of the Unicode character set which certain component fonts can render. For Windows, the following names are predefined: alphabetic, arabic, chinese-ms936, chinese-gb18030, chinese-ms950, chinese-hkscs, cyrillic-iso8859-5, cyrillic-cp1251, cyrillic-koi8-r, devanagari, dingbats, greek, hebrew, japanese, korean, latin, symbol, thai. For Solaris and Linux, the following names are predefined: arabic, chinese-gb2312, chinese-gbk, chinese-gb18030-0, chinese-gb18030-1, chinese-cns11643-1, chinese-cns11643-2, chinese-cns11643-3, chinese-big5, chinese-hkscs, cyrillic, devanagari, dingbats, greek, hebrew, japanese-x0201, japanese-x0208, japanese-x0212, korean, korean-johab, latin-1, latin-2, latin-4, latin-5, latin-7, latin-9, symbol,thai. A font configuration file may define additional names to identify additional character subsets.
  • Encoding - the canonical name of the default encoding, as provided by java.nio.charset.Charset.defaultCharset().name().
  • Language - the language of the initial default locale.
  • Country - the country of the initial default locale.

Properties for All Platforms

Properties that are applicable to all platforms enable you to specify the font configuration format version, component font mappings, search sequences, exclusion ranges, proportional fonts, font file names, and appended font path.

Version Property

The version property identifies the font configuration format version. This document specifies version 1.

The complete property has the form:

version=1

Component Font Mappings

Component font mapping properties describe which physical font to use to render characters from a given character subset with a given logical font in a given style.

The keys have the forms:

allfonts.CharacterSubsetName
LogicalFontName.StyleName.CharacterSubsetName

The first form is used if the same font is used for a character subset independent of logical font and style (in this case, the font rendering engines apply algorithmic styles to the font). The second form is used if different physical fonts are used for a character subset for different logical fonts and styles. In this case, properties must be specified for each combination of logical font and style, so 20 properties for one character subset. If a property of the first form is present for a character subset, then properties of the second form for the same character subset are ignored.

The values are platform font names, as described in Names Used in Font Configuration Files.

Since the character subsets supported by given fonts often overlap, separate search sequence properties are used to define in which order to try the fonts when rendering a character.

Search Sequences

The Java runtime uses sequence properties to determine search sequences for the five logical fonts. However, a font configuration file may specify properties that are specific to a combination of encoding, language, and country, and the runtime will then use a lookup to determine the search sequence property for each logical font.

The keys have the form:

sequence.allfonts.Encoding.Language.Country
sequence.LogicalFontName.Encoding.Language.Country
sequence.allfonts.Encoding.Language
sequence.LogicalFontName.Encoding.Language
sequence.allfonts.Encoding
sequence.LogicalFontName.Encoding
sequence.allfonts
sequence.LogicalFontName

The allfonts forms are used if the sequence is used for all five logical fonts. The forms specifying logical font names are used if different sequences are used for different logical fonts.

For each logical font, the Java runtime uses the property value with the first of the above keys. This property determines the primary search sequence for the logical font.

The file may also define a single fallback search sequence. The key for the fallback search sequence property is:

sequence.fallback

The values of all search sequence properties have the form:

SearchSequenceValue:
  CharacterSubsetName
  CharacterSubsetName , SearchSequenceValue

The primary search sequence properties specify character subset names for required fonts, which are used for both AWT and 2D font rendering. The fallback search sequence property gives character subset names for optional fonts, which are used as fallbacks for all logical fonts, but only for 2D font rendering. On Windows, if there is a system EUDC (End User Defined Characters) font registered with Windows, the runtime automatically adds this font as well as a fallback font for 2D rendering.

The sequence properties determine in which sequence component fonts are tried to render a given character. For example, given the following properties:

sequence.monospaced=japanese,alphabetic
sequence.fallback=korean
monospaced.plain.alphabetic=Arial
monospaced.plain.japanese=MSGothic
monospaced.plain.korean=Gulim

The runtime will first attempt to render a character with the MSGothic font. If that font doesn't provide a glyph for the character, it will attempt the Arial font. For 2D rendering, it will also try the Gulim font as well as any TrueType, OpenType, or Type 1 fonts in the system's standard font locations. For 2D rendering on Windows, if there is a system EUDC font registered with Windows, the runtime will also try this EUDC font.

When calculating font metrics for a logical font without reference to a string, only the required fonts are taken into consideration. For the example above, the FontMetrics.getMaxDescent method would return results based on the MSGothic and Arial fonts, but not the Gulim font. In this way, simple user interface elements such as buttons, which sometimes calculate their size based on font metrics, are not affected by an extended list of component fonts which their labels usually don't use. On the other hand, text components typically calculate metrics based on the text they contain and thus will obtain correct results.

The sequence properties that the runtime obtains for the five logical fonts should list the same character subsets, but may list them in different order.

Exclusion Ranges

The exclusion range properties specify Unicode character ranges which should be excluded from being rendered with the fonts corresponding to a given character subset. This is used if a font with a large character repertoire needs to be placed early in the search sequence (for example, for performance reasons), but some characters that it supports should be drawn with a different font instead. These properties are optional, so there's at most one per character subset.

The keys have the form:

exclusion.CharacterSubsetName

The values have the form:

ExclusionRangeValue:
  Range
  Range , ExclusionRangeValue

Range:
  Char - Char

Char:
  HexDigit HexDigit HexDigit HexDigit
  HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit

A Char is a Unicode character represented as a hexadecimal value.

Proportional Fonts

The proportional font properties describe the relationship between proportional and non-proportional variants of otherwise equivalent fonts. These properties are used to implement preferences specified by the GraphicsEnvironment.preferProportionalFonts method.

The keys have the form:

proportional.PlatformFontName

Space characters in the platform font name must be replaced with underscore characters (_).

The values have the form:

PlatformFontName

In values, space characters are left unmodified.

Each property indicates that the font named in the value is the proportional equivalent of the font named in the key, and also that the font named in the key is the non-proportional equivalent of the font named in the value.

Font File Names

Font file name properties provide the names of the files containing the physical fonts used in the font configuration file. File names are required for all physical fonts on Windows and recommended for all physical fonts on Solaris and Linux.

The keys have the form:

filename.PlatformFontName

Space characters in the platform font name must be replaced with underscore characters (_).

The values are the file names of the files containing the fonts. On Windows, simple file names are used; and the runtime environment looks for each file first in its own lib/fonts directory, then in the Windows fonts directory. On Solaris and Linux, absolute path names, path names starting with "$JRE_LIB_FONTS" for the runtime environment's own lib/fonts directory, or xlfd names are used.

Appended Font Path

The Java runtime can automatically determine a number of directories that contain font files, such as its own lib/fonts directory or the Windows fonts folder. Additional directories can be specified to be appended to the font path.

The key has the form:

appendedfontpath

The value has the form:

AppendedFontPathValue:
  Directory
  Directory PathSeparator AppendedFontPathValue

The path separator is the platform dependent value of java.io.File.pathSeparator.

Properties for Windows

There are no platform-specific properties for Windows. However, there is a special form of the character subset name used in search sequences. The name "alphabetic" can take a suffix indicating the character encoding associated with the subset:

alphabetic
alphabetic/default
alphabetic/1252

This information is only used for AWT, not for 2D. The /default suffix restricts use of the component fonts for this character subset to the character set of the default encoding; the /1252 suffix to the Windows-1252 character set. For accessing component font mappings and exclusion ranges, the character encoding suffix is omitted. For all other character subsets, the AWT character encoding is determined internally by the Java runtime.

Property for Solaris and Linux

The only property that is specific to Solaris and Linux is the AWT font path, which identifies platform directories that should be added to the X11 server font path.

The keys have the form:

awtfontpath.CharacterSubsetName

The values have the form:

AWTFontPathValue:
  Directory
  Directory : AWTFontPathValue

The directories must be valid X11 font directories. The Java runtime ensures that the directories for all character subsets of a primary search sequence found by the search sequence lookup (see Search Sequences) are part of the X11 font path. The implementation assumes that all logical fonts use the same set of character subsets for a given environment of encoding, language, and country.