Each platform has a list of fonts that are available for use. An
application queries the platform to find out which fonts are available using a
pattern-matching search mechanism. The platform returns all matching
font names. The application then loads the appropriate font into
memory, assigns the font to a graphics context and issues string drawing
operations. After the application is finished with the font, it unloads
it from memory.
The following example illustrates the complete font process described in the steps above. Each step is described in detail in the subsections following the example.
| fontNames font gc | "Query the system for the string names of two available fonts" fontNames := CgDisplay default listFonts: '*' maxnames: 2. "Use the font string name to load a font" font := CgDisplay default loadFont: (fontNames at: 2). gc := CgCGdefault
"Assign the font for use in drawing operations" gc setFont: font. CgWindow default "Perform a string drawing operation" drawString: gc x: 10 y: 100 string: 'hello world'.
"Free the font" font unloadFont.