About Japanese String display on CGUITextField

hello.
I'm using Guiliani 2.4.
I'm trying to display a Japanese string in a TextField on the screen from StreamRuntime, but the characters are garbled.
The file encoding of MyGUI_SR.CPP is UTF-8.

The code is below.

pTextField = static_cast (GETGUI, GetObjectByID(AID_TXT_CONFIRM_MSG));
if (pTextField) {
  eC_String s = "xxyyzz";
  pTextField->SetLabel( s );
}

"xxyyzz" is actually a Japanese string.
The font of AID_TXT_CONFIRM_MSG specifies a Japanese font, and the Japanese specified by GSE is displayed correctly.


Please give me advice.

  • Hello tomi2791,

    the  eC_String-class can handle different source-encodings which will be converted to an internal representation used for the GUI.

    If you want to create an eC_String-object from a non-latin text-string you should use the constructor "eC_String(const eC_Char *pcString, eC_UInt uiLength, eStringFormat_t eFormat);". This will take your string and convert it from the specified source-format into the internal format and prevents changes due to a different interpretation of the characters.

    Generally you should not enter non-latin strings inside cpp-files as characters. Instead convert them to a series of hexadecimal values (e.g. https://www.branah.com/unicode-converter can do this for your). So instead of adding the text "減ざっ風子れす樹金ナメ氏訪ホ。" to your code, just use the string "\xe6\xb8\x9b\xe3\x81\x96\xe3\x81\xa3\xe9\xa2\xa8\xe5\xad\x90\xe3\x82\x8c\xe3\x81\x99\xe6\xa8\xb9\xe9\x87\x91\xe3\x83\x8a\xe3\x83\xa1\xe6\xb0\x8f\xe8\xa8\xaa\xe3\x83\x9b\xe3\x80\x82". This will be more portable and does not need the editor to handle Unicode-characters.

    So by changing your code to the following will do the trick:

    eC_String s = eC_String("\xe6\xb8\x9b\xe3\x81\x96\xe3\x81\xa3\xe9\xa2\xa8\xe5\xad\x90\xe3\x82\x8c\xe3\x81\x99\xe6\xa8\xb9\xe9\x87\x91\xe3\x83\x8a\xe3\x83\xa1\xe6\xb0\x8f\xe8\xa8\xaa\xe3\x83\x9b\xe3\x80\x82", 0, eC_String::UTF8);

    pTextField->SetLabel(s);

    Note the 0 for the uiLength parameter: the constructor will not need a length-information for a string-literal, so it can be 0.

    The easier way, of course, is the use of TextIDs inside the GSE and use them in your application. The strings will be always correctly displayed, when using a font which supports the character-set.

    Best Regards,

    Guiliani Support

  • thank you for your advice
    I was able to solve it with the method you taught me.
    The third parameter of eC_String is eC_String::eUTF8.

    Basically, TEXT-ID is used for multilingualization, but this time I used SetLabel() to display the character string received by serial communication.