From bf4e45fc67fc953814debd34f37792eeeabd4534 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 23 Apr 2022 16:21:56 +0200 Subject: [PATCH] Fix Cairo DPI when no wxWindow is associated Always multiply with the content scale factor, also on macOS. --- src/generic/graphicc.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 452cf9c0dd..2460ad932e 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -2764,27 +2764,13 @@ void wxCairoContext::Flush() void wxCairoContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const { - if ( GetWindow() ) - { - const wxSize dpi = GetWindow()->GetDPI(); + const wxSize dpi = GetWindow() ? GetWindow()->GetDPI() : + (wxDisplay::GetStdPPI() * GetContentScaleFactor()); - if ( dpiX ) - *dpiX = dpi.x; - if ( dpiY ) - *dpiY = dpi.y; - } - else - { - double dpi = (double)wxDisplay::GetStdPPIValue(); -#ifndef __WXMAC__ - dpi *= GetContentScaleFactor(); -#endif - - if ( dpiX ) - *dpiX = dpi; - if ( dpiY ) - *dpiY = dpi; - } + if (dpiX ) + *dpiX = dpi.x; + if ( dpiY ) + *dpiY = dpi.y; } void wxCairoContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )