Skip to content
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

gui: option to use system font face #7412

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/OrcaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,6 @@ int CLI::run(int argc, char **argv)
bool start_gui = m_actions.empty() && !downward_check;
if (start_gui) {
BOOST_LOG_TRIVIAL(info) << "no action, start gui directly" << std::endl;
::Label::initSysFont();
#ifdef SLIC3R_GUI
/*#if !defined(_WIN32) && !defined(__APPLE__)
// likely some linux / unix system
Expand Down
6 changes: 6 additions & 0 deletions src/slic3r/GUI/GUI_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ int GUI_Run(GUI_InitParams &params)
try {
//GUI::GUI_App* gui = new GUI::GUI_App(params.start_as_gcodeviewer ? GUI::GUI_App::EAppMode::GCodeViewer : GUI::GUI_App::EAppMode::Editor);
GUI::GUI_App* gui = new GUI::GUI_App();

/* initialize wxWidgets, so we could correctly init fonts */
wxInitialize();
bool useSystemFonts = gui->app_config->get("app", "use_system_fonts") == "true";
::Label::initSysFont(useSystemFonts);

//if (gui->get_app_mode() != GUI::GUI_App::EAppMode::GCodeViewer) {
// G-code viewer is currently not performing instance check, a new G-code viewer is started every time.
bool gui_single_instance_setting = gui->app_config->get("app", "single_instance") == "true";
Expand Down
62 changes: 33 additions & 29 deletions src/slic3r/GUI/Widgets/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@ wxFont Label::sysFont(int size, bool bold)
size = size * 4 / 5;
#endif

wxString face = "HarmonyOS Sans SC";

// Check if the current locale is Korean
if (wxLocale::GetSystemLanguage() == wxLANGUAGE_KOREAN) {
face = "NanumGothic";
}

wxFont font{size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL, false, face};
font.SetFaceName(face);
wxFont font{size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL, false, fontFace};
if (!font.IsOk()) {
BOOST_LOG_TRIVIAL(warning) << boost::format("Can't find %1% font") % face;
BOOST_LOG_TRIVIAL(warning) << boost::format("Can't find %1% font") % fontFace.ToStdString();
font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
BOOST_LOG_TRIVIAL(warning) << boost::format("Use system font instead: %1%") % font.GetFaceName();
if (bold)
Expand Down Expand Up @@ -58,28 +50,40 @@ wxFont Label::Body_10;
wxFont Label::Body_9;
wxFont Label::Body_8;

void Label::initSysFont()
wxString Label::fontFace{"HarmonyOS Sans SC"};

void Label::initSysFont(bool useSystemFonts)
{
if (useSystemFonts) {
fontFace.assign(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetFaceName());
BOOST_LOG_TRIVIAL(info) << "Use system fonts";
} else {
#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");
bool result = wxFont::AddPrivateFont(font_path);
// 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");
result = wxFont::AddPrivateFont(font_path);
// 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 NanumGothic Regular and Bold
font_path = wxString::FromUTF8(resource_path + "/fonts/NanumGothic-Regular.ttf");
result = wxFont::AddPrivateFont(font_path);
// BOOST_LOG_TRIVIAL(info) << boost::format("add font of NanumGothic-Regular returns %1%")%result;
printf("add font of NanumGothic-Regular returns %d\n", result);
font_path = wxString::FromUTF8(resource_path + "/fonts/NanumGothic-Bold.ttf");
result = wxFont::AddPrivateFont(font_path);
// BOOST_LOG_TRIVIAL(info) << boost::format("add font of NanumGothic-Bold returns %1%")%result;
printf("add font of NanumGothic-Bold returns %d\n", result);
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;
printf("add font of HarmonyOS_Sans_SC_Bold returns %d\n", result);
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;
printf("add font of HarmonyOS_Sans_SC_Regular returns %d\n", result);
// Adding NanumGothic Regular and Bold
font_path = wxString::FromUTF8(resource_path + "/fonts/NanumGothic-Regular.ttf");
result = wxFont::AddPrivateFont(font_path);
// BOOST_LOG_TRIVIAL(info) << boost::format("add font of NanumGothic-Regular returns %1%")%result;
printf("add font of NanumGothic-Regular returns %d\n", result);
font_path = wxString::FromUTF8(resource_path + "/fonts/NanumGothic-Bold.ttf");
result = wxFont::AddPrivateFont(font_path);
// BOOST_LOG_TRIVIAL(info) << boost::format("add font of NanumGothic-Bold returns %1%")%result;
printf("add font of NanumGothic-Bold returns %d\n", result);
#endif
// Check if the current locale is Korean
if (wxLocale::GetSystemLanguage() == wxLANGUAGE_KOREAN) {
fontFace.assign("NanumGothic");
}
}

Head_48 = Label::sysFont(48, true);
Head_32 = Label::sysFont(32, true);
Head_24 = Label::sysFont(24, true);
Expand Down
6 changes: 4 additions & 2 deletions src/slic3r/GUI/Widgets/Label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Label : public wxStaticText
wxString m_text;
bool m_skip_size_evt = false;

static wxString fontFace;

public:
static wxFont Head_48;
static wxFont Head_32;
Expand All @@ -53,8 +55,8 @@ class Label : public wxStaticText
static wxFont Body_11;
static wxFont Body_9;
static wxFont Body_8;
static void initSysFont();

static void initSysFont(bool useSystemFont);

static wxFont sysFont(int size, bool bold = false);

Expand Down