-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with displaying chinese #307
Comments
If you read the top of https://github.com/ocornut/imgui/blob/master/imgui.cpp you will see the answer is: A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. ImGui will support UTF-8 encoding across the board. Character input depends on you passing the right character code to io.AddInputCharacter(). The example applications do that.
` |
I have tried that, it didn`t work. I try to display chinese characters, but just english. io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 16.0f, NULL, io.Fonts->GetGlyphRangesChinese()); The demo example that I run in widows, also can`t display non-latin characters. |
The Cousine font doesn't have any Asian character. Use Arial Unicode or a font that support those characters. |
I have tried fonts below, but it doesn`t work. It shows "?????" or "口口口" instead. |
Only the last one here has the correct parameter io.Fonts->GetGlyphRangesChinese(). Try to load only one font at a time - If you try to load more than one font you need to change font with PushFont/PopFont. Make sure you use
If you are not sure about your source code encoding, first try with |
I tried what you said, that doesn`t work. |
does "../../extra_fonts/Arial.ttf" exists? It is a full unicode font? |
I copy from C:\Windows\Fonts |
It works here. Are you copying ArialUni.ttf and NOT Arial.ttf ?
[...]
|
What's the size of your font file? |
No, we probably have the same one. You aren't answering all questions clearly when asked, making is harder to help you. Post your program code on pastebin.com or gist. |
I don |
I downloaded ArialUni.ttf online, and added to the project. But below, can`t display any characters, like the first picture I uploaded before. Anyway, thanks for helping! |
|
I tried, even the English can`t be displayed correctly! |
It looks like your problem is with uploading the texture. With the default oversampling settings the texture will be very big and it may not work with your drivers. What rendering backend are you using? Lower quality:
OversampleH is by default 3. You can try 1 or 2. This is mainly because the atlas system is not currently dynamic..we're uploading all 22000 characters to a texture which is a big big waste here. |
The second line has spaces I wonder if perhaps they have incorrect width.
|
What happen if you remove the spacing between 在哪 and 里文 ? You can load a limited range, by copying and modifying this function
If you know the ranges of characters you need. Otherwise, unfortunately you can't yet. I need to rewrite ImFontAtlas to allocate characters dynamically as they are needed. |
It displayed like the third line of the picture that I uploaded. The space is a Chinese character, too. Unfortunately, I don't know the range of Chinese characters. I will try to find it on line later. |
I'd like to know which character it is (it appears like a normal space when pasted on Github).
|
Sorry could you try this one
I'll look at it tomorrow :) |
22K characters? so THAT'S where all the gpu vidmem went |
@hypernewbie Sorry, I don`t understand what you said. Could you tell me more? |
\xE4\xBB\x3F looks like invalid UTF-8 This page doesn't decode it: https://mothereff.in/utf-8
"件" should be \xE4\xBB\xB6 There's no way I can recover the 6 meaningful bits from B6 with 3F, I think it is an encoding bug with Visual Studio. Maybe you have invalid UTF8 data in your file and Visual Studio is being confused. If I paste your data here the data becomes correct (probably corrected/filtered by github). Right after is \xE6\x88\x91 which is 我 |
I have made a change to the UTF-8 decoder to avoid terminating a string on malformed input. So it is easier to understand what's going on, but it is a bug in your data/software/visual studio. Maybe if you just delete the line and input it again it will be correct? As for VRAM correct, it is in my task list to allocate and render memory only when characters are used, but I don't know when I can do it. |
It seems workd after I add prefix 「u8」to the string. Looks like this ImGui::Text(u8"hello 菜单 在哪里文件我是中文a"); // success on Visual Studio 2015
ImGui::Text("hello 菜单 在哪里文件我是中文a"); // didn't workd Maybe it is the problem of Visual Studio ?(unicode font have been loaded as texture data already) |
Using u8 if the standard c++11 way to request a string literal in utf-8. I've been starting to make that more explicit in the docs/examples.
|
@BentleyBlanks i think thats because ur code file is not unicode(u8 or gb2132?) format. |
Facing this weird stuff today. The program just fine 2 minutes ago and I re-compile it then every character becomes white box |
How can I support to display multi-language using format like this It's possible to make it? |
Please read FAQ and |
thx a lot! figured out codecvt works |
It works for me with the code for latest imgui
|
@xfdang: You really should not rely on the system codepage being UTF-8, doing so means your project won't compile correctly on other machines. You're much better off either setting it explicitly, using UTF-8 BOM encoding for your files, or using the |
Now everyone have a good solution |
Such as the title.
The text was updated successfully, but these errors were encountered: