<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTypesetter/willSetLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTypesetter(im)willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:"
  },
  "title" : "willSetLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:)"
}
-->

# willSetLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:)

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

```
func willSetLineFragmentRect(_ lineRect: NSRectPointer, forGlyphRange glyphRange: NSRange, usedRect: NSRectPointer, baselineOffset: UnsafeMutablePointer<CGFloat>)
```

## Parameters

`lineRect`

The rectangle in which the glyphs in `glyphRange` are laid out.

`glyphRange`

The range of the glyphs to lay out.

`usedRect`

The portion of `lineRect`, in the NSTextContainer object’s coordinate system, that actually contains glyphs or other marks that are drawn (including the text container’s line fragment padding). The `usedRect` must be equal to or contained within `lineRect`.

`baselineOffset`

The vertical distance in pixels from the line fragment origin to the baseline on which the glyphs align.

## Discussion

Called by the typesetter just prior to calling [`setLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:)`](/documentation/AppKit/NSTypesetter/setLineFragmentRect(_:forGlyphRange:usedRect:baselineOffset:)) which stores the actual line fragment rectangle location in the layout manager.

A subclass can override this method to customize the text layout process. For example, it could change the shape of the line fragment rectangle. The subclass is responsible for ensuring that the modified rectangle remains valid (for example, that it lies within the text container).

---

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)