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

    text

    The text that needs to be typeset.

    defaultAttributes

    The 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) -> Int

    Parameters

    codeUnitRange

    The UTF-16 range for break calculations.

    extent

    The requested break extent.

    mode

    The 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.Index

    Parameters

    characterRange

    The character range for break calculations.

    extent

    The requested break extent.

    mode

    The 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) -> Int

    Parameters

    codeUnitRange

    The UTF-16 range for break calculations.

    extent

    The requested break extent.

    mode

    The 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.Index

    Parameters

    characterRange

    The character range for break calculations.

    extent

    The requested break extent.

    mode

    The 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>) -> ComposedLine

    Parameters

    codeUnitRange

    The 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>) -> ComposedLine

    Parameters

    characterRange

    The 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?) -> ComposedLine

    Parameters

    codeUnitRange

    The UTF-16 range of the line in source string.

    extent

    The extent at which truncation will begin.

    breakMode

    The truncation mode to be used on the line.

    truncationPlace

    The place of truncation for the line.

    tokenString

    The 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?) -> ComposedLine

    Parameters

    characterRange

    The range of the line in source string.

    extent

    The extent at which truncation will begin.

    breakMode

    The truncation mode to be used on the line.

    truncationPlace

    The place of truncation for the line.

    tokenString

    The 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) -> ComposedLine

    Parameters

    codeUnitRange

    The UTF-16 range of the line in source string.

    extent

    The extent at which truncation will begin.

    breakMode

    The truncation mode to be used on the line.

    truncationPlace

    The place of truncation for the line.

    tokenLine

    The 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) -> ComposedLine

    Parameters

    characterRange

    The character range of the line in source string.

    extent

    The extent at which truncation will begin.

    breakMode

    The truncation mode to be used on the line.

    truncationPlace

    The place of truncation for the line.

    tokenLine

    The 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) -> ComposedLine

    Parameters

    codeUnitRange

    The UTF-16 range of the line in source string.

    justificationFactor

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

    justificationExtent

    The 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) -> ComposedLine

    Parameters

    characterRange

    The character range of the line in source string.

    justificationFactor

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

    justificationExtent

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