From 8ceadd3029024b827464010985221e2276585b54 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 8 Oct 2019 21:07:43 +0200 Subject: [PATCH] Improve wxD2DContext::GetDPI and wxGDIPlusContext::GetDPI If there is a valid wxWindow, use its DPI. Otherwise use a dedicated function of the context to get the DPI. Don't use the common wxGraphicsContext::GetDPI because this will return hard-coded 72 when there is no valid wxWindow. --- src/msw/graphics.cpp | 21 +++++++++++++++++++++ src/msw/graphicsd2d.cpp | 23 +++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 6bbf407a73..d3a981c60d 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -458,6 +458,7 @@ public: virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const wxOVERRIDE; virtual bool ShouldOffset() const wxOVERRIDE; virtual void GetSize( wxDouble* width, wxDouble *height ); + virtual void GetDPI(wxDouble* dpiX, wxDouble* dpiY) const wxOVERRIDE; Graphics* GetGraphics() const { return m_context; } @@ -2397,6 +2398,26 @@ void wxGDIPlusContext::GetSize( wxDouble* width, wxDouble *height ) *height = m_height; } +void wxGDIPlusContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const +{ + if ( GetWindow() ) + { + const wxSize dpi = GetWindow()->GetDPI(); + + if ( dpiX ) + *dpiX = dpi.x; + if ( dpiY ) + *dpiY = dpi.y; + } + else + { + if ( dpiX ) + *dpiX = GetGraphics()->GetDpiX(); + if ( dpiY ) + *dpiY = GetGraphics()->GetDpiY(); + } +} + //----------------------------------------------------------------------------- // wxGDIPlusPrintingContext implementation //----------------------------------------------------------------------------- diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index ce6aaeeedc..b84bfa0d1d 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -4576,10 +4576,25 @@ void wxD2DContext::Flush() void wxD2DContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const { - FLOAT x, y; - GetRenderTarget()->GetDpi(&x, &y); - if (dpiX != NULL) *dpiX = x; - if (dpiY != NULL) *dpiY = y; + if ( GetWindow() ) + { + const wxSize dpi = GetWindow()->GetDPI(); + + if ( dpiX ) + *dpiX = dpi.x; + if ( dpiY ) + *dpiY = dpi.y; + } + else + { + FLOAT x, y; + GetRenderTarget()->GetDpi(&x, &y); + + if ( dpiX ) + *dpiX = x; + if ( dpiY ) + *dpiY = y; + } } //-----------------------------------------------------------------------------