From 8d489a5e4bbe809f18a5db15e65b58219cf48354 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 9 Oct 2012 21:01:29 +0000 Subject: [PATCH] Fix printing in landscape mode in wxGTK. Only apply Cairo transforms in StartPage(), doing it earlier interferes with the code doing the coordinate system rotation inside GTK+ itself when a non-portrait printing mode is used. Closes #14732. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72646 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/gtk/print.cpp | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9a7e08d7e1..0e1cb3a0ca 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -575,6 +575,7 @@ wxGTK: - Generate clipboard events for wxComboBox and not only wxTextCtrl. - Improve drag-and-drop of URLs. - Make key event handling consistent with wxMSW (John Rails). +- Fix printing in landscape mode (Marcin Wojdyr). wxMSW: diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index 3c689cbba9..f2f1b27f40 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -1179,8 +1179,6 @@ wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& da #if wxCAIRO_SCALE m_PS2DEV = 1.0; m_DEV2PS = 1.0; - - cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution ); #else m_PS2DEV = (double)m_resolution / 72.0; m_DEV2PS = 72.0 / (double)m_resolution; @@ -1192,15 +1190,6 @@ wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& da m_signX = 1; // default x-axis left to right. m_signY = 1; // default y-axis bottom up -> top down. - - // By default the origin of the Cairo context is in the upper left - // corner of the printable area. We need to translate it so that it - // is in the upper left corner of the paper (without margins) - GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); - gdouble ml, mt; - ml = gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS); - mt = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS); - cairo_translate(m_cairo, -ml, -mt); } wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl() @@ -2102,7 +2091,24 @@ void wxGtkPrinterDCImpl::EndDoc() void wxGtkPrinterDCImpl::StartPage() { - return; + // Notice that we may change the Cairo transformation matrix only here and + // not before (e.g. in wxGtkPrinterDCImpl ctor as we used to do) in order + // to not affect _gtk_print_context_rotate_according_to_orientation() which + // is used in GTK+ itself and wouldn't work correctly if we applied these + // transformations before it is called. + + // By default the origin of the Cairo context is in the upper left + // corner of the printable area. We need to translate it so that it + // is in the upper left corner of the paper (without margins) + GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc ); + gdouble ml, mt; + ml = gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS); + mt = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS); + cairo_translate(m_cairo, -ml, -mt); + +#if wxCAIRO_SCALE + cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution ); +#endif } void wxGtkPrinterDCImpl::EndPage() -- 2.45.2