Common Desktop Environment: Internationalization Programmer's Guide

Font Management

When rendering text in an X WindowsTM client, at least two aspects are sensitive to internationalization:

"Extracting Localized Text" describes how to choose the correct fonts to render localized text.

Matching Fonts to Character Sets

A font contains a set of glyphs used to render the characters of a locale. However, you may also want to do the following for a given locale:

The last two fields of a font XFLD identify which glyphs are contained in a font and which value is used to obtain a specific glyph from the set. These last two fields identify the encoding of the glyphs contained in the font.

For example:

-adobe-courier-medium-r-normal--24-240-75-75-m-150-iso8859-1

The last two fields of this XLFD name are iso8859 and 1. These fields specify that the ISO8859-1 standard glyphs are contained in the font. Further, it specifies that the character code values of the ISO8859-1 standard are used to index the corresponding glyph for each character.

The font charset used by the application to render data depends on the locale you select. Because the font charset of the data changes is based on the choice of locale, the font specification must not be hardcoded by the application. Instead, it should be placed in a locale-specific app-defaults file, allowing localized versions of the app-defaults file to be created.

Further, the font should be specified as a fontset. A fontset is an Xlib concept in which an XLFD is used to specify the fonts. The font charset fields of the XLFD are specified by the Xlib code that creates the fontset and fills in these fields based on the locale that the user has specified.

For many languages (such as Japanese, Chinese, and Korean), multiple font charsets are combined to support single encoding. In these cases, multiple fonts must be opened to render the character data. Further, the data must be parsed into segments that correspond to each font, and in some cases, these segments must be transformed to convert the character values into glyphs indexes. The XFontset, which is a collection of all fonts necessary to render character data in a given locale, also deals with this set of problems. Further, a set of rendering and metric routines are provided that internally take care of breaking strings into character-set-consistent segments and transforming values into glyph indexes. These routines relieve the burden of the application developer, who needs only the user fontsets and the new X11R5 rendering and metric application program interfaces (APIs).

Font Objects

This section describes the following font objects:

Font Sets

Generally, all internationalized programs expecting to draw localized text using Xlib are required to use an XmFontSet() for specifying the locale-dependent fonts. Specific fonts within a font set should be specified using XLFD naming conventions without the charset field specified. The resource name for an XFontset is *fontSet. Refer to "Localized Resources" for a list of font resources.

Applications directly using Xlib to render text (as opposed to using XmString functions or widgets) may take advantage of the string-to-fontSet converter provided by Xt. For example, the following code fragment shows how to obtain a fontset when using Xt and when not using Xt:

/* pardon the double negative... means "If using Xt..." */  
#ifndef NO_XT  
typedef struct {
 		XFontSet fontset;
  			char *foo;  
} ApplicationData,  *ApplicationData r;
 static XtResource my_resources[] = {
  	{ XtNfontSet, XtCFontSet, XtRFontSet, sizeof (XFontSet),
  	XtOffset (ApplicationDataPtr, fontset), XtRString,
 "*-18-*"}}  
#endif /* NO_XT */  
...  
#ifdef NO_XT  
fontset = XCreateFontSet (dpy, "*-18-*", &missing_charsets,
  	&num_missing_charsets. &default_string);
if (num_missing_charsets > 0) {
  	(void) fprintf(stderr, "&s: missing charsets.\n",
  					program_name);
 	XFreeStringList(missing_charsets);  
}  
#else 
XtGetApplicationResources(toplevel, &data, my_resources,
		 XtNumber(my_resources), NULL, 0);  
fontset = data.fontset;  
#endif /* NO_XT */

Fonts

Internationalized programs should avoid using fonts directly, that is, XFontStruct, unless they are being used for a specific charset and a specific character set. Use of XFontStruct may be limiting if the server you are connecting to does not support the specific charsets needed by a locale. The resource name for an XFontStruct is *font.

Font Lists

All programs using widgets or XmString to draw localized text are required to specify an XFontList name for specifying fonts. A font list is a list of one or more fontsets or fonts, or both. It is used to convey the list of fonts and fontsets a widget should use to render text. For more complicated applications, a font list may specify multiple font sets with each font set being tagged with a name; for example, Bold, Large, Small, and so on. The tags are to be associated with a tag of an XmString segment. A tag may be used to identify a specific font or fontset within a font list.

Font Set and Font List Syntax

Table 2-1 shows the syntax for a font set and font list.

Table 2-1 Font Set and Font List Syntax

Resource Type 

XLFD Separator 

Terminator 

FontEntry Separator 

*fontSet: (Xlib)

comma 

None 

None 

*fontList: (Motif)

semicolon 

colon 

comma 

Here are some examples of font resource specifications:

app_foo*fontList: -adobe-courier-medium-r-normal--24-240-75-75-m-\  150-*:

The preceding fontList specifies a fontset, consisting of one or more 24-point Adobe Courier fonts, as appropriate for the user's locale.

app_foo*fontList: -adobe-courier-medium-r-normal--18-*; *-gothic-\  *-18-*:

This fontList specifies a fontset consisting of an 18-point Courier font (if available) for some characters in the users data, and an 18-point Gothic font for the others.

Motif-based applications sometimes need direct access to the font set contained in a font list. For example, an application that uses a DrawingArea widget may want to label one of the images drawn there. The following sample code shows how to extract a font set from a font list. In this example, the tag XmFONTLIST_DEFAULT_TAG looks for the font set because this is the tag that says "codeset of the locale." Applications should use the tag XmFONTLIST_DEFAULT_TAG for any string that could contain localized data.

XFontSet FontList2FontSet( XmFontList fontlist)  
{  
XmFontContext context;
 XmFontListEntry next_entry;  
XmFontType type_return = XmFONT_IS_FONT;  
char* font_tag;  
XFontSet fontset;  
XFontSet first_fontset;  
Boolean have_font_set = False;   

if ( !XmFontListInitFontContext(&context, fontlist)) {
		 XtWarning("fl2fs: can't create fontlist context...");
		 exit 0;  
}   

while ((next_entry = XmFontListNextEntry(context) != NULL) {
  fontset = (XFontSet) XmFontListEntryGetFont(next_entry,
				 &type_return);
  if (type_return == XmFONT_IS_FONTSET ) {
  		font_tag = XmFontListEntryGetTag(next_entry);

      if (!strcmp(XmFONTLIST_DEFAULT_TAG, font_tag) {
              return fontset;
      }
      /* Remember the 1st fontset, just in case... */
      if (!have_font_set) {
              first_fontset = fontset;
					  have_font_set = True;
      }
   }
}  
if (have_font_set)
      return first_fontset;  
return (XFontSet)NULL; 
}

Font Functions

The following Xlib font management API functions are available:

The following Motif FontListAPI functions are available:

Font Charsets

To improve basic interchange, fonts are organized according to the standard X-Consortium font charsets.

Default Font Set Per Language Group

Selecting base font names of a font set associated with a developer's language is usually easy because the developer is familiar with the language and the set of fonts needed.

Yet, when selecting the base font names of a font set for various locales, this task can be difficult because an XLFD font specification consists of 15 fields. For localized usage, the following fields are critical for selecting font sets:

This simplifies the number of fields, yet the possible values for each of these fields may vary per locale. The actual point size (POINT_SIZE) may vary across platforms.

Throughout this documentation, the following convention should be used when specifying localized fonts:

-dt-%F-%W-%S-normal-%A-*-*-*-%SP-*

The following describes the minimum set of recommended values for each field to be used within the desktop for the critical fields when specifying font sets in resource (app-defaults) files.

Latin ISO8859-1 Fonts

FOUNDRY

`dt'

FAMILY_NAME

`interface user'

`interface system'

`application'

WEIGHT_NAME

medium or bold

SLANT

r or i

ADD_STYLE

sans or serif

SPACING

p or m

Other ISO8859 Fonts

The same values defined for ISO8859-1 are recommended.

JIS Japanese Font

FOUNDRY

`dt'

FAMILY_NAME

Gothic or Mincho

WEIGHT_NAME

medium or bold

SLANT

r

ADD_STYLE

*

SPACING

m

KSC Korean Font

FOUNDRY

`dt'

FAMILY_NAME

Totum or Pathang

WEIGHT_NAME

medium or bold

SLANT

r

ADD_STYLE

*

SPACING

m


Note -

The FAMILY_NAME values may change depending on the official romanization of the two common font families in use. As background, Totum corresponds to fonts typically shipped as Gothic, Kodig, or Dotum; Pathang corresponds to fonts typically shipped as Myungo or Myeongjo.


CNS Traditional Chinese Font

FOUNDRY

`dt'

FAMILY_NAME

Sung and Kai

WEIGHT_NAME

medium or bold

SLANT

r

ADD_STYLE

*

SPACING

m

GB Simplified Chinese Font

FOUNDRY

`dt'

FAMILY_NAME

Song and Kai

WEIGHT_NAME

medium or bold

SLANT

r

ADD_STYLE

*

SPACING

m