• 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: Getting exact height of NSAttributedString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting exact height of NSAttributedString


  • Subject: Re: Getting exact height of NSAttributedString
  • From: email@hidden
  • Date: Wed, 8 Feb 2006 15:22:46 -0800

I completely agree and didn't really mean to hardcode anything. I was just curious whether there is a direct way of getting the actual bounding box and was a little surprised that the size method includes space under the baseline even when the characters in the string do not drop below baseline (I also understand why this is useful anyway). But I'll try your suggestion, thanks.

http://developer.apple.com/documentation/Cocoa/Conceptual/ FontHandling/Tasks/GettingFontMetrics.html#//apple_ref/doc/uid/20000439
http://developer.apple.com/documentation/Carbon/Reference/ ATSUI_Reference/Reference/reference.html#//apple_ref/doc/c_ref/ ATSUMeasureTextImage (mainly for reference; you shouldn't need to use ATSUI yourself)


By default most bounding-size related methods return the typographical bounds, not the image bounds. Typographical bounds always include the ascent and descent. You don't want uneven vertical space, that's dependent on your content. Horizontal space is another deal entirely - that's usually why you're using these methods.

So, if you're only using the system font, or similar, and can be almost certain you don't have to worry about the glyphs descending below the baseline, then yes, just getting the ascent will be all you need. Otherwise, perhaps you could get a character set of all the numbers (and related, e.g. '-', 'e', etc) that you'll be drawing, and then find the tallest one. You'd only have to do that once each time you change your font settings, which might just be once per application launch. Not a big deal to do.

Wade
_______________________________________________
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


References: 
 >Re: Getting exact height of NSAttributedString (From: Greg Herlihy <email@hidden>)
 >Re: Getting exact height of NSAttributedString (From: Ivan Kourtev <email@hidden>)

  • Prev by Date: Re: ivar name clashes with gcc3
  • Next by Date: Re: Getting exact height of NSAttributedString
  • Previous by thread: Re: Getting exact height of NSAttributedString
  • Next by thread: Re: Getting exact height of NSAttributedString
  • Index(es):
    • Date
    • Thread