• 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: email@hidden
  • Date: Mon, 6 Feb 2006 16:11:26 -0800

You should be able to do better than binary search with linear extrapolation.

Meaning, given size size of your string is "fontSize" at "baseSize" (e.g. 12 or whatever is a suitable default):


nextTestSize = baseSize * (availableSize / fontSize)

Just looping with that might spin you for a while - you could try that once and then start shrinking the text size until it fits. That's good if you're happy to step down in integer sizes... if you're going to be doing -= 0.0000000001 each time through your loop, you're still stuck.

This will probably be more accurate for larger base sizes, as antialiasing will have less of an effect, so a base size of 100 or somesuch might be a better default than 12. It doesn't matter if it's clearly too big - you'll likely only need to scale it once.

Wade
_______________________________________________
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>)
 >Re: Fastest way to predict bounding box for a string (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: Fastest way to predict bounding box for a string
  • Next by Date: Re: subclassing a window
  • 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