]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/print.cpp
Fix compilation with MinGW -std=c++11 option.
[wxWidgets.git] / src / gtk / print.cpp
index fc72bdf4d525f1fd1302d7453613400d3f5f6f4b..6076ef552fadeef910f45033c3c0750e51e2ddc1 100644 (file)
@@ -1,9 +1,9 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        wx/gtk/print.cpp
+// Name:        src/gtk/print.cpp
 // Author:      Anthony Bretaudeau
 // Purpose:     GTK printing support
 // Created:     2007-08-25
-// RCS-ID:      $Id: print.cpp,v 1 2007-08-25 05:44:44 PC Exp $
+// RCS-ID:      $Id$
 // Copyright:   (c) 2007 wxWidgets development team
 // Licence:     wxWindows Licence
 /////////////////////////////////////////////////////////////////////////////
 #endif
 
 #include "wx/fontutil.h"
-#include "wx/gtk/private.h"
 #include "wx/dynlib.h"
 #include "wx/paper.h"
-#include "wx/rawbmp.h"
+#include "wx/scopeguard.h"
+#include "wx/testing.h"
 
 #include <gtk/gtk.h>
+
+#if GTK_CHECK_VERSION(2,14,0)
+#include <gtk/gtkunixprint.h>
+#else
 #include <gtk/gtkpagesetupunixdialog.h>
+#endif
+
+
+#if wxUSE_GRAPHICS_CONTEXT
+#include "wx/graphics.h"
+#endif
 
 #include "wx/link.h"
 wxFORCE_LINK_THIS_MODULE(gtk_print)
@@ -46,12 +56,12 @@ wxFORCE_LINK_THIS_MODULE(gtk_print)
 #include "wx/gtk/gnome/gprint.h"
 #endif
 
-// Usefull to convert angles from/to Rad to/from Deg.
+#include "wx/gtk/private/object.h"
+
+// Useful to convert angles from/to Rad to/from Deg.
 static const double RAD2DEG  = 180.0 / M_PI;
 static const double DEG2RAD  = M_PI / 180.0;
 
-static wxCairoLibrary* gs_cairo = NULL;
-
 //----------------------------------------------------------------------------
 // wxGtkPrintModule
 // Initialized when starting the app : if it successfully load the gtk-print framework,
@@ -66,11 +76,11 @@ public:
     {
 #if wxUSE_LIBGNOMEPRINT
         // This module must be initialized AFTER gnomeprint's one
-        AddDependency(CLASSINFO(wxGnomePrintModule));
+        AddDependency(wxCLASSINFO(wxGnomePrintModule));
 #endif
     }
     bool OnInit();
-    void OnExit();
+    void OnExit() {}
 
 private:
     DECLARE_DYNAMIC_CLASS(wxGtkPrintModule)
@@ -78,17 +88,15 @@ private:
 
 bool wxGtkPrintModule::OnInit()
 {
-    gs_cairo = wxCairoLibrary::Get();
-    if (gs_cairo && gtk_check_version(2,10,0) == NULL)
+#ifndef __WXGTK3__
+    if (gtk_check_version(2,10,0) == NULL)
+#endif
+    {
         wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory );
+    }
     return true;
 }
 
-void wxGtkPrintModule::OnExit()
-{
-    gs_cairo = NULL;
-}
-
 IMPLEMENT_DYNAMIC_CLASS(wxGtkPrintModule, wxModule)
 
 //----------------------------------------------------------------------------
@@ -217,25 +225,6 @@ extern "C"
 
         printout->OnEndPrinting();
     }
-
-    static gboolean
-    gtk_preview_print_callback(GtkPrintOperation * WXUNUSED(operation),
-                               GtkPrintOperationPreview * WXUNUSED(preview),
-                               GtkPrintContext *context,
-                               GtkWindow *parent,
-                               gpointer user_data)
-    {
-        wxPrintout *printout = (wxPrintout *) user_data;
-
-        printout->SetIsPreview(true);
-
-        /* We create a Cairo context with 72dpi resolution. This resolution is
-         * only used for positioning. */
-        cairo_t *cairo = gdk_cairo_create(GTK_WIDGET(parent)->window);
-        gtk_print_context_set_cairo_context(context, cairo, 72, 72);
-
-        return false;
-    }
 }
 
 //----------------------------------------------------------------------------
@@ -247,11 +236,13 @@ IMPLEMENT_CLASS(wxGtkPrintNativeData, wxPrintNativeDataBase)
 wxGtkPrintNativeData::wxGtkPrintNativeData()
 {
     m_config = gtk_print_settings_new();
+    m_job = NULL;
+    m_context = NULL;
 }
 
 wxGtkPrintNativeData::~wxGtkPrintNativeData()
 {
-    g_object_unref (m_config);
+    g_object_unref(m_config);
 }
 
 // Convert datas stored in m_config to a wxPrintData.
@@ -261,15 +252,24 @@ bool wxGtkPrintNativeData::TransferTo( wxPrintData &data )
     if(!m_config)
         return false;
 
-    GtkPrintQuality quality = gtk_print_settings_get_quality(m_config);
-    if (quality == GTK_PRINT_QUALITY_HIGH)
-        data.SetQuality(wxPRINT_QUALITY_HIGH);
-    else if (quality == GTK_PRINT_QUALITY_LOW)
-        data.SetQuality(wxPRINT_QUALITY_LOW);
-    else if (quality == GTK_PRINT_QUALITY_DRAFT)
-        data.SetQuality(wxPRINT_QUALITY_DRAFT);
-    else
-        data.SetQuality(wxPRINT_QUALITY_MEDIUM);
+    int resolution = gtk_print_settings_get_resolution(m_config);
+    if ( resolution > 0 )
+    {
+        // if resolution is explicitly set, use it
+        data.SetQuality(resolution);
+    }
+    else // use more vague "quality"
+    {
+        GtkPrintQuality quality = gtk_print_settings_get_quality(m_config);
+        if (quality == GTK_PRINT_QUALITY_HIGH)
+            data.SetQuality(wxPRINT_QUALITY_HIGH);
+        else if (quality == GTK_PRINT_QUALITY_LOW)
+            data.SetQuality(wxPRINT_QUALITY_LOW);
+        else if (quality == GTK_PRINT_QUALITY_DRAFT)
+            data.SetQuality(wxPRINT_QUALITY_DRAFT);
+        else
+            data.SetQuality(wxPRINT_QUALITY_MEDIUM);
+    }
 
     data.SetNoCopies(gtk_print_settings_get_n_copies(m_config));
 
@@ -402,6 +402,9 @@ bool wxGtkPrintNativeData::TransferTo( wxPrintData &data )
         data.SetPaperId( wxPAPER_FANFOLD_LGL_GERMAN);
     else
         data.SetPaperId(wxPAPER_NONE);
+
+    data.SetPrinterName(gtk_print_settings_get_printer(m_config));
+
     return true;
 }
 
@@ -550,6 +553,8 @@ bool wxGtkPrintNativeData::TransferFrom( const wxPrintData &data )
         default:                break;
     }
 
+    gtk_print_settings_set_printer(m_config, data.GetPrinterName().utf8_str());
+
     return true;
 }
 
@@ -619,7 +624,7 @@ wxGtkPrintDialog::~wxGtkPrintDialog()
 // This is called even if we actually don't want the dialog to appear.
 int wxGtkPrintDialog::ShowModal()
 {
-    GtkPrintOperationResult response;
+    WX_TESTING_SHOW_MODAL_HOOK();
 
     // We need to restore the settings given in the constructor.
     wxPrintData data = m_printDialogData.GetPrintData();
@@ -645,17 +650,26 @@ int wxGtkPrintDialog::ShowModal()
         gtk_print_settings_set_page_ranges (settings, range, 1);
     }
 
+    GtkPrintOperation * const printOp = native->GetPrintJob();
+
     // If the settings are OK, we restore it.
     if (settings != NULL)
-        gtk_print_operation_set_print_settings (native->GetPrintJob(), settings);
-    gtk_print_operation_set_default_page_setup (native->GetPrintJob(), native->GetPageSetupFromSettings(settings));
+        gtk_print_operation_set_print_settings (printOp, settings);
+    gtk_print_operation_set_default_page_setup (printOp, native->GetPageSetupFromSettings(settings));
 
     // Show the dialog if needed.
     GError* gError = NULL;
-    if (GetShowDialog())
-        response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError);
-    else
-        response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError);
+    GtkPrintOperationResult response = gtk_print_operation_run
+                                       (
+                                           printOp,
+                                           GetShowDialog()
+                                            ? GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
+                                            : GTK_PRINT_OPERATION_ACTION_PRINT,
+                                           m_parent
+                                            ? GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget))
+                                            : NULL,
+                                           &gError
+                                       );
 
     // Does everything went well?
     if (response == GTK_PRINT_OPERATION_RESULT_CANCEL)
@@ -664,16 +678,22 @@ int wxGtkPrintDialog::ShowModal()
     }
     else if (response == GTK_PRINT_OPERATION_RESULT_ERROR)
     {
+        wxLogError(_("Error while printing: ") + wxString(gError ? gError->message : "???"));
         g_error_free (gError);
-        wxLogError(_("Error while printing: ") + wxString::Format(_("%s"), gError->message));
         return wxID_NO; // We use wxID_NO because there is no wxID_ERROR available
     }
 
     // Now get the settings and save it.
-    GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings (native->GetPrintJob());
+    GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings(printOp);
     native->SetPrintConfig(newSettings);
     data.ConvertFromNative();
 
+    // Set PrintDialogData variables
+    m_printDialogData.SetPrintData(data);
+    m_printDialogData.SetCollate(data.GetCollate());
+    m_printDialogData.SetNoCopies(data.GetNoCopies());
+    m_printDialogData.SetPrintToFile(data.GetPrinterName() == "Print to File");
+
     // Same problem as a few lines before.
     switch (gtk_print_settings_get_print_pages(newSettings))
     {
@@ -730,6 +750,8 @@ wxGtkPageSetupDialog::~wxGtkPageSetupDialog()
 
 int wxGtkPageSetupDialog::ShowModal()
 {
+    WX_TESTING_SHOW_MODAL_HOOK();
+
     // Get the config.
     m_pageDialogData.GetPrintData().ConvertToNative();
     wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData();
@@ -751,43 +773,82 @@ int wxGtkPageSetupDialog::ShowModal()
         }
     }
 
-    // Now show the dialog.
-    GtkPageSetup* newPageSetup = gtk_print_run_page_setup_dialog (GTK_WINDOW(m_parent->m_widget),
-                                                           oldPageSetup,
-                                                           nativeData);
-
-    int ret;
-    if (newPageSetup != oldPageSetup)
-    {
-        native->SetPageSetupToSettings(nativeData, newPageSetup);
-        m_pageDialogData.GetPrintData().ConvertFromNative();
 
-        // Store custom paper format if any.
-        if (m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE)
-        {
-            gdouble ml,mr,mt,mb,pw,ph;
-            ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM);
-            mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM);
-            mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM);
-            mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM);
+    // Set selected printer
+    gtk_print_settings_set(nativeData, "format-for-printer",
+                           gtk_print_settings_get_printer(nativeData));
 
-            pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM);
-            ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM);
+    // Create custom dialog
+    wxString title(GetTitle());
+    if ( title.empty() )
+        title = _("Page Setup");
+    GtkWidget *
+        dlg = gtk_page_setup_unix_dialog_new(title.utf8_str(),
+                                             m_parent
+                                                ? GTK_WINDOW(m_parent->m_widget)
+                                                : NULL);
 
-            m_pageDialogData.SetMarginTopLeft( wxPoint( (int)(ml+0.5), (int)(mt+0.5)) );
-            m_pageDialogData.SetMarginBottomRight( wxPoint( (int)(mr+0.5), (int)(mb+0.5)) );
+    gtk_page_setup_unix_dialog_set_print_settings(
+        GTK_PAGE_SETUP_UNIX_DIALOG(dlg), nativeData);
+    gtk_page_setup_unix_dialog_set_page_setup(
+        GTK_PAGE_SETUP_UNIX_DIALOG(dlg), oldPageSetup);
 
-            m_pageDialogData.SetPaperSize( wxSize( (int)(pw+0.5), (int)(ph+0.5) ) );
-        }
+    int result = gtk_dialog_run(GTK_DIALOG(dlg));
+    gtk_widget_hide(dlg);
 
-        ret = wxID_OK;
-    }
-    else
+    switch ( result )
     {
-        ret = wxID_CANCEL;
+        case GTK_RESPONSE_OK:
+        case GTK_RESPONSE_APPLY:
+            {
+                // Store Selected Printer Name
+                gtk_print_settings_set_printer
+                (
+                    nativeData,
+                    gtk_print_settings_get(nativeData, "format-for-printer")
+                );
+
+                wxGtkObject<GtkPageSetup>
+                    newPageSetup(gtk_page_setup_unix_dialog_get_page_setup(
+                                        GTK_PAGE_SETUP_UNIX_DIALOG(dlg)));
+                native->SetPageSetupToSettings(nativeData, newPageSetup);
+
+                m_pageDialogData.GetPrintData().ConvertFromNative();
+
+                // Store custom paper format if any.
+                if ( m_pageDialogData.GetPrintData().GetPaperId() == wxPAPER_NONE )
+                {
+                    gdouble ml,mr,mt,mb,pw,ph;
+                    ml = gtk_page_setup_get_left_margin (newPageSetup, GTK_UNIT_MM);
+                    mr = gtk_page_setup_get_right_margin (newPageSetup, GTK_UNIT_MM);
+                    mt = gtk_page_setup_get_top_margin (newPageSetup, GTK_UNIT_MM);
+                    mb = gtk_page_setup_get_bottom_margin (newPageSetup, GTK_UNIT_MM);
+
+                    pw = gtk_page_setup_get_paper_width (newPageSetup, GTK_UNIT_MM);
+                    ph = gtk_page_setup_get_paper_height (newPageSetup, GTK_UNIT_MM);
+
+                    m_pageDialogData.SetMarginTopLeft(wxPoint((int)(ml+0.5),
+                                                              (int)(mt+0.5)));
+                    m_pageDialogData.SetMarginBottomRight(wxPoint((int)(mr+0.5),
+                                                                  (int)(mb+0.5)));
+
+                    m_pageDialogData.SetPaperSize(wxSize((int)(pw+0.5),
+                                                         (int)(ph+0.5)));
+                }
+
+                result = wxID_OK;
+            }
+            break;
+
+        default:
+        case GTK_RESPONSE_CANCEL:
+            result = wxID_CANCEL;
+            break;
     }
 
-    return ret;
+    gtk_widget_destroy(dlg);
+
+    return result;
 }
 
 //----------------------------------------------------------------------------
@@ -848,11 +909,10 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
     wxPrintData printdata = GetPrintDialogData().GetPrintData();
     wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
 
-    GtkPrintOperation *printOp = gtk_print_operation_new ();
-
-    native->SetPrintJob( printOp );
-
-    printout->SetIsPreview(false);
+    wxGtkObject<GtkPrintOperation> printOp(gtk_print_operation_new());
+    native->SetPrintJob(printOp);
+    wxON_BLOCK_EXIT_OBJ1(*native, wxGtkPrintNativeData::SetPrintJob,
+                         static_cast<GtkPrintOperation*>(NULL));
 
     wxPrinterToGtkData dataToSend;
     dataToSend.printer = this;
@@ -862,7 +922,6 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
     g_signal_connect (printOp, "begin-print", G_CALLBACK (gtk_begin_print_callback), &dataToSend);
     g_signal_connect (printOp, "draw-page", G_CALLBACK (gtk_draw_page_print_callback), &dataToSend);
     g_signal_connect (printOp, "end-print", G_CALLBACK (gtk_end_print_callback), printout);
-    g_signal_connect (printOp, "preview", G_CALLBACK (gtk_preview_print_callback), printout);
 
     // This is used to setup the DC and
     // show the dialog if desired
@@ -882,8 +941,6 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
         wxFAIL_MSG(_("The print dialog returned an error."));
     }
 
-    g_object_unref (printOp);
-
     return (sm_lastError == wxPRINTER_NO_ERROR);
 }
 
@@ -892,6 +949,12 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation
     wxPrintData printdata = GetPrintDialogData().GetPrintData();
     wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
 
+    // We need to update printdata with the new data from the dialog and we
+    // have to do this here because this method needs this new data and we
+    // cannot update it earlier
+    native->SetPrintConfig(gtk_print_operation_get_print_settings(operation));
+    printdata.ConvertFromNative();
+
     SetPrintContext(context);
     native->SetPrintContext( context );
 
@@ -907,11 +970,8 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation
         }
         return;
     }
-    wxSize ScreenPixels = wxGetDisplaySize();
-    wxSize ScreenMM = wxGetDisplaySizeMM();
 
-    printout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
-                            (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
+    printout->SetPPIScreen(wxGetDisplayPPI());
     printout->SetPPIPrinter( printDC->GetResolution(),
                              printDC->GetResolution() );
 
@@ -1066,7 +1126,7 @@ wxDC* wxGtkPrinter::PrintDialog( wxWindow *parent )
     }
 
     m_printDialogData = dialog.GetPrintDialogData();
-    
+
     return new wxPrinterDC( m_printDialogData.GetPrintData() );
 }
 
@@ -1080,16 +1140,28 @@ bool wxGtkPrinter::Setup( wxWindow * WXUNUSED(parent) )
 // wxGtkPrinterDC
 //-----------------------------------------------------------------------------
 
+#define wxCAIRO_SCALE 1
+
+#if wxCAIRO_SCALE
+
+#define XLOG2DEV(x)     LogicalToDeviceX(x)
+#define XLOG2DEVREL(x)  LogicalToDeviceXRel(x)
+#define YLOG2DEV(x)     LogicalToDeviceY(x)
+#define YLOG2DEVREL(x)  LogicalToDeviceYRel(x)
+
+#else
+
 #define XLOG2DEV(x)     ((double)(LogicalToDeviceX(x)) * m_DEV2PS)
 #define XLOG2DEVREL(x)  ((double)(LogicalToDeviceXRel(x)) * m_DEV2PS)
 #define YLOG2DEV(x)     ((double)(LogicalToDeviceY(x)) * m_DEV2PS)
 #define YLOG2DEVREL(x)  ((double)(LogicalToDeviceYRel(x)) * m_DEV2PS)
 
+#endif
 
 IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl, wxDCImpl)
 
-wxGtkPrinterDCImpl::wxGtkPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data ) :
-   wxDCImpl( owner )
+wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& data)
+                  : wxDCImpl( owner )
 {
     m_printData = data;
 
@@ -1103,30 +1175,26 @@ wxGtkPrinterDCImpl::wxGtkPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& d
     if (m_resolution < 0)
         m_resolution = (1 << (m_resolution+4)) *150;
 
-    m_PS2DEV = (double)m_resolution / 72.0;
-    m_DEV2PS = 72.0 / (double)m_resolution;
-
     m_context = gtk_print_context_create_pango_context( m_gpc );
     m_layout = gtk_print_context_create_pango_layout ( m_gpc );
     m_fontdesc = pango_font_description_from_string( "Sans 12" );
 
     m_cairo = gtk_print_context_get_cairo_context ( m_gpc );
 
+#if wxCAIRO_SCALE
+    m_PS2DEV = 1.0;
+    m_DEV2PS = 1.0;
+#else
+    m_PS2DEV = (double)m_resolution / 72.0;
+    m_DEV2PS = 72.0 / (double)m_resolution;
+#endif
+
     m_currentRed = 0;
     m_currentBlue = 0;
     m_currentGreen = 0;
 
     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);
-    gs_cairo->cairo_translate(m_cairo, -ml, -mt);
 }
 
 wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
@@ -1140,10 +1208,20 @@ bool wxGtkPrinterDCImpl::IsOk() const
     return m_gpc != NULL;
 }
 
+void* wxGtkPrinterDCImpl::GetCairoContext() const
+{
+    return (void*) cairo_reference( m_cairo );
+}
+
+void* wxGtkPrinterDCImpl::GetHandle() const
+{
+    return GetCairoContext();
+}
+
 bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1),
                                wxCoord WXUNUSED(y1),
                                const wxColour& WXUNUSED(col),
-                               int WXUNUSED(style))
+                               wxFloodFillStyle WXUNUSED(style))
 {
     // We can't access the given coord as a Cairo context is scalable, ie a
     // coord doesn't mean anything in this context.
@@ -1160,7 +1238,8 @@ void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect& rect, const wxCo
     wxCoord w =  rect.width;
     wxCoord h = rect.height;
 
-    double radius = sqrt((w/2)*(w/2)+(h/2)*(h/2));
+    const double r2 = (w/2)*(w/2)+(h/2)*(h/2);
+    double radius = sqrt(r2);
 
     unsigned char redI = initialColour.Red();
     unsigned char blueI = initialColour.Blue();
@@ -1182,16 +1261,16 @@ void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect& rect, const wxCo
 
     // Create a pattern with the gradient.
     cairo_pattern_t* gradient;
-    gradient = gs_cairo->cairo_pattern_create_radial (XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), 0, XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), radius * m_DEV2PS );
-    gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS);
-    gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS);
+    gradient = cairo_pattern_create_radial (XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), 0, XLOG2DEV(xC+xR), YLOG2DEV(yC+yR), radius * m_DEV2PS );
+    cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS);
+    cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS);
 
     // Fill the rectangle with this pattern.
-    gs_cairo->cairo_set_source(m_cairo, gradient);
-    gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEV(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) );
-    gs_cairo->cairo_fill(m_cairo);
+    cairo_set_source(m_cairo, gradient);
+    cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEV(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) );
+    cairo_fill(m_cairo);
 
-    gs_cairo->cairo_pattern_destroy(gradient);
+    cairo_pattern_destroy(gradient);
 
     CalcBoundingBox(xR, yR);
     CalcBoundingBox(xR+w, yR+h);
@@ -1224,24 +1303,24 @@ void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect& rect, const wxColour
 
     // Create a pattern with the gradient.
     cairo_pattern_t* gradient;
-    gradient = gs_cairo->cairo_pattern_create_linear (XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x+w), YLOG2DEV(y));
+    gradient = cairo_pattern_create_linear (XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x+w), YLOG2DEV(y));
 
     if (nDirection == wxWEST)
     {
-        gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 0.0, redDPS, greenDPS, blueDPS, alphaDPS);
-        gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 1.0, redIPS, greenIPS, blueIPS, alphaIPS);
+        cairo_pattern_add_color_stop_rgba (gradient, 0.0, redDPS, greenDPS, blueDPS, alphaDPS);
+        cairo_pattern_add_color_stop_rgba (gradient, 1.0, redIPS, greenIPS, blueIPS, alphaIPS);
     }
     else {
-        gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS);
-        gs_cairo->cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS);
+        cairo_pattern_add_color_stop_rgba (gradient, 0.0, redIPS, greenIPS, blueIPS, alphaIPS);
+        cairo_pattern_add_color_stop_rgba (gradient, 1.0, redDPS, greenDPS, blueDPS, alphaDPS);
     }
 
     // Fill the rectangle with this pattern.
-    gs_cairo->cairo_set_source(m_cairo, gradient);
-    gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(w), YLOG2DEVREL(h) );
-    gs_cairo->cairo_fill(m_cairo);
+    cairo_set_source(m_cairo, gradient);
+    cairo_rectangle (m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(w), YLOG2DEVREL(h) );
+    cairo_fill(m_cairo);
 
-    gs_cairo->cairo_pattern_destroy(gradient);
+    cairo_pattern_destroy(gradient);
 
     CalcBoundingBox(x, y);
     CalcBoundingBox(x+w, y+h);
@@ -1257,12 +1336,13 @@ bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1),
 
 void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
 {
-    if  (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if ( m_pen.IsTransparent() )
+        return;
 
     SetPen( m_pen );
-    gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) );
-    gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV(x2), YLOG2DEV(y2) );
-    gs_cairo->cairo_stroke ( m_cairo );
+    cairo_move_to ( m_cairo, XLOG2DEV(x1), YLOG2DEV(y1) );
+    cairo_line_to ( m_cairo, XLOG2DEV(x2), YLOG2DEV(y2) );
+    cairo_stroke ( m_cairo );
 
     CalcBoundingBox( x1, y1 );
     CalcBoundingBox( x2, y2 );
@@ -1275,12 +1355,12 @@ void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x, wxCoord y)
 
     SetPen(m_pen);
 
-    gs_cairo->cairo_move_to (m_cairo, XLOG2DEV(x), 0);
-    gs_cairo->cairo_line_to (m_cairo, XLOG2DEV(x), YLOG2DEVREL(h));
-    gs_cairo->cairo_move_to (m_cairo, 0, YLOG2DEV(y));
-    gs_cairo->cairo_line_to (m_cairo, XLOG2DEVREL(w), YLOG2DEV(y));
+    cairo_move_to (m_cairo, XLOG2DEV(x), 0);
+    cairo_line_to (m_cairo, XLOG2DEV(x), YLOG2DEVREL(h));
+    cairo_move_to (m_cairo, 0, YLOG2DEV(y));
+    cairo_line_to (m_cairo, XLOG2DEVREL(w), YLOG2DEV(y));
 
-    gs_cairo->cairo_stroke (m_cairo);
+    cairo_stroke (m_cairo);
     CalcBoundingBox( 0, 0 );
     CalcBoundingBox( w, h );
 }
@@ -1320,17 +1400,17 @@ void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,w
     alpha1 *= DEG2RAD;
     alpha2 *= DEG2RAD;
 
-    gs_cairo->cairo_new_path(m_cairo);
+    cairo_new_path(m_cairo);
 
-    gs_cairo->cairo_arc_negative ( m_cairo, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2);
-    gs_cairo->cairo_line_to(m_cairo, XLOG2DEV(xc), YLOG2DEV(yc));
-    gs_cairo->cairo_close_path (m_cairo);
+    cairo_arc_negative ( m_cairo, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2);
+    cairo_line_to(m_cairo, XLOG2DEV(xc), YLOG2DEV(yc));
+    cairo_close_path (m_cairo);
 
     SetBrush( m_brush );
-    gs_cairo->cairo_fill_preserve( m_cairo );
+    cairo_fill_preserve( m_cairo );
 
     SetPen (m_pen);
-    gs_cairo->cairo_stroke( m_cairo );
+    cairo_stroke( m_cairo );
 
     CalcBoundingBox (x1, y1);
     CalcBoundingBox (xc, yc);
@@ -1339,25 +1419,25 @@ void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,w
 
 void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
 {
-    gs_cairo->cairo_save( m_cairo );
+    cairo_save( m_cairo );
 
-    gs_cairo->cairo_new_path(m_cairo);
+    cairo_new_path(m_cairo);
 
-    gs_cairo->cairo_translate( m_cairo, XLOG2DEV((wxCoord) (x + w / 2.)), XLOG2DEV((wxCoord) (y + h / 2.)) );
+    cairo_translate( m_cairo, XLOG2DEV((wxCoord) (x + w / 2.)), XLOG2DEV((wxCoord) (y + h / 2.)) );
     double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w);
-    gs_cairo->cairo_scale( m_cairo, 1.0, scale );
+    cairo_scale( m_cairo, 1.0, scale );
 
-    gs_cairo->cairo_arc_negative ( m_cairo, 0, 0, XLOG2DEVREL(w/2), -sa*DEG2RAD, -ea*DEG2RAD);
+    cairo_arc_negative ( m_cairo, 0, 0, XLOG2DEVREL(w/2), -sa*DEG2RAD, -ea*DEG2RAD);
 
     SetPen (m_pen);
-    gs_cairo->cairo_stroke_preserve( m_cairo );
+    cairo_stroke_preserve( m_cairo );
 
-    gs_cairo->cairo_line_to(m_cairo, 0,0);
+    cairo_line_to(m_cairo, 0,0);
 
     SetBrush( m_brush );
-    gs_cairo->cairo_fill( m_cairo );
+    cairo_fill( m_cairo );
 
-    gs_cairo->cairo_restore( m_cairo );
+    cairo_restore( m_cairo );
 
     CalcBoundingBox( x, y);
     CalcBoundingBox( x+w, y+h );
@@ -1365,20 +1445,23 @@ void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord
 
 void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
 {
-    if  (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if ( m_pen.IsTransparent() )
+        return;
 
     SetPen( m_pen );
 
-    gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
-    gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
-    gs_cairo->cairo_stroke ( m_cairo );
+    cairo_move_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
+    cairo_line_to ( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
+    cairo_stroke ( m_cairo );
 
     CalcBoundingBox( x, y );
 }
 
-void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
+void wxGtkPrinterDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset)
 {
-    if (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if ( m_pen.IsTransparent() )
+        return;
+
 
     if (n <= 0) return;
 
@@ -1388,49 +1471,53 @@ void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, w
     for ( i =0; i<n ; i++ )
         CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset);
 
-    gs_cairo->cairo_move_to ( m_cairo, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );
+    cairo_move_to ( m_cairo, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );
 
     for (i = 1; i < n; i++)
-        gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
+        cairo_line_to ( m_cairo, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
 
-    gs_cairo->cairo_stroke ( m_cairo);
+    cairo_stroke ( m_cairo);
 }
 
-void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxGtkPrinterDCImpl::DoDrawPolygon(int n, const wxPoint points[],
+                                       wxCoord xoffset, wxCoord yoffset,
+                                       wxPolygonFillMode fillStyle)
 {
     if (n==0) return;
 
-    gs_cairo->cairo_save(m_cairo);
+    cairo_save(m_cairo);
     if (fillStyle == wxWINDING_RULE)
-        gs_cairo->cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_WINDING);
+        cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_WINDING);
     else
-        gs_cairo->cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_EVEN_ODD);
+        cairo_set_fill_rule( m_cairo, CAIRO_FILL_RULE_EVEN_ODD);
 
     int x = points[0].x + xoffset;
     int y = points[0].y + yoffset;
-    gs_cairo->cairo_new_path(m_cairo);
-    gs_cairo->cairo_move_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
+    cairo_new_path(m_cairo);
+    cairo_move_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
     int i;
     for (i = 1; i < n; i++)
     {
-        int x = points[i].x + xoffset;
-        int y = points[i].y + yoffset;
-        gs_cairo->cairo_line_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
+        int xx = points[i].x + xoffset;
+        int yy = points[i].y + yoffset;
+        cairo_line_to( m_cairo, XLOG2DEV(xx), YLOG2DEV(yy) );
     }
-    gs_cairo->cairo_close_path(m_cairo);
+    cairo_close_path(m_cairo);
 
     SetBrush( m_brush );
-    gs_cairo->cairo_fill_preserve( m_cairo );
+    cairo_fill_preserve( m_cairo );
 
     SetPen (m_pen);
-    gs_cairo->cairo_stroke( m_cairo );
+    cairo_stroke( m_cairo );
 
     CalcBoundingBox( x, y );
 
-    gs_cairo->cairo_restore(m_cairo);
+    cairo_restore(m_cairo);
 }
 
-void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
+                                           wxCoord xoffset, wxCoord yoffset,
+                                           wxPolygonFillMode fillStyle)
 {
     wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
 }
@@ -1440,14 +1527,14 @@ void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wx
     width--;
     height--;
 
-    gs_cairo->cairo_new_path(m_cairo);
-    gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
+    cairo_new_path(m_cairo);
+    cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
 
     SetBrush( m_brush );
-    gs_cairo->cairo_fill_preserve( m_cairo );
+    cairo_fill_preserve( m_cairo );
 
     SetPen (m_pen);
-    gs_cairo->cairo_stroke( m_cairo );
+    cairo_stroke( m_cairo );
 
     CalcBoundingBox( x, y );
     CalcBoundingBox( x + width, y + height );
@@ -1467,35 +1554,35 @@ void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord wi
 
     wxCoord rad = (wxCoord) radius;
 
-    gs_cairo->cairo_new_path(m_cairo);
-    gs_cairo->cairo_move_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y));
-    gs_cairo->cairo_curve_to(m_cairo,
+    cairo_new_path(m_cairo);
+    cairo_move_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y));
+    cairo_curve_to(m_cairo,
                                 XLOG2DEV(x + rad),YLOG2DEV(y),
                                 XLOG2DEV(x),YLOG2DEV(y),
                                 XLOG2DEV(x),YLOG2DEV(y + rad));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x),YLOG2DEV(y + height - rad));
-    gs_cairo->cairo_curve_to(m_cairo,
+    cairo_line_to(m_cairo,XLOG2DEV(x),YLOG2DEV(y + height - rad));
+    cairo_curve_to(m_cairo,
                                 XLOG2DEV(x),YLOG2DEV(y + height - rad),
                                 XLOG2DEV(x),YLOG2DEV(y + height),
                                 XLOG2DEV(x + rad),YLOG2DEV(y + height));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
-    gs_cairo->cairo_curve_to(m_cairo,
+    cairo_line_to(m_cairo,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
+    cairo_curve_to(m_cairo,
                                 XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
                                 XLOG2DEV(x + width),YLOG2DEV(y + height),
                                 XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x + width),YLOG2DEV(y + rad));
-    gs_cairo->cairo_curve_to(m_cairo,
+    cairo_line_to(m_cairo,XLOG2DEV(x + width),YLOG2DEV(y + rad));
+    cairo_curve_to(m_cairo,
                                 XLOG2DEV(x + width),YLOG2DEV(y + rad),
                                 XLOG2DEV(x + width),YLOG2DEV(y),
                                 XLOG2DEV(x + width - rad),YLOG2DEV(y));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y));
-    gs_cairo->cairo_close_path(m_cairo);
+    cairo_line_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y));
+    cairo_close_path(m_cairo);
 
     SetBrush(m_brush);
-    gs_cairo->cairo_fill_preserve(m_cairo);
+    cairo_fill_preserve(m_cairo);
 
     SetPen(m_pen);
-    gs_cairo->cairo_stroke(m_cairo);
+    cairo_stroke(m_cairo);
 
     CalcBoundingBox(x,y);
     CalcBoundingBox(x+width,y+height);
@@ -1506,24 +1593,24 @@ void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCo
     width--;
     height--;
 
-    gs_cairo->cairo_save (m_cairo);
+    cairo_save (m_cairo);
 
-    gs_cairo->cairo_new_path(m_cairo);
+    cairo_new_path(m_cairo);
 
-    gs_cairo->cairo_translate (m_cairo, XLOG2DEV((wxCoord) (x + width / 2.)), YLOG2DEV((wxCoord) (y + height / 2.)));
-    gs_cairo->cairo_scale(m_cairo, 1, (double)YLOG2DEVREL(height)/(double)XLOG2DEVREL(width));
-    gs_cairo->cairo_arc ( m_cairo, 0, 0, XLOG2DEVREL(width/2), 0, 2 * M_PI);
+    cairo_translate (m_cairo, XLOG2DEV((wxCoord) (x + width / 2.)), YLOG2DEV((wxCoord) (y + height / 2.)));
+    cairo_scale(m_cairo, 1, (double)YLOG2DEVREL(height)/(double)XLOG2DEVREL(width));
+    cairo_arc ( m_cairo, 0, 0, XLOG2DEVREL(width/2), 0, 2 * M_PI);
 
     SetBrush( m_brush );
-    gs_cairo->cairo_fill_preserve( m_cairo );
+    cairo_fill_preserve( m_cairo );
 
     SetPen (m_pen);
-    gs_cairo->cairo_stroke( m_cairo );
+    cairo_stroke( m_cairo );
 
     CalcBoundingBox( x, y );
     CalcBoundingBox( x + width, y + height );
 
-    gs_cairo->cairo_restore (m_cairo);
+    cairo_restore (m_cairo);
 }
 
 #if wxUSE_SPLINES
@@ -1548,9 +1635,9 @@ void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points)
     y3 =
          (double)(y1 + d) / 2;
 
-    gs_cairo->cairo_new_path( m_cairo );
-    gs_cairo->cairo_move_to( m_cairo, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) );
-    gs_cairo->cairo_line_to( m_cairo, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
+    cairo_new_path( m_cairo );
+    cairo_move_to( m_cairo, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) );
+    cairo_line_to( m_cairo, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
 
     CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
     CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
@@ -1569,7 +1656,7 @@ void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points)
         x3 = (double)(x2 + c) / 2;
         y3 = (double)(y2 + d) / 2;
 
-        gs_cairo->cairo_curve_to(m_cairo,
+        cairo_curve_to(m_cairo,
             XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
             XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2),
             XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
@@ -1580,16 +1667,16 @@ void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points)
         node = node->GetNext();
     }
 
-    gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );
+    cairo_line_to ( m_cairo, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );
 
-    gs_cairo->cairo_stroke( m_cairo );
+    cairo_stroke( m_cairo );
 }
 #endif // wxUSE_SPLINES
 
 bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest,
                           wxCoord width, wxCoord height,
                           wxDC *source, wxCoord xsrc, wxCoord ysrc,
-                          int rop, bool useMask,
+                          wxRasterOperationMode rop, bool useMask,
                           wxCoord WXUNUSED_UNLESS_DEBUG(xsrcMask),
                           wxCoord WXUNUSED_UNLESS_DEBUG(ysrcMask))
 {
@@ -1620,113 +1707,41 @@ void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoor
 {
     wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
 
-    cairo_surface_t* surface;
     x = wxCoord(XLOG2DEV(x));
     y = wxCoord(YLOG2DEV(y));
     int bw = bitmap.GetWidth();
     int bh = bitmap.GetHeight();
+#ifndef __WXGTK3__
     wxBitmap bmpSource = bitmap;  // we need a non-const instance.
-    unsigned char* buffer = new unsigned char[bw*bh*4];
-    wxUint32* data = (wxUint32*)buffer;
-
-    wxMask *mask = NULL;
-    if (useMask) mask = bmpSource.GetMask();
-
-    // Create a surface object and copy the bitmap pixel data to it. If the image has alpha (or a mask represented as alpha)
-    // then we'll use a different format and iterator than if it doesn't.
-    if (bmpSource.HasAlpha() || mask)
-    {
-        surface = gs_cairo->cairo_image_surface_create_for_data(
-            buffer, CAIRO_FORMAT_ARGB32, bw, bh, bw*4);
-        wxAlphaPixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh));
-        wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data."));
-
-        wxAlphaPixelData::Iterator p(pixData);
-        int y, x;
-        for (y=0; y<bh; y++)
-        {
-            wxAlphaPixelData::Iterator rowStart = p;
-            for (x=0; x<bw; x++)
-            {
-                // Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity,
-                // with alpha in the upper 8 bits, then red, then green, then
-                // blue. The 32-bit quantities are stored native-endian.
-                // Pre-multiplied alpha is used.
-                unsigned char alpha = p.Alpha();
-
-                if (!bmpSource.HasAlpha() && mask)
-                    alpha = 255;
-
-                if (alpha == 0)
-                    *data = 0;
-                else
-                    *data = ( alpha                  << 24
-                              | (p.Red() * alpha/255)    << 16
-                              | (p.Green() * alpha/255)  <<  8
-                              | (p.Blue() * alpha/255) );
-                ++data;
-                ++p;
-            }
-            p = rowStart;
-            p.OffsetY(pixData, 1);
-        }
-    }
-    else  // no alpha
-    {
-        surface = gs_cairo->cairo_image_surface_create_for_data(
-            buffer, CAIRO_FORMAT_RGB24, bw, bh, bw*4);
-        wxNativePixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh));
-        wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data."));
-
-        wxNativePixelData::Iterator p(pixData);
-        int y, x;
-        for (y=0; y<bh; y++)
-        {
-            wxNativePixelData::Iterator rowStart = p;
-            for (x=0; x<bw; x++)
-            {
-                // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
-                // the upper 8 bits unused. Red, Green, and Blue are stored in
-                // the remaining 24 bits in that order.  The 32-bit quantities
-                // are stored native-endian.
-                *data = ( p.Red() << 16 | p.Green() << 8 | p.Blue() );
-                ++data;
-                ++p;
-            }
-            p = rowStart;
-            p.OffsetY(pixData, 1);
-        }
-    }
-
+    if (!useMask && !bitmap.HasPixbuf() && bitmap.GetMask())
+        bmpSource.SetMask(NULL);
+#endif
 
-    gs_cairo->cairo_save(m_cairo);
+    cairo_save(m_cairo);
 
     // Prepare to draw the image.
-    gs_cairo->cairo_translate(m_cairo, x, y);
+    cairo_translate(m_cairo, x, y);
 
     // Scale the image
-    cairo_filter_t filter = CAIRO_FILTER_BILINEAR;
-    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface);
-    cairo_pattern_set_filter(pattern,filter);
     wxDouble scaleX = (wxDouble) XLOG2DEVREL(bw) / (wxDouble) bw;
     wxDouble scaleY = (wxDouble) YLOG2DEVREL(bh) / (wxDouble) bh;
     cairo_scale(m_cairo, scaleX, scaleY);
 
-    gs_cairo->cairo_set_source(m_cairo, pattern);
+#ifdef __WXGTK3__
+    bitmap.Draw(m_cairo, 0, 0, useMask, &m_textForegroundColour, &m_textBackgroundColour);
+#else
+    gdk_cairo_set_source_pixbuf(m_cairo, bmpSource.GetPixbuf(), 0, 0);
+    cairo_pattern_set_filter(cairo_get_source(m_cairo), CAIRO_FILTER_NEAREST);
     // Use the original size here since the context is scaled already.
-    gs_cairo->cairo_rectangle(m_cairo, 0, 0, bw, bh);
+    cairo_rectangle(m_cairo, 0, 0, bw, bh);
     // Fill the rectangle using the pattern.
-    gs_cairo->cairo_fill(m_cairo);
-
-    // Clean up.
-    gs_cairo->cairo_pattern_destroy(pattern);
-    gs_cairo->cairo_surface_destroy(surface);
-    delete [] buffer;
+    cairo_fill(m_cairo);
+#endif
 
     CalcBoundingBox(0,0);
     CalcBoundingBox(bw,bh);
 
-    gs_cairo->cairo_restore(m_cairo);
+    cairo_restore(m_cairo);
 }
 
 void wxGtkPrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
@@ -1741,25 +1756,12 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo
 
     angle = -angle;
 
-    bool underlined = m_font.Ok() && m_font.GetUnderlined();
-
-    const wxUTF8Buf data = text.utf8_str();
+    const wxScopedCharBuffer data = text.utf8_str();
 
-    size_t datalen = strlen(data);
-    pango_layout_set_text( m_layout, data, datalen);
+    pango_layout_set_text(m_layout, data, data.length());
 
-    if (underlined)
-    {
-        PangoAttrList *attrs = pango_attr_list_new();
-        PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
-        a->start_index = 0;
-        a->end_index = datalen;
-        pango_attr_list_insert(attrs, a);
-        pango_layout_set_attributes(m_layout, attrs);
-        pango_attr_list_unref(attrs);
-    }
-
-    if (m_textForegroundColour.Ok())
+    const bool setAttrs = m_font.GTKSetPangoAttrs(m_layout);
+    if (m_textForegroundColour.IsOk())
     {
         unsigned char red = m_textForegroundColour.Red();
         unsigned char blue = m_textForegroundColour.Blue();
@@ -1773,7 +1775,7 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo
             double greenPS = (double)(green) / 255.0;
             double alphaPS = (double)(alpha) / 255.0;
 
-            gs_cairo->cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
+            cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
 
             m_currentRed = red;
             m_currentBlue = blue;
@@ -1782,65 +1784,49 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo
         }
     }
 
-    int w,h;
-
-    // Scale font description.
-    gint oldSize = pango_font_description_get_size( m_fontdesc );
-    double size = oldSize;
-    size = size * m_scaleX;
-    pango_font_description_set_size( m_fontdesc, (gint)size );
-
-    // Actually apply scaled font.
-    pango_layout_set_font_description( m_layout, m_fontdesc );
+    // Draw layout.
+    cairo_move_to (m_cairo, xx, yy);
 
-    pango_layout_get_pixel_size( m_layout, &w, &h );
+    cairo_save( m_cairo );
 
-        if ( m_backgroundMode == wxSOLID )
-        {
-            unsigned char red = m_textBackgroundColour.Red();
-            unsigned char blue = m_textBackgroundColour.Blue();
-            unsigned char green = m_textBackgroundColour.Green();
-            unsigned char alpha = m_textBackgroundColour.Alpha();
+    if (fabs(angle) > 0.00001)
+        cairo_rotate( m_cairo, angle*DEG2RAD );
 
-            double redPS = (double)(red) / 255.0;
-            double bluePS = (double)(blue) / 255.0;
-            double greenPS = (double)(green) / 255.0;
-            double alphaPS = (double)(alpha) / 255.0;
+    cairo_scale(m_cairo, m_scaleX, m_scaleY);
 
-            gs_cairo->cairo_save(m_cairo);
-            gs_cairo->cairo_translate(m_cairo, xx, yy);
-            gs_cairo->cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
-            gs_cairo->cairo_rotate(m_cairo,angle*DEG2RAD);
-            gs_cairo->cairo_rectangle(m_cairo, 0, 0, w, h);   // still in cairo units
-            gs_cairo->cairo_fill(m_cairo);
-            gs_cairo->cairo_restore(m_cairo);
-        }
+    int w,h;
+    pango_layout_get_pixel_size( m_layout, &w, &h );
 
-    // Draw layout.
-    gs_cairo->cairo_move_to (m_cairo, xx, yy);
+    if ( m_backgroundMode == wxBRUSHSTYLE_SOLID )
+    {
+        unsigned char red = m_textBackgroundColour.Red();
+        unsigned char blue = m_textBackgroundColour.Blue();
+        unsigned char green = m_textBackgroundColour.Green();
+        unsigned char alpha = m_textBackgroundColour.Alpha();
 
-    gs_cairo->cairo_save( m_cairo );
+        double redPS = (double)(red) / 255.0;
+        double bluePS = (double)(blue) / 255.0;
+        double greenPS = (double)(green) / 255.0;
+        double alphaPS = (double)(alpha) / 255.0;
 
-    if (fabs(angle) > 0.00001)
-        gs_cairo->cairo_rotate( m_cairo, angle*DEG2RAD );
+        cairo_save(m_cairo);
+        cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
+        cairo_rectangle(m_cairo, 0, 0, w, h);   // still in cairo units
+        cairo_fill(m_cairo);
+        cairo_restore(m_cairo);
+    }
 
-    gs_cairo->pango_cairo_update_layout (m_cairo, m_layout);
-    gs_cairo->pango_cairo_show_layout (m_cairo, m_layout);
+    pango_cairo_update_layout (m_cairo, m_layout);
+    pango_cairo_show_layout (m_cairo, m_layout);
 
-    gs_cairo->cairo_restore( m_cairo );
+    cairo_restore( m_cairo );
 
-    if (underlined)
+    if (setAttrs)
     {
         // Undo underline attributes setting
         pango_layout_set_attributes(m_layout, NULL);
     }
 
-    // Reset unscaled size.
-    pango_font_description_set_size( m_fontdesc, oldSize );
-
-    // Actually apply unscaled font.
-    pango_layout_set_font_description( m_layout, m_fontdesc );
-
     // Back to device units:
     CalcBoundingBox (x, y);
     CalcBoundingBox (x + w, y + h);
@@ -1849,13 +1835,13 @@ void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCo
 void wxGtkPrinterDCImpl::Clear()
 {
 // Clear does nothing for printing, but keep the code
-// for later reuse 
+// for later reuse
 /*
-    gs_cairo->cairo_save(m_cairo);
-    gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
+    cairo_save(m_cairo);
+    cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
     SetBrush(m_backgroundBrush);
-    gs_cairo->cairo_paint(m_cairo);
-    gs_cairo->cairo_restore(m_cairo);
+    cairo_paint(m_cairo);
+    cairo_restore(m_cairo);
 */
 }
 
@@ -1863,37 +1849,35 @@ void wxGtkPrinterDCImpl::SetFont( const wxFont& font )
 {
     m_font = font;
 
-    if (m_font.Ok())
+    if (m_font.IsOk())
     {
         if (m_fontdesc)
             pango_font_description_free( m_fontdesc );
 
-        m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); // m_fontdesc is now set to device units
+        m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );
 
-        // Scale font description from device units to pango units
-        gint oldSize = pango_font_description_get_size( m_fontdesc );
-        double size = oldSize *m_DEV2PS;                          // scale to cairo units
-        pango_font_description_set_size( m_fontdesc, (gint)size );    // apply to description
+        float size = pango_font_description_get_size( m_fontdesc );
+        size = size * GetFontPointSizeAdjustment(72.0);
+        pango_font_description_set_size( m_fontdesc, (gint)size );
 
-        // Actually apply scaled font.
         pango_layout_set_font_description( m_layout, m_fontdesc );
     }
 }
 
 void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
 {
-    if (!pen.Ok()) return;
+    if (!pen.IsOk()) return;
 
     m_pen = pen;
 
     double width;
-    
+
     if (m_pen.GetWidth() <= 0)
         width = 0.1;
     else
         width = (double) m_pen.GetWidth();
 
-    gs_cairo->cairo_set_line_width( m_cairo, width * m_DEV2PS * m_scaleX );
+    cairo_set_line_width( m_cairo, width * m_DEV2PS * m_scaleX );
     static const double dotted[] = {2.0, 5.0};
     static const double short_dashed[] = {4.0, 4.0};
     static const double long_dashed[] = {4.0, 8.0};
@@ -1901,11 +1885,11 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
 
     switch (m_pen.GetStyle())
     {
-        case wxDOT:           gs_cairo->cairo_set_dash( m_cairo, dotted, 2, 0 ); break;
-        case wxSHORT_DASH:    gs_cairo->cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break;
-        case wxLONG_DASH:     gs_cairo->cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break;
-        case wxDOT_DASH:      gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 4, 0 );  break;
-        case wxUSER_DASH:
+        case wxPENSTYLE_DOT:        cairo_set_dash( m_cairo, dotted, 2, 0 ); break;
+        case wxPENSTYLE_SHORT_DASH: cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break;
+        case wxPENSTYLE_LONG_DASH:  cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break;
+        case wxPENSTYLE_DOT_DASH:   cairo_set_dash( m_cairo, dotted_dashed, 4, 0 );  break;
+        case wxPENSTYLE_USER_DASH:
         {
             wxDash *wx_dashes;
             int num = m_pen.GetDashes (&wx_dashes);
@@ -1913,29 +1897,29 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
             int i;
             for (i = 0; i < num; ++i)
                 g_dashes[i] = (gdouble) wx_dashes[i];
-            gs_cairo->cairo_set_dash( m_cairo, g_dashes, num, 0);
+            cairo_set_dash( m_cairo, g_dashes, num, 0);
             g_free( g_dashes );
         }
         break;
-        case wxSOLID:
-        case wxTRANSPARENT:
-        default:              gs_cairo->cairo_set_dash( m_cairo, NULL, 0, 0 );   break;
+        case wxPENSTYLE_SOLID:
+        case wxPENSTYLE_TRANSPARENT:
+        default:              cairo_set_dash( m_cairo, NULL, 0, 0 );   break;
     }
 
     switch (m_pen.GetCap())
     {
-        case wxCAP_PROJECTING:  gs_cairo->cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_SQUARE); break;
-        case wxCAP_BUTT:        gs_cairo->cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_BUTT); break;
+        case wxCAP_PROJECTING:  cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_SQUARE); break;
+        case wxCAP_BUTT:        cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_BUTT); break;
         case wxCAP_ROUND:
-        default:                gs_cairo->cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_ROUND); break;
+        default:                cairo_set_line_cap (m_cairo, CAIRO_LINE_CAP_ROUND); break;
     }
 
     switch (m_pen.GetJoin())
     {
-        case wxJOIN_BEVEL:  gs_cairo->cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_BEVEL); break;
-        case wxJOIN_MITER:  gs_cairo->cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_MITER); break;
+        case wxJOIN_BEVEL:  cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_BEVEL); break;
+        case wxJOIN_MITER:  cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_MITER); break;
         case wxJOIN_ROUND:
-        default:            gs_cairo->cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_ROUND); break;
+        default:            cairo_set_line_join (m_cairo, CAIRO_LINE_JOIN_ROUND); break;
     }
 
     unsigned char red = m_pen.GetColour().Red();
@@ -1950,7 +1934,7 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
         double greenPS = (double)(green) / 255.0;
         double alphaPS = (double)(alpha) / 255.0;
 
-        gs_cairo->cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
+        cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
 
         m_currentRed = red;
         m_currentBlue = blue;
@@ -1961,13 +1945,13 @@ void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
 
 void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
 {
-    if (!brush.Ok()) return;
+    if (!brush.IsOk()) return;
 
     m_brush = brush;
 
-    if (m_brush.GetStyle() == wxTRANSPARENT)
+    if (m_brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT)
     {
-        gs_cairo->cairo_set_source_rgba( m_cairo, 0, 0, 0, 0 );
+        cairo_set_source_rgba( m_cairo, 0, 0, 0, 0 );
         m_currentRed = 0;
         m_currentBlue = 0;
         m_currentGreen = 0;
@@ -1988,7 +1972,7 @@ void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
 
     if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue && alpha == m_currentAlpha))
     {
-        gs_cairo->cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
+        cairo_set_source_rgba( m_cairo, redPS, greenPS, bluePS, alphaPS );
 
         m_currentRed = red;
         m_currentBlue = blue;
@@ -2000,104 +1984,106 @@ void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
     {
         cairo_t * cr;
         cairo_surface_t *surface;
-        surface = gs_cairo->cairo_surface_create_similar(gs_cairo->cairo_get_target(m_cairo),CAIRO_CONTENT_COLOR_ALPHA,10,10);
-        cr = gs_cairo->cairo_create(surface);
-        gs_cairo->cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
-        gs_cairo->cairo_set_line_width(cr, 1);
-        gs_cairo->cairo_set_line_join(cr,CAIRO_LINE_JOIN_MITER);
+        surface = cairo_surface_create_similar(cairo_get_target(m_cairo),CAIRO_CONTENT_COLOR_ALPHA,10,10);
+        cr = cairo_create(surface);
+        cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
+        cairo_set_line_width(cr, 1);
+        cairo_set_line_join(cr,CAIRO_LINE_JOIN_MITER);
 
         switch (m_brush.GetStyle())
         {
-            case wxCROSS_HATCH:
-                gs_cairo->cairo_move_to(cr, 5, 0);
-                gs_cairo->cairo_line_to(cr, 5, 10);
-                gs_cairo->cairo_move_to(cr, 0, 5);
-                gs_cairo->cairo_line_to(cr, 10, 5);
+            case wxBRUSHSTYLE_CROSS_HATCH:
+                cairo_move_to(cr, 5, 0);
+                cairo_line_to(cr, 5, 10);
+                cairo_move_to(cr, 0, 5);
+                cairo_line_to(cr, 10, 5);
                 break;
-            case wxBDIAGONAL_HATCH:
-                gs_cairo->cairo_move_to(cr, 0, 10);
-                gs_cairo->cairo_line_to(cr, 10, 0);
+            case wxBRUSHSTYLE_BDIAGONAL_HATCH:
+                cairo_move_to(cr, 0, 10);
+                cairo_line_to(cr, 10, 0);
                 break;
-            case wxFDIAGONAL_HATCH:
-                gs_cairo->cairo_move_to(cr, 0, 0);
-                gs_cairo->cairo_line_to(cr, 10, 10);
+            case wxBRUSHSTYLE_FDIAGONAL_HATCH:
+                cairo_move_to(cr, 0, 0);
+                cairo_line_to(cr, 10, 10);
                 break;
-            case wxCROSSDIAG_HATCH:
-                gs_cairo->cairo_move_to(cr, 0, 0);
-                gs_cairo->cairo_line_to(cr, 10, 10);
-                gs_cairo->cairo_move_to(cr, 10, 0);
-                gs_cairo->cairo_line_to(cr, 0, 10);
+            case wxBRUSHSTYLE_CROSSDIAG_HATCH:
+                cairo_move_to(cr, 0, 0);
+                cairo_line_to(cr, 10, 10);
+                cairo_move_to(cr, 10, 0);
+                cairo_line_to(cr, 0, 10);
                 break;
-            case wxHORIZONTAL_HATCH:
-                gs_cairo->cairo_move_to(cr, 0, 5);
-                gs_cairo->cairo_line_to(cr, 10, 5);
+            case wxBRUSHSTYLE_HORIZONTAL_HATCH:
+                cairo_move_to(cr, 0, 5);
+                cairo_line_to(cr, 10, 5);
                 break;
-            case wxVERTICAL_HATCH:
-                gs_cairo->cairo_move_to(cr, 5, 0);
-                gs_cairo->cairo_line_to(cr, 5, 10);
+            case wxBRUSHSTYLE_VERTICAL_HATCH:
+                cairo_move_to(cr, 5, 0);
+                cairo_line_to(cr, 5, 10);
                 break;
             default:
                 wxFAIL_MSG(_("Couldn't get hatch style from wxBrush."));
         }
 
-        gs_cairo->cairo_set_source_rgba(cr, redPS, greenPS, bluePS, alphaPS);
-        gs_cairo->cairo_stroke (cr);
+        cairo_set_source_rgba(cr, redPS, greenPS, bluePS, alphaPS);
+        cairo_stroke (cr);
 
-        gs_cairo->cairo_destroy(cr);
-        cairo_pattern_t * pattern = gs_cairo->cairo_pattern_create_for_surface (surface);
-        gs_cairo->cairo_surface_destroy(surface);
-        gs_cairo->cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
-        gs_cairo->cairo_set_source(m_cairo, pattern);
-        gs_cairo->cairo_pattern_destroy(pattern);
+        cairo_destroy(cr);
+        cairo_pattern_t * pattern = cairo_pattern_create_for_surface (surface);
+        cairo_surface_destroy(surface);
+        cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+        cairo_set_source(m_cairo, pattern);
+        cairo_pattern_destroy(pattern);
     }
 }
 
-void wxGtkPrinterDCImpl::SetLogicalFunction( int function )
+void wxGtkPrinterDCImpl::SetLogicalFunction( wxRasterOperationMode function )
 {
     if (function == wxCLEAR)
-        gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR);
+        cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR);
     else if (function == wxOR)
-        gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_OUT);
+        cairo_set_operator (m_cairo, CAIRO_OPERATOR_OUT);
     else if (function == wxNO_OP)
-        gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST);
+        cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST);
     else if (function == wxAND)
-        gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_ADD);
+        cairo_set_operator (m_cairo, CAIRO_OPERATOR_ADD);
     else if (function == wxSET)
-        gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SATURATE);
+        cairo_set_operator (m_cairo, CAIRO_OPERATOR_SATURATE);
     else if (function == wxXOR)
-        gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_XOR);
+        cairo_set_operator (m_cairo, CAIRO_OPERATOR_XOR);
     else // wxCOPY or anything else.
-        gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
+        cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
 }
 
 void wxGtkPrinterDCImpl::SetBackground( const wxBrush& brush )
 {
     m_backgroundBrush = brush;
-    gs_cairo->cairo_save(m_cairo);
-    gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST_OVER);
+    cairo_save(m_cairo);
+    cairo_set_operator (m_cairo, CAIRO_OPERATOR_DEST_OVER);
 
     SetBrush(m_backgroundBrush);
-    gs_cairo->cairo_paint(m_cairo);
-    gs_cairo->cairo_restore(m_cairo);
+    cairo_paint(m_cairo);
+    cairo_restore(m_cairo);
 }
 
 void wxGtkPrinterDCImpl::SetBackgroundMode(int mode)
 {
-    if (mode == wxSOLID)
-        m_backgroundMode = wxSOLID;
+    if (mode == wxBRUSHSTYLE_SOLID)
+        m_backgroundMode = wxBRUSHSTYLE_SOLID;
     else
-        m_backgroundMode = wxTRANSPARENT;
+        m_backgroundMode = wxBRUSHSTYLE_TRANSPARENT;
 }
 
 void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 {
-    gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
-    gs_cairo->cairo_clip(m_cairo);
+    cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
+    cairo_clip(m_cairo);
+
+    wxDCImpl::DoSetClippingRegion(x, y, width, height);
 }
 
 void wxGtkPrinterDCImpl::DestroyClippingRegion()
 {
-    gs_cairo->cairo_reset_clip(m_cairo);
+    cairo_reset_clip(m_cairo);
 }
 
 bool wxGtkPrinterDCImpl::StartDoc(const wxString& WXUNUSED(message))
@@ -2112,7 +2098,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()
@@ -2159,43 +2162,49 @@ void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width,
         return;
     }
 
-    // Set layout's text
-    const wxUTF8Buf dataUTF8 = string.utf8_str();
+    cairo_save( m_cairo );
+    cairo_scale(m_cairo, m_scaleX, m_scaleY);
 
-    PangoFontDescription *desc = m_fontdesc;
-    if (theFont) desc = theFont->GetNativeFontInfo()->description;
+    // Set layout's text
+    const wxScopedCharBuffer dataUTF8 = string.utf8_str();
 
-    gint oldSize = pango_font_description_get_size( desc );
-    double size = oldSize;
-    size = size * m_scaleY;
-    pango_font_description_set_size( desc, (gint)size );
+    gint oldSize=0;
+    if ( theFont )
+    {
+        // scale the font and apply it
+        PangoFontDescription *desc = theFont->GetNativeFontInfo()->description;
+        oldSize = pango_font_description_get_size(desc);
+        const float size = oldSize * GetFontPointSizeAdjustment(72.0);
+        pango_font_description_set_size(desc, (gint)size);
 
-    // apply scaled font
-    pango_layout_set_font_description( m_layout, desc );
+        pango_layout_set_font_description(m_layout, desc);
+    }
 
     pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) );
 
-    int w, h;
-    pango_layout_get_pixel_size( m_layout, &w, &h );
-
-    if (width)
-        *width = wxRound( (double)w / m_scaleX * m_PS2DEV );
-    if (height)
-        *height = wxRound( (double)h / m_scaleY * m_PS2DEV );
+    int h;
+    pango_layout_get_pixel_size( m_layout, width, &h );
+    if ( height )
+        *height = h;
 
     if (descent)
     {
         PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
         int baseline = pango_layout_iter_get_baseline(iter);
         pango_layout_iter_free(iter);
-        *descent = wxRound( (h - PANGO_PIXELS(baseline)) * m_PS2DEV );
+        *descent = h - PANGO_PIXELS(baseline);
     }
 
-    // Reset unscaled size.
-    pango_font_description_set_size( desc, oldSize );
+    if ( theFont )
+    {
+        // restore font and reset font's size back
+        pango_layout_set_font_description(m_layout, m_fontdesc);
+
+        PangoFontDescription *desc = theFont->GetNativeFontInfo()->description;
+        pango_font_description_set_size(desc, oldSize);
+    }
 
-    // Reset unscaled font.
-    pango_layout_set_font_description( m_layout, m_fontdesc );
+    cairo_restore( m_cairo );
 }
 
 void wxGtkPrinterDCImpl::DoGetSize(int* width, int* height) const
@@ -2203,9 +2212,9 @@ void wxGtkPrinterDCImpl::DoGetSize(int* width, int* height) const
     GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc );
 
     if (width)
-        *width = wxRound( gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * m_PS2DEV );
+        *width = wxRound( (double)gtk_page_setup_get_paper_width( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 );
     if (height)
-        *height = wxRound( gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * m_PS2DEV );
+        *height = wxRound( (double)gtk_page_setup_get_paper_height( setup, GTK_UNIT_POINTS ) * (double)m_resolution / 72.0 );
 }
 
 void wxGtkPrinterDCImpl::DoGetSizeMM(int *width, int *height) const
@@ -2228,9 +2237,9 @@ void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData& data)
     m_printData = data;
 }
 
-// overriden for wxPrinterDC Impl
+// overridden for wxPrinterDC Impl
 
-wxRect wxGtkPrinterDCImpl::GetPaperRect()
+wxRect wxGtkPrinterDCImpl::GetPaperRect() const
 {
     // Does GtkPrint support printer margins?
     int w = 0;
@@ -2239,7 +2248,7 @@ wxRect wxGtkPrinterDCImpl::GetPaperRect()
     return wxRect( 0,0,w,h );
 }
 
-int wxGtkPrinterDCImpl::GetResolution()
+int wxGtkPrinterDCImpl::GetResolution() const
 {
     return m_resolution;
 }
@@ -2251,25 +2260,59 @@ int wxGtkPrinterDCImpl::GetResolution()
 IMPLEMENT_CLASS(wxGtkPrintPreview, wxPrintPreviewBase)
 
 void wxGtkPrintPreview::Init(wxPrintout * WXUNUSED(printout),
-                                    wxPrintout * WXUNUSED(printoutForPrinting))
+                             wxPrintout * WXUNUSED(printoutForPrinting),
+                             wxPrintData *data)
 {
+    // convert wxPrintQuality to resolution (input pointer can be NULL)
+    wxPrintQuality quality = data ? data->GetQuality() : wxPRINT_QUALITY_MEDIUM;
+    switch ( quality )
+    {
+        case wxPRINT_QUALITY_HIGH:
+            m_resolution = 1200;
+            break;
+
+        case wxPRINT_QUALITY_LOW:
+            m_resolution = 300;
+            break;
+
+        case wxPRINT_QUALITY_DRAFT:
+            m_resolution = 150;
+            break;
+
+        default:
+            if ( quality > 0 )
+            {
+                // positive values directly indicate print resolution
+                m_resolution = quality;
+                break;
+            }
+
+            wxFAIL_MSG( "unknown print quality" );
+            // fall through
+
+        case wxPRINT_QUALITY_MEDIUM:
+            m_resolution = 600;
+            break;
+
+    }
+
     DetermineScaling();
 }
 
 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout,
-                                                   wxPrintout *printoutForPrinting,
-                                                   wxPrintDialogData *data)
-                        : wxPrintPreviewBase(printout, printoutForPrinting, data)
+                                     wxPrintout *printoutForPrinting,
+                                     wxPrintDialogData *data)
+                 : wxPrintPreviewBase(printout, printoutForPrinting, data)
 {
-    Init(printout, printoutForPrinting);
+    Init(printout, printoutForPrinting, data ? &data->GetPrintData() : NULL);
 }
 
 wxGtkPrintPreview::wxGtkPrintPreview(wxPrintout *printout,
-                                                   wxPrintout *printoutForPrinting,
-                                                   wxPrintData *data)
-                        : wxPrintPreviewBase(printout, printoutForPrinting, data)
+                                     wxPrintout *printoutForPrinting,
+                                     wxPrintData *data)
+                 : wxPrintPreviewBase(printout, printoutForPrinting, data)
 {
-    Init(printout, printoutForPrinting);
+    Init(printout, printoutForPrinting, data);
 }
 
 wxGtkPrintPreview::~wxGtkPrintPreview()
@@ -2295,21 +2338,20 @@ void wxGtkPrintPreview::DetermineScaling()
 
     if (paper)
     {
-        wxSize ScreenPixels = wxGetDisplaySize();
-        wxSize ScreenMM = wxGetDisplaySizeMM();
-
-        m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
-                                         (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
+        const wxSize screenPPI = wxGetDisplayPPI();
+        int logPPIScreenX = screenPPI.GetWidth();
+        int logPPIScreenY = screenPPI.GetHeight();
+        int logPPIPrinterX = m_resolution;
+        int logPPIPrinterY = m_resolution;
 
-        // TODO !!!!!!!!!!!!!!!      
-        int resolution = 600;
-        m_previewPrintout->SetPPIPrinter( resolution, resolution );
+        m_previewPrintout->SetPPIScreen( logPPIScreenX, logPPIScreenY );
+        m_previewPrintout->SetPPIPrinter( logPPIPrinterX, logPPIPrinterY );
 
         // Get width and height in points (1/72th of an inch)
         wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
+        sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)m_resolution / 72.0);
+        sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)m_resolution / 72.0);
 
-        sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)resolution / 72.0);
-        sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)resolution / 72.0);
         wxSize sizeTenthsMM(paper->GetSize());
         wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
 
@@ -2330,8 +2372,8 @@ void wxGtkPrintPreview::DetermineScaling()
         m_previewPrintout->SetPaperRectPixels(wxRect(0, 0, m_pageWidth, m_pageHeight));
 
         // At 100%, the page should look about page-size on the screen.
-        m_previewScaleX = 0.8 * 72.0 / (double)resolution;
-        m_previewScaleY = m_previewScaleX;
+        m_previewScaleX = float(logPPIScreenX) / logPPIPrinterX;
+        m_previewScaleY = float(logPPIScreenY) / logPPIPrinterY;
     }
 }