From 9a215bb393556ae9e2b74a1c504291bff847d5a4 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 16 Apr 2016 21:06:03 +0200 Subject: [PATCH] Fixed creating wxGraphicsContext from wxPrinterDC with Cairo (MSW). Modification of the mapping mode of underlying DC encapsulated in wxPrinterDC (from MM_ANISOTROPIC to MM_TEXT) which is done prior to creating Cairo context affects the value of device origin which needs to be applied to the Cairo context. Due to the change of the mapping mode it has to be rescaled based on the current scaling factor value. See #17496. --- src/generic/graphicc.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 6d6049499e..2000c7bef8 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1746,7 +1746,15 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& ::SetMapMode(hdc, MM_TEXT); m_mswSurface = cairo_win32_printing_surface_create(hdc); Init( cairo_create(m_mswSurface) ); -#endif + + wxSize sz = dc.GetSize(); + m_width = sz.x; + m_height = sz.y; + // Transfer transformation settings from source DC to Cairo context on our own. + // Since we switched from MM_ANISOTROPIC to MM_TEXT mapping mode + // we have to apply rescaled DC's device origin to Cairo context. + ApplyTransformFromDC(dc, Apply_scaled_dev_origin); +#endif // __WXMSW__ #ifdef __WXGTK20__ const wxDCImpl *impl = dc.GetImpl(); @@ -1755,7 +1763,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& Init(cairo_reference(cr)); else m_context = NULL; -#endif + wxSize sz = dc.GetSize(); m_width = sz.x; m_height = sz.y; @@ -1780,6 +1788,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& org = dc.GetLogicalOrigin(); cairo_translate( m_context, -org.x, -org.y ); +#endif } #endif