Some of the settings in the graphics state that apply to painting paths also apply to text drawing. Stroke color and fill color are two such attributes. (See “Paths”) for other attributes and operations that affect text rendering.)
Several text drawing attributes apply only to text. You can set the values of these attributes using the Quartz functions listed in Table 17-1. Notice that the function CGContextSelectFont sets both the font and the font size. It also sets the text encoding. “Drawing Text” discusses the difference between using CGContextSelectFont and CGContextSetFont.
Attribute | Function | Specifies |
|---|---|---|
Font | Typeface. | |
Font size | Size in text space units. | |
Character spacing | The amount of extra space (in text space units) between character glyphs. | |
Text drawing mode | How Quartz renders the individual glyphs onscreen. See Table 17-2 for a list of text drawing modes. | |
Text matrix | The transform from text space to user space. | |
Text position | The location at which text is drawn. |
The text matrix is a transform that operates similarly to the current transformation matrix (CTM), but only on text. You can apply transforms to the text matrix, using any of the affine transform functions to build as complex a transform as you’d like. When you draw the text, Quartz uses the text matrix you supply along with the CTM. When you draw anything other than text, Quartz uses the CTM and not the text matrix.
Use this mode | When you want to . . . | Example |
|---|---|---|
Perform a fill operation on the text. |
| |
Perform a stroke operation on the text. |
| |
Perform both fill and stroke operations on the text. |
| |
Get text positions for the purpose of measuring text but not display the text. Note that the text position (x, y) is updated, as with all of the drawing modes. |
| |
Perform a fill operation, then add the text to the clipping area. |
| |
Perform a stroke operation, then add the text to the clipping area. |
| |
Perform both fill and stroke operations, then add the text to the clipping area. |
| |
Add the text to the clipping area, but do not draw the text. |
|
Last updated: 2007-12-11