armadillu / ofxFontStash

Easy (and fast) unicode string rendering addon for OpenFrameworks. FontStash is made by Andreas Krinke and Mikko Mononen
http://uri.cat/
92 stars 42 forks source link

Unicode characters dissapearing #24

Open zzart opened 7 years ago

zzart commented 7 years ago

Hey, thanks for the addon! It's great. I've discovered on issue though. I have a sketch when every time I hit a key on the keyboard some predefined text (one character at the time) gets printed on the screen using ie. font.drawMultiLineColumn funtion. It works great for US character set , but when it has to print some non US characters ie. "ężćńą" the first stroke clears the entire line and nothing gets displayed , then the second stroke prints line + the unicode character. It's a bit weird so I've attached the screen.

Typing away ... step1 Next key stroke - this should type 'ź' but it clears the line instead step2 Finally after 2nd keystroke the character gets printed step3

armadillu commented 7 years ago

hm are you sure the character input you are getting is right? Can u try loading the non-ascii chars from a file, or hardcoding them in your source code? Otherwise post some of your code and I can have a look

agalloch21 commented 7 years ago

Sorry, same problem here. of0.9.7 + vs2015 + windows 10. I just used the example code and unicode characters won't show up.

agalloch21 commented 7 years ago

Now it works after I change LocaleToUtf8() to a previous version:

string LocaleToUtf8(const string & locale){

int size = MultiByteToWideChar(CP_THREAD_ACP, // code page
                               MB_ERR_INVALID_CHARS, // character-type options
                               locale.c_str(), // address of string to map
                               -1, // NULL terminated
                               NULL, // address of wide-character buffer
                               0) + 1;               // size of buffer

WCHAR * pWideChar = new WCHAR[size];

MultiByteToWideChar(CP_THREAD_ACP, // code page
                    MB_ERR_INVALID_CHARS, // character-type options
                    locale.c_str(), // address of string to map
                    -1, // NULL terminated
                    pWideChar, // address of wide-character buffer
                    size);                // size of buffer

size = WideCharToMultiByte(CP_UTF8, // code page
                           0, // performance and mapping flags
                           pWideChar, // address of wide-character string
                           -1, // NULL terminated
                           NULL, // address of buffer for new string
                           0, // size of buffer
                           NULL, // address of default for unmappable characters
                           NULL) + 1; // address of flag set when default char used

char * pUtf8 = new char[size];

WideCharToMultiByte(CP_UTF8, // code page
                    0, // address of wide-character string
                    pWideChar, // address of wide-character string
                    -1, // NULL terminated
                    pUtf8, // address of buffer for new string
                    size, // size of buffer
                    NULL, // address of default for unmappable characters
                    NULL);     // address of flag set when default char used

string Utf8 = pUtf8;

delete[] pWideChar;
delete[] pUtf8;
return Utf8;

}

gongzai1219 commented 7 years ago

Hi, I encountered the same problem. The example works fine. But when I created a new project, and copied and pasted the code in the example, it did not show the unicode characters. 1499422880 1 Do I need to do some settings? I did not see any suggested steps in your "readme".

ghjingrui0564 commented 5 years ago

Hi, I encountered the same problem. The example works fine. But when I created a new project, and copied and pasted the code in the example, it did not show the unicode characters. 1499422880 1 Do I need to do some settings? I did not see any suggested steps in your "readme".

have you solved the problem yet?

gongzai1219 commented 5 years ago

Hi, I encountered the same problem. The example works fine. But when I created a new project, and copied and pasted the code in the example, it did not show the unicode characters. 1499422880 1 Do I need to do some settings? I did not see any suggested steps in your "readme".

have you solved the problem yet?

Hi, sorry for lllllllate reply. Can you try another Chinese TTF font? I used a '.ttf' font and it worked perfect. And you have to save the file as Unicode (UTF-8 without signature)-Codepage 65001. Hope this can help you.