Drawing with Glyphs


So far you have been given a glimpse of the process of converting a string of characters into a series of glyph IDs. Glyph IDs are little more than an index into the table of character shapes that are stored in a particular font. As a result, glyph IDs are specific to the particular font you are drawing. Generating a sequence of glyphs from a particular character string can be a complex process. Nevertheless, if your application has custom mechanisms for generating or discovering, glyph IDs, then you can use Quartz 2D to draw text using glyph indexes as well.

There are two fundamental drawing routines that correspond to the simple string drawing routines discussed in the previous section. These are CGContextShowGlyphs and CGContextShowGlyphsAtPoint. Each of these routines combine information from the text settings in the current context with an array of glyph indices to draw text on the context. The CGContextShowGlyphsAtPoint routine also accepts a text position as a parameter, overriding the current text position in the graphics state.

The third routine for drawing text in the current context with glyph IDs is CGContextShowGlyphsWithAdvances. This routine also accepts an array of glyph indices as a parameter. It also takes a corresponding array of floating point values specifying the advance widths to use for the glyphs to be drawn. These advance widths override the values that Quartz reads out of the font tables.

One common technique used by applications that have special drawing needs is to rely on higher-level facilities like Cocoa Text or ATSUI to handle the conversion from characters to glyphs and then to use the glyph drawing routines to actually put the glyphs on a context. For example, ATSUI has the ATSUGetGlyphInfo routine to return information, including the glyph indices of arranged text. Cocoa programmers can use any of a number of routines in an NSLayoutManager that begin with the prefix "getGlyphs."




Quartz 2D Graphics for Mac OS X Developers
Quartz 2D Graphics for Mac OS X Developers
ISBN: 0321336631
EAN: 2147483647
Year: 2006
Pages: 100

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net