Typesetter
public class Typesetter
Represents a typesetter which performs text layout. It can be used to create lines, perform line breaking, and do other contextual analysis based on the characters in the string.
-
The source text for which this typesetter object was created.
Declaration
Swift
public let text: NSAttributedString -
Creates a typesetter using the specified text and the default attributes.
Declaration
Swift
public init(text: NSAttributedString, defaultAttributes: [NSAttributedString.Key : Any])Parameters
textThe text that needs to be typeset.
defaultAttributesThe default attributes that should be applied on the text.
-
Suggests a forward break index based on the specified range and the extent. The measurement proceeds from first UTF-16 code unit to last code unit. If there is still room after measuring all characters, then last index is returned. Otherwise, break index is returned.
Declaration
Swift
public func suggestForwardBreak(inCodeUnitRange codeUnitRange: Range<Int>, extent: CGFloat, breakMode: BreakMode) -> IntParameters
codeUnitRangeThe UTF-16 range for break calculations.
extentThe requested break extent.
modeThe requested break mode.
Return Value
The index (exclusive) that would cause the break.
-
Suggests a forward break index based on the specified range and the extent. The measurement proceeds from first character to last character. If there is still room after measuring all characters, then last index is returned. Otherwise, break index is returned.
Declaration
Swift
public func suggestForwardBreak(inCharacterRange characterRange: Range<String.Index>, extent: CGFloat, breakMode: BreakMode) -> String.IndexParameters
characterRangeThe character range for break calculations.
extentThe requested break extent.
modeThe requested break mode.
Return Value
The index (exclusive) that would cause the break.
-
Suggests a backward break index based on the specified range and the extent. The measurement proceeds from last UTF-16 code unit to first code unit. If there is still room after measuring all characters, then start index is returned. Otherwise, break index is returned.
Declaration
Swift
public func suggestBackwardBreak(inCodeUnitRange codeUnitRange: Range<Int>, extent: CGFloat, breakMode: BreakMode) -> IntParameters
codeUnitRangeThe UTF-16 range for break calculations.
extentThe requested break extent.
modeThe requested break mode.
Return Value
The index (inclusive) that would cause the break.
-
Suggests a backward break index based on the specified range and the extent. The measurement proceeds from last character to first character. If there is still room after measuring all characters, then start index is returned. Otherwise, break index is returned.
Declaration
Swift
public func suggestBackwardBreak(inCharacterRange characterRange: Range<String.Index>, extent: CGFloat, breakMode: BreakMode) -> String.IndexParameters
characterRangeThe character range for break calculations.
extentThe requested break extent.
modeThe requested break mode.
Return Value
The index (inclusive) that would cause the break.
-
Creates a simple line having the specified UTF-16 range.
Declaration
Swift
public func makeSimpleLine(codeUnitRange: Range<Int>) -> ComposedLineParameters
codeUnitRangeThe UTF-16 range of the line in source string.
Return Value
The new line.
-
Creates a simple line having the specified character range.
Declaration
Swift
public func makeSimpleLine(characterRange: Range<String.Index>) -> ComposedLineParameters
characterRangeThe character range of the line in source string.
Return Value
The new line.
-
Creates a line of specified UTF-16 range, truncating it if it overflows the specified extent.
Declaration
Swift
public func makeTruncatedLine(codeUnitRange: Range<Int>, extent: CGFloat, breakMode: BreakMode, truncationPlace: TruncationPlace, tokenString: String?) -> ComposedLineParameters
codeUnitRangeThe UTF-16 range of the line in source string.
extentThe extent at which truncation will begin.
breakModeThe truncation mode to be used on the line.
truncationPlaceThe place of truncation for the line.
tokenStringThe token string to indicate the line truncation.
Return Value
The new line which is truncated if it overflows the
extent. -
Creates a line of specified string range, truncating it if it overflows the specified extent.
Declaration
Swift
public func makeTruncatedLine(characterRange: Range<String.Index>, extent: CGFloat, breakMode: BreakMode, truncationPlace: TruncationPlace, tokenString: String?) -> ComposedLineParameters
characterRangeThe range of the line in source string.
extentThe extent at which truncation will begin.
breakModeThe truncation mode to be used on the line.
truncationPlaceThe place of truncation for the line.
tokenStringThe token string to indicate the line truncation.
Return Value
The new line which is truncated if it overflows the
extent. -
Creates a line of specified UTF-16 range, truncating it if it overflows the specified extent.
Declaration
Swift
public func makeTruncatedLine(codeUnitRange: Range<Int>, extent: CGFloat, breakMode: BreakMode, truncationPlace: TruncationPlace, tokenLine: ComposedLine) -> ComposedLineParameters
codeUnitRangeThe UTF-16 range of the line in source string.
extentThe extent at which truncation will begin.
breakModeThe truncation mode to be used on the line.
truncationPlaceThe place of truncation for the line.
tokenLineThe token line to indicate the line truncation.
Return Value
The new line which is truncated if it overflows the
extent. -
Creates a line of specified character range, truncating it if it overflows the specified extent.
Declaration
Swift
public func makeTruncatedLine(characterRange: Range<String.Index>, extent: CGFloat, breakMode: BreakMode, truncationPlace: TruncationPlace, tokenLine: ComposedLine) -> ComposedLineParameters
characterRangeThe character range of the line in source string.
extentThe extent at which truncation will begin.
breakModeThe truncation mode to be used on the line.
truncationPlaceThe place of truncation for the line.
tokenLineThe token line to indicate the line truncation.
Return Value
The new line which is truncated if it overflows the
extent. -
Creates a justified line of specified UTF-16 range.
Declaration
Swift
public func makeJustifiedLine(codeUnitRange: Range<Int>, justificationFactor: CGFloat, justificationExtent: CGFloat) -> ComposedLineParameters
codeUnitRangeThe UTF-16 range of the line in source string.
justificationFactorThe factor that specifies the full or partial justification. When set to 1.0 or greater, full justification is performed. If this parameter is set to less than 1.0, varying degrees of partial justification are performed. If it is set to 0 or less, no justification is performed.
justificationExtentThe extent at which the line should be justified. If it is less than the actual width of the line, then negative justification is performed (that is, words are squeezed together).
Return Value
The new justified line.
-
Creates a justified line of specified character range.
Declaration
Swift
public func makeJustifiedLine(characterRange: Range<String.Index>, justificationFactor: CGFloat, justificationExtent: CGFloat) -> ComposedLineParameters
characterRangeThe character range of the line in source string.
justificationFactorThe factor that specifies the full or partial justification. When set to 1.0 or greater, full justification is performed. If this parameter is set to less than 1.0, varying degrees of partial justification are performed. If it is set to 0 or less, no justification is performed.
justificationExtentThe extent at which the line should be justified. If it is less than the actual width of the line, then negative justification is performed (that is, words are squeezed together).
Return Value
The new justified line.
View on GitHub
Install in Dash
Typesetter Class Reference