Link to home
Start Free TrialLog in
Avatar of VSmolensky
VSmolensky

asked on

TImage and Input Locale

Hello,

I use Canvas on a TImage for writing Russian text on it. It looks OK while the default system locale on my computer is set to Russian. When I switch it to something different, all the cyrillic letters turn into "??????". Assigning Canvas.Font.Charset:='RUSSIAN CHARSET' doesn't help. Is there any method to make my text look cyrillic under ANY system settings?

I want to emphasize, just in case, that it's not the problem of "localization". I don't care about menus and buttons. I only care about the text written on TImage.

Vadim Smolensky,
Saint-Petersburg, Russia
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Have you set the font's character set?

Try this:
procedure TForm1.Button1Click(Sender: TObject);
begin
  canvas.Font.Charset:= RUSSIAN_CHARSET;
  canvas.TextOut(20,20, 'Hello world! '#$9C#$9D#$9E#$9F);
end;
Avatar of VSmolensky
VSmolensky

ASKER

> Have you set the font's character set?

If you'd read my question carefully, you wouldn't have asked me this.
sorry, It's a bit late over here... Obviously need some rest
I've tested on my machine. By setting the canvas.font.charset to RUSSIAN_CHARSET on my machine it works.
Are you sure you've set the charset of the correct canvas?

Maybe You should also set font name to such which have russian_charset.
To mokule: the font name is OK, otherwise it wouldn't work under Russian locale either, but it does.

To PierreC: did you test it under XP? I have 2000. When I tried it under XP, the results were really strange: it was OK either with Russian default locale and no additional operators or with English default locale and assigning Canvas.Font.Charset:='russian_charset'. BUT: when it had Russian default locale and assigning russian_charset, it didn't work again! A paradox, isn't it?

I think I know how to deal with it, I just have to determine the default locale in the runtime and assign or not assign the charset depending on it. How to do this?

V.S.
And yet, I think that You are giving such font parameters that don't exist in a system and Windows selects the nearest font. Who knows what will be chosen?
To mokule: please, believe me, it's not a problem of particular fonts. It's a problem of system settings. It goes the same with any possible font.
>>>To PierreC: did you test it under XP? I have 2000.

Yes, I tested under Win XP.


>>>... I just have to determine the default locale in the runtime and assign or not assign the charset depending on it. How to >>>do this?

You can get the default user or system locale by using one the following 2 windows API functions:

GetSystemDefaultLCID
GetUserDefaultLCID

e.g.
uses Windows;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowMessage('Default system locale: '
              +Languages.NameFromLocaleID[GetSystemDefaultLCID]+#13+
              'Default user locale: '
              +Languages.NameFromLocaleID[GetUserDefaultLCID]);
end;
Thank you. It gave me Russian for System Default and English (UK) for User Default. Could you please explain the difference between the two (system default and user default)?

And one more thing: the compiler gave me a warning: "Symbol 'NameFromLocaleID' is specific to a platform". Does this mean that under a certain version of Windows this operator can provoke an exception? If yes, how can I avoid it?
ASKER CERTIFIED SOLUTION
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial