I'm definitely aware of the font issues, and those I can deal with (I
think?). In particular, if I can line up the decimal separators
vertically, everything else should align, as I should be able to force
a font that has lining figures.

My reasoning for measuring the strings in a fixed locale with a
specific format string was specifically to eliminate the issues of
localization: have a known decimal separator and nothing else but
digits, so that counting the characters doesn't have to account for
thousands separators, etc.

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.

On Fri, Aug 10, 2012 at 9:29 AM, Jens Alfke <j...@mooseyard.com> wrote:
>
> On Aug 10, 2012, at 8:58 AM, Sixten Otto <hims...@sfko.com> wrote:
>
> In order to make the columns line up, and to know how much space I'll
> need, what I'd like to do is to figure out, for each set of numbers,
> the width of the format I'll need. In other words, the maximum number
> of integer places, and the maximum number of fractional places.
>
>
> Just to make things even more complicated: you're assuming digits are
> monospaced. In many fonts they are not — it generally looks better if a 1 is
> narrower than a 0, for instance. The "." is also pretty much guaranteed to
> be a lot narrower than a digit, and the "e" in scientific notation will be a
> different width too.
>
> There's also the matter that number formatting is localizable. Many
> countries use "," for a decimal point.
>
> One workaround might be to convert each number to a string in the
> POSIX locale, and then measure its length and the position of the
> decimal point.
>
>
> That doesn't seem like a workaround, it seems like the correct solution
> (although why not use the user's real locale?). Fundamentally you are trying
> to display and align character strings, so you have to treat the numbers as
> strings when computing their alignment. For best results use AppKit (or
> UIKit?) methods to compute the pixel width of each string in the font you're
> using.
>
> —Jens

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to