• 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: Fastest way to predict bounding box for a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fastest way to predict bounding box for a string


  • Subject: Re: Fastest way to predict bounding box for a string
  • From: Charlton Wilbur <email@hidden>
  • Date: Mon, 6 Feb 2006 19:25:23 -0500


On Feb 6, 2006, at 6:56 PM, Ivan Kourtev wrote:

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?

There may be a better way, but this is what I'd try. It's an artificial-intelligence approach called simulated annealing, where you make large changes early on in your search and gradually reduce the size of the change as you approach the solution.


Pick two sizes a good distance apart. Figure out what the bounding box for each is, and extrapolate to an estimate.

Then repeat for x in 20%, 10%, 5%, 2%, 2%, 1%, 1% : if the current estimate is inside the desired bounding box, add x% to the current estimate and try again. If the current estimate is outside the desired bounding box, subtract x% from the current estimate and try again.

(The more iterations you do, the closer you're likely to get, but the more time it will take. The quality of the estimate matters too -- with a reliable estimate, you can eliminate the 20% iteration and possibly the 10% iteration, but as long as you're within 20% of the target this approach will work.)

Charlton


-- Charlton Wilbur email@hidden 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
References: 
 >Fastest way to predict bounding box for a string (From: Ivan Kourtev <email@hidden>)

  • Prev by Date: RE: subclassing a window
  • Next by Date: Advice on restricting/monitoring character input in NSTextView
  • Previous by thread: Re: Fastest way to predict bounding box for a string
  • Next by thread: Re: Fastest way to predict bounding box for a string
  • Index(es):
    • Date
    • Thread