Pangolin
Pangolin copied to clipboard
Non-English character support in GUI
How can I generate a GUI whose buttons are named in Chinese? I have tried in this way :" complete("ui.完成.", false, false), pause("ui.暂停", false, true), save("ui.保存", false, false), resetAll("ui.重置", false, false)" but after I builded it, the GUI's buttons can't display the Chinese chracters. How can I display Chinese characters?? Thanks a lot!!!!!
I would love to support this feature, but I've never tried it. I don't know what is likely to be failing. It's possible I'm assuming ASCII somewhere, or perhaps the font that I've embedded doesn't have those characters.
You could try changing the default pangolin font to one you know should work by editing:
glfont.cpp, line 54 to take a filename instead of the embedded data.
I committed 53c6d6f93506de1baca1521bae0aff27532e8dcb to make it easy to use different fonts and 0abbfe803ce4b28b00b8a15275a7431a054c5d6e to fix a bug loading larger font files (which I encountered trying to load a font which supported Chinese characters).
With those fixes, Chinese text still shows blank because the relevant codepoints are not getting loaded here https://github.com/stevenlovegrove/Pangolin/blob/84569fa5ec75b74b9b79b24012dda2a70ca4ac26/components/pango_opengl/src/glfont.cpp#L104.
Using the stb_truetype.h library I can't work out how to find all available codepoints in the font file to put in the font texture. I'm also currently using a dense kern table which would probably need to be sparse if there are large number of characters (how many are there typically?) https://github.com/stevenlovegrove/Pangolin/blob/84569fa5ec75b74b9b79b24012dda2a70ca4ac26/components/pango_opengl/src/glfont.cpp#L127.
Perhaps someone familiar with stb_truetype.h and Chinese text has some ideas?
Using the stb_truetype.h library I can't work out how to find all available codepoints in the font file to put in the font texture. I'm also currently using a dense kern table which would probably need to be sparse if there are large number of characters (how many are there typically?)
There are ~3k high-frequency characters and overall in order of 10,000 in encoding systems like Unicode
I made a start on adding support today and have a branch which I believe is working here: https://github.com/stevenlovegrove/Pangolin/blob/unicode/examples/SimpleDisplay/main.cpp#L45

I've not merged it into the master branch yet because the loading time is very long (for generating the kern table I think) and I had to increase the font texture size which I would like to do dynamically so that people loading smaller fonts don't have to pay the penalty.
Since I can't read any languages with extended character sets I would appreciate anyone who can trying out the branch and playing around a little to make sure it is working as expected (you'll just have to wait several seconds for the program to start whilst the font is loaded for now).
The font (tested with https://fonts.google.com/specimen/Zhi+Mang+Xing?subset=chinese-simplified&preview.text=%E4%BB%96%E4%BB%AC%E6%89%80%E6%9C%89%E7%9A%84%E8%AE%BE%E5%A4%87%E5%92%8C%E4%BB%AA%E5%99%A8%E5%BD%B7%E4%BD%9B%E9%83%BD%E6%98%AF%E6%9C%89%E7%94%9F%E5%91%BD%E7%9A%84%E3%80%82&preview.text_type=custom) is hardcoded for now on this line which you should modify for experimenting: https://github.com/stevenlovegrove/Pangolin/blob/unicode/examples/SimpleDisplay/main.cpp#L17