Common Desktop Environment: Internationalization Programmer's Guide

Fonts, Font Sets, and Font Lists

All X clients use fonts for drawing text. The basic object used in drawing text is XFontStruct(), which identifies the font that contains the images to be drawn.

The desktop already supports fonts by way of the XFontStruct() data structure defined by Xlib; yet, the encoding of the characters within the font must be known to an internationalized application. To communicate this information, the program expects that all fonts at the server are identified by an X Logical Font Description (XLFD) name. The XLFD name enables users to describe both the base characteristics and the charset (encoding of font glyphs). The term charset is used to denote the encoding of glyphs within the font, while the term code set means the encoding of characters within the locale. The charset for a given font is determined by the CharSetRegistry and CharSetEncoding fields of the XLFD() name. Text and symbols are drawn as defined by the codes in the fonts.

A font set (for example, an XFontSet() data structure defined by Xlib) is a collection of one or more fonts that enables all characters defined for a given locale to be drawn. Internationalized applications may be required to draw text encoded in the code sets of the locale where the value of an encoded character is not identical to the glyph index. Additionally, multiple fonts may be required to render all characters of the locale using one or more fonts whose encodings may be different than the code set of the locale. Since both code sets and charsets may vary from locale to locale, the concept of a font set is introduced through XFontSet().

While fonts are identified by their XLFD name, font sets are identified by a list of XLFD names. The list can consist of one or more XLFD names with the exception that only the base characteristics are significant; the encoding of the desired fonts is determined from the locale. Any charsets specified in the XLFD base name list are ignored and users need only concentrate on specifying the base characteristics, such as point size, style, and weight. A font set is said to be locale-sensitive and is used to draw text that is encoded in the code set of the locale. Internationalized applications should use font sets instead of font structs to render text data.

A font list is a libXm Toolkit object that is a collection of one or more font list entries. Font sets can be specified within a font list. Each font list entry designates either a font or a font set and is tagged with a name. If there is no tag in a font list entry, a default tag (XmFONTLIST_DEFAULT_TAG) is used. The font list can be used with the XmString() functions found in the libXm Toolkit library. A font list enables drawing of compound strings that consist of one or more segments, each identified by a tag. This allows the drawing of strings with different base characteristics (for example, drawing a bold and italic string within one operation). Some non-XmString()-based widgets, such as XmText() of the libXm library, use only one font list entry in the font list. Motif font lists use the suffix : (colon) to identify a font set within a font list.

The user is generally asked to specify either a font list (which may contain either a font or font set) or a font set. In an internationalized environment, the user must be able to specify fonts that are independent of the code set because the specification can be used under various locales with different code sets than the character set (charset) of the font. Therefore, it is recommended that all font lists be specified with a font set.

Font Specification

The font specification can be either an X Logical Function Description (XLFD) name or an alias for the XLFD name. For example, the following are valid font specifications for a 14-point font:

-dt-application-medium-r-normal-serif-*-*-*-*-p-*-iso8859-1

OR

-*-r-*-14-*iso8859-1

Font Set Specification

The font set specification is a list of names (XLFD names or their aliases) and is sometimes called a base name list. All names are separated by commas, with any blank spaces before or after the comma being ignored. Pattern-matching (wildcard) characters can be specified to help shorten XLFD names.

Remember that a font set specification is determined by the locale that is running. For example, the ja_JP Japanese locale defines three fonts (character sets) necessary to display all of its characters; the following identifies the set of Gothic fonts needed.

The preceding two cases can be used with a Japanese locale as long as fonts exist that match the base name list.

Font List Specification

A font list specification can consist of one or more entries, each of which can be either a font specification or a font set specification.

Each entry can be tagged with a name that is used when drawing a compound string. The tags are application-defined and are usually names representing the expected style of font; for example, bold(), italic(), bigbold(). A null tag is used to denote the default entry and is associated with the XmFONTLIST_DEFAULT_TAG identifier used in XmString() functions.

A font tag is identified when it is prefixed with an = (equal sign); for example, =bigbold() (this matches the first font defined at the server). If an = is specified but there is no name following it, the specification is considered the default font list entry.

A font set tag is identified when it is prefixed with a : (colon); for example, :bigbold() (this matches the first server set of fonts that satisfy the locale). If a : is specified but no name is given, the specification is considered the default font list entry. Within a font list entry specification, a base name list is separated by ; (semicolons) rather than by , (commas).

Example Font List Specification

For the Latin 1 locales, enter:

-*-r-*-14-*: ,\         
            # default font list entry -*-b-*-18-*:bigbold
            # Large Bold fonts

Base Font Name List Specification

The base font name list is a list of base font names associated with a font set as defined by the locale. The base font names are in a comma-separated list and are assumed to be characters from the portable character set; otherwise, the result is undefined. Blank space immediately on either side of a separating comma is ignored.

Use of XLFD font names permits international applications to obtain the fonts needed for a variety of locales from a single locale-independent base font name. The single base font name specifies a family of fonts whose members are encoded in the various charsets needed by the locales of interest.

An XLFD base font name can explicitly name the font's charset needed for the locale. This enables the user to specify an exact font for use with a charset required by a locale, fully controlling the font selection.

If a base font name is not an XLFD name, an attempt is made to obtain an XLFD name from the font properties for the font.

The following algorithm is used to select the fonts that are used to display text with font sets.

For each charset required by the locale, the base font name list is searched for the first of the following cases that names a set of fonts that exist at the server.

For example, assume a locale requires the following charsets:

You can supply a base font name list that explicitly specifies the charsets, ensuring that specific fonts are used if they exist, as shown in the following example:

"-dt-mincho-Medium-R-Normal-*-*-*-*-*-M-*-JISX0208.1983-0,\
-dt-mincho-Medium-R-Normal-*-*-*-*-*-M- \ *-JISX0201.jisx0201\.1976-1,\
-dt-song-Medium-R-Normal-*-*-*-*-*-M-*-GB2312-1980.0,\
-*-default-Bold-R-Normal-*-*-*-*-M-*-ISO8859-1"

You can supply a base font name list that omits the charsets, which selects fonts for each required code set, as shown in the following example:

"-dt-Fixed-Medium-R-Normal-*-*-*-*-*-M-*,\
-dt-Fixed-Medium-R-Normal-*-*-*-*-*-M-*,\
-dt-Fixed-Medium-R-Normal-*-*-*-*-*-M-*,\
-*-Courier-Bold-R-Normal-*-*-*-*-M-*"

Alternatively, the user can supply a single base font name that selects from all available fonts that meet certain minimum XLFD property requirements, as shown in the following example:

"-*-*-*-R-Normal--*-*-*-*-*-M-*"