Fastest way to predict bounding box for a string
Fastest way to predict bounding box for a string
- Subject: Fastest way to predict bounding box for a string
- From: Ivan Kourtev <email@hidden>
- Date: Mon, 6 Feb 2006 18:56:43 -0500
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