Common Desktop Environment: Internationalization Programmer's Guide

Font List Structure

The desktop requires a font list for text display. A font list is a list of font structures, font sets, or both, each of which has a tag to identify it. A font set ensures that all characters in the current language can be displayed. With font structures, the responsibility for ensuring that all characters can be displayed rests with the programmer (including converting from the code set of the locale to glyph indexes).

Each entry in a font list is in the form of a {tag, element} pair, where element can be either a single font or a font set. The application can create a font list entry from either a single font or a font set. For example, the following code segment creates a font list entry for a font set:

char font1[] =
 		"-adobe-courier-medium-r-normal--10-100-75-75-M-60";  
font_list_entry = XmFontListEntryLoad (displayID, font1,
  		XmFONT_IS_FONTSET, "font_tag");

The XmFontListEntryLoad() function loads a font or creates and loads a font set. The following are the four arguments to the function:

displayID

Display on which the font list is to be used.

fontname

A string that represents either a font name or a base font name list, depending on the nametype argument.

nametype

A value that specifies whether the fontname argument refers to a font name or a base font name list.

tag

A string that represents the tag for this font list entry.

If the nametype argument is XmFONT_IS_FONTSET, the XmFontListEntryLoad() function creates a font set in the current locale from the value in the fontname argument. The character sets of the fonts specified in the font set are dependent on the locale. If nametype is XmFONT_IS_FONT, the XmFontListEntryLoad() function opens the font found in fontname. In either case, the font or font set is placed into a font list entry.

The following code example creates a new font list and appends the entry font_list_entry to it:

XmFontList font_list;  
XmFontListEntry font_list_entry;
  		.
  		.
font_list = XmFontListAppendEntry (NULL, font_list_entry);  
XmFontListEntryFree (font_list_entry);

Once a font list has been created, the XmFontListAppendEntry() function adds a new entry to it. The following example uses the XmFontListEntryCreate() function to create a new font list entry for an existing font list.

XFontSet font2;  
char *font_tag;  
XmFontListEntry font_list_entry2;
  		.
  		.  
font_list_entry2 = XmFontListEntryCreate (font_tag,
  		 XmFONT_IS_FONTSET, (XtPointer)font2);

The font2 parameter specifies an XFontSet returned by the XCreateFontSet() function. The arguments to the XmFontListEntryCreate() function are font_tag, XmFONT_IS_FONTSET, and font2, which are the tag, type, and font, respectively. The tag and the font set are the {tag, element} pair of the font list entry.

To add this entry to the font list, use the XmFontListAppendEntry() function again, only this time, its first parameter specifies the existing font list.

font_list = XmFontListAppendEntry(font_list, font_list_entry2); 
XmFontListEntryFree(font_list_entry2);