Class

NSATSTypesetter

A concrete subclass of NSTypesetter that places glyphs during the text layout process.

Overview

The typesetter creates line fragment rectangles, positions glyphs within the line fragments, determines line breaks by word wrapping and hyphenation, and handles tab positioning.

NSATSTypesetter encapsulates the advanced typesetting capabilities of Core Text. NSATSTypesetter provides line and character spacing accuracy and supports many languages, including bidirectional languages.

Subclassing

NSATSTypesetter introduced a set of interfaces in OS X version 10.3 that facilitated subclassing and made it possible to substitute a custom layout engine into the Cocoa text system. In OS X version 10.4, those interfaces moved to NSTypesetter, which you can subclass to the same effect. See the NSTypesetter reference documentation for relevant subclassing notes.

Topics

Getting a typesetter

class var shared: NSATSTypesetter

Returns a shared instance of NSATSTypesetter.

Managing the layout manager

var layoutManager: NSLayoutManager?

The layout manager for the text being typeset.

var usesFontLeading: Bool

A Boolean value controlling whether the typesetter uses the leading (or line gap) value specified in the font metric information.

var hyphenationFactor: Float

The threshold controlling when hyphenation is attempted

Managing the text container

var currentTextContainer: NSTextContainer?

The text container for the text being typeset.

var lineFragmentPadding: CGFloat

The amount (in points) by which text is inset within line fragment rectangles

Mapping screen and printer fonts

func substituteFont(for: NSFont)

Returns a screen font suitable for use in place of the specified original font, or simply returns the original font if a screen font can’t be used or isn’t available.

Managing text tabs

func textTab(forGlyphLocation: CGFloat, writingDirection: NSWritingDirection, maxLocation: CGFloat)

Returns the text tab next closest to a given glyph location, indexing in the specified direction but not beyond a given glyph location.

Bidirectional text processing

var bidiProcessingEnabled: Bool

A Boolean value controlling whether the typesetter performs bidirectional text processing.

Accessing paragraph typesetting information

var attributedString: NSAttributedString?

The text backing store on which this typesetter operates.

func setParagraphGlyphRange(NSRange, separatorGlyphRange: NSRange)

Sets the current glyph range being processed and the paragraph separator glyph range (the range of the paragraph separator character or characters).

var paragraphGlyphRange: NSRange

The current glyph range being processed

var paragraphSeparatorGlyphRange: NSRange

The current paragraph separator range, which is the full range that contains the current glyph range and that extends from one paragraph separator character to the next.

Paragraph layout

func layoutParagraph(at: UnsafeMutablePointer<NSPoint>)

Lays out glyphs in the current glyph range until the next paragraph separator is reached.

Line and paragraph spacing

func lineSpacing(afterGlyphAt: Int, withProposedLineFragmentRect: NSRect)

Returns the line spacing in effect following the specified glyph.

func paragraphSpacing(afterGlyphAt: Int, withProposedLineFragmentRect: NSRect)

Returns the paragraph spacing, the number of points of space added following a paragraph, which is in effect after the specified glyph.

func paragraphSpacing(beforeGlyphAt: Int, withProposedLineFragmentRect: NSRect)

Returns the number of points of space added before a paragraph, which is in effect before the specified glyph.

Glyph caching

func setHardInvalidation(Bool, forGlyphRange: NSRange)

Sets a Boolean value controlling whether to force the layout manager to invalidate the portion of the glyph cache in the given glyph range when invalidating layout.

Laying out glyphs

func boundingBox(forControlGlyphAt: Int, for: NSTextContainer, proposedLineFragment: NSRect, glyphPosition: NSPoint, characterIndex: Int)

Returns the bounding rectangle for the given control glyph, at the given glyph position and character index, in the given text container.

func hyphenCharacter(forGlyphAt: Int)

Returns the hyphen character to be inserted after the given glyph when hyphenation is enabled in the layout manager.

func hyphenationFactor(forGlyphAt: Int)

Returns the hyphenation factor in effect at the given glyph index.

func shouldBreakLine(byHyphenatingBeforeCharacterAt: Int)

The typesetter calls this method, if implemented by a subclass, before breaking a line by hyphenating before the character at the given character index, enabling the subclass to control line breaking.

func shouldBreakLine(byWordBeforeCharacterAt: Int)

The typesetter calls this method, if implemented by a subclass, before breaking a line by word wrapping before the character at the given character index, enabling the subclass to control line breaking.

func willSetLineFragmentRect(UnsafeMutablePointer<NSRect>, forGlyphRange: NSRange, usedRect: UnsafeMutablePointer<NSRect>, baselineOffset: UnsafeMutablePointer<CGFloat>)

Called by the typesetter just prior to calling setLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:) which stores the actual line fragment rectangle location in the layout manager.

Relationships

Inherits From

Conforms To

See Also

Layout

class NSLayoutManager

An object that coordinates the layout and display of characters held in an NSTextStorage object.

protocol NSLayoutManagerDelegate

A set of optional methods implemented by delegates of NSLayoutManager objects.

class NSTextContainer

A region where text is laid out.

class NSTextBlock

A block of text laid out in a subregion of the text container.

class NSTypesetter

An abstract class that performs various type layout tasks.

protocol NSTextLayoutOrientationProvider

A set of methods that define the orientation of text for an object.