From 4b6c0718e9c373c0c74636871c71fb7d5da19f32 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 7 Apr 2016 19:30:01 +0200 Subject: [PATCH] Fixed inheriting wxMemoryDC transformation settings by wxGraphicsContext with Cairo renderer (GTK+ 2). When wxGraphicsContext is created from wxMemoryDC then transformation settings applied to the source wxMemoryDC are not passed directly to the Cairo context through underlying GdkDrawable and therefore they need to be passed to the context explicitly. These inherited transformations settings should be used only internally by wxGraphicsContext object and shouldn't be exposed through e.g. GetTransform() function and hence they are stored separately (in a dedicated variable) and "subtracted" from actual transformation settings for reporting purposes. Closes #17482. --- src/generic/graphicc.cpp | 57 ++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 419252ce5f..61e618543a 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -491,6 +491,7 @@ protected: virtual void DoDrawText( const wxString &str, wxDouble x, wxDouble y ) wxOVERRIDE; void Init(cairo_t *context); + void ApplyTransformFromDC(const wxDC& dc); #ifdef __WXQT__ QPainter* m_qtPainter; @@ -1928,22 +1929,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& cairo_matrix_init(&m_internalTransform, 1.0, 0.0, 0.0, -1.0, 0.0, height); // Transfer transformation settings from source DC to Cairo context on our own. - wxPoint org = dc.GetDeviceOrigin(); - cairo_matrix_translate(&m_internalTransform, org.x, org.y); - - double sx, sy; - dc.GetUserScale(&sx, &sy); - double lsx, lsy; - dc.GetLogicalScale(&lsx, &lsy); - sx *= lsx; - sy *= lsy; - cairo_matrix_scale(&m_internalTransform, sx, sy); - - org = dc.GetLogicalOrigin(); - cairo_matrix_translate(&m_internalTransform, -org.x, -org.y); - - // Apply all above transformations. - cairo_set_matrix(m_context, &m_internalTransform); + ApplyTransformFromDC(dc); } #endif // __WXMSW__ @@ -1955,21 +1941,8 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); -#if 0 - wxGraphicsMatrix matrix = CreateMatrix(); - - wxPoint org = dc.GetDeviceOrigin(); - matrix.Translate( org.x, org.y ); - - org = dc.GetLogicalOrigin(); - matrix.Translate( -org.x, -org.y ); - - double sx,sy; - dc.GetUserScale( &sx, &sy ); - matrix.Scale( sx, sy ); - - ConcatTransform( matrix ); -#endif + // Transfer transformation settings from source DC to Cairo context on our own. + ApplyTransformFromDC(dc); #endif #ifdef __WXX11__ @@ -2132,6 +2105,28 @@ void wxCairoContext::Init(cairo_t *context) PushState(); } +void wxCairoContext::ApplyTransformFromDC(const wxDC& dc) +{ + // Transfer transformation settings from source DC to Cairo context + // and store it as an internal transformation + // (which is not going to be exposed). + wxPoint org = dc.GetDeviceOrigin(); + cairo_matrix_translate(&m_internalTransform, org.x, org.y); + + double sx, sy; + dc.GetUserScale(&sx, &sy); + double lsx, lsy; + dc.GetLogicalScale(&lsx, &lsy); + sx *= lsx; + sy *= lsy; + cairo_matrix_scale(&m_internalTransform, sx, sy); + + org = dc.GetLogicalOrigin(); + cairo_matrix_translate(&m_internalTransform, -org.x, -org.y); + + // Apply all above transformations. + cairo_set_matrix(m_context, &m_internalTransform); +} void wxCairoContext::Clip( const wxRegion& region ) {