Fixed rare font scaling issue on Windows 10.
This commit is contained in:
parent
53b2a033db
commit
563a1a8441
@ -726,7 +726,7 @@ const char* FirmwareDialog::priv::avr109_dev_name(Avr109Pid usb_pid) {
|
|||||||
return "Prusa MMU 2.0 Control";
|
return "Prusa MMU 2.0 Control";
|
||||||
break;
|
break;
|
||||||
case USB_PID_CW1_BOOT:
|
case USB_PID_CW1_BOOT:
|
||||||
return "Prusa CurWa";
|
return "Original Prusa CW1";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: throw std::runtime_error((boost::format("Invalid avr109 device USB PID: %1%") % usb_pid.boot).str());
|
default: throw std::runtime_error((boost::format("Invalid avr109 device USB PID: %1%") % usb_pid.boot).str());
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
#include <wx/checkbox.h>
|
#include <wx/checkbox.h>
|
||||||
#include <wx/dcclient.h>
|
#include <wx/dcclient.h>
|
||||||
|
#include <wx/font.h>
|
||||||
|
#include <wx/fontutil.h>
|
||||||
|
|
||||||
#include "libslic3r/Config.hpp"
|
#include "libslic3r/Config.hpp"
|
||||||
|
|
||||||
@ -113,6 +115,32 @@ int get_dpi_for_window(wxWindow *window)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxFont get_default_font_for_dpi(int dpi)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
// First try to load the font with the Windows 10 specific way.
|
||||||
|
struct SystemParametersInfoForDpi_t { typedef BOOL (WINAPI *FN)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); };
|
||||||
|
static auto SystemParametersInfoForDpi_fn = winapi_get_function<SystemParametersInfoForDpi_t>(L"User32.dll", "SystemParametersInfoForDpi");
|
||||||
|
if (SystemParametersInfoForDpi_fn != nullptr) {
|
||||||
|
NONCLIENTMETRICS nm;
|
||||||
|
memset(&nm, 0, sizeof(NONCLIENTMETRICS));
|
||||||
|
nm.cbSize = sizeof(NONCLIENTMETRICS);
|
||||||
|
if (SystemParametersInfoForDpi_fn(SPI_GETNONCLIENTMETRICS, 0, &nm, 0, dpi)) {
|
||||||
|
wxNativeFontInfo info;
|
||||||
|
info.lf = nm.lfMessageFont;
|
||||||
|
return wxFont(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Then try to guesstimate the font DPI scaling on Windows 8.
|
||||||
|
// Let's hope that the font returned by the SystemParametersInfo(), which is used by wxWidgets internally, makes sense.
|
||||||
|
int dpi_primary = get_dpi_for_window(nullptr);
|
||||||
|
if (dpi_primary != dpi) {
|
||||||
|
// Rescale the font.
|
||||||
|
return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Scaled(float(dpi) / float(dpi_primary));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||||
|
}
|
||||||
|
|
||||||
CheckboxFileDialog::ExtraPanel::ExtraPanel(wxWindow *parent)
|
CheckboxFileDialog::ExtraPanel::ExtraPanel(wxWindow *parent)
|
||||||
: wxPanel(parent, wxID_ANY)
|
: wxPanel(parent, wxID_ANY)
|
||||||
|
@ -34,6 +34,7 @@ void on_window_geometry(wxTopLevelWindow *tlw, std::function<void()> callback);
|
|||||||
enum { DPI_DEFAULT = 96 };
|
enum { DPI_DEFAULT = 96 };
|
||||||
|
|
||||||
int get_dpi_for_window(wxWindow *window);
|
int get_dpi_for_window(wxWindow *window);
|
||||||
|
wxFont get_default_font_for_dpi(int dpi);
|
||||||
|
|
||||||
struct DpiChangedEvent : public wxEvent {
|
struct DpiChangedEvent : public wxEvent {
|
||||||
int dpi;
|
int dpi;
|
||||||
@ -58,12 +59,10 @@ public:
|
|||||||
const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
|
const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
|
||||||
: P(parent, id, title, pos, size, style, name)
|
: P(parent, id, title, pos, size, style, name)
|
||||||
{
|
{
|
||||||
m_scale_factor = (float)get_dpi_for_window(this) / (float)DPI_DEFAULT;
|
int dpi = get_dpi_for_window(this);
|
||||||
|
m_scale_factor = (float)dpi / (float)DPI_DEFAULT;
|
||||||
m_prev_scale_factor = m_scale_factor;
|
m_prev_scale_factor = m_scale_factor;
|
||||||
float scale_primary_display = (float)get_dpi_for_window(nullptr) / (float)DPI_DEFAULT;
|
m_normal_font = get_default_font_for_dpi(dpi);
|
||||||
m_normal_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
|
||||||
if (std::abs(m_scale_factor - scale_primary_display) > 1e-6)
|
|
||||||
m_normal_font = m_normal_font.Scale(m_scale_factor / scale_primary_display);
|
|
||||||
|
|
||||||
// initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
|
// initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
|
||||||
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user