Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Common Desktop Environment: Internationalization Programmer's Guide > Chapter 2 Internationalization and the Common Desktop Environment

Font Management

» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

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

  • Obtaining the localized text itself

  • Selecting the one or more fonts that contain all the glyphs needed to render the characters in the localized text.

“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:

  • Determine the fonts needed

  • Specify the necessary fonts

  • Determine the charset of a font in a resource file

  • Choose multiple fonts per 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-normal24-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 an 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 Xlib rendering and metric application program interfaces (APIs).

For more information on matching fonts to character sets, refer to DtStdInterfaceFontNames(1,5). Also note that if your CDE provides the set of Standard Application Font Names, you can use a locale-independent resource.

Font Objects

This section describes the following font objects:

  • Font sets

  • Fonts

  • Render tables

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, *ApplicationDataPtr;
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.

Render Tables

For information on render tables, refer to Motif Programmer's Guide.

Font Set and Render Table Syntax

Table 2-1 “Font Set and Render Table Syntax” shows the syntax for a font set and render table.

Table 2-1 Font Set and Render Table Syntax

Resource Type

XLFD Separator

Terminator

FontEntry Separator

*fontSet: (Xlib)

comma

None

None

*renderTable: (Motif)

semicolon

colon

comma

 

Here are some examples of font resource specifications:

app_foo*renderTable: -adobe-courier-medium-r-normal24-240-75-75-m-\
150-*:

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

app_foo*renderTable: -adobe-courier-medium-r-normal18-*; *-gothic-\
*-18-*:

This renderTable 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.

Font and Render Table Functions

The following Xlib font management API functions are available:

  • XCreateFontSet()

  • XLocaleOfFontSet()

  • XFontsOfFontSet()

  • XBaseFontNameListOfFontSet()

  • XFreeFontSet()

The following Motif Render Table API functions are available:

  • XmRenderTableAddRenditions()

  • XmRenderTableCopy()

  • XmRenderTableCvtFromProp()

  • XmRenderTableCvtToProp()

  • XmRenderTableFree()

  • XmRenderTableGetRendition()

  • XmRenderTableGetRenditions()

  • XmRenderTableGetTags()

  • XmRenderTableRemoveRenditions()

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:

  • FAMILY_NAME %F

  • WEIGHT_NAME %W

  • SLANT %S

  • ADD_STYLE %A

  • SPACING %SP

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

interface user, interface system, application, Gothic or Mincho

WEIGHT_NAME

medium or bold

SLANT

r

ADD_STYLE

*

SPACING

m

KSC Korean Font

FOUNDRY

`dt'

FAMILY_NAME

interface user, interface system, application, 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

interface user, interface system, application, Sung and Kai

WEIGHT_NAME

medium or bold

SLANT

r

ADD_STYLE

*

SPACING

m

GB Simplified Chinese Font

FOUNDRY

`dt'

FAMILY_NAME

interface user, interface system, application, Song and Kai

WEIGHT_NAME

medium or bold

SLANT

r

ADD_STYLE

*

SPACING

m

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.