From 1cdd31fa99ab7f26b31e0f1e557667a71bf9cdef Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Mon, 15 Jan 2024 07:01:43 -0600 Subject: [PATCH] Fix garbled text when display scalling > 300% (#3402) * Fix garbled text when display scalling > 300% On Windows, if your display scaling is greater than 300%, the text rendered by imgui will be garbled. Allowing imgui to do the scaling instead of making the font to large corrects the issue. * Only use modified scaling on Windows And only if the system's scaling factor is greater than 300%. --------- Co-authored-by: SoftFever --- src/slic3r/GUI/GLCanvas3D.cpp | 12 +++++++++++- src/slic3r/GUI/ImGuiWrapper.cpp | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ae48ff8eb3..fc50c716a1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -6422,7 +6422,17 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) m_last_w = w; m_last_h = h; - const float font_size = 1.5f * wxGetApp().em_unit(); + float font_size = wxGetApp().em_unit(); + +#ifdef _WIN32 + // On Windows, if manually scaled here, rendering issues can occur when the system's Display + // scaling is greater than 300% as the font's size gets to be to large. So, use imgui font + // scaling instead (see: ImGuiWrapper::init_font() and issue #3401) + font_size *= (font_size > 30.0f) ? 1.0f : 1.5f; +#else + font_size *= 1.5f; +#endif + #if ENABLE_RETINA_GL imgui->set_scaling(font_size, 1.0f, m_retina_helper->get_scale_factor()); #else diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index c385662f91..3926e15630 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -2663,6 +2663,15 @@ void ImGuiWrapper::init_font(bool compress) if (bold_font == nullptr) { throw Slic3r::RuntimeError("ImGui: Could not load deafult font"); } } +#ifdef _WIN32 + // Render the text a bit larger (see GLCanvas3D::_resize() and issue #3401), but only if the scale factor + // for the Display is greater than 300%. + if (wxGetApp().em_unit() > 30) { + default_font->Scale = 1.5f; + bold_font->Scale = 1.5f; + } +#endif + #ifdef __APPLE__ ImFontConfig config; config.MergeMode = true;