How to display muilty-language characters correctly in TextEditor?

For example:

Bonne année, 明けましておめでとう, Frohes neues Jahr, 新年快乐,Happy new year, 
새해 복 많이 받으세요, С Новым Годом, 新年快樂, Ευτυχισμένος ο καινούριος χρόνος

??

20 words…

Which OS are you using and which font? This should work fine on OS X/Windows as long as you are using a font that supports all those characters. The linux backend of JUCE does not support all multi-language texts.

Besides the OS and font issue, you might want to check how you are getting that text compiled into your executable. You shouldn’t do something like textEditor.setText(“新年快乐”) in your source code. With debug builds running under the debugger JUCE should assert about that anyway, though. But the more correct way would be to use textEditor.setText(CharPointer_UTF8(“新年快乐”)); The best would probably be to avoid having text like that in the source code completely and use some other mechanism to populate the text editor.

Re: putting unicode text in your source code, remember that the Projucer has a tool for this, which lets you paste your text, which it converts to safe ascii C++ with escape sequences for the extended chars!

1 Like

Thanks for your replies, gentlemen :slight_smile: I think what I’m talking about is not:

myLookAndFeel->setDefaultSansSerifTypefaceName  ("fontName");

not:

textEditor->setFont (Font (...));

not:

te->setText (L"非ASCII字符");
xxxx->setText ("CharPointer_UTF8 ("\xe8\x8b\xb1\xe6\x96\x87\xe5\xad\x97\xe7\xac\xa6");

and so on…

Why should we set font when we’re writing codes with a modern C++ GUI library? And if that font doesn’t include other language characters, it’ll display an ugly, wrong result… Why don’t use the OS default font settings for this thing? Or just like the CSS: font-family – if the first one doesn’t include some certain characters, then it’ll auto use the second one…

I typed those words above in my browser, no need to set any font. it displayed correctly. If someone tell me must set some fonts before I type it, I’ll kill him… A browser can do this, why JUCE can’t? Is the library surely only for music plugins and audio field??

Thank for Andrew, I figured out how to find the user’s default font on Windows. On the other OSes, surely JUCE team can implement them… I know my code are very ugly, I’m very ashamed…

String fontName;

#if JUCE_WINDOWS
    NONCLIENTMETRICS ourMetrics = {sizeof (ourMetrics)};
    const bool success = bool (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof (ourMetrics), &ourMetrics, 0));

    if (success) 
    {
        char* fontName_char = ourMetrics.lfMessageFont.lfFaceName;
        int charSize = MultiByteToWideChar (CP_ACP, 0, fontName_char, -1, NULL, 0);

        wchar_t* fonatName_wchar_t = new wchar_t[charSize];
        MultiByteToWideChar (CP_ACP, 0, fontName_char, -1, fonatName_wchar_t, charSize);

        fontName = CharPointer_UTF16 (fonatName_wchar_t);
        delete[] fonatName_wchar_t;
    }        

#elif JUCE_OTHER_OSES
    // don't know how to figure them out...
#endif  

    // DBG (fontName);
    defaultLookAndFeel->setDefaultSansSerifTypefaceName (fontName);      

Sorry for my poor English. I tried my best to express my thoughts, but it seems I said nothing… so sadly…

Let me make it more clearly. although I didn’t hold too much hope on JUCE team all about these requests.

  1. The JUCE library should update its ‘font-usage-mechanism’. Using the default font setting of user’s OS seems a better way than currently. it should be the first step. By this way, LocalisedStrings::setCurrentMappings() and the TRANS() macro will implement multi-language app more easily and beautiful. In other words, you don’t have to set a special font for each language OS and the text’s fashion of GUI will make the users more satisfactory.

  2. Font-fallback-technique in JUCE. I know this is a huge work, perhaps impossible to be done faultlessly in a short time.

Someone would blame on me, too much demand of you idiot, why don’t you implement these things by yourself? OK, i’ve nothing more to blablabla except say sorry…

if you want to have full control over your font rendering you need to cook it yourself. that’s juce! you can always write a free function somewhere in your sources to do what you want :smiley: