<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextContainer/lineFragmentRect(forProposedRect:at:writingDirection:remaining:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextContainer(im)lineFragmentRectForProposedRect:atIndex:writingDirection:remainingRect:"
  },
  "title" : "lineFragmentRect(forProposedRect:at:writingDirection:remaining:)"
}
-->

# lineFragmentRect(forProposedRect:at:writingDirection:remaining:)

Returns the bounds of a line fragment rectangle inside the text container for the proposed rectangle.

```
func lineFragmentRect(forProposedRect proposedRect: CGRect, at characterIndex: Int, writingDirection baseWritingDirection: NSWritingDirection, remaining remainingRect: UnsafeMutablePointer<CGRect>?) -> CGRect
```

## Parameters

`proposedRect`

A rectangle in which to lay out text proposed by the layout manager.

`characterIndex`

The character location inside the text storage for the line fragment being processed.

`baseWritingDirection`

The direction of advancement for line fragments inside a visual horizontal line. The values passed into the method are either [`NSWritingDirection.leftToRight`](/documentation/AppKit/NSWritingDirection/leftToRight) or [`NSWritingDirection.rightToLeft`](/documentation/AppKit/NSWritingDirection/rightToLeft).

`remainingRect`

The remainder of the proposed rectangle that was excluded from returned rectangle. It can be passed in as the proposed rectangle for the next iteration.

## Discussion

The bounds of the line fragment rectangle are determined by the intersection of `proposedRect` and the text container’s bounding rectangle defined by its [`NSTextContainer`](/documentation/AppKit/NSTextContainer) property. The regions defined by the [`NSTextContainer`](/documentation/AppKit/NSTextContainer) property are excluded from the return value. It is possible that `proposedRect` can be divided into multiple line fragments due to exclusion paths. In that case, `remainingRect` returns the remainder that can be passed in as the proposed rectangle for the next iteration.

This method can be overridden by subclasses for further text container region customization.

---

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)