lineBreakBeforeIndex Question
lineBreakBeforeIndex Question
- Subject: lineBreakBeforeIndex Question
- From: Kynerd Coleman <email@hidden>
- Date: Mon, 10 Oct 2005 20:19:29 -0400
I am trying to detect where within an NSAttributedString a line of
text breaks in an NSRect.
I have found a function that will return the best place to break a
line based on a given index. For example, in the below call, the
function returns the highest position within the range less than 30
that represents a space (intended as a good spot for breaking a line).
// s is an NSAttributedString
aRange = NSMakeRange(0, [s length]);
int aBreak;
aBreak = [s lineBreakBeforeIndex:30 withinRange:aRange];
The function works fine. The problem is, how do I know what to use in
terms of the index value (ex. 30 above). It seems to me for the above
to work, you have to know the number of characters that will fit on a
line (i.e. index) before you write it out so that you can ask for the
proper place to break the text. I am writing to an NSRect with a
width of 300 for example, but with variable font width and unknown
potential height. The width of the NSRect is not measured in
characters.
Therefore, I don't know before I drawInRect how much will fit on the
line and once I drawInRect, I can't see how to get at a row within an
NSREct to see what text is on a given line and if it broke badly or
cutoff the string due to improper height.
If it helps, I am trying to manually control pagination with an NSRect
containing wrapped text that may need to exceed the page height and
therefore page break it at an appropriate spot so as not to print a
partial height text representation. I know NSRect does a good job of
wrapping, but that doesn't handle situations where my NSRect is not
tall enough or the text will exceed a printed page boundary and need
to be split across pages.
Thanks to all.
Kynerd
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden