Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Controlling How Text Looks

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.

Table 17-1  Text attributes and the functions that control them

Attribute

Function

Specifies

Font

CGContextSetFont

CGContextSelectFont

Typeface.

Font size

CGContextSetFontSize

CGContextSelectFont

Size in text space units.

Character spacing

CGContextSetCharacterSpacing

The amount of extra space (in text space units) between character glyphs.

Text drawing mode

CGContextSetTextDrawingMode

How Quartz renders the individual glyphs onscreen. See Table 17-2 for a list of text drawing modes.

Text matrix

CGContextSetTextMatrix

The transform from text space to user space.

Text position

CGContextSetTextPosition

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.

Table 17-2  Text drawing modes

Use this mode

When you want to . . .

Example

kCGTextFill

Perform a fill operation on the text.

Filled text

kCGTextStroke

Perform a stroke operation on the text.

Stroked text.

kCGTextFillStroke

Perform both fill and stroke operations on the text.

Filled and stroked test.

kCGTextInvisible

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.

Invisible text.

kCGTextFillClip

Perform a fill operation, then add the text to the clipping area.

Filled text added to the clipping area.

kCGTextStrokeClip

Perform a stroke operation, then add the text to the clipping area.

Stroked text, added to the clipping area

kCGTextFillStrokeClip

Perform both fill and stroke operations, then add the text to the clipping area.

Filled and stroked text, aded to the clipping area

kCGTextClip

Add the text to the clipping area, but do not draw the text.

Test added to the clipping area, but not drawn



< Previous PageNext Page > Hide TOC


Last updated: 2007-12-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice