Re: Fastest way to predict bounding box for a string
Re: Fastest way to predict bounding box for a string
- Subject: Re: Fastest way to predict bounding box for a string
- From: Greg Herlihy <email@hidden>
- Date: Mon, 06 Feb 2006 17:43:49 -0800
- Thread-topic: Fastest way to predict bounding box for a string
Per Apple's documentation the fastest way to obtain the height of a single
line of text is to call NSTextLayout's defaultLineHeightForFont method,
passing it the NSFont that will be used to render the text.
The contents of the string to be drawn is not relevant, since all the
application needs is the minimal height needed to display any string in that
font.
Greg
On 2/6/06 3:56 PM, "Ivan Kourtev" <email@hidden> wrote:
> Hello,
>
> I have an application where I need to draw a single-word attributed
> string as big as possible but not exceeding a specific fitting
> rectangle. I did this in principle by starting with a certain font
> size, getting the string bounding box, then increasing or decreasing
> the font size (while changing the string font attribute) until the
> bounding box is the largest fitting in the rectangle. I am assuming
> this method can be computationally expensive -- as a matter of fact I
> can 'see' a nearly one second delay (on a G5 DC 2GHz) when the
> rectangle to fit in is around 1,000x1,000.
>
> Any ideas on how to get this size quicker? Is there any way that has
> escaped my attention that can return the biggest font size such that
> the particular string does not exceed a given bounding rectangle? Or
> should I just fall back to binary search of a certain interval of
> font sizes? Maybe caching the the size of a representative character
> in every size and getting a very good first guess for the required
> font size (particularly if the font is fixed width)? Any ideas or
> suggestions?
>
> Thanks for any help.
>
> --
> 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