Re: Most efficient way of measuring text
Re: Most efficient way of measuring text
- Subject: Re: Most efficient way of measuring text
- From: Graham Cox <email@hidden>
- Date: Wed, 13 May 2009 11:31:50 +1000
On 13/05/2009, at 7:16 AM, Dave Keck wrote:
text rects. Has anyone come up with a very fast way to estimate the
size of
some text, more importantly the vertical size given a width.
You didn't mention that you tried NSAttributedString (specifically,
its -size method.) Does it suit your needs, or is it what you consider
too slow?
The -size method assumes the text is laid out on one line, so the
height it returns is the line height. Even then it's usually pretty
inaccurate - I've found it typically underestimates the necessary
space by about 25% in each dimension, though it depends on the exact
fonts the string is using.
The methods in NSLayoutManager are the best way to accurately measure
text, as the OP is already doing.
You might be able to speed things up by keeping the layout manager
around so that the information it caches is not destroyed every time.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden