XPCE's font specification is a two-stage process. In the first stage, XPCE physical fonts are mapped to fonts of the underlying windowing system. In this stage, fonts are identified by their family, style and size. For example
font(screen, roman, 13)
Refers to a fixed-width font designed for use on the screen that has normal weight, not slanted and 13-pixels high characters.
In the second stage, logical font-names are mapped to their physical implementation. At this level, fonts are identified by a single name from an extensible, but preferably small set.
See section B.5 for a description of Windows specific font issues.
The default physical font set is built when the first font object is opened (i.e. its window counterpart is located and made available to the text-drawing functions). This set is created from class-variables on the display object. The first class-variable is display.font_families, which defines a chain with names of the font-families. The default value is:11See section 8 for the default syntax.
display.font_families: \ [ screen_fonts, \ courier_fonts, \ helvetica_fonts, \ times_fonts, \ symbol_fonts ]
Each of these names refers to the name of another resource of class
the members of this font family. The default value can be examined using
the online manual. Below is the default value for the
font-set for X11:
display.screen_fonts: \ [ font(screen, roman, 10, "6x10"), \ font(screen, roman, 12, "6x12"), \ font(screen, roman, 13, "8x13"), \ font(screen, roman, 14, "7x14"), \ font(screen, roman, 15, "9x15"), \ font(screen, bold, 13, "8x13bold"), \ font(screen, bold, 14, "7x14bold"), \ font(screen, bold, 15, "9x15bold") \ ]
The set of predefined physical fonts can be examined using the FontViewer demo application accessible through the online manual tools.
If an application needs additional fonts, such fonts can be declared using directives. The fourth initialisation argument of class font determines the window-system font that will be mapped. The syntax for this argument depends on the window-system used. For this Unix/X11 version it is a string consisting of 15 `-' separated fields. A font can be searched using xfontsel(1) or the much better GNOME-project gfontsel(1).
For example, the 14-points `courier new' TrueType font can be registered using:
:- initialization new(_, font(courier, roman, 14, '-winfonts-courier new-medium-r-normal-*-*-140-*-*-m-*-iso8859-1')).
This specification has various drawbacks. For example, another library or application loaded on top of the same XPCE process may be using the symbol,roman,14 specification, but bound to another window-system font. A user may try to run your application on an environment that does not have this font. Part of these problems can be eliminated by binding the font to a logical font name. See also section 10.9.2.
:- initialization send(@display, font_alias, adobesymbol, font(symbol, roman, 14, '-*-symbol-*-*-*-*-14-*-*-*-*-*-adobe-*')).
The application will refer to this font using the font-alias. user has other preferences or the font is not available, the user may specify the font using the display.user_fonts class-variable described in section 10.9.2.
It is not wise let your application code speak about physical fonts as the user or interface guidelines may prefer using a different font-palette. For this reason the display defines a mapping between logical font names and physical fonts. Applications are encouraged to use logical font names as much as possible and leave the assignment to physical fonts to the users preferences. XPCE predefines the following logical font-names. The value gives the default assignment for these fonts.
normalfont(helvetica, roman, 12)
boldfont(helvetica, bold, 12)
italicfont(helvetica, oblique, 12)
smallfont(helvetica, roman, 10)
largefont(helvetica, roman, 14)
boldlargefont(helvetica, bold, 14)
hugefont(helvetica, roman, 18)
boldhugefont(helvetica, bold, 18)
fixedfont(screen, roman, 13)
ttfont(screen, roman, 13)
boldttfont(screen, bold, 13)
symbolfont(symbol, roman, 12)
The end-user of an XPCE application can define the class-variable display.user_fonts to overrule fonts. The example below re-binds the most commonly used fonts to be slightly larger and choose from the Times font family rather than the Helvetica fonts.
display.user_fonts: \ [ normal := font(times, roman, 14), \ bold := font(times, bold, 14), \ italic := font(times, italic, 14) \ ]
The mapping between logical font names and physical fonts is realised
by the methods `display
additional font aliases may be loaded using `display
Class font's predefined conversion will translate names to font objects. This implies that for any method expecting a font object the programmer can specify the font-name instead. In those (rare) cases where a font needs to be passed, but the type-specification does not require this, the conversion must be done explicitly. The preferred way to make the conversion is using the font type object:
..., get(type(font), check, bold, BoldFont), ...,