Programmer Reference : Common Graphics : Using fonts : Querying the system for fonts
Querying the system for fonts
The system is queried for available fonts by sending the listFonts:maxnames: message to a CgDisplay. The message includes two arguments: a pattern-matching string and the maximum number of font string names to be returned.
Pattern matching
The Common Graphics subsystem defines font names using the X Logical Font Description (XLFD) convention. This convention is described in detail in the X11R4 and R5 reference manuals. Valid search patterns can be created using any combination of wildcard (* or ?) or literal values. The "*" represents a string of zero or more arbitrary characters. The "?" represents a single arbitrary character. The "-" is used as a separator between fields in the XLFD name. The following example shows the meaning of each field in the XLFD name:

Fields in the XLFD name
The following table describes the fields of an XLFD name.
Table 18. X logical font description fields
Field name
Valid field values
Examples
Font foundry
X-registered manufacturer name
adobe, bitstream, microsoft
Family name
Font family name
helvetica, times, courier
Weight
Blackness or density
medium, bold
Slant
Vertical posture of font characters
r (roman), i (italic), o (oblique), ri (reverse italic), ro (reverse oblique), ot (other)
Set_width_name
Width of font characters (usually normal)
normal, condensed, narrow, double wide
Add_style_name
Additional information (often blank)
serif, sans serif, informal, decorated, iso9241
Pixel_size
Font vertical height measurement in pixels
8, 10, 12, 14, and so on (zero indicates a scalable font)
Point_size
Font vertical height measurement in 1/10ths of 1/72 of an inch (24 point = 240)
120, 140, 180, 240, 360 (zero indicates a scalable font)
Resolution_x
Horizontal resolution of display in dots per inch
75, 100
Resolution_y
Vertical resolution of display in dots per inch
75, 100
Spacing
Font spacing
p (proportional), m (monospaced), c (character cell)
Average_width
Average width of all the glyphs in 1/10 of pixel increments. Used for monospaced fonts and character cell fonts to calculate characters per line
50, 60, 70, and so on (zero indicates a scalable font)
Charset_registry/ encoding
X registered name that identifies the coding authority for the character set
iso8859-1
The following table shows the sample values for the character set and registry/encoding fields.
Table 19. Example platform charset_registry/encoding names
Family Name
Charset
Registry/Encoding
Description
courier
iso8859
1
courier matches iso8859 specification
symbol
microsoft
fontspecific
microsoft symbol font
@system
microsoft
@shiftjis
microsoft system double-byte font, double-byte characters rotated 90° counter-clockwise
terminal
microsoft
shiftjis
microsoft terminal double-byte font double-byte characters not rotated
courier
ibm
437
ibm courier for code page 437
courier
ibm
932.sbcs
ibm courier single-byte font for code page 932
mincho
ibm
932
ibm mincho double-byte font for code page 932 (zero indicates a scalable font)
Note:
The CdLogicalFontDescription class can be used to assist in creating XLFD font names and in parsing the fields out of font names. Its use is illustrated in Determining whether a font is scalable and Parsing a scalable font name.
The following example finds a maximum of two font strings of any description (*):
| fontNames |
fontNames := CgDisplay default
listFonts: '*'
maxnames: 2.
The following example finds a maximum of 20 helvetica fonts. Note that all fourteen fields are specified, either as wildcards or not. It is not necessary to specify all fourteen fields. However, if all fourteen fields are specified and either the pixel size or point size fields are not wildcards (that is, a specific size is desired), then scalable fonts will match the pattern, filling in the pixel size and point size fields appropriately. Scalable fonts are described in detail in the next section.
| fontNames |
fontNames := CgDisplay default
listFonts: '-*-helvetica-*-*-*-*-*-*-*-*-*-*-*-*'
maxnames: 20
Tip:
The listFonts: method is not required to include scalable fonts in the returned list unless all XLFD fields are specified in the pattern. To ensure that scalable fonts are included in the list, specify all 14 XLFD fields as in the previous example rather than using a single wildcard to match across several fields.
As a general rule, it is best to specify the font's family name, weight, slant, and point size fields explicitly.
It is better to match the point size field and leave the pixel field as a wildcard because this allows the most appropriate match for the resolution of the display.
Last modified date: 05/12/2020