DTCoreTextLayoutFrame Class Reference
| Inherits from | NSObject |
| Declared in | DTCoreTextLayoutFrame.h |
Overview
This class represents a single frame of text and basically wraps CTFrame. It provides an array of text lines that fit in the given rectangle.
Both styles of layouting are supported: open ended (suitable for scroll views) and limited to a given rectangle. To use the open-ended style specify CGFLOAT_HEIGHT_UNKNOWN for the frame height when creating a layout frame.
The array of lines is built lazily the first time it is accessed or - for open-ended frames - when the frame property is being queried.
The Cursor category extends DTCoreTextLayoutFrame for working with a caret and determine the string index of touch coordinates.
Tasks
Creating Layout Frames
Getting Information
-
– visibleStringRange -
– attributedStringFragment -
– stringIndices -
frameproperty -
– intrinsicContentFrame
Drawing
Working with Glyphs
Working with Text Lines
-
linesproperty -
– linesVisibleInRect: -
– linesContainedInRect: -
– lineContainingIndex: -
– isLineFirstInParagraph: -
– isLineLastInParagraph: -
– baselineOriginToPositionLine:afterLine:options: -
– baselineOriginToPositionLine:afterLine: -
justifyRatioproperty
Text Attachments
Getting Paragraph Info
-
– paragraphIndexContainingStringIndex: -
– paragraphRangeContainingStringRange: -
– linesInParagraphAtIndex: -
paragraphRangesproperty
Debugging
Truncation
-
numberOfLinesproperty -
lineBreakModeproperty -
truncationStringproperty
Cursor Methods
Properties
frame
The frame rectangle for the layout frame.
@property (nonatomic, assign, readonly) CGRect frameDeclared In
DTCoreTextLayoutFrame.hjustifyRatio
The ratio to decide when to create a justified line
@property (nonatomic, readwrite) CGFloat justifyRatioDeclared In
DTCoreTextLayoutFrame.hlineBreakMode
Line break mode used to indicate how truncation should occur
@property (nonatomic, assign) NSLineBreakMode lineBreakModeDeclared In
DTCoreTextLayoutFrame.hlines
The text lines that belong to the receiver.
@property (nonatomic, strong, readonly) NSArray *linesDeclared In
DTCoreTextLayoutFrame.hnumberOfLines
Maximum number of lines to display before truncation. Default is 0 which indicates no limit.
@property (nonatomic, assign) NSInteger numberOfLinesDeclared In
DTCoreTextLayoutFrame.hparagraphRanges
An array of NSRange values encapsulated in NSValue instances. Each range is the string range contained in the corresponding paragraph.
@property (nonatomic, strong, readonly) NSArray *paragraphRangesDeclared In
DTCoreTextLayoutFrame.hClass Methods
setShouldDrawDebugFrames:
Switches on the debug drawing mode where individual glph runs, baselines, et ceter get individually marked.
+ (void)setShouldDrawDebugFrames:(BOOL)debugFramesParameters
- debugFrames
if the debug drawing should occur
Declared In
DTCoreTextLayoutFrame.hInstance Methods
attributedStringFragment
This is a copy of the attributed string owned by the layouter of the receiver.
- (NSAttributedString *)attributedStringFragmentDeclared In
DTCoreTextLayoutFrame.hbaselineOriginToPositionLine:afterLine:
Finds the appropriate baseline origin for a line to position it at the correct distance from a previous line using the DTCoreTextLayoutFrameLinePositioningOptionAlgorithmLegacy algorithm.
- (CGPoint)baselineOriginToPositionLine:(DTCoreTextLayoutLine *)line afterLine:(DTCoreTextLayoutLine *)previousLineParameters
- line
The line
- previousLine
The line after which to position the line.
Return Value
The correct baseline origin for the line.
Discussion
Warning: This method is deprecated, use -[baselineOriginToPositionLine:afterLine:algorithm:] instead
Declared In
DTCoreTextLayoutFrame.hbaselineOriginToPositionLine:afterLine:options:
Finds the appropriate baseline origin for a line to position it at the correct distance from a previous line.
- (CGPoint)baselineOriginToPositionLine:(DTCoreTextLayoutLine *)line afterLine:(DTCoreTextLayoutLine *)previousLine options:(DTCoreTextLayoutFrameLinePositioningOptions)optionsParameters
- line
The line
- previousLine
The line after which to position the line.
- options
The layout options to employ for positioning lines
Return Value
The correct baseline origin for the line.
Discussion
Support Layout options are:
- DTCoreTextLayoutFrameLinePositioningAlgorithmWebKit,
- DTCoreTextLayoutFrameLinePositioningAlgorithmLegacy
Declared In
DTCoreTextLayoutFrame.hclosestCursorIndexToPoint:
Determines the closest string index to a point in the receiver’s frame.
- (NSInteger)closestCursorIndexToPoint:(CGPoint)pointParameters
- point
The point
Return Value
The resulting string index
Discussion
This can be used to find the cursor position to position an input caret at.
Declared In
DTCoreTextLayoutFrame+Cursor.hcursorRectAtIndex:
The rectangle to draw a caret for a given index
- (CGRect)cursorRectAtIndex:(NSInteger)indexParameters
- index
The string index for which to determine a cursor frame
Return Value
The cursor rectangle
Declared In
DTCoreTextLayoutFrame+Cursor.hdrawInContext:drawImages:drawLinks:
Draws the receiver into the given graphics context.
- (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages drawLinks:(BOOL)drawLinksParameters
- context
A graphics context to draw into
- drawImages
Whether images should be drawn together with the text. If you specify
NOthen space is left blank where images would go and you have to add your own views to display these images.
- drawLinks
Whether hyperlinks should be drawn together with the text. If you specify
NOthen space is left blank where links would go and you have to add your own views to display these images.
Discussion
Warning: This method is deprecated, use [DTCoreTextLayoutFrame drawInContext:options:] instead
Declared In
DTCoreTextLayoutFrame.hdrawInContext:options:
Draws the receiver into the given graphics context.
- (void)drawInContext:(CGContextRef)context options:(DTCoreTextLayoutFrameDrawingOptions)optionsParameters
- context
A graphics context to draw into
- options
The drawing options. See DTCoreTextLayoutFrameDrawingOptions for available options.
Declared In
DTCoreTextLayoutFrame.hframeOfGlyphAtIndex:
Retrieves the frame of the glyph at the given glyph index.
- (CGRect)frameOfGlyphAtIndex:(NSInteger)indexParameters
- index
The index of the glyph
Return Value
The frame of this glyph
Declared In
DTCoreTextLayoutFrame.hinitWithFrame:layouter:
Creates a Layout Frame with the given frame using the attributed string loaded into the layouter.
- (id)initWithFrame:(CGRect)frame layouter:(DTCoreTextLayouter *)layouterParameters
- frame
The rectangle specifying origin and size of available for text. Specify
CGFLOAT_WIDTH_UNKNOWNto not limit the width. SpecifyCGFLOAT_HEIGHT_UNKNOWNto not limit the height.
- layouter
A reference to the layouter for this text box.
Declared In
DTCoreTextLayoutFrame.hinitWithFrame:layouter:range:
Creates a Layout Frame with the given frame using the attributed string loaded into the layouter.
- (id)initWithFrame:(CGRect)frame layouter:(DTCoreTextLayouter *)layouter range:(NSRange)rangeParameters
- frame
The rectangle specifying origin and size of available for text. Specify
CGFLOAT_WIDTH_UNKNOWNto not limit the width. SpecifyCGFLOAT_HEIGHT_UNKNOWNto not limit the height.
- layouter
A reference to the layouter for the receiver. Note: The layouter owns the attributed string.
- range
The range within the attributed string to layout into the receiver.
Declared In
DTCoreTextLayoutFrame.hintrinsicContentFrame
Calculates the frame that is covered by the text content.
- (CGRect)intrinsicContentFrameReturn Value
The area that is covered by the text content.
Discussion
The result is calculated by enumerating over all lines and creating a union over all their frames. This is different than the frame property since this gets calculated.
Note: The width depends on how many glyphs Core Text was able to fit into a line. A line that gets broken might not have glyphs all the way to the margin. The y origin is always adjusted to be the same as frame since the first line might have some leading. The height is the minimum height that fits all layout lines.
Declared In
DTCoreTextLayoutFrame.hisLineFirstInParagraph:
Determins if the given line is the first in a paragraph.
- (BOOL)isLineFirstInParagraph:(DTCoreTextLayoutLine *)lineParameters
- line
The Line
Return Value
YES if the given line is the first in a paragraph
Discussion
This is needed for example to determine whether paragraphSpaceBefore needs to be applied before it.
Declared In
DTCoreTextLayoutFrame.hisLineLastInParagraph:
Determins if the given line is the last in a paragraph.
- (BOOL)isLineLastInParagraph:(DTCoreTextLayoutLine *)lineParameters
- line
The Line
Return Value
YES if the given line is the last in a paragraph
Discussion
This is needed for example to determine whether paragraph spacing needs to be applied after it.
Declared In
DTCoreTextLayoutFrame.hlineContainingIndex:
The layout line that contains the given string index.
- (DTCoreTextLayoutLine *)lineContainingIndex:(NSUInteger)indexParameters
- index
The string index
Return Value
The layout line that this index belongs to
Declared In
DTCoreTextLayoutFrame.hlineIndexForGlyphIndex:
Retrieves the index of the text line that contains the given glyph index.
- (NSInteger)lineIndexForGlyphIndex:(NSInteger)indexParameters
- index
The index of the glyph
Return Value
The index of the line containing this glyph
Declared In
DTCoreTextLayoutFrame.hlinesContainedInRect:
- (NSArray *)linesContainedInRect:(CGRect)rectParameters
- rect
The rectangle
Return Value
An array, sorted from top to bottom, of lines fully visible
Declared In
DTCoreTextLayoutFrame.hlinesInParagraphAtIndex:
The text lines that belong to the specified paragraph.
- (NSArray *)linesInParagraphAtIndex:(NSUInteger)indexParameters
- index
The index of the paragraph
Return Value
An array, sorted from top to bottom, of lines in this paragraph
Declared In
DTCoreTextLayoutFrame.hlinesVisibleInRect:
- (NSArray *)linesVisibleInRect:(CGRect)rectParameters
- rect
The rectangle
Return Value
An array, sorted from top to bottom, of lines at least partially visible
Declared In
DTCoreTextLayoutFrame.hparagraphIndexContainingStringIndex:
Finding which paragraph a given string index belongs to.
- (NSUInteger)paragraphIndexContainingStringIndex:(NSUInteger)stringIndexParameters
- stringIndex
The index in the string to look for
Return Value
The index of the paragraph, numbered from 0
Declared In
DTCoreTextLayoutFrame.hparagraphRangeContainingStringRange:
Determines the paragraph range (of paragraph indexes) that encompass the entire given string Range.
- (NSRange)paragraphRangeContainingStringRange:(NSRange)stringRangeParameters
- stringRange
The string range for which the paragraph range is sought for
Return Value
The range of paragraphs that fully enclose the string range
Declared In
DTCoreTextLayoutFrame.hstringIndices
An array that maps glyphs with string indices.
- (NSArray *)stringIndicesDeclared In
DTCoreTextLayoutFrame.htextAttachments
The array of all DTTextAttachment instances that belong to the receiver.
- (NSArray *)textAttachmentsReturn Value
All text attachments of the receiver.
Declared In
DTCoreTextLayoutFrame.htextAttachmentsWithPredicate:
The array of all DTTextAttachment instances that belong to the receiver which also match the specified predicate.
- (NSArray *)textAttachmentsWithPredicate:(NSPredicate *)predicateParameters
- predicate
A predicate that uses properties of DTTextAttachment to reduce the returned array
Return Value
A filtered array of text attachments.
Declared In
DTCoreTextLayoutFrame.h