Support of international chars in CGE

I am trying to do some experiments with handling Cyrillic (Russian) chars in CGE.
In the example:
\examples\2d_standard_ui\edit_test\edit_test.exe
If I enter Russian chars into TCastleEdit they are displayed as ?
While I may enter latin chars without any problems.
Now I added TCastleControlBase on TForm and OnPress I try to see that are returned by
procedure CastleControlBase1Press(Sender: TObject;
const Event: TInputPressRelease);

For example, when I press Russian ф (f) char which is located on the same button as latin a then I see in Debug - Local Variables:

EVENT={EVENTTYPE = ITKEY, KEY = KEYA, KEYSTRING = ‘ф’, MODIFIERSDOWN = [], KEYREPEATED = false, MOUSEBUTTON = MBLEFT, FINGERINDEX = 0, POSITION = {DATA = {0, 0}}, MOUSEWHEELSCROLL = 0, MOUSEWHEELVERTICAL = false}

But they I try to print KEYSTRING on put it into string:

procedure TForm1.CastleControlBase1Press(Sender: TObject;
		const Event: TInputPressRelease);
var
   st: string;
begin
   case Event.EventType of
   	 itKey: begin
   		 st:= 'key: '+IntToStr(integer(Event.Key))+', keychar: '+Event.KeyCharacter+', key str: '+Event.KeyString;

So I see that in st it’s recorded just as:
key: 65, keychar:

Could you please comment it? Why it’s not possible to enter Russian chars into TCastleEdit
and why I cannot catch Event.KeyString into st? (It works fine if I switch keyboard into EN layout and press Latin/English chars.

I am new to Lazarus while I have 20+ years of Delphi development exprience.
In Lazarus I created a simple application. I put TEdit on TForm.
Then I do:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
begin
  ShowMessage(Key);
end;  

Then I press ф button. I am on Windows.
It’s strange that in Local Variables i’ts displayed as ?
Then in ShowMessage it’s displayed as ?
But on TEdit it’s printed well as ф
Could someone comment on it? Maybe I should simply enable something in Lazarus? I know that Lazarus is using UTF-8 strings.

screenshot000208

This problem is connected to those characters unavailable in default font (which contains only ASCII characters). You need to manually specify the font to render the string or specify default font in configuration.

E.g. create a data/CastleSettings.xml file like this:

<?xml version="1.0" encoding="utf-8"?>
<castle_settings>
  <default_font>
    <regular
      url="DejaVuSans.ttf"
      size="25"
      sizes_at_load="20 40"
      anti_aliased="true"
      sample_text="йцукенгшщзхъфывапролджэячсмитьбюёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮЁ"
    />
  </default_font>
</castle_settings>

Add DejaVuSans.ttf font (or any other, adjusting the variable above as necessary) to the data folder too.

And then in the game load this settings file:

Window.Container.LoadSettings('castle-data:/CastleSettings.xml');

Note, that on Windows you’ll need to have corresponding 32 or 64 bit FreeType library available on PATH or in the game folder. Pick the necessary DLL from tools\build-tool\data\external_libraries\

I’m not sure about that. It should work fine. Note absence of key str: text in st output. It looks like KeyCharacter is some sort of a control character, which cuts the next content of the line. Also note that Windows console output works in Win-1251 only (for Russian Windows) and it often gets confused when getting UTF-8 characters.

This is a different problem. Note, that Key is passed as char - char is a 8-bit symbol, i.e. an ASCII symbol, which by default doesn’t support UTF-8 characters, such as “ф” - so, don’t expect anything reasonable in Key here. I don’t remember if there is a workaround - there most certainly should be, as I remember to have been successfully using Cyrillic characters in TEdit.