I had exactly the same problem and solved it by using the NSStringDrawingUsesDeviceMetrics option instead of NSStringDrawingDisableScreenFontSubstitution.
Tim Am 25.01.2012 um 16:26 schrieb Tony Pollard: > Hi folks, > > I'm having a strange problem with NSAttributedString boundingRectWithSize in > getting the needed height for a fixed width. It works 99% of the time, but > it consistently underestimates the height for certain text (by approximately > one line). There doesn't appear to be a pattern for the text that works and > the text that fails (tested on 10.6 and 10.7). > > The code is: > > NSRect textRect = [attrString boundingRectWithSize:NSMakeSize(300.0, 0.0) > // Width 300, any height (max height also > fails) > > options: NSStringDrawingUsesLineFragmentOrigin | // Needed for > multi-line > > NSStringDrawingDisableScreenFontSubstitution]; > > The attributed strings are built from data sources. Here's one that fails: > > Printing description of attrString: > n. { > CdctPhraseType = Grammer; > NSColor = NSCalibratedRGBColorSpace 0.878431 0.0980392 0.160784 1; > NSFont = "LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85"; > }A hopper is a device shaped like a large funnel, in which substances such as > grain, coal, animal food, or sand can be stored.{ > CdctPhraseType = Transition; > NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1; > NSFont = "LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85"; > } > { > }F.ex: Large trailers came along and tipped it into a big hopper.{ > CdctPhraseType = Transition; > NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1; > NSFont = "LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85"; > } > > The resulting Rect is too short by about 9 pixels. Anyone had the same > problem? > > Tony Pollard > > > > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please 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: > https://lists.apple.com/mailman/options/cocoa-dev/tim%40timschroeder.net > > This email sent to t...@timschroeder.net _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com