From a65ada2a5ec1466fa2d17567b0220af7750fff42 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Mon, 1 Jan 2024 13:52:10 -0800 Subject: [PATCH] Simplify mm-to-pixel conversion wxDisplay can already tell us the PPI, just convert it to mm. --- src/common/dcbase.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index e1060ae402..e11e10176f 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -1397,13 +1397,17 @@ float wxDCImpl::GetFontPointSizeAdjustment(float dpi) return float(wxDisplay::GetStdPPIValue()) / dpi; } +static void mmToPx(wxWindow* win, double& x, double& y) +{ + const wxSize ppi(win ? wxDisplay(win).GetPPI() : wxGetDisplayPPI()); + x = ppi.x * mm2inches; + y = ppi.y * mm2inches; +} + double wxDCImpl::GetMMToPXx() const { if ( wxIsNullDouble(m_mm_to_pix_x) ) - { - m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / - (double)wxGetDisplaySizeMM().GetWidth(); - } + mmToPx(m_window, m_mm_to_pix_x, m_mm_to_pix_y); return m_mm_to_pix_x; } @@ -1411,10 +1415,7 @@ double wxDCImpl::GetMMToPXx() const double wxDCImpl::GetMMToPXy() const { if ( wxIsNullDouble(m_mm_to_pix_y) ) - { - m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / - (double)wxGetDisplaySizeMM().GetHeight(); - } + mmToPx(m_window, m_mm_to_pix_x, m_mm_to_pix_y); return m_mm_to_pix_y; }