Whodvethunk it'd be GDI+ injecting a little sanity into digit shenanigans?

by Michael S. Kaplan, published on 2011/09/28 07:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2011/09/28/10217550.aspx

Reader Angel asked about Digit Substitution:

Hello Michael!

I randomly found your blog while googling about digit substitution. I read all the entries in your blog about this subject, but didn’t find an answer for my problem. However, I think you might be able to help me.

I’m working on a MFC application which uses several custom controls. One of those custom control displays text using the DrawString method from GDI+, and digit substitution is not working very well on it. I’m getting the following results:

|User Locale (Format)| Standard digits      | Use native digits | Displayed digits |
 --------------- --------------------------- ------------------- ------------------
| English (USA)      | Arabic               | National          | Arabic           |
| English (USA)      | Hindi                | National          | Arabic           |
| Arabic (Egypt)     | Arabic               | National          | Arabic           |
| Arabic (Egypt)     | Hindi                | National          | Hindi            |
| Arabic (Egypt)     | Other strange digits | National          | Hindi            |
 ------------------- ---------------------- ------------------- -------------------

So for me it looks like the substitution is only performed if the selected ‘Standard Digits’ are in the codepage for the locale. Because of this, digit substitution only works with the Arabic locale and Hindi or Arabic numbers. If the ‘Standard Digits’ are not in the codepage, then the national default ones will be used: Arabic in the case of English and Hindi in the case of Arabic. I know codepages and unicode are very different things, but I cannot think of any other explanation.

The application is Unicode, and digit substitution works everywhere else (buttons, window titles, etc) but in this custom control, which is used to display the static text in all the application. The TextFormat the DrawString method uses has DigitSubstitution set to StringDigitSubstituteUser (although I’ve tried all the other values with no good results). LOCALE_IDIGITSUBSTITUTION == 2 and LOCALE_SDIGITSUBSTITUTION returns the “Use native digits” digits when I check their values just before DrawString.

Any ideas?

Please, tell me if you need any additional info or clarification about the problem.

Thank you very much!!!

It isn't exactly about code pages, since the Arabic code page, Windows code page 1256, only contain the ASCII digits.

In fact, most of the locales that explicitly support digit sustitution don't even have code pages!

Thus the code page itself can't do much here.

The real problem (to the extent it is a problem, a point I'll discuss in a moment), is that GDI+ doesn't really play well when the digits are overridden to not be the kind that typically gets used for the locale.

By letter of the law, well of the user preference, whatever "batshit crazy nonsense" you set in the dialog is what should be used.

Though in practice, the indirect way the digits are used in the original GDI and Uniscribe cases (ref: Digits -- there is no substitute and Windows doesn't let you choose the pinch hitter in digit substitution cases) leads to lots of of confusion anyway.

I feel like the GDI+ insistence on having some consistency here is probably a forcing function to take some really potentially whacked out functionality and be a little more sensible.

In the end, you have to decide how much sense you think this UI really makes:

Bonus points if you know what the last row is without setting it and programmatically checking the results, and even more bonus points if you know why they don't show up!

no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day