<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTypesetter",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTypesetter"
  },
  "title" : "NSTypesetter"
}
-->

# NSTypesetter

An abstract class that performs various type layout tasks.

```
class NSTypesetter
```

## Overview

[`NSLayoutManager`](/documentation/AppKit/NSLayoutManager) uses concrete subclasses of [`NSTypesetter`](/documentation/AppKit/NSTypesetter) to perform line layout, which includes word wrapping, hyphenation, and line breaking in either vertical or horizontal rectangles. By default, the text system uses the concrete subclass [`NSATSTypesetter`](/documentation/AppKit/NSATSTypesetter).

> Note:
> Use this class with ``doc://com.apple.appkit/documentation/AppKit/NSLayoutManager`` in macOS11 and earlier. In macOS12 and later, consider using ``doc://com.apple.appkit/documentation/AppKit/NSLayoutManager`` which provides improved support for international scripts.

### Subclassing Notes

`NSTypesetter` provides concrete subclasses with default implementation interfacing with the Cocoa text system. By subclassing `NSTypesetter`, an application can override the [`layoutParagraph(at:)`](/documentation/AppKit/NSTypesetter/layoutParagraph(at:)) method to integrate a custom typesetting engine into the Cocoa text system. On the other hand, an application can subclass [`NSATSTypesetter`](/documentation/AppKit/NSATSTypesetter) and override the glyph storage interface to integrate the concrete subclass into its own custom layout system.

`NSTypesetter` methods belong to three categories: glyph storage interface methods, layout phase interface methods, and core typesetter methods. The glyph storage interface methods map to [`NSLayoutManager`](/documentation/AppKit/NSLayoutManager) methods. The typesetter itself calls these methods, and their default implementations call the Cocoa layout manager. An `NSTypesetter` subclass can override these methods to call its own glyph storage facility, in which case it should override all of them. (This doesn’t preclude the overridden method calling its superclass implementation if appropriate).

The layout phase interface provides control points similar to delegate methods; if implemented, the system invokes these methods to notify an `NSTypesetter` subclass of events in the layout process so it can intervene as needed.

The remainder of the `NSTypesetter` methods are primitive, core typesetter methods. The core typesetter methods correlate with typesetting state attributes; the layout manager calls these methods to store its values before starting the layout process. If you subclass `NSTypesetter` and override the glyph storage interface methods, you can call the core methods to control the typesetter directly.

#### Glyph Storage Interface

Override these methods to use `NSTypesetter`’s built-in concrete subclass, [`NSATSTypesetter`](/documentation/AppKit/NSATSTypesetter), with a custom glyph storage and layout system other than the Cocoa layout manager and text container mechanism.

- [`characterRange(forGlyphRange:actualGlyphRange:)`](/documentation/AppKit/NSTypesetter/characterRange(forGlyphRange:actualGlyphRange:))
- [`glyphRange(forCharacterRange:actualCharacterRange:)`](/documentation/AppKit/NSTypesetter/glyphRange(forCharacterRange:actualCharacterRange:))
- [`getGlyphs(in:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:)`](/documentation/AppKit/NSTypesetter/getGlyphs(in:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:))
- [`getLineFragmentRect(_:usedRect:remaining:forStartingGlyphAt:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:)`](/documentation/AppKit/NSTypesetter/getLineFragmentRect(_:usedRect:remaining:forStartingGlyphAt:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:))
- [`setLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:)`](/documentation/AppKit/NSTypesetter/setLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:))
- [`substituteGlyphs(in:withGlyphs:)`](/documentation/AppKit/NSTypesetter/substituteGlyphs(in:withGlyphs:))
- [`insertGlyph(_:atGlyphIndex:characterIndex:)`](/documentation/AppKit/NSTypesetter/insertGlyph(_:atGlyphIndex:characterIndex:))
- [`deleteGlyphs(in:)`](/documentation/AppKit/NSTypesetter/deleteGlyphs(in:))
- [`setNotShownAttribute(_:forGlyphRange:)`](/documentation/AppKit/NSTypesetter/setNotShownAttribute(_:forGlyphRange:))
- [`setDrawsOutsideLineFragment(_:forGlyphRange:)`](/documentation/AppKit/NSTypesetter/setDrawsOutsideLineFragment(_:forGlyphRange:))
- [`setLocation(_:withAdvancements:forStartOfGlyphRange:)`](/documentation/AppKit/NSTypesetter/setLocation(_:withAdvancements:forStartOfGlyphRange:))
- [`setAttachmentSize(_:forGlyphRange:)`](/documentation/AppKit/NSTypesetter/setAttachmentSize(_:forGlyphRange:))
- [`setBidiLevels(_:forGlyphRange:)`](/documentation/AppKit/NSTypesetter/setBidiLevels(_:forGlyphRange:))

#### Layout Phase Interface

Override these methods to customize the text layout process, including modifying line fragments, controlling line breaking and hyphenation, and controlling the behavior of tabs and other control glyphs.

- [`willSetLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:)`](/documentation/AppKit/NSTypesetter/willSetLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:))
- [`shouldBreakLine(byWordBeforeCharacterAt:)`](/documentation/AppKit/NSTypesetter/shouldBreakLine(byWordBeforeCharacterAt:))
- [`shouldBreakLine(byHyphenatingBeforeCharacterAt:)`](/documentation/AppKit/NSTypesetter/shouldBreakLine(byHyphenatingBeforeCharacterAt:))
- [`hyphenationFactor(forGlyphAt:)`](/documentation/AppKit/NSTypesetter/hyphenationFactor(forGlyphAt:))
- [`hyphenCharacter(forGlyphAt:)`](/documentation/AppKit/NSTypesetter/hyphenCharacter(forGlyphAt:))
- [`boundingBox(forControlGlyphAt:for:proposedLineFragment:glyphPosition:characterIndex:)`](/documentation/AppKit/NSTypesetter/boundingBox(forControlGlyphAt:for:proposedLineFragment:glyphPosition:characterIndex:))

## Topics

### Getting a typesetter

[`sharedSystemTypesetter`](/documentation/AppKit/NSTypesetter/sharedSystemTypesetter)

Returns a shared instance of a reentrant typesetter.

[`+  sharedSystemTypesetterForBehavior:`](/documentation/AppKit/NSTypesetter/sharedSystemTypesetter(for:))

Returns a shared instance of a reentrant typesetter that implements typesetting with the specified behavior.

### Getting information about a typesetter

[`defaultTypesetterBehavior`](/documentation/AppKit/NSTypesetter/defaultTypesetterBehavior)

Returns the default typesetter behavior.

### Getting information about glyphs

[`+  printingAdjustmentInLayoutManager:forNominallySpacedGlyphRange:packedGlyphs:count:`](/documentation/AppKit/NSTypesetter/printingAdjustment(in:forNominallySpacedGlyphRange:packedGlyphs:count:))

Returns the interglyph spacing in the specified range when sent to a printer.

[`-  baselineOffsetInLayoutManager:glyphIndex:`](/documentation/AppKit/NSTypesetter/baselineOffset(in:glyphIndex:))

Returns the distance from the bottom of the line fragment rectangle in which the glyph resides to the glyph baseline.

### Accessing the layout manager

[`layoutManager`](/documentation/AppKit/NSTypesetter/layoutManager)

Returns the layout manager for the text being typeset.

[`usesFontLeading`](/documentation/AppKit/NSTypesetter/usesFontLeading)

Returns whether the typesetter uses the leading (or line gap) value specified in the font metric information of the current font.

[`typesetterBehavior`](/documentation/AppKit/NSTypesetter/typesetterBehavior)

Returns the current typesetter behavior.

[`hyphenationFactor`](/documentation/AppKit/NSTypesetter/hyphenationFactor)

Returns the current hyphenation factor.

### Managing text containers

[`currentTextContainer`](/documentation/AppKit/NSTypesetter/currentTextContainer)

Returns the text container for the text being typeset.

[`textContainers`](/documentation/AppKit/NSTypesetter/textContainers)

Returns an array containing the text containers belonging to the current layout manager.

[`lineFragmentPadding`](/documentation/AppKit/NSTypesetter/lineFragmentPadding)

Returns the current line fragment padding, in points.

### Performing font substitution

[`-  substituteFontForFont:`](/documentation/AppKit/NSTypesetter/substituteFont(for:))

Returns a screen font suitable for use in place of a given font.

### Getting the location of text tabs

[`-  textTabForGlyphLocation:writingDirection:maxLocation:`](/documentation/AppKit/NSTypesetter/textTab(forGlyphLocation:writingDirection:maxLocation:))

Returns the text tab next closest to a given glyph location within the given parameters.

### Bidirectional text processing

[`bidiProcessingEnabled`](/documentation/AppKit/NSTypesetter/bidiProcessingEnabled)

Returns whether bidirectional text processing is enabled.

### Accessing paragraph typesetting information

[`currentParagraphStyle`](/documentation/AppKit/NSTypesetter/currentParagraphStyle)

Returns the paragraph style object for the text being typeset.

[`attributedString`](/documentation/AppKit/NSTypesetter/attributedString)

Returns the text backing store, usually an instance of `NSTextStorage`.

[`-  setParagraphGlyphRange:separatorGlyphRange:`](/documentation/AppKit/NSTypesetter/setParagraphGlyphRange(_:separatorGlyphRange:))

Sets the current glyph range being processed.

[`paragraphGlyphRange`](/documentation/AppKit/NSTypesetter/paragraphGlyphRange)

Returns the glyph range currently being processed.

[`paragraphSeparatorGlyphRange`](/documentation/AppKit/NSTypesetter/paragraphSeparatorGlyphRange)

Returns the current paragraph separator range.

[`paragraphCharacterRange`](/documentation/AppKit/NSTypesetter/paragraphCharacterRange)

Returns the character range currently being processed.

[`paragraphSeparatorCharacterRange`](/documentation/AppKit/NSTypesetter/paragraphSeparatorCharacterRange)

Returns the current paragraph separator character range.

[`attributesForExtraLineFragment`](/documentation/AppKit/NSTypesetter/attributesForExtraLineFragment)

Returns the attributes used to lay out the extra line fragment.

### Getting spacing information

[`-  lineSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:`](/documentation/AppKit/NSTypesetter/lineSpacing(afterGlyphAt:withProposedLineFragmentRect:))

Returns the line spacing in effect following the specified glyph.

[`-  paragraphSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:`](/documentation/AppKit/NSTypesetter/paragraphSpacing(afterGlyphAt:withProposedLineFragmentRect:))

Returns the paragraph spacing that is in effect after the specified glyph.

[`-  paragraphSpacingBeforeGlyphAtIndex:withProposedLineFragmentRect:`](/documentation/AppKit/NSTypesetter/paragraphSpacing(beforeGlyphAt:withProposedLineFragmentRect:))

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

### Laying out a paragraph

[`-  layoutParagraphAtPoint:`](/documentation/AppKit/NSTypesetter/layoutParagraph(at:))

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

[`-  beginParagraph`](/documentation/AppKit/NSTypesetter/beginParagraph())

Sets up layout parameters at the beginning of a paragraph.

[`-  endParagraph`](/documentation/AppKit/NSTypesetter/endParagraph())

Sets up layout parameters at the end of a paragraph.

[`-  beginLineWithGlyphAtIndex:`](/documentation/AppKit/NSTypesetter/beginLine(withGlyphAt:))

Sets up layout parameters at the beginning of a line during typesetting.

[`-  endLineWithGlyphRange:`](/documentation/AppKit/NSTypesetter/endLine(withGlyphRange:))

Sets up layout parameters at the end of a line during typesetting.

### Laying out characters

[`-  layoutCharactersInRange:forLayoutManager:maximumNumberOfLineFragments:`](/documentation/AppKit/NSTypesetter/layoutCharacters(in:for:maximumNumberOfLineFragments:))

Lays out characters in the given character range for the specified layout manager.

### Laying out glyphs

[`-  layoutGlyphsInLayoutManager:startingAtGlyphIndex:maxNumberOfLineFragments:nextGlyphIndex:`](/documentation/AppKit/NSTypesetter/layoutGlyphs(in:startingAtGlyphIndex:maxNumberOfLineFragments:nextGlyphIndex:))

Lays out glyphs in the specified layout manager starting at a specified glyph.

[`-  boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment:glyphPosition:characterIndex:`](/documentation/AppKit/NSTypesetter/boundingBox(forControlGlyphAt:for:proposedLineFragment:glyphPosition:characterIndex:))

Returns the bounding rectangle for the specified control glyph with the specified parameters.

[`-  getLineFragmentRect:usedRect:forParagraphSeparatorGlyphRange:atProposedOrigin:`](/documentation/AppKit/NSTypesetter/getLineFragmentRect(_:usedRect:forParagraphSeparatorGlyphRange:atProposedOrigin:))

Calculates the line fragment rectangle and line fragment used rectangle for blank lines.

[`-  getLineFragmentRect:usedRect:remainingRect:forStartingGlyphAtIndex:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:`](/documentation/AppKit/NSTypesetter/getLineFragmentRect(_:usedRect:remaining:forStartingGlyphAt:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:))

Calculates line fragment rectangle, line fragment used rectangle, and remaining rectangle for a line fragment.

[`-  hyphenCharacterForGlyphAtIndex:`](/documentation/AppKit/NSTypesetter/hyphenCharacter(forGlyphAt:))

Returns the hyphen character to be inserted after the specified glyph.

[`-  hyphenationFactorForGlyphAtIndex:`](/documentation/AppKit/NSTypesetter/hyphenationFactor(forGlyphAt:))

Returns the hyphenation factor in effect at a specified location.

[`-  shouldBreakLineByHyphenatingBeforeCharacterAtIndex:`](/documentation/AppKit/NSTypesetter/shouldBreakLine(byHyphenatingBeforeCharacterAt:))

Returns whether the line being laid out should be broken by hyphenating at the specified character.

[`-  shouldBreakLineByWordBeforeCharacterAtIndex:`](/documentation/AppKit/NSTypesetter/shouldBreakLine(byWordBeforeCharacterAt:))

Returns whether the line being laid out should be broken by a word break at the specified character.

[`-  willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:`](/documentation/AppKit/NSTypesetter/willSetLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:))

Called by the typesetter just prior to storing the actual line fragment rectangle location in the layout manager.

[`-  setHardInvalidation:forGlyphRange:`](/documentation/AppKit/NSTypesetter/setHardInvalidation(_:forGlyphRange:))

Sets whether to force the layout manager to invalidate the specified portion of the glyph cache when invalidating layout.

### Interfacing with Glyph Storage

[`-  characterRangeForGlyphRange:actualGlyphRange:`](/documentation/AppKit/NSTypesetter/characterRange(forGlyphRange:actualGlyphRange:))

Returns the range for the characters in the receiver’s text store that are mapped to the specified glyphs.

[`-  glyphRangeForCharacterRange:actualCharacterRange:`](/documentation/AppKit/NSTypesetter/glyphRange(forCharacterRange:actualCharacterRange:))

Returns the range for the glyphs mapped to the characters of the text store in the specified range.

[`-  setAttachmentSize:forGlyphRange:`](/documentation/AppKit/NSTypesetter/setAttachmentSize(_:forGlyphRange:))

Sets the size the specified glyphs (assumed to be attachments) will be asked to draw themselves at.

[`-  setBidiLevels:forGlyphRange:`](/documentation/AppKit/NSTypesetter/setBidiLevels(_:forGlyphRange:))

Sets the direction of the specified glyphs for bidirectional text.

[`-  setDrawsOutsideLineFragment:forGlyphRange:`](/documentation/AppKit/NSTypesetter/setDrawsOutsideLineFragment(_:forGlyphRange:))

Sets whether the specified glyphs exceed the bounds of the line fragment in which they are laid out.

[`-  setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:`](/documentation/AppKit/NSTypesetter/setLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:))

Sets the line fragment rectangle where the specified glyphs are laid out.

[`-  setLocation:withAdvancements:forStartOfGlyphRange:`](/documentation/AppKit/NSTypesetter/setLocation(_:withAdvancements:forStartOfGlyphRange:))

Sets the location where the specified glyphs are laid out.

[`-  setNotShownAttribute:forGlyphRange:`](/documentation/AppKit/NSTypesetter/setNotShownAttribute(_:forGlyphRange:))

Sets whether the specified glyphs are not shown.

### Deprecated

[`-  actionForControlCharacterAtIndex:`](/documentation/AppKit/NSTypesetter/actionForControlCharacter(at:))

Returns the action associated with a control character.

[`-  deleteGlyphsInRange:`](/documentation/AppKit/NSTypesetter/deleteGlyphs(in:))

Deletes the specified glyphs from the glyph cache maintained by the layout manager.

[`-  substituteGlyphsInRange:withGlyphs:`](/documentation/AppKit/NSTypesetter/substituteGlyphs(in:withGlyphs:))

Replaces the specified glyphs with specified replacement glyphs.

[`-  getGlyphsInRange:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:`](/documentation/AppKit/NSTypesetter/getGlyphs(in:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:))

Extracts the information needed to lay out the provided glyphs from the provided range.

[`-  insertGlyph:atGlyphIndex:characterIndex:`](/documentation/AppKit/NSTypesetter/insertGlyph(_:atGlyphIndex:characterIndex:))

Enables the typesetter to insert a new glyph into the stream.

[`NSTypesetterControlCharacterAction`](/documentation/AppKit/NSTypesetterControlCharacterAction)

The following constants are possible values returned by the [`actionForControlCharacter(at:)`](/documentation/AppKit/NSTypesetter/actionForControlCharacter(at:)) method to determine the action associated with a control character.

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Inherited By

[`NSATSTypesetter`](/documentation/AppKit/NSATSTypesetter)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)