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.
This commit is contained in:
Maarten Bent
2019-10-08 21:07:43 +02:00
parent c538e8f9d6
commit 8ceadd3029
2 changed files with 40 additions and 4 deletions

View File

@@ -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
//-----------------------------------------------------------------------------

View File

@@ -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;
}
}
//-----------------------------------------------------------------------------