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

# lineFragmentRect(forProposedRect:sweepDirection:movementDirection:remaining:)

Calculates and returns the longest rectangle available in the proposed rectangle for displaying text.

```
func lineFragmentRect(forProposedRect proposedRect: NSRect, sweepDirection: NSLineSweepDirection, movementDirection: NSLineMovementDirection, remaining remainingRect: NSRectPointer?) -> NSRect
```

## Parameters

`proposedRect`

The proposed rectangle in which to layout text.

`sweepDirection`

The line sweep direction.

`movementDirection`

The line movement direction.

`remainingRect`

Upon return, the unused, possibly shifted, portion of `proposedRect` that’s available for further text, or `NSZeroRect` if there is no remainder.

## Return Value

The longest rectangle available in the proposed rectangle for displaying text, or `NSZeroRect` if there is none according to the receiver’s region definition.

## Discussion

There is no guarantee as to the width of the proposed rectangle or to its location. For example, the proposed rectangle is likely to be much wider than the width of the receiver. The receiver should examine `proposedRect` to see that it intersects its bounding rectangle and should return a modified rectangle based on `sweepDirection` and `movementDirection`, whose possible values are listed in the class description. If `sweepDirection` is `NSLineSweepRight`, for example, the receiver uses this information to trim the right end of `proposedRect` as needed rather than the left end.

If `proposedRect` doesn’t completely overlap the region along the axis of `movementDirection` and `movementDirection` isn’t `NSLineDoesntMove`, this method can either shift the rectangle in that direction as much as needed so that it does completely overlap, or return `NSZeroRect` to indicate that the proposed rectangle simply doesn’t fit.

---

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)