# Font Overview

### Contents

> Physical Fonts and Logical Fonts
> The font.properties Files
> Location of Physical Fonts
> Adding Fonts

### Physical Fonts and Logical Fonts

> There are two types of fonts -- physical fonts and logical fonts. Physical fonts are the actual font libraries consisting of, for example, TrueType or PostScript Type 1 fonts. The physical fonts may be Time, Helvetica, Courier, or any number of other fonts, including international fonts. For more information, see Physical Fonts.

> Logical fonts are the five font types that have been recognized by the Java platform since version 1.0: Serif, Sans-serif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries that are installed anywhere on your system. They are merely font-type names recognized by the Java runtime which must be mapped to some physical font that is installed on your system. In addition to the five logical font types, the Java runtime recognizes four logical font styles: plain, bold, italic, and bolditalic.

### The font.properties Files

> The mapping of logical font types (and styles) to physical fonts is handled by the font.properties files. The font.properties files are located in the `jre/lib` directory of the Java 2 SDK or the `lib` directory of the Java 2 Runtime Environment. Because the physical fonts available will depend on the operating system and the locale, the SDK and Runtime Environments come with a variety of font.properties files for different locales and (in the case of the Solaris operating system) for different operating system versions.

> When an application or applet wants to invoke a font by using a logical name such as Serif or Monospace, the runtime environment looks up in the font.properties file the physical font that is mapped to that logical name and then loads and uses that physical font. For example, on both Solaris 2.6/2.7 and Microsoft Windows operating systems, the font.properties file maps the Serif logical font to the Times New Roman physical font. This means that the following two constructors would create the same font:

> >     new Font("Serif", Font.PLAIN, 12)  // Logical font name is mapped
> >                                        // to Times New Roman by
> >                                        // font.properties file

> >     new Font("Times New Roman", Font.PLAIN, 12) // Physical font is
> >                                                 // invoked directly;
> >                                                 // no need for mapping

> Here we see that the first (String) parameter in the Font constructor can be either a logical font type or the family name of a physical font. Available font family names may be obtained by using the `getAvailableFontFamilyNames` method of class `java.awt.Graphdics Environment`.

### Location of Physical Fonts

> Physical font files can be installed in either an operating system's standard location for fonts or in the `jre/lib/fonts` library of the Java 2 SDK (or in the `lib/fonts` directory of the Java 2 Runtime Environment). Fonts in either the operating system's standard location or in the `lib/font` directory will be on the Java runtime's "font path" and can be used by applications and applets.

### Adding Fonts

> The following TrueType fonts come already installed in the Java 2 SDK's `jre/lib/font` directory.

> >     LucidaBrightDemiBold.ttf
> >     LucidaBrightDemiItalic.ttf
> >     LucidaBrightItalic.ttf
> >     LucidaBrightRegular.ttf
> >     LucidaSansDemiBold.ttf
> >     LucidaSansDemiOblique.ttf
> >     LucidaSansOblique.ttf
> >     LucidaSansRegular.ttf
> >     LucidaTypewriterBold.ttf
> >     LucidaTypewriterBoldOblique.ttf
> >     LucidaTypewriterOblique.ttf
> >     LucidaTypewriterRegular.ttf

> In addition, many are fonts pre-installed on Microsoft Windows and Solaris operating systems. Other fonts can be easily added. The additional fonts may be installed by the operating system so that they are placed in the operating system's standard font location. For example, Asian fonts are available for Win32 systems from Microsoft's web site and on the Windows NT 4.0 installation CD-ROM. The Win32 operating systems will install these fonts in the standard location for fonts. These fonts can then be found by the Java runtime.

> Another option for installing fonts is for the user to place the fonts directory in the SDK's `jre/lib/font` directory (or the Runtime Environment's `lib/font` directory). Fonts located there will also be found by the Java runtime. Files placed in `jre/lib/font` directory must be Unicode encoded TrueType fonts.

> It is not necessary to edit the font.properties files after you have added new fonts to your system. You can invoke the new font directly by using its font family name. You would need to edit the font.properties files only in the situation in which you wanted to map one of the logical font types (Serif, Sans-serif, Monospace, Dialog, and DialogInput) to a new font, or if you want to make some locale-specific mapping. For information on editing the font.proprerties files, see Editing the font.properites Files

Copyright © 2000 Sun Microsystems, Inc. All Rights Reserved. | Java Software