diff --git a/include/wx/dc.h b/include/wx/dc.h index 8a3e796114..d6c2881ef2 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -539,6 +539,8 @@ public: virtual double GetContentScaleFactor() const { return m_contentScaleFactor; } + virtual double GetDPIScaleFactor() const { return 1.0; } + #ifdef __WXMSW__ // Native Windows functions using the underlying HDC don't honour GDI+ // transformations which may be applied to it. Using this function we can @@ -827,6 +829,9 @@ public: double GetContentScaleFactor() const { return m_pimpl->GetContentScaleFactor(); } + double GetDPIScaleFactor() const + { return m_pimpl->GetDPIScaleFactor(); } + // Right-To-Left (RTL) modes void SetLayoutDirection(wxLayoutDirection dir) diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index 29671a841b..a57e8168e1 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -101,6 +101,7 @@ public: virtual bool CanGetTextExtent() const wxOVERRIDE; virtual int GetDepth() const wxOVERRIDE; virtual wxSize GetPPI() const wxOVERRIDE; + virtual double GetDPIScaleFactor() const wxOVERRIDE; virtual void SetLogicalFunction(wxRasterOperationMode function) wxOVERRIDE; diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 5defa492d9..849e5353e9 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -880,6 +880,7 @@ public: void SetContentScaleFactor(double contentScaleFactor); double GetContentScaleFactor() const { return m_contentScaleFactor; } + double GetDPIScaleFactor() const; #ifdef __WXMSW__ virtual WXHDC GetNativeHDC() = 0; diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index cbfbccd3f4..ae04c80566 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -77,7 +77,7 @@ public: virtual bool CanGetTextExtent() const wxOVERRIDE; virtual int GetDepth() const wxOVERRIDE; virtual wxSize GetPPI() const wxOVERRIDE; - + virtual double GetDPIScaleFactor() const wxOVERRIDE; virtual void SetMapMode(wxMappingMode mode) wxOVERRIDE; virtual void SetUserScale(double x, double y) wxOVERRIDE; diff --git a/include/wx/msw/dcmemory.h b/include/wx/msw/dcmemory.h index 7449e27885..88547f314d 100644 --- a/include/wx/msw/dcmemory.h +++ b/include/wx/msw/dcmemory.h @@ -27,6 +27,7 @@ public: virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE; virtual void DoGetSize(int* width, int* height) const wxOVERRIDE; virtual void DoSelect(const wxBitmap& bitmap) wxOVERRIDE; + virtual double GetDPIScaleFactor() const wxOVERRIDE; virtual wxBitmap DoGetAsBitmap(const wxRect* subrect) const wxOVERRIDE { return subrect == NULL ? GetSelectedBitmap() : GetSelectedBitmap().GetSubBitmapOfHDC(*subrect, GetHDC() );} diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index da3a4d9f48..368ddfed83 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -24,6 +24,8 @@ #include "wx/geometry.h" #endif +#include "wx/display.h" + //----------------------------------------------------------------------------- // Local functions //----------------------------------------------------------------------------- @@ -485,7 +487,12 @@ wxSize wxGCDCImpl::GetPPI() const // This is the same value that wxGraphicsContext::GetDPI() returns by // default. - return wxSize(72, 72); + return wxDisplay::GetStdPPI(); +} + +double wxGCDCImpl::GetDPIScaleFactor() const +{ + return m_graphicContext ? m_graphicContext->GetDPIScaleFactor() : 1.0; } int wxGCDCImpl::GetDepth() const diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 15a74aa8d5..59803b8789 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -34,6 +34,7 @@ #endif #include "wx/private/graphics.h" +#include "wx/display.h" //----------------------------------------------------------------------------- @@ -612,6 +613,13 @@ void wxGraphicsContext::SetContentScaleFactor(double contentScaleFactor) m_contentScaleFactor = contentScaleFactor; } + double wxGraphicsContext::GetDPIScaleFactor() const +{ + wxDouble x, y; + GetDPI(&x, &y); + return x / (double)wxDisplay::GetStdPPIValue(); +} + #if 0 void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) ) { @@ -635,8 +643,8 @@ void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY) const { // Use some standard DPI value, it doesn't make much sense for the // contexts not using any pixels anyhow. - *dpiX = 72.0; - *dpiY = 72.0; + *dpiX = wxDisplay::GetStdPPIValue(); + *dpiY = wxDisplay::GetStdPPIValue(); } } @@ -908,8 +916,8 @@ wxGraphicsContext::CreateLinearGradientBrush( return GetRenderer()->CreateLinearGradientBrush ( x1, y1, - x2, y2, - gradientStops, + x2, y2, + gradientStops, matrix ); } diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 6dbca59f88..33cc1cf537 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -2661,6 +2661,11 @@ wxSize wxMSWDCImpl::GetPPI() const return ppi; } +double wxMSWDCImpl::GetDPIScaleFactor() const +{ + return GetPPI().x / 96.0; +} + // ---------------------------------------------------------------------------- // DC caching // ---------------------------------------------------------------------------- diff --git a/src/msw/dcmemory.cpp b/src/msw/dcmemory.cpp index 7218fa34eb..83799ff4ed 100644 --- a/src/msw/dcmemory.cpp +++ b/src/msw/dcmemory.cpp @@ -143,6 +143,11 @@ void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) SetFont(GetFont()); } +double wxMemoryDCImpl::GetDPIScaleFactor() const +{ + return m_contentScaleFactor; +} + void wxMemoryDCImpl::SetFont(const wxFont& font) { // We need to adjust the font size by the ratio between the scale factor we