From 4ad1a3d9695c118ac85c3ea9f6fba519122f5ab4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Jan 2018 14:58:08 +0100 Subject: [PATCH] Return display PPI from wxDC::GetPPI() in wxGTK3 For wxDC associated with a window, such as wx{Window,Client,Paint}DC, this method should return the window PPI, not the hard coded 72 DPI of Cairo graphics context. This still doesn't work correctly when using multiple monitors with different DPI settings, but is still a (modest) improvement. --- include/wx/gtk/dc.h | 5 +++++ src/gtk/dc.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/wx/gtk/dc.h b/include/wx/gtk/dc.h index 6c8fb391e3..de09ee2494 100644 --- a/include/wx/gtk/dc.h +++ b/include/wx/gtk/dc.h @@ -32,9 +32,14 @@ public: virtual bool DoStretchBlit(int xdest, int ydest, int dstWidth, int dstHeight, wxDC* source, int xsrc, int ysrc, int srcWidth, int srcHeight, wxRasterOperationMode rop, bool useMask, int xsrcMask, int ysrcMask) wxOVERRIDE; virtual void* GetCairoContext() const wxOVERRIDE; + virtual wxSize GetPPI() const wxOVERRIDE; + protected: int m_width, m_height; +private: + bool TryGetWindowSize(wxSize& size, wxSize& sizeMM) const; + wxDECLARE_NO_COPY_CLASS(wxGTKCairoDCImpl); }; //----------------------------------------------------------------------------- diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index 711b96d517..ed846c0899 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -15,6 +15,7 @@ #include "wx/dcclient.h" #include "wx/dcmemory.h" #include "wx/dcscreen.h" +#include "wx/gdicmn.h" #include "wx/icon.h" #include "wx/gtk/dc.h" @@ -237,6 +238,18 @@ void* wxGTKCairoDCImpl::GetCairoContext() const return cr; } +wxSize wxGTKCairoDCImpl::GetPPI() const +{ + if ( m_window ) + { + return wxGetDisplayPPI(); + } + + // For a non-window-based DC the concept of PPI doesn't make much sense + // anyhow, so just return the hardcoded value used by the base class. + return wxGCDCImpl::GetPPI(); +} + //----------------------------------------------------------------------------- wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window)