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.

Methods that extend DTCoreTextLayoutFrame for use by editors.

The Cursor category extends DTCoreTextLayoutFrame for working with a caret and determine the string index of touch coordinates.

Properties

frame

The frame rectangle for the layout frame.

@property (nonatomic, assign, readonly) CGRect frame

Declared In

DTCoreTextLayoutFrame.h

justifyRatio

The ratio to decide when to create a justified line

@property (nonatomic, readwrite) CGFloat justifyRatio

Declared In

DTCoreTextLayoutFrame.h

lineBreakMode

Line break mode used to indicate how truncation should occur

@property (nonatomic, assign) NSLineBreakMode lineBreakMode

Declared In

DTCoreTextLayoutFrame.h

lines

The text lines that belong to the receiver.

@property (nonatomic, strong, readonly) NSArray *lines

Declared In

DTCoreTextLayoutFrame.h

numberOfLines

Maximum number of lines to display before truncation. Default is 0 which indicates no limit.

@property (nonatomic, assign) NSInteger numberOfLines

Declared In

DTCoreTextLayoutFrame.h

paragraphRanges

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 *paragraphRanges

Declared In

DTCoreTextLayoutFrame.h

textBlockHandler

Set a custom handler to be executed before text belonging to a text block is drawn. Of type .

@property (nonatomic, copy) DTCoreTextLayoutFrameTextBlockHandler textBlockHandler

Declared In

DTCoreTextLayoutFrame.h

truncationString

Optional attributed string tu use as truncation indicator. If nil, will use “…” w/ attributes taken from text being truncated

@property (nonatomic, strong) NSAttributedString *truncationString

Declared In

DTCoreTextLayoutFrame.h

Class Methods

setShouldDrawDebugFrames:

Switches on the debug drawing mode where individual glph runs, baselines, et ceter get individually marked.

+ (void)setShouldDrawDebugFrames:(BOOL)debugFrames

Parameters

debugFrames

if the debug drawing should occur

Declared In

DTCoreTextLayoutFrame.h

shouldDrawDebugFrames

the current value of the debug frame drawing

+ (BOOL)shouldDrawDebugFrames

Return Value

the current value of the debug frame drawing

Declared In

DTCoreTextLayoutFrame.h

Instance Methods

attributedStringFragment

This is a copy of the attributed string owned by the layouter of the receiver.

- (NSAttributedString *)attributedStringFragment

Declared In

DTCoreTextLayoutFrame.h

baselineOriginToPositionLine: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 *)previousLine

Parameters

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.h

baselineOriginToPositionLine: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)options

Parameters

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.h

closestCursorIndexToPoint:

Determines the closest string index to a point in the receiver’s frame.

- (NSInteger)closestCursorIndexToPoint:(CGPoint)point

Parameters

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.h

cursorRectAtIndex:

The rectangle to draw a caret for a given index

- (CGRect)cursorRectAtIndex:(NSInteger)index

Parameters

index

The string index for which to determine a cursor frame

Return Value

The cursor rectangle

Declared In

DTCoreTextLayoutFrame+Cursor.h

drawInContext:drawImages:drawLinks:

Draws the receiver into the given graphics context.

- (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages drawLinks:(BOOL)drawLinks

Parameters

context

A graphics context to draw into

drawImages

Whether images should be drawn together with the text. If you specify NO then 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 NO then 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.h

drawInContext:options:

Draws the receiver into the given graphics context.

- (void)drawInContext:(CGContextRef)context options:(DTCoreTextLayoutFrameDrawingOptions)options

Parameters

context

A graphics context to draw into

options

The drawing options. See DTCoreTextLayoutFrameDrawingOptions for available options.

Declared In

DTCoreTextLayoutFrame.h

firstRectForRange:

A rectangle starting encompassing the range, or first line whichever is smaller

- (CGRect)firstRectForRange:(NSRange)range

Parameters

range

The string range

Return Value

The rectangle

Declared In

DTCoreTextLayoutFrame+DTRichText.h

frameOfGlyphAtIndex:

Retrieves the frame of the glyph at the given glyph index.

- (CGRect)frameOfGlyphAtIndex:(NSInteger)index

Parameters

index

The index of the glyph

Return Value

The frame of this glyph

Declared In

DTCoreTextLayoutFrame.h

indexForPositionDownwardsFromIndex:offset:

Determines the string index you arrive at if you start at a given index and to a certain number of lines downwards.

- (NSInteger)indexForPositionDownwardsFromIndex:(NSInteger)index offset:(NSInteger)offset

Parameters

index

The index to start at

offset

The number of lines to move downwards

Return Value

The resulting string index

Declared In

DTCoreTextLayoutFrame+DTRichText.h

indexForPositionUpwardsFromIndex:offset:

Determines the string index you arrive at if you start at a given index and to a certain number of lines upwards.

- (NSInteger)indexForPositionUpwardsFromIndex:(NSInteger)index offset:(NSInteger)offset

Parameters

index

The index to start at

offset

The number of lines to move upwards

Return Value

The resulting string index

Declared In

DTCoreTextLayoutFrame+DTRichText.h

initWithFrame:layouter:

Creates a Layout Frame with the given frame using the attributed string loaded into the layouter.

- (id)initWithFrame:(CGRect)frame layouter:(DTCoreTextLayouter *)layouter

Parameters

frame

The rectangle specifying origin and size of available for text. Specify CGFLOAT_WIDTH_UNKNOWN to not limit the width. Specify CGFLOAT_HEIGHT_UNKNOWN to not limit the height.

layouter

A reference to the layouter for this text box.

Declared In

DTCoreTextLayoutFrame.h

initWithFrame: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)range

Parameters

frame

The rectangle specifying origin and size of available for text. Specify CGFLOAT_WIDTH_UNKNOWN to not limit the width. Specify CGFLOAT_HEIGHT_UNKNOWN to 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.h

intrinsicContentFrame

Calculates the frame that is covered by the text content.

- (CGRect)intrinsicContentFrame

Return 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.h

isLineFirstInParagraph:

Determins if the given line is the first in a paragraph.

- (BOOL)isLineFirstInParagraph:(DTCoreTextLayoutLine *)line

Parameters

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.h

isLineLastInParagraph:

Determins if the given line is the last in a paragraph.

- (BOOL)isLineLastInParagraph:(DTCoreTextLayoutLine *)line

Parameters

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.h

lineContainingIndex:

The layout line that contains the given string index.

- (DTCoreTextLayoutLine *)lineContainingIndex:(NSUInteger)index

Parameters

index

The string index

Return Value

The layout line that this index belongs to

Declared In

DTCoreTextLayoutFrame.h

lineIndexForGlyphIndex:

Retrieves the index of the text line that contains the given glyph index.

- (NSInteger)lineIndexForGlyphIndex:(NSInteger)index

Parameters

index

The index of the glyph

Return Value

The index of the line containing this glyph

Declared In

DTCoreTextLayoutFrame.h

linesContainedInRect:

The text lines that are visible inside the given rectangle. Only fully visible lines are included.

- (NSArray *)linesContainedInRect:(CGRect)rect

Parameters

rect

The rectangle

Return Value

An array, sorted from top to bottom, of lines fully visible

Declared In

DTCoreTextLayoutFrame.h

linesInParagraphAtIndex:

The text lines that belong to the specified paragraph.

- (NSArray *)linesInParagraphAtIndex:(NSUInteger)index

Parameters

index

The index of the paragraph

Return Value

An array, sorted from top to bottom, of lines in this paragraph

Declared In

DTCoreTextLayoutFrame.h

linesVisibleInRect:

The text lines that are visible inside the given rectangle. Also incomplete lines are included.

- (NSArray *)linesVisibleInRect:(CGRect)rect

Parameters

rect

The rectangle

Return Value

An array, sorted from top to bottom, of lines at least partially visible

Declared In

DTCoreTextLayoutFrame.h

paragraphIndexContainingStringIndex:

Finding which paragraph a given string index belongs to.

- (NSUInteger)paragraphIndexContainingStringIndex:(NSUInteger)stringIndex

Parameters

stringIndex

The index in the string to look for

Return Value

The index of the paragraph, numbered from 0

Declared In

DTCoreTextLayoutFrame.h

paragraphRangeContainingStringRange:

Determines the paragraph range (of paragraph indexes) that encompass the entire given string Range.

- (NSRange)paragraphRangeContainingStringRange:(NSRange)stringRange

Parameters

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.h

selectionRectsForRange:

The selection rects for a given range, represented as DTTextSelectionRect instances.

- (NSArray *)selectionRectsForRange:(NSRange)range

Parameters

range

The string range

Return Value

An arrow of the selection rects

Declared In

DTCoreTextLayoutFrame+DTRichText.h

stringIndices

An array that maps glyphs with string indices.

- (NSArray *)stringIndices

Declared In

DTCoreTextLayoutFrame.h

textAttachments

The array of all DTTextAttachment instances that belong to the receiver.

- (NSArray *)textAttachments

Return Value

All text attachments of the receiver.

Declared In

DTCoreTextLayoutFrame.h

textAttachmentsWithPredicate:

The array of all DTTextAttachment instances that belong to the receiver which also match the specified predicate.

- (NSArray *)textAttachmentsWithPredicate:(NSPredicate *)predicate

Parameters

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

visibleStringRange

The string range that is visible i.e. fits into the given rectangle. For open-ended frames this is typically the entire string. For frame-contrained layout frames it is the substring that fits.

- (NSRange)visibleStringRange

Declared In

DTCoreTextLayoutFrame.h