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
The following table shows the sample values for the character set and registry/encoding fields.
Table 19. Example platform charset_registry/encoding names
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.