Programmer Reference : Common Graphics : Using fonts : A simplified view of the font process
A simplified view of the font process
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.
Font process
Using fonts
1. Query the system for available fonts (CgDisplay).
2. Load the requested font(s) into memory (CgDisplay).
3. Assign the font for use in drawing operations (CgGC).
4. Perform the drawing operations (CgDrawable).
5. Free the font(s) from memory (CgFont).
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.
Last modified date: 12/21/2017