Support of CJK languages in ImGUI:

Added glyph tables & CJK font (huge file!)
Added glyph tables for Turkish and Vietnamese.
Added glyph tables Thai (font is still missing)
This commit is contained in:
bubnikv 2019-05-23 18:04:27 +02:00
parent 0a43cf0674
commit ded5ad0517
4 changed files with 58 additions and 5 deletions

Binary file not shown.

View File

@ -0,0 +1,12 @@
NotoSans-Regular.ttf
--------------------
Name: Noto Sans Regular. Version 2.000;GOOG;noto-source:20170915:90ef993387c0; ttfautohint (v1.7)
It was designed by Monotype Design Team Manufacturer: Monotype Imaging Inc.
© Copyright 2015 Google Inc. All Rights Reserved.
License: This Font Software is licensed under the SIL Open Font License, Version 1.1. This Font Software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the SIL Open Font License for the specific language, permissions and limitations governing your use of this Font Software.
Supported languages: Afrikaans Albanian Azerbaijani Belarusian Bosnian Bulgarian Catalan Croatian Czech Danish Dutch English Estonian Finnish French German Greek Hungarian Icelandic Italian Latvian Lithuanian Macedonian Maltese Norwegian Ossetic Polish Portugese Romanian Russian Serbian Slovak Slovenian Spanisch Swedish Turkish Ukrainian Uzbek Vietnamese Zulu
NotoSansCJK-Regular.ttc
-----------------------
Noto Sans CJK and Noto Serif CJK comprehensively cover Simplified Chinese, Traditional Chinese, Japanese, and Korean in a unified font family. This includes the full coverage of CJK Ideographs with variation support for 4 regions, Kangxi radicals, Japanese Kana, Korean Hangul, and other CJK symbols and letters in the Basic Multilingual Plane of Unicode. It also provides limited coverage of CJK Ideographs in Plane 2 of Unicode as necessary to support standards from China and Japan.
https://www.google.com/get/noto/help/cjk/

View File

@ -28,6 +28,7 @@ namespace GUI {
ImGuiWrapper::ImGuiWrapper()
: m_glyph_ranges(nullptr)
, m_font_cjk(false)
, m_font_size(18.0)
, m_font_texture(0)
, m_style_scaling(1.0)
@ -68,16 +69,52 @@ void ImGuiWrapper::set_language(const std::string &language)
0x0100, 0x017F, // Latin Extended-A
0,
};
static const ImWchar ranges_turkish[] = {
0x0020, 0x01FF, // Basic Latin + Latin Supplement
0x0100, 0x017F, // Latin Extended-A
0x0180, 0x01FF, // Turkish
0,
};
static const ImWchar ranges_vietnamese[] =
{
0x0020, 0x00FF, // Basic Latin
0x0102, 0x0103,
0x0110, 0x0111,
0x0128, 0x0129,
0x0168, 0x0169,
0x01A0, 0x01A1,
0x01AF, 0x01B0,
0x1EA0, 0x1EF9,
0,
};
m_font_cjk = false;
if (lang == "cs" || lang == "pl") {
ranges = ranges_latin2;
} else if (lang == "ru" || lang == "uk") {
ranges = ImGui::GetIO().Fonts->GetGlyphRangesCyrillic();
ranges = ImGui::GetIO().Fonts->GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
} else if (lang == "tr") {
ranges = ranges_turkish;
} else if (lang == "vi") {
ranges = ranges_vietnamese;
} else if (lang == "jp") {
ranges = ImGui::GetIO().Fonts->GetGlyphRangesJapanese();
ranges = ImGui::GetIO().Fonts->GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
m_font_cjk = true;
} else if (lang == "ko") {
ranges = ImGui::GetIO().Fonts->GetGlyphRangesKorean();
ranges = ImGui::GetIO().Fonts->GetGlyphRangesKorean(); // Default + Korean characters
m_font_cjk = true;
} else if (lang == "zh") {
ranges = ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon();
ranges = (language == "zh_TW") ?
// Traditional Chinese
// Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK Unified Ideographs
ImGui::GetIO().Fonts->GetGlyphRangesChineseFull() :
// Simplified Chinese
// Default + Half-Width + Japanese Hiragana/Katakana + set of 2500 CJK Unified Ideographs for common simplified Chinese
ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon();
m_font_cjk = true;
} else if (lang == "th") {
ranges = ImGui::GetIO().Fonts->GetGlyphRangesThai(); // Default + Thai characters
} else {
ranges = ImGui::GetIO().Fonts->GetGlyphRangesDefault(); // Basic Latin, Extended Latin
}
if (ranges != m_glyph_ranges) {
@ -352,7 +389,9 @@ void ImGuiWrapper::init_font()
ImGuiIO& io = ImGui::GetIO();
io.Fonts->Clear();
ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf").c_str(), m_font_size, nullptr, m_glyph_ranges);
//FIXME replace with io.Fonts->AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, m_font_size, nullptr, m_glyph_ranges);
//https://github.com/ocornut/imgui/issues/220
ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/" + (m_font_cjk ? "NotoSansCJK-Regular.ttc" : "NotoSans-Regular.ttf")).c_str(), m_font_size, nullptr, m_glyph_ranges);
if (font == nullptr) {
font = io.Fonts->AddFontDefault();
if (font == nullptr) {

View File

@ -19,6 +19,8 @@ namespace GUI {
class ImGuiWrapper
{
const ImWchar *m_glyph_ranges;
// Chinese, Japanese, Korean
bool m_font_cjk;
float m_font_size;
unsigned m_font_texture;
float m_style_scaling;