From 580424701b0e4c724d6724a5bc09ccc3ac5c86a0 Mon Sep 17 00:00:00 2001 From: Hotsolidinfill <138652683+Hotsolidinfill@users.noreply.github.com> Date: Fri, 4 Aug 2023 20:15:15 +0900 Subject: [PATCH] fix Korean font not be loaded properly (#1681) * Update Korean Translation - Make overhang printable - Lift Z Enforcement - etc * fix Korean font not be loaded --- src/slic3r/GUI/Widgets/Label.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/Widgets/Label.cpp b/src/slic3r/GUI/Widgets/Label.cpp index 1dd8b616d5..2e25dd2d45 100644 --- a/src/slic3r/GUI/Widgets/Label.cpp +++ b/src/slic3r/GUI/Widgets/Label.cpp @@ -1,6 +1,7 @@ #include "libslic3r/Utils.hpp" #include "Label.hpp" #include "StaticBox.hpp" +#include // For wxLocale wxFont Label::sysFont(int size, bool bold) { @@ -11,11 +12,17 @@ wxFont Label::sysFont(int size, bool bold) size = size * 4 / 5; #endif - auto face = wxString::FromUTF8("HarmonyOS Sans SC"); + wxString face = "HarmonyOS Sans SC"; + + // Check if the current locale is Korean + if (wxLocale::GetSystemLanguage() == wxLANGUAGE_KOREAN) { + face = "Noto Sans KR"; + } + wxFont font{size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL, false, face}; font.SetFaceName(face); if (!font.IsOk()) { - BOOST_LOG_TRIVIAL(warning) << boost::format("Cann't find HarmonyOS Sans SC font"); + BOOST_LOG_TRIVIAL(warning) << boost::format("Can't find %1% font") % face; font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); BOOST_LOG_TRIVIAL(warning) << boost::format("Use system font instead: %1%") % font.GetFaceName(); if (bold) @@ -49,17 +56,25 @@ wxFont Label::Body_9; void Label::initSysFont() { #if defined(__linux__) || defined(_WIN32) - const std::string& resource_path = Slic3r::resources_dir(); - wxString font_path = wxString::FromUTF8(resource_path+"/fonts/HarmonyOS_Sans_SC_Bold.ttf"); + const std::string &resource_path = Slic3r::resources_dir(); + wxString font_path = wxString::FromUTF8(resource_path + "/fonts/HarmonyOS_Sans_SC_Bold.ttf"); bool result = wxFont::AddPrivateFont(font_path); - //BOOST_LOG_TRIVIAL(info) << boost::format("add font of HarmonyOS_Sans_SC_Bold returns %1%")%result; + // BOOST_LOG_TRIVIAL(info) << boost::format("add font of HarmonyOS_Sans_SC_Bold returns %1%")%result; printf("add font of HarmonyOS_Sans_SC_Bold returns %d\n", result); - font_path = wxString::FromUTF8(resource_path+"/fonts/HarmonyOS_Sans_SC_Regular.ttf"); + font_path = wxString::FromUTF8(resource_path + "/fonts/HarmonyOS_Sans_SC_Regular.ttf"); result = wxFont::AddPrivateFont(font_path); - //BOOST_LOG_TRIVIAL(info) << boost::format("add font of HarmonyOS_Sans_SC_Regular returns %1%")%result; + // BOOST_LOG_TRIVIAL(info) << boost::format("add font of HarmonyOS_Sans_SC_Regular returns %1%")%result; printf("add font of HarmonyOS_Sans_SC_Regular returns %d\n", result); + // Adding Noto Sans KR Regular and Bold + font_path = wxString::FromUTF8(resource_path + "/fonts/NotoSansKR-Regular.otf"); + result = wxFont::AddPrivateFont(font_path); + // BOOST_LOG_TRIVIAL(info) << boost::format("add font of NotoSansKR-Regular returns %1%")%result; + printf("add font of NotoSansKR-Regular returns %d\n", result); + font_path = wxString::FromUTF8(resource_path + "/fonts/NotoSansKR-Bold.otf"); + result = wxFont::AddPrivateFont(font_path); + // BOOST_LOG_TRIVIAL(info) << boost::format("add font of NotoSansKR-Bold returns %1%")%result; + printf("add font of NotoSansKR-Bold returns %d\n", result); #endif - Head_48 = Label::sysFont(48, true); Head_32 = Label::sysFont(32, true); Head_24 = Label::sysFont(24, true);