• 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: "Orphaned" words not reported by NSString -boundingRectWithSize...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Orphaned" words not reported by NSString -boundingRectWithSize...


  • Subject: Re: "Orphaned" words not reported by NSString -boundingRectWithSize...
  • From: Shamyl Zakariya <email@hidden>
  • Date: Tue, 29 May 2007 10:16:05 -0400

That is *exactly* what it was, and I'm a little embarrassed. Thanks for the clue-stick!

email@hidden
    lorem ipsum dolor sit amet,


On May 25, 2007, at 2:18 PM, Aki Inoue wrote:

The code shown should do exactly what you're trying to do, and I cannot reproduce it with a simple sample project.
So, I'm not sure.


On thing to note if you're rendering the text using NSCell.

NSCell as paddings on both sides of text when center-aligned.

If that's the case, you might be measuring with width slightly wider than the one used at the rendering time.

Aki

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


_______________________________________________

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


References: 
 >"Orphaned" words not reported by NSString -boundingRectWithSize... (From: Shamyl Zakariya <email@hidden>)
 >Re: "Orphaned" words not reported by NSString -boundingRectWithSize... (From: Aki Inoue <email@hidden>)

  • Prev by Date: Re: observing dealloc
  • Next by Date: Re: Database communication with Cocoa UI
  • Previous by thread: Re: "Orphaned" words not reported by NSString -boundingRectWithSize...
  • Next by thread: [ANN]: DSClickableURLTextField updated
  • Index(es):
    • Date
    • Thread