Re: Getting exact height of NSAttributedString
Re: Getting exact height of NSAttributedString
- Subject: Re: Getting exact height of NSAttributedString
- From: Greg Herlihy <email@hidden>
- Date: Wed, 08 Feb 2006 11:55:33 -0800
- Thread-topic: Getting exact height of NSAttributedString
I would call [NSFont ascender] to find out how far above baseline any string
in a particular font could extend. It's also possible to use NSFont routines
to measure each glyph individually; but for a single line of text, it hardly
seems worth the effort.
There are of course some fonts on the Mac whose numbers do drop below
baseline; so I am not sure I would want to hardcode any assumptions about a
font's metrics into an app.
Greg
On 2/8/06 11:11 AM, "Ivan Kourtev" <email@hidden> wrote:
> Hello,
>
> My application needs to draw a single-word NSAttributString as big as
> possible but not exceeding a specific fitting rectangle. I use the
> size method of NSAttributedString to find out whether at certain font
> size the bounding box of the string exceeds the fitting rectangle --
> this works fine.
>
> However, I noticed that the size method returns a height which is
> bigger than the actual height and accounts for the possibility that
> some characters (such as 'g') can extend below the baseline. So, for
> example, the NSAttributedString's "60" and "6g" have a bounding box
> with the same height (according to the size method).
>
> As my single-word strings are actually numbers and will _never_
> contain characters that extend under the baseline, is there any way
> to get the actual height of the string, without the under-the-
> baseline adjustment? I looked into the suggested NSLayoutManager but
> decided it was too heavyweight to use for my needs.
>
> Is this a feature or a bug? Why not have three methods that return
>
> BOOL -- whether there is a part of the string under the baseline
> NSSize -- bounding box with the under-the-baseline adjustment (the
> current size method)
> float -- how much of the height is under the baseline
>
> Or does this API exist and I am missing it?
>
> Thanks,
>
> -- ivan
> _______________________________________________
> 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
_______________________________________________
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