Who Should Read This Document
Organization of This Document
See Also
Text Layout Programming Guide describes how the Cocoa text system lays out text. Text layout is the process of converting a string of text characters, font information, and page specifications into lines of glyphs placed at specific locations on a page, suitable for display and printing.
You should read this document if you need to understand how the text system layout mechanism works and how to work directly with an NSLayoutManager
object to accomplish the programming goals described in the articles.
To understand the information in this document, you should have read Text System Overview. You should also understand basic Cocoa programming conventions, such as delegation.
This programming topic contains the following articles:
“The Layout Manager” introduces the NSLayoutManager
class, describing its features and explaining how it performs text layout.
“Typesetters” describes the responsibilities of the typesetter object, instantiated from a concrete subclass of NSTypesetter
, which generates the line fragments and glyph positions on behalf of the layout manager.
“Line Fragment Generation” explains how the typesetter and text container work together to create line fragment rectangles.
“Drawing Strings” explains how to use the layout manager, rather than NSString
convenience methods, to draw strings of text efficiently.
“Laying Out Text Along an Arbitrary Path” shows how to use the layout manager without a text view to lay out glyphs along a calculated path.
“Calculating Text Height” shows how to determine the height of a block of text laid out in a fixed-width area.
“Counting Lines of Text” explains how you can programmatically count the number of lines in a string of text, whether the lines are defined by hard line-break characters or laid out in a text container.
“Using Text Tables” explains how you can add text table support to your application in Mac OS X version 10.4 and later.
For further reading, refer to the following documents:
Text System Storage Layer Overview discusses the facilities that the Cocoa text system uses to store the text and geometric shape information used for text layout.
Text Attributes describes the text-related attributes maintained by the Cocoa text system, which provide the distinguishing characteristics of rich text and other formatting information for paragraphs and documents.
In addition, please refer to Cocoa Text and Fonts Sample Code and the Application Kit examples installed with Xcode Tools.
© 2003, 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)