]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/print.cpp
mac paths updated
[wxWidgets.git] / src / gtk / print.cpp
index e44a6ede0b8854997d233c8e7d7a0faf7d799720..a1cd4c3043d578abf9a0f9f28bcfe2def6b8fdbb 100644 (file)
 #ifndef WX_PRECOMP
 #include "wx/log.h"
 #include "wx/dcmemory.h"
+#include "wx/dcprint.h"
 #include "wx/icon.h"
 #include "wx/math.h"
 #include "wx/image.h"
 #include "wx/module.h"
+#include "wx/crt.h"
 #endif
 
 #include "wx/fontutil.h"
 #include <gtk/gtk.h>
 #include <gtk/gtkpagesetupunixdialog.h>
 
+#if wxUSE_GRAPHICS_CONTEXT
+#include "wx/graphics.h"
+#endif
+
 #include "wx/link.h"
 wxFORCE_LINK_THIS_MODULE(gtk_print)
 
@@ -60,7 +66,7 @@ static wxCairoLibrary* gs_cairo = NULL;
 class wxGtkPrintModule: public wxModule
 {
 public:
-    wxGtkPrintModule() 
+    wxGtkPrintModule()
     {
 #if wxUSE_LIBGNOMEPRINT
         // This module must be initialized AFTER gnomeprint's one
@@ -135,14 +141,16 @@ bool wxGtkPrintFactory::HasPrintSetupDialog()
     return false;
 }
 
-wxDialog *wxGtkPrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data )
+wxDialog *
+wxGtkPrintFactory::CreatePrintSetupDialog(wxWindow * WXUNUSED(parent),
+                                          wxPrintData * WXUNUSED(data))
 {
     return NULL;
 }
 
-wxDC* wxGtkPrintFactory::CreatePrinterDC( const wxPrintData& data )
+wxDCImpl* wxGtkPrintFactory::CreatePrinterDCImpl( wxPrinterDC *owner, const wxPrintData& data )
 {
-    return new wxGtkPrintDC(data);
+    return new wxGtkPrinterDCImpl( owner, data );
 }
 
 bool wxGtkPrintFactory::HasOwnPrintToFile()
@@ -182,13 +190,12 @@ wxPrintNativeDataBase *wxGtkPrintFactory::CreatePrintNativeData()
 // Callback functions for Gtk Printings.
 //----------------------------------------------------------------------------
 
-// We use it to pass useful objets to gtk printing callback functions.
-typedef struct
+// We use it to pass useful objects to GTK printing callback functions.
+struct wxPrinterToGtkData
 {
    wxGtkPrinter * printer;
    wxPrintout * printout;
-}
-wxPrinterToGtkData;
+};
 
 extern "C"
 {
@@ -206,20 +213,28 @@ extern "C"
         data->printer->DrawPage(data->printout, operation, context, page_nr);
     }
 
-    static void gtk_end_print_callback (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
+    static void gtk_end_print_callback(GtkPrintOperation * WXUNUSED(operation),
+                                       GtkPrintContext * WXUNUSED(context),
+                                       gpointer user_data)
     {
         wxPrintout *printout = (wxPrintout *) user_data;
 
         printout->OnEndPrinting();
     }
 
-    static gboolean gtk_preview_print_callback (GtkPrintOperation *operation, GtkPrintOperationPreview *preview, GtkPrintContext *context, GtkWindow *parent, gpointer user_data)
+    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 positionning. */
+        /* 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);
 
@@ -250,15 +265,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));
 
@@ -552,11 +576,11 @@ void wxGtkPrintNativeData::SetPrintConfig( GtkPrintSettings * config )
 GtkPageSetup* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings* settings)
 {
     GtkPageSetup* page_setup = gtk_page_setup_new();
-       gtk_page_setup_set_orientation (page_setup, gtk_print_settings_get_orientation (settings));
+    gtk_page_setup_set_orientation (page_setup, gtk_print_settings_get_orientation (settings));
 
-       GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (settings);
-       if (paper_size != NULL)
-               gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size);
+    GtkPaperSize *paper_size = gtk_print_settings_get_paper_size (settings);
+    if (paper_size != NULL)
+        gtk_page_setup_set_paper_size_and_default_margins (page_setup, paper_size);
 
     return page_setup;
 }
@@ -565,7 +589,7 @@ GtkPageSetup* wxGtkPrintNativeData::GetPageSetupFromSettings(GtkPrintSettings* s
 void wxGtkPrintNativeData::SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup)
 {
     gtk_print_settings_set_orientation ( settings, gtk_page_setup_get_orientation (page_setup));
-       gtk_print_settings_set_paper_size ( settings, gtk_page_setup_get_paper_size (page_setup));
+    gtk_print_settings_set_paper_size ( settings, gtk_page_setup_get_paper_size (page_setup));
 }
 
 //----------------------------------------------------------------------------
@@ -637,14 +661,14 @@ int wxGtkPrintDialog::ShowModal()
     // 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_default_page_setup (native->GetPrintJob(), 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, (GtkWindow *) m_parent, &gError);
+        response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError);
 
     // Does everything went well?
     if (response == GTK_PRINT_OPERATION_RESULT_CANCEL)
@@ -678,8 +702,8 @@ int wxGtkPrintDialog::ShowModal()
             range = gtk_print_settings_get_page_ranges (newSettings, &num_ranges);
             if (num_ranges >= 1)
             {
-            m_printDialogData.SetFromPage( range[0].start );
-            m_printDialogData.SetToPage( range[0].end );
+                m_printDialogData.SetFromPage( range[0].start );
+                m_printDialogData.SetToPage( range[0].end );
             }
             else {
                 m_printDialogData.SetAllPages( true );
@@ -847,19 +871,29 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
     dataToSend.printer = this;
     dataToSend.printout = printout;
 
-    // These Gtk signals are catched here.
+    // These Gtk signals are caught here.
     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);
 
-    m_showDialog = true;
-    if (!prompt)
-        m_showDialog = false;
+    // This is used to setup the DC and
+    // show the dialog if desired
+    wxGtkPrintDialog dialog( parent, &m_printDialogData );
+    dialog.SetPrintDC(m_dc);
+    dialog.SetShowDialog(prompt);
 
-    // PrintDialog returns a wxDC but we created it before so we don't need it anymore: we just delete it.
-    wxDC* uselessdc = PrintDialog( parent );
-    delete uselessdc;
+    // doesn't necessarily show
+    int ret = dialog.ShowModal();
+    if (ret == wxID_CANCEL)
+    {
+        sm_lastError = wxPRINTER_CANCELLED;
+    }
+    if (ret == wxID_NO)
+    {
+        sm_lastError = wxPRINTER_ERROR;
+        wxFAIL_MSG(_("The print dialog returned an error."));
+    }
 
     g_object_unref (printOp);
 
@@ -871,10 +905,16 @@ 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 );
 
-    wxGtkPrintDC *printDC = new wxGtkPrintDC( printdata );
+    wxPrinterDC *printDC = new wxPrinterDC( printdata );
     m_dc = printDC;
 
     if (!m_dc->IsOk())
@@ -882,7 +922,7 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation
         if (sm_lastError != wxPRINTER_CANCELLED)
         {
             sm_lastError = wxPRINTER_ERROR;
-            wxFAIL_MSG(_("The wxGtkPrintDC cannot be used."));
+            wxFAIL_MSG(_("The wxGtkPrinterDC cannot be used."));
         }
         return;
     }
@@ -958,7 +998,10 @@ void wxGtkPrinter::BeginPrint(wxPrintout *printout, GtkPrintOperation *operation
     gtk_print_operation_set_n_pages(operation, numPages);
 }
 
-void wxGtkPrinter::DrawPage(wxPrintout *printout, GtkPrintOperation *operation, GtkPrintContext *context, int page_nr)
+void wxGtkPrinter::DrawPage(wxPrintout *printout,
+                            GtkPrintOperation *operation,
+                            GtkPrintContext * WXUNUSED(context),
+                            int page_nr)
 {
     int fromPage, toPage, minPage, maxPage, startPage, endPage;
     printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
@@ -981,8 +1024,8 @@ void wxGtkPrinter::DrawPage(wxPrintout *printout, GtkPrintOperation *operation,
             // We don't need to verify these values as it has already been done in wxGtkPrinter::BeginPrint.
             if (num_ranges >= 1)
             {
-            startPage = range[0].start + 1;
-            endPage = range[0].end + 1;
+                startPage = range[0].start + 1;
+                endPage = range[0].end + 1;
             }
             else {
                 startPage = minPage;
@@ -1023,13 +1066,11 @@ void wxGtkPrinter::DrawPage(wxPrintout *printout, GtkPrintOperation *operation,
 wxDC* wxGtkPrinter::PrintDialog( wxWindow *parent )
 {
     wxGtkPrintDialog dialog( parent, &m_printDialogData );
-    int ret;
 
     dialog.SetPrintDC(m_dc);
+    dialog.SetShowDialog(true);
 
-    dialog.SetShowDialog(m_showDialog);
-
-    ret = dialog.ShowModal();
+    int ret = dialog.ShowModal();
 
     if (ret == wxID_CANCEL)
     {
@@ -1044,27 +1085,42 @@ wxDC* wxGtkPrinter::PrintDialog( wxWindow *parent )
     }
 
     m_printDialogData = dialog.GetPrintDialogData();
-    return new wxGtkPrintDC( m_printDialogData.GetPrintData() );
+    
+    return new wxPrinterDC( m_printDialogData.GetPrintData() );
 }
 
-bool wxGtkPrinter::Setup( wxWindow *parent )
+bool wxGtkPrinter::Setup( wxWindow * WXUNUSED(parent) )
 {
     // Obsolete, for backward compatibility.
     return false;
 }
 
 //-----------------------------------------------------------------------------
-// wxGtkPrintDC
+// 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)
 
-IMPLEMENT_CLASS(wxGtkPrintDC, wxDC)
+#endif
+
+IMPLEMENT_ABSTRACT_CLASS(wxGtkPrinterDCImpl, wxDCImpl)
 
-wxGtkPrintDC::wxGtkPrintDC( const wxPrintData& data )
+wxGtkPrinterDCImpl::wxGtkPrinterDCImpl(wxPrinterDC *owner, const wxPrintData& data)
+                  : wxDCImpl( owner )
 {
     m_printData = data;
 
@@ -1073,31 +1129,37 @@ wxGtkPrintDC::wxGtkPrintDC( const wxPrintData& data )
 
     m_gpc = native->GetPrintContext();
 
-    // RR: what does this do?
+    // Match print quality to resolution (high = 1200dpi)
     m_resolution = m_printData.GetQuality(); // (int) gtk_print_context_get_dpi_x( m_gpc );
-    if (m_resolution < 0) 
+    if (m_resolution < 0)
         m_resolution = (1 << (m_resolution+4)) *150;
 
-    wxPrintf( "resolution %d\n", m_resolution );
-    
-    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;
+    
+    gs_cairo->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;
+#endif
+
     m_currentRed = 0;
     m_currentBlue = 0;
     m_currentGreen = 0;
 
-    m_signX =  1;  // default x-axis left to right.
+    m_signX = 1;  // default x-axis left to right.
     m_signY = 1;  // default y-axis bottom up -> top down.
 
-    // By default the origine of cairo contexte 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 (i.e. doesn't care about margins)
+    // 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);
@@ -1105,25 +1167,34 @@ wxGtkPrintDC::wxGtkPrintDC( const wxPrintData& data )
     gs_cairo->cairo_translate(m_cairo, -ml, -mt);
 }
 
-wxGtkPrintDC::~wxGtkPrintDC()
+wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
 {
     g_object_unref(m_context);
     g_object_unref(m_layout);
 }
 
-bool wxGtkPrintDC::IsOk() const
+bool wxGtkPrinterDCImpl::IsOk() const
 {
-    return (m_gpc != NULL);
+    return m_gpc != NULL;
 }
 
-bool wxGtkPrintDC::DoFloodFill(wxCoord x1, wxCoord y1, const wxColour &col, int style )
+void* wxGtkPrinterDCImpl::GetCairoContext() const
 {
-    // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
+    return (void*) cairo_reference( m_cairo );
+}
+
+bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1),
+                               wxCoord WXUNUSED(y1),
+                               const wxColour& WXUNUSED(col),
+                               int 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.
     wxFAIL_MSG(_("not implemented"));
     return false;
 }
 
-void wxGtkPrintDC::DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter)
+void wxGtkPrinterDCImpl::DoGradientFillConcentric(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, const wxPoint& circleCenter)
 {
     wxCoord xC = circleCenter.x;
     wxCoord yC = circleCenter.y;
@@ -1154,13 +1225,13 @@ void wxGtkPrintDC::DoGradientFillConcentric(const wxRect& rect, const wxColour&
 
     // Create a pattern with the gradient.
     cairo_pattern_t* gradient;
-    gradient = gs_cairo->cairo_pattern_create_radial (XLOG2DEV(xC+xR), YLOG2DEVREL(yC+yR), 0, XLOG2DEV(xC+xR), YLOG2DEVREL(yC+yR), radius * m_DEV2PS );
+    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);
 
     // Fill the rectangle with this pattern.
     gs_cairo->cairo_set_source(m_cairo, gradient);
-    gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEVREL(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) );
+    gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(xR), YLOG2DEV(yR), XLOG2DEVREL(w), YLOG2DEVREL(h) );
     gs_cairo->cairo_fill(m_cairo);
 
     gs_cairo->cairo_pattern_destroy(gradient);
@@ -1169,7 +1240,7 @@ void wxGtkPrintDC::DoGradientFillConcentric(const wxRect& rect, const wxColour&
     CalcBoundingBox(xR+w, yR+h);
 }
 
-void wxGtkPrintDC::DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection)
+void wxGtkPrinterDCImpl::DoGradientFillLinear(const wxRect& rect, const wxColour& initialColour, const wxColour& destColour, wxDirection nDirection)
 {
     wxCoord x = rect.x;
     wxCoord y = rect.y;
@@ -1196,7 +1267,7 @@ void wxGtkPrintDC::DoGradientFillLinear(const wxRect& rect, const wxColour& init
 
     // Create a pattern with the gradient.
     cairo_pattern_t* gradient;
-    gradient = gs_cairo->cairo_pattern_create_linear (XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(x+w), YLOG2DEVREL(y));
+    gradient = gs_cairo->cairo_pattern_create_linear (XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x+w), YLOG2DEV(y));
 
     if (nDirection == wxWEST)
     {
@@ -1210,7 +1281,7 @@ void wxGtkPrintDC::DoGradientFillLinear(const wxRect& rect, const wxColour& init
 
     // Fill the rectangle with this pattern.
     gs_cairo->cairo_set_source(m_cairo, gradient);
-    gs_cairo->cairo_rectangle (m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(w), YLOG2DEVREL(h) );
+    gs_cairo->cairo_rectangle (m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(w), YLOG2DEVREL(h) );
     gs_cairo->cairo_fill(m_cairo);
 
     gs_cairo->cairo_pattern_destroy(gradient);
@@ -1219,44 +1290,45 @@ void wxGtkPrintDC::DoGradientFillLinear(const wxRect& rect, const wxColour& init
     CalcBoundingBox(x+w, y+h);
 }
 
-bool wxGtkPrintDC::DoGetPixel(wxCoord x1, wxCoord y1, wxColour *col) const
+bool wxGtkPrinterDCImpl::DoGetPixel(wxCoord WXUNUSED(x1),
+                              wxCoord WXUNUSED(y1),
+                              wxColour * WXUNUSED(col)) const
 {
-    // We can't access the given coord as a cairo context is scalable, ie a coord doesn't mean anything in this context.
     wxFAIL_MSG(_("not implemented"));
     return false;
 }
 
-void wxGtkPrintDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
+void wxGtkPrinterDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
 {
-    if  (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if  (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
 
     SetPen( m_pen );
-    gs_cairo->cairo_move_to ( m_cairo, XLOG2DEVREL(x1), YLOG2DEVREL(y1) );
-    gs_cairo->cairo_line_to ( m_cairo, XLOG2DEVREL(x2), YLOG2DEVREL(y2) );
+    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 );
 
     CalcBoundingBox( x1, y1 );
     CalcBoundingBox( x2, y2 );
 }
 
-void wxGtkPrintDC::DoCrossHair(wxCoord x, wxCoord y)
+void wxGtkPrinterDCImpl::DoCrossHair(wxCoord x, wxCoord y)
 {
     int w, h;
     DoGetSize(&w, &h);
 
     SetPen(m_pen);
 
-    gs_cairo->cairo_move_to (m_cairo, XLOG2DEVREL(x), 0);
-    gs_cairo->cairo_line_to (m_cairo, XLOG2DEVREL(x), h * m_DEV2PS);
-    gs_cairo->cairo_move_to (m_cairo, 0, YLOG2DEVREL(y));
-    gs_cairo->cairo_line_to (m_cairo, w * m_DEV2PS, YLOG2DEVREL(y));
+    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));
 
     gs_cairo->cairo_stroke (m_cairo);
     CalcBoundingBox( 0, 0 );
     CalcBoundingBox( w, h );
 }
 
-void wxGtkPrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)
+void wxGtkPrinterDCImpl::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord xc,wxCoord yc)
 {
     double dx = x1 - xc;
     double dy = y1 - yc;
@@ -1293,8 +1365,8 @@ void wxGtkPrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord
 
     gs_cairo->cairo_new_path(m_cairo);
 
-    gs_cairo->cairo_arc_negative ( m_cairo, XLOG2DEVREL(xc), YLOG2DEVREL(yc), XLOG2DEVREL((int)radius), alpha1, alpha2);
-    gs_cairo->cairo_line_to(m_cairo, XLOG2DEVREL(xc), YLOG2DEVREL(yc));
+    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);
 
     SetBrush( m_brush );
@@ -1308,13 +1380,13 @@ void wxGtkPrintDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2,wxCoord
     CalcBoundingBox (x2, y2);
 }
 
-void wxGtkPrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
+void wxGtkPrinterDCImpl::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
 {
     gs_cairo->cairo_save( m_cairo );
 
     gs_cairo->cairo_new_path(m_cairo);
 
-    gs_cairo->cairo_translate( m_cairo, XLOG2DEVREL((wxCoord) (x + w / 2.)), XLOG2DEVREL((wxCoord) (y + h / 2.)) );
+    gs_cairo->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 );
 
@@ -1334,22 +1406,22 @@ void wxGtkPrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,dou
     CalcBoundingBox( x+w, y+h );
 }
 
-void wxGtkPrintDC::DoDrawPoint(wxCoord x, wxCoord y)
+void wxGtkPrinterDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
 {
-    if  (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if  (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
 
     SetPen( m_pen );
 
-    gs_cairo->cairo_move_to ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y) );
-    gs_cairo->cairo_line_to ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y) );
+    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 );
 
     CalcBoundingBox( x, y );
 }
 
-void wxGtkPrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
+void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
 {
-    if (m_pen.GetStyle() == wxTRANSPARENT) return;
+    if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return;
 
     if (n <= 0) return;
 
@@ -1359,15 +1431,15 @@ void wxGtkPrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord
     for ( i =0; i<n ; i++ )
         CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset);
 
-    gs_cairo->cairo_move_to ( m_cairo, XLOG2DEVREL(points[0].x+xoffset), YLOG2DEVREL(points[0].y+yoffset) );
+    gs_cairo->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, XLOG2DEVREL(points[i].x+xoffset), YLOG2DEVREL(points[i].y+yoffset) );
+        gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );
 
     gs_cairo->cairo_stroke ( m_cairo);
 }
 
-void wxGtkPrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
 {
     if (n==0) return;
 
@@ -1380,13 +1452,13 @@ void wxGtkPrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoo
     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, XLOG2DEVREL(x), YLOG2DEVREL(y) );
+    gs_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, XLOG2DEVREL(x), YLOG2DEVREL(y) );
+        gs_cairo->cairo_line_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
     }
     gs_cairo->cairo_close_path(m_cairo);
 
@@ -1401,15 +1473,18 @@ void wxGtkPrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoo
     gs_cairo->cairo_restore(m_cairo);
 }
 
-void wxGtkPrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
+void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
 {
-    wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
+    wxDCImpl::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
 }
 
-void wxGtkPrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxGtkPrinterDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 {
+    width--;
+    height--;
+
     gs_cairo->cairo_new_path(m_cairo);
-    gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
+    gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
 
     SetBrush( m_brush );
     gs_cairo->cairo_fill_preserve( m_cairo );
@@ -1421,8 +1496,11 @@ void wxGtkPrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord
     CalcBoundingBox( x + width, y + height );
 }
 
-void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
+void wxGtkPrinterDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
 {
+    width--;
+    height--;
+
     if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
 
     wxCoord dd = 2 * (wxCoord) radius;
@@ -1433,27 +1511,27 @@ void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, w
     wxCoord rad = (wxCoord) radius;
 
     gs_cairo->cairo_new_path(m_cairo);
-    gs_cairo->cairo_move_to(m_cairo,XLOG2DEVREL(x + rad),YLOG2DEVREL(y));
+    gs_cairo->cairo_move_to(m_cairo,XLOG2DEV(x + rad),YLOG2DEV(y));
     gs_cairo->cairo_curve_to(m_cairo,
-                                XLOG2DEVREL(x + rad),YLOG2DEVREL(y),
-                                XLOG2DEVREL(x),YLOG2DEVREL(y),
-                                XLOG2DEVREL(x),YLOG2DEVREL(y + rad));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x),YLOG2DEVREL(y + height - rad));
+                                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,
-                                XLOG2DEVREL(x),YLOG2DEVREL(y + height - rad),
-                                XLOG2DEVREL(x),YLOG2DEVREL(y + height),
-                                XLOG2DEVREL(x + rad),YLOG2DEVREL(y + height));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x + width - rad),YLOG2DEVREL(y + height));
+                                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,
-                                XLOG2DEVREL(x + width - rad),YLOG2DEVREL(y + height),
-                                XLOG2DEVREL(x + width),YLOG2DEVREL(y + height),
-                                XLOG2DEVREL(x + width),YLOG2DEVREL(y + height - rad));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x + width),YLOG2DEVREL(y + rad));
+                                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,
-                                XLOG2DEVREL(x + width),YLOG2DEVREL(y + rad),
-                                XLOG2DEVREL(x + width),YLOG2DEVREL(y),
-                                XLOG2DEVREL(x + width - rad),YLOG2DEVREL(y));
-    gs_cairo->cairo_line_to(m_cairo,XLOG2DEVREL(x + rad),YLOG2DEVREL(y));
+                                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);
 
     SetBrush(m_brush);
@@ -1466,13 +1544,16 @@ void wxGtkPrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, w
     CalcBoundingBox(x+width,y+height);
 }
 
-void wxGtkPrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 {
+    width--;
+    height--;
+
     gs_cairo->cairo_save (m_cairo);
 
     gs_cairo->cairo_new_path(m_cairo);
 
-    gs_cairo->cairo_translate (m_cairo, XLOG2DEVREL((wxCoord) (x + width / 2.)), YLOG2DEVREL((wxCoord) (y + height / 2.)));
+    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);
 
@@ -1489,20 +1570,20 @@ void wxGtkPrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord he
 }
 
 #if wxUSE_SPLINES
-void wxGtkPrintDC::DoDrawSpline(wxList *points)
+void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points)
 {
     SetPen (m_pen);
 
     double c, d, x1, y1, x2, y2, x3, y3;
     wxPoint *p, *q;
 
-    wxList::compatibility_iterator node = points->GetFirst();
-    p = (wxPoint *)node->GetData();
+    wxPointList::compatibility_iterator node = points->GetFirst();
+    p = node->GetData();
     x1 = p->x;
     y1 = p->y;
 
     node = node->GetNext();
-    p = (wxPoint *)node->GetData();
+    p = node->GetData();
     c = p->x;
     d = p->y;
     x3 =
@@ -1511,8 +1592,8 @@ void wxGtkPrintDC::DoDrawSpline(wxList *points)
          (double)(y1 + d) / 2;
 
     gs_cairo->cairo_new_path( m_cairo );
-    gs_cairo->cairo_move_to( m_cairo, XLOG2DEVREL((wxCoord)x1), YLOG2DEVREL((wxCoord)y1) );
-    gs_cairo->cairo_line_to( m_cairo, XLOG2DEVREL((wxCoord)x3), YLOG2DEVREL((wxCoord)y3) );
+    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) );
 
     CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
     CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
@@ -1520,7 +1601,7 @@ void wxGtkPrintDC::DoDrawSpline(wxList *points)
     node = node->GetNext();
     while (node)
     {
-        q = (wxPoint *)node->GetData();
+        q = node->GetData();
 
         x1 = x3;
         y1 = y3;
@@ -1532,9 +1613,9 @@ void wxGtkPrintDC::DoDrawSpline(wxList *points)
         y3 = (double)(y2 + d) / 2;
 
         gs_cairo->cairo_curve_to(m_cairo,
-            XLOG2DEVREL((wxCoord)x1), YLOG2DEVREL((wxCoord)y1),
-            XLOG2DEVREL((wxCoord)x2), YLOG2DEVREL((wxCoord)y2),
-            XLOG2DEVREL((wxCoord)x3), YLOG2DEVREL((wxCoord)y3) );
+            XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
+            XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2),
+            XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );
 
         CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
         CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );
@@ -1542,16 +1623,22 @@ void wxGtkPrintDC::DoDrawSpline(wxList *points)
         node = node->GetNext();
     }
 
-    gs_cairo->cairo_line_to ( m_cairo, XLOG2DEVREL((wxCoord)c), YLOG2DEVREL((wxCoord)d) );
+    gs_cairo->cairo_line_to ( m_cairo, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );
 
     gs_cairo->cairo_stroke( m_cairo );
 }
 #endif // wxUSE_SPLINES
 
-bool wxGtkPrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
-            wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask,
-            wxCoord xsrcMask, wxCoord ysrcMask)
+bool wxGtkPrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest,
+                          wxCoord width, wxCoord height,
+                          wxDC *source, wxCoord xsrc, wxCoord ysrc,
+                          int rop, bool useMask,
+                          wxCoord WXUNUSED_UNLESS_DEBUG(xsrcMask),
+                          wxCoord WXUNUSED_UNLESS_DEBUG(ysrcMask))
 {
+    wxASSERT_MSG( xsrcMask == wxDefaultCoord && ysrcMask == wxDefaultCoord,
+                  wxT("mask coordinates are not supported") );
+
     wxCHECK_MSG( source, false, wxT("invalid source dc") );
 
     // Blit into a bitmap.
@@ -1562,23 +1649,23 @@ bool wxGtkPrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord h
     memDC.SelectObject(wxNullBitmap);
 
     // Draw bitmap. scaling and positioning is done there.
-    DrawBitmap( bitmap, xdest, ydest, useMask );
+    GetOwner()->DrawBitmap( bitmap, xdest, ydest, useMask );
 
     return true;
 }
 
-void wxGtkPrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
+void wxGtkPrinterDCImpl::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
 {
     DoDrawBitmap( icon, x, y, true );
 }
 
-void wxGtkPrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
+void wxGtkPrinterDCImpl::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
 {
-    wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrintDC::DoDrawBitmap"));
+    wxCHECK_RET( bitmap.IsOk(), wxT("Invalid bitmap in wxGtkPrinterDCImpl::DoDrawBitmap"));
 
     cairo_surface_t* surface;
-    x = wxCoord(XLOG2DEVREL(x));
-    y = wxCoord(YLOG2DEVREL(y));
+    x = wxCoord(XLOG2DEV(x));
+    y = wxCoord(YLOG2DEV(y));
     int bw = bitmap.GetWidth();
     int bh = bitmap.GetHeight();
     wxBitmap bmpSource = bitmap;  // we need a non-const instance.
@@ -1664,8 +1751,8 @@ void wxGtkPrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, b
     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) bw * m_DEV2PS / (wxDouble) bw;
-    wxDouble scaleY = (wxDouble) bh * m_DEV2PS / (wxDouble) bh;
+    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);
@@ -1685,12 +1772,12 @@ void wxGtkPrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, b
     gs_cairo->cairo_restore(m_cairo);
 }
 
-void wxGtkPrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
+void wxGtkPrinterDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
 {
     DoDrawRotatedText( text, x, y, 0.0 );
 }
 
-void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
+void wxGtkPrinterDCImpl::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
 {
     double xx = XLOG2DEV(x);
     double yy = YLOG2DEV(y);
@@ -1699,12 +1786,7 @@ void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
 
     bool underlined = m_font.Ok() && m_font.GetUnderlined();
 
-// FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
-#if wxUSE_UNICODE_UTF8
-    const char *data = text.utf8_str();
-#else
-    const wxCharBuffer data = text.utf8_str();
-#endif
+    const wxUTF8Buf data = text.utf8_str();
 
     size_t datalen = strlen(data);
     pango_layout_set_text( m_layout, data, datalen);
@@ -1743,13 +1825,20 @@ void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
         }
     }
 
-    
-    // TODO: steal scale implementation from GNOME print
+    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 );
 
-    int w,h;    
-    pango_layout_get_pixel_size( m_layout, &w, &h );           // cairo units
+    // Actually apply scaled font.
+    pango_layout_set_font_description( m_layout, m_fontdesc );
 
-        if ( m_backgroundMode == wxSOLID )
+    pango_layout_get_pixel_size( m_layout, &w, &h );
+
+        if ( m_backgroundMode == wxBRUSHSTYLE_SOLID )
         {
             unsigned char red = m_textBackgroundColour.Red();
             unsigned char blue = m_textBackgroundColour.Blue();
@@ -1772,17 +1861,15 @@ void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
 
     // Draw layout.
     gs_cairo->cairo_move_to (m_cairo, xx, yy);
-    
+
     gs_cairo->cairo_save( m_cairo );
-    
-    gs_cairo->cairo_scale( m_cairo, m_scaleX, m_scaleY );
-    
+
     if (fabs(angle) > 0.00001)
         gs_cairo->cairo_rotate( m_cairo, angle*DEG2RAD );
-        
+
     gs_cairo->pango_cairo_update_layout (m_cairo, m_layout);
     gs_cairo->pango_cairo_show_layout (m_cairo, m_layout);
-    
+
     gs_cairo->cairo_restore( m_cairo );
 
     if (underlined)
@@ -1790,13 +1877,19 @@ void wxGtkPrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
         // 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);
 }
 
-void wxGtkPrintDC::Clear()
+void wxGtkPrinterDCImpl::Clear()
 {
 // Clear does nothing for printing, but keep the code
 // for later reuse 
@@ -1809,7 +1902,7 @@ void wxGtkPrintDC::Clear()
 */
 }
 
-void wxGtkPrintDC::SetFont( const wxFont& font )
+void wxGtkPrinterDCImpl::SetFont( const wxFont& font )
 {
     m_font = font;
 
@@ -1821,7 +1914,7 @@ void wxGtkPrintDC::SetFont( const wxFont& font )
         m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); // m_fontdesc is now set to device units
 
         // Scale font description from device units to pango units
-        gint oldSize = pango_font_description_get_size( m_fontdesc ); 
+        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
 
@@ -1830,16 +1923,20 @@ void wxGtkPrintDC::SetFont( const wxFont& font )
     }
 }
 
-void wxGtkPrintDC::SetPen( const wxPen& pen )
+void wxGtkPrinterDCImpl::SetPen( const wxPen& pen )
 {
     if (!pen.Ok()) return;
 
     m_pen = pen;
 
-    double width = (double) m_pen.GetWidth();
-    if (width == 0) width = 0.1;
+    double width;
+    
+    if (m_pen.GetWidth() <= 0)
+        width = 0.1;
+    else
+        width = (double) m_pen.GetWidth();
 
-    gs_cairo->cairo_set_line_width( m_cairo, XLOG2DEVREL( (wxCoord)((1000.0 * (double)width ) / 1000.0)) );
+    gs_cairo->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};
@@ -1847,11 +1944,11 @@ void wxGtkPrintDC::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:        gs_cairo->cairo_set_dash( m_cairo, dotted, 2, 0 ); break;
+        case wxPENSTYLE_SHORT_DASH: gs_cairo->cairo_set_dash( m_cairo, short_dashed, 2, 0 ); break;
+        case wxPENSTYLE_LONG_DASH:  gs_cairo->cairo_set_dash( m_cairo, long_dashed, 2, 0 ); break;
+        case wxPENSTYLE_DOT_DASH:   gs_cairo->cairo_set_dash( m_cairo, dotted_dashed, 4, 0 );  break;
+        case wxPENSTYLE_USER_DASH:
         {
             wxDash *wx_dashes;
             int num = m_pen.GetDashes (&wx_dashes);
@@ -1863,8 +1960,8 @@ void wxGtkPrintDC::SetPen( const wxPen& pen )
             g_free( g_dashes );
         }
         break;
-        case wxSOLID:
-        case wxTRANSPARENT:
+        case wxPENSTYLE_SOLID:
+        case wxPENSTYLE_TRANSPARENT:
         default:              gs_cairo->cairo_set_dash( m_cairo, NULL, 0, 0 );   break;
     }
 
@@ -1905,13 +2002,13 @@ void wxGtkPrintDC::SetPen( const wxPen& pen )
     }
 }
 
-void wxGtkPrintDC::SetBrush( const wxBrush& brush )
+void wxGtkPrinterDCImpl::SetBrush( const wxBrush& brush )
 {
     if (!brush.Ok()) 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 );
         m_currentRed = 0;
@@ -1954,31 +2051,31 @@ void wxGtkPrintDC::SetBrush( const wxBrush& brush )
 
         switch (m_brush.GetStyle())
         {
-            case wxCROSS_HATCH:
+            case wxBRUSHSTYLE_CROSS_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);
                 break;
-            case wxBDIAGONAL_HATCH:
+            case wxBRUSHSTYLE_BDIAGONAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 0, 10);
                 gs_cairo->cairo_line_to(cr, 10, 0);
                 break;
-            case wxFDIAGONAL_HATCH:
+            case wxBRUSHSTYLE_FDIAGONAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 0, 0);
                 gs_cairo->cairo_line_to(cr, 10, 10);
                 break;
-            case wxCROSSDIAG_HATCH:
+            case wxBRUSHSTYLE_CROSSDIAG_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);
                 break;
-            case wxHORIZONTAL_HATCH:
+            case wxBRUSHSTYLE_HORIZONTAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 0, 5);
                 gs_cairo->cairo_line_to(cr, 10, 5);
                 break;
-            case wxVERTICAL_HATCH:
+            case wxBRUSHSTYLE_VERTICAL_HATCH:
                 gs_cairo->cairo_move_to(cr, 5, 0);
                 gs_cairo->cairo_line_to(cr, 5, 10);
                 break;
@@ -1998,7 +2095,7 @@ void wxGtkPrintDC::SetBrush( const wxBrush& brush )
     }
 }
 
-void wxGtkPrintDC::SetLogicalFunction( int function )
+void wxGtkPrinterDCImpl::SetLogicalFunction( int function )
 {
     if (function == wxCLEAR)
         gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_CLEAR);
@@ -2016,7 +2113,7 @@ void wxGtkPrintDC::SetLogicalFunction( int function )
         gs_cairo->cairo_set_operator (m_cairo, CAIRO_OPERATOR_SOURCE);
 }
 
-void wxGtkPrintDC::SetBackground( const wxBrush& brush )
+void wxGtkPrinterDCImpl::SetBackground( const wxBrush& brush )
 {
     m_backgroundBrush = brush;
     gs_cairo->cairo_save(m_cairo);
@@ -2027,44 +2124,46 @@ void wxGtkPrintDC::SetBackground( const wxBrush& brush )
     gs_cairo->cairo_restore(m_cairo);
 }
 
-void wxGtkPrintDC::SetBackgroundMode(int mode)
+void wxGtkPrinterDCImpl::SetBackgroundMode(int mode)
 {
-    if (mode == wxSOLID) m_backgroundMode = wxSOLID;
-    else m_backgroundMode = wxTRANSPARENT;
+    if (mode == wxBRUSHSTYLE_SOLID)
+        m_backgroundMode = wxBRUSHSTYLE_SOLID;
+    else
+        m_backgroundMode = wxBRUSHSTYLE_TRANSPARENT;
 }
 
-void wxGtkPrintDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
+void wxGtkPrinterDCImpl::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 {
-    gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEVREL(x), YLOG2DEVREL(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
+    gs_cairo->cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
     gs_cairo->cairo_clip(m_cairo);
 }
 
-void wxGtkPrintDC::DestroyClippingRegion()
+void wxGtkPrinterDCImpl::DestroyClippingRegion()
 {
     gs_cairo->cairo_reset_clip(m_cairo);
 }
 
-bool wxGtkPrintDC::StartDoc(const wxString& message)
+bool wxGtkPrinterDCImpl::StartDoc(const wxString& WXUNUSED(message))
 {
     return true;
 }
 
-void wxGtkPrintDC::EndDoc()
+void wxGtkPrinterDCImpl::EndDoc()
 {
     return;
 }
 
-void wxGtkPrintDC::StartPage()
+void wxGtkPrinterDCImpl::StartPage()
 {
     return;
 }
 
-void wxGtkPrintDC::EndPage()
+void wxGtkPrinterDCImpl::EndPage()
 {
     return;
 }
 
-wxCoord wxGtkPrintDC::GetCharHeight() const
+wxCoord wxGtkPrinterDCImpl::GetCharHeight() const
 {
     pango_layout_set_text( m_layout, "H", 1 );
 
@@ -2074,7 +2173,7 @@ wxCoord wxGtkPrintDC::GetCharHeight() const
     return wxRound( h * m_PS2DEV );
 }
 
-wxCoord wxGtkPrintDC::GetCharWidth() const
+wxCoord wxGtkPrinterDCImpl::GetCharWidth() const
 {
     pango_layout_set_text( m_layout, "H", 1 );
 
@@ -2084,7 +2183,7 @@ wxCoord wxGtkPrintDC::GetCharWidth() const
     return wxRound( w * m_PS2DEV );
 }
 
-void wxGtkPrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
+void wxGtkPrinterDCImpl::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height,
                      wxCoord *descent,
                      wxCoord *externalLeading,
                      const wxFont *theFont ) const
@@ -2104,12 +2203,7 @@ void wxGtkPrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoo
     }
 
     // Set layout's text
-    // FIXME-UTF8: wouldn't be needed if utf8_str() always returned a buffer
-#if wxUSE_UNICODE_UTF8
-    const char *dataUTF8 = string.utf8_str();
-#else
-    const wxCharBuffer dataUTF8 = string.utf8_str();
-#endif
+    const wxUTF8Buf dataUTF8 = string.utf8_str();
 
     PangoFontDescription *desc = m_fontdesc;
     if (theFont) desc = theFont->GetNativeFontInfo()->description;
@@ -2131,7 +2225,7 @@ void wxGtkPrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoo
         *width = wxRound( (double)w / m_scaleX * m_PS2DEV );
     if (height)
         *height = wxRound( (double)h / m_scaleY * m_PS2DEV );
-        
+
     if (descent)
     {
         PangoLayoutIter *iter = pango_layout_get_iter(m_layout);
@@ -2147,17 +2241,17 @@ void wxGtkPrintDC::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoo
     pango_layout_set_font_description( m_layout, m_fontdesc );
 }
 
-void wxGtkPrintDC::DoGetSize(int* width, int* height) const
+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 wxGtkPrintDC::DoGetSizeMM(int *width, int *height) const
+void wxGtkPrinterDCImpl::DoGetSizeMM(int *width, int *height) const
 {
     GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc );
 
@@ -2167,23 +2261,28 @@ void wxGtkPrintDC::DoGetSizeMM(int *width, int *height) const
         *height = wxRound( gtk_page_setup_get_paper_height( setup, GTK_UNIT_MM ) );
 }
 
-wxSize wxGtkPrintDC::GetPPI() const
+wxSize wxGtkPrinterDCImpl::GetPPI() const
 {
     return wxSize( (int)m_resolution, (int)m_resolution );
 }
 
-void wxGtkPrintDC::SetPrintData(const wxPrintData& data)
+void wxGtkPrinterDCImpl::SetPrintData(const wxPrintData& data)
 {
     m_printData = data;
 }
 
-void wxGtkPrintDC::SetResolution(int ppi)
+// overriden for wxPrinterDC Impl
+
+wxRect wxGtkPrinterDCImpl::GetPaperRect()
 {
-    // We can't change ppi of the GtkPrintContext.
-    // TODO: should we really support this?
+    // Does GtkPrint support printer margins?
+    int w = 0;
+    int h = 0;
+    DoGetSize( &w, &h );
+    return wxRect( 0,0,w,h );
 }
 
-int wxGtkPrintDC::GetResolution()
+int wxGtkPrinterDCImpl::GetResolution()
 {
     return m_resolution;
 }
@@ -2195,25 +2294,59 @@ int wxGtkPrintDC::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()
@@ -2244,16 +2377,14 @@ void wxGtkPrintPreview::DetermineScaling()
 
         m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
                                          (int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
-                         
-        // TODO !!!!!!!!!!!!!!!      
-        int resolution = 600;
-        m_previewPrintout->SetPPIPrinter( resolution, resolution );
-        
+
+        m_previewPrintout->SetPPIPrinter( m_resolution, m_resolution );
+
         // Get width and height in points (1/72th of an inch)
         wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
-
-        sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)resolution / 72.0);
-        sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)resolution / 72.0);
+        sizeDevUnits.x = wxRound((double)sizeDevUnits.x * (double)m_resolution / 72.0);
+        sizeDevUnits.y = wxRound((double)sizeDevUnits.y * (double)m_resolution / 72.0);
+        
         wxSize sizeTenthsMM(paper->GetSize());
         wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
 
@@ -2274,7 +2405,7 @@ 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_previewScaleX = 0.8 * 72.0 / (double)m_resolution;
         m_previewScaleY = m_previewScaleX;
     }
 }