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: Allan Odgaard <email@hidden>
- Date: Tue, 17 Feb 2004 01:26:49 +0100
On 16. Feb 2004, at 20:08, Chris Kenny wrote:
Alternatively you can create a non-rectangular NSTextContainer which
measures the text and shapes itself to the width of each line (of 80
characters).
Right, I've tried that, but I can't seem to figure out how many
characters are on the current line from my NSTextContainer subclass's
lineFragmentRectForProposedRect:sweepDirection:movementDirection:
remainingRect: method [...]
No, you would overload "isSimpleRectangularTextContainer" to return NO
and "containsPoint:" to return YES/NO. You would have to pre-layout the
text, similar to:
std::vector<float> lineWidths;
NSString* txt = ...;
OakStringIterator it = beginof(txt), end = endof(txt), eol;
while(it != end)
{
eol = end-it < 80 ? end : it+80;
lineWidths.push_back(text_width(it, eol));
it = eol;
}
And containsPoint: would then use the lineWidths similar to:
int line = point.y / lineHeight;
return lineWidths[line] <= point.x ? YES : NO;
Though some assumptions would have to be made with respect to padding,
and text_width should preferably be implemented using NSLayoutManager,
although ATSUI is probably easier.
Another approach is to overload the
shouldBreakLineByWordBeforeCharacterAtIndex: method of the type setter
used by the layout manager, but I do not think it gets called for every
character.
Maybe you should re-think your program? Why is it you need to display
text in a NSTextView always wrapped at character 80?
_______________________________________________
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.