Re: Getting exact height of NSAttributedString
Re: Getting exact height of NSAttributedString
- Subject: Re: Getting exact height of NSAttributedString
- From: Ivan Kourtev <email@hidden>
- Date: Wed, 8 Feb 2006 18:41:29 -0500
Speaking of which, what exactly is the NSSize argument to
boundingRectWithSize:options: supposed to be?
The docs are conspicuously silent about it. (I noticed this method
first but didn't even try it because of compatibility with pre-tiger,
plus the above question).
--
ivan
On Feb 8, 2006, at 6:24 PM, Aki Inoue wrote:
We added a new method in Tiger exactly to solve this issue.
-[NSAttributedString boundingRectWithSize:options:]. You can
specify NSStringDrawingUsesDeviceMetrics to get union of all glyph
bounds.
Pre-Tiger, I'm afraid you need to set up an NSLayoutManager and do
the calculation by yourself.
Aki
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.
--
ivan
On Feb 8, 2006, at 2:55 PM, Greg Herlihy wrote:
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:
40pacbell.net
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
_______________________________________________
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