Code

Fix for Bug #373309 (Print has offset on page), by Adrian Johnson.
authorJazzyNico <JazzyNico@users.sourceforge.net>
Wed, 12 Aug 2009 06:45:56 +0000 (06:45 +0000)
committerJazzyNico <JazzyNico@users.sourceforge.net>
Wed, 12 Aug 2009 06:45:56 +0000 (06:45 +0000)
src/ui/dialog/print.cpp

index d15773ecb9fa31aab81f794d2591bb720a57091b..214b1a6db9ebaa9ec3d3f22f74ad36fce2251e3f 100644 (file)
@@ -13,6 +13,7 @@
 #endif
 #ifdef WIN32
 #include <io.h>
+#include <windows.h>
 #endif
 
 #include <gtkmm/stock.h>
@@ -31,7 +32,7 @@
 
 
 static void
-draw_page (GtkPrintOperation */*operation*/,
+draw_page (GtkPrintOperation *operation,
            GtkPrintContext   *context,
            gint               /*page_nr*/,
            gpointer           user_data)
@@ -106,6 +107,24 @@ draw_page (GtkPrintOperation */*operation*/,
         cairo_surface_t *surface = cairo_get_target(cr);
         cairo_matrix_t ctm;
         cairo_get_matrix(cr, &ctm);
+#ifdef WIN32
+        //Gtk+ does not take the non printable area into account
+        //http://bugzilla.gnome.org/show_bug.cgi?id=381371
+        //
+        // This workaround translates the origin from the top left of the
+        // printable area to the top left of the page.
+        GtkPrintSettings *settings = gtk_print_operation_get_print_settings(operation);
+        const gchar *printerName = gtk_print_settings_get_printer(settings);
+        HDC hdc = CreateDC("WINSPOOL", printerName, NULL, NULL);
+        if (hdc) {
+            cairo_matrix_t mat;
+            int x_off = GetDeviceCaps (hdc, PHYSICALOFFSETX);
+            int y_off = GetDeviceCaps (hdc, PHYSICALOFFSETY);
+            cairo_matrix_init_translate(&mat, -x_off, -y_off);
+            cairo_matrix_multiply (&ctm, &ctm, &mat);
+            DeleteDC(hdc);
+        }
+#endif             
         bool ret = ctx->setSurfaceTarget (surface, true, &ctm);
         if (ret) {
             ret = renderer.setupDocument (ctx, junk->_doc, TRUE, NULL);