• 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: boundingRectWithSize problem?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: boundingRectWithSize problem?


  • Subject: Re: boundingRectWithSize problem?
  • From: Tony Pollard <email@hidden>
  • Date: Tue, 07 Feb 2012 18:05:18 +0000

Using a temporary Text container/storage/layout seems to fix the problem.  See:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/Tasks/StringHeight.html

The NS(Attributed)String+Geometrics category by Jerry Krinock is also handy:
 https://github.com/jerrykrinock/CategoriesObjC.git

Cheers!

Tony Pollard

On 27 Jan 2012, at 11:26 am, Tony Pollard wrote:

> Good thought Tim,  but for some reason it doesn't work in this case (both on 10.6 & 10.7).
>
> As you would expect, it is size/font sensitive so I can get the same failure result (for the sample text given) with Times-Roman 11 point.  Of the various text samples, it's only 1 in 10,000 or so that don't get their height calculated correctly.
>
> Tony
>
>
> On 26 Jan 2012, at 6:59 pm, Tim Schröder wrote:
>
>> 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 (email@hidden)
>>>
>>> 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:
>>>
>>> This email sent to email@hidden
>>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Prev by Date: Lion's 'restore windows' vs. app with initial 'login'
  • Next by Date: Re: Sandbox, 10.6, Core Duo, XCode 4.... where is the entitlement page?
  • Previous by thread: Re: Lion's 'restore windows' vs. app with initial 'login'
  • Next by thread: Re: Difficulty Calling NSTableView's validateDrop: Method for Unit Testing
  • Index(es):
    • Date
    • Thread