"Orphaned" words not reported by NSString -boundingRectWithSize...
"Orphaned" words not reported by NSString -boundingRectWithSize...
- Subject: "Orphaned" words not reported by NSString -boundingRectWithSize...
- From: Shamyl Zakariya <email@hidden>
- Date: Fri, 25 May 2007 13:51:38 -0400
I've made a window where messages ( just strings ) stack from top to
bottom. The window is fixed width, so if a message is too long it
word wraps. Finally, since I show several messages, I have to keep
track of how tall each is so I can lay it out correctly.
Now, 99% of the time this works. But when the text is just long
enough that a single word wraps to the next line, the reported height
for the string doesn't show that line, just the lines up to it. I can
better show this with code:
First, here's how I set up the string attributes:
NSMutableParagraphStyle *pstyle = [[NSMutableParagraphStyle alloc]
init];
[pstyle setParagraphStyle: [NSParagraphStyle defaultParagraphStyle]];
[pstyle setAlignment: NSCenterTextAlignment];
[pstyle setLineBreakMode: NSLineBreakByWordWrapping];
_textDisplayAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont messageFontOfSize: [NSFont smallSystemFontSize]],
NSFontAttributeName,
[NSColor whiteColor], NSForegroundColorAttributeName,
pstyle, NSParagraphStyleAttributeName,
nil] retain];
And here's the method preferredHeight which returns the height needed
for the string to display properly:
- (float) preferredHeight
{
NSRect br = [_message boundingRectWithSize: NSMakeSize( _width,
0 ) options:NSStringDrawingUsesLineFragmentOrigin attributes:
_textDisplayAttributes];
return br.size.height + (2.0 * _vPad);
}
I have no idea why an orphaned word wouldn't be reported. Am I doing
something bone-headed here?
Thanks,
email@hidden
"obviously, you're not a golfer"
-- the Dude
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden