diff --git a/resources/fonts/NotoSans-hinted.zip b/resources/fonts/NotoSans-hinted.zip deleted file mode 100644 index 861c1be8c..000000000 Binary files a/resources/fonts/NotoSans-hinted.zip and /dev/null differ diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 65015e7f6..2205aa00f 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -412,6 +412,7 @@ bool GUI_App::select_language( wxArrayString & names, //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. wxSetlocale(LC_NUMERIC, "C"); Preset::update_suffix_modified(); + m_imgui->set_language(m_wxLocale->GetCanonicalName().ToUTF8().data()); return true; } return false; @@ -440,6 +441,7 @@ bool GUI_App::load_language() //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. wxSetlocale(LC_NUMERIC, "C"); Preset::update_suffix_modified(); + m_imgui->set_language(m_wxLocale->GetCanonicalName().ToUTF8().data()); return true; } } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index e36a68eda..0da858b2a 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -25,7 +25,8 @@ namespace GUI { ImGuiWrapper::ImGuiWrapper() - : m_font_texture(0) + : m_glyph_ranges(nullptr) + , m_font_texture(0) , m_style_scaling(1.0) , m_mouse_buttons(0) , m_disabled(false) @@ -49,6 +50,35 @@ bool ImGuiWrapper::init() return true; } +void ImGuiWrapper::set_language(const std::string &language) +{ + const ImWchar *ranges = nullptr; + size_t idx = language.find('_'); + std::string lang = (idx == std::string::npos) ? language : language.substr(0, idx); + static const ImWchar ranges_latin2[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x0100, 0x017F, // Latin Extended-A + 0, + }; + if (lang == "cs" || lang == "pl") { + ranges = ranges_latin2; + } else if (lang == "ru" || lang == "uk") { + ranges = ImGui::GetIO().Fonts->GetGlyphRangesCyrillic(); + } else if (lang == "jp") { + ranges = ImGui::GetIO().Fonts->GetGlyphRangesJapanese(); + } else if (lang == "kr") { + ranges = ImGui::GetIO().Fonts->GetGlyphRangesKorean(); + } else if (lang == "zh") { + ranges = ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon(); + } + + if (ranges != m_glyph_ranges) { + m_glyph_ranges = ranges; + init_default_font(m_style_scaling); + } +} + void ImGuiWrapper::set_display_size(float w, float h) { ImGuiIO& io = ImGui::GetIO(); @@ -210,7 +240,7 @@ void ImGuiWrapper::init_default_font(float scaling) ImGuiIO& io = ImGui::GetIO(); io.Fonts->Clear(); - ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf").c_str(), font_size * scaling); + ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf").c_str(), font_size * scaling, nullptr, m_glyph_ranges); if (font == nullptr) { font = io.Fonts->AddFontDefault(); if (font == nullptr) { diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index 47a1fb937..0f94f5d38 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -20,6 +20,7 @@ class ImGuiWrapper typedef std::map FontsMap; FontsMap m_fonts; + const ImWchar *m_glyph_ranges; unsigned m_font_texture; float m_style_scaling; unsigned m_mouse_buttons; @@ -32,6 +33,7 @@ public: bool init(); void read_glsl_version(); + void set_language(const std::string &language); void set_display_size(float w, float h); void set_style_scaling(float scaling); bool update_mouse_data(wxMouseEvent &evt); @@ -59,6 +61,7 @@ public: bool want_keyboard() const; bool want_text_input() const; bool want_any_input() const; + private: void init_default_font(float scaling); void create_device_objects();