Re: Formatting a set of NSDecimalNumber values
Re: Formatting a set of NSDecimalNumber values
- Subject: Re: Formatting a set of NSDecimalNumber values
- From: Jens Alfke <email@hidden>
- Date: Fri, 10 Aug 2012 11:15:40 -0700
On Aug 10, 2012, at 10:55 AM, Sixten Otto <email@hidden> wrote:
> I could, as you say, measure the drawn sizes of the localized strings.
> I guess my resistance to that idea is really that I'd have to do it a
> couple of times (the width of the whole string, and the position of
> the decimal separator), and that it seems likely to be really slow.
No slower than the kind of layout the text system is already doing in most apps. :)
I think all you need to do is measure each number once. Find the offset in the string of the decimal point, measure the width of the substring before it, then move that far to the left of your desired decimal guideline before drawing the entire string.
If you want to find the maximum width, then you'll also need to measure the width of the entire string. (Don't just measure the width of the substring starting at the decimal point and add that to the first width; due to factors like kerning, you can't add substring widths that way.)
—Jens
_______________________________________________
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