• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do I soft-wrap text at a specific line length?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I soft-wrap text at a specific line length?


  • Subject: Re: How do I soft-wrap text at a specific line length?
  • From: Chris Kenny <email@hidden>
  • Date: Mon, 16 Feb 2004 01:28:56 -0500

On Feb 9, 2004, at 12:11 PM, Ryan Bates wrote:

I don't think there's any easy way to do this. It probably involves subclassing NSTextContainer.

Have you seen the TipWrapper example? I realize it's not exactly what you're looking for, but it works closely with the text layer and therefore might have some helpful code:

<http://developer.apple.com/samplecode/Sample_Code/Cocoa/ TipWrapper.htm>

Hmm. If I subclass NSTextContainer and override lineFragmentRectForProposedRect:sweepDirection:movementDirection: remainingRect:, then I can play with the location where the text wraps, by modifying the proposed NSRect. That would be perfect if I just wanted to wrap after a specific number of pixels, or a certain distance from the edge of the view.

Wrapping at a certain character length seems a lot more tricky though. I guess I need to figure out how many characters are already in the proposed rect and how much space they take up, and then set the proposed rect's size such than another character won't fit.

Nothing passed to that NSTextContainer method gives any hint about how many characters are on the current line, though. If I try to get the glyph range for the proposed NSRect using NSLayoutManager's glyphRangeForBoundingRect:inTextContainer:, I end up in an infinite loop. Apparently that method calls the NSTextContainer method....

I freely admit I have no real idea what I'm doing here, and I'd be quite thankful if anyone could point me in the right direction.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >How do I soft-wrap text at a specific line length? (From: Chris Kenny <email@hidden>)
 >Re: How do I soft-wrap text at a specific line length? (From: Ryan Bates <email@hidden>)

  • Prev by Date: Re: General Question: Debugging these "NS" Objects: Answered
  • Next by Date: NSTableView/NSPopUpButtonCell Mysteries
  • Previous by thread: Re: How do I soft-wrap text at a specific line length?
  • Next by thread: Re: How do I soft-wrap text at a specific line length?
  • Index(es):
    • Date
    • Thread