Re: How do I soft-wrap text at a specific line length?
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.