--- old/gtkprintcontext.c	2008-10-16 21:06:20.000000000 -0700
+++ gtkprintcontext.c	2009-04-26 02:14:16.293042500 -0700
@@ -218,6 +218,11 @@
   left = gtk_page_setup_get_left_margin (context->page_setup, GTK_UNIT_INCH);
   top = gtk_page_setup_get_top_margin (context->page_setup, GTK_UNIT_INCH);
 
+  if (priv->margin_adjust)
+  {
+      priv->margin_adjust(context->op, &top, NULL, &left, NULL);
+  }
+
   cairo_translate (context->cr,
 		   left * context->surface_dpi_x / context->pixels_per_unit_x,
 		   top * context->surface_dpi_y / context->pixels_per_unit_y);
--- old/gtkprintoperation-private.h	2008-10-16 21:06:20.000000000 -0700
+++ gtkprintoperation-private.h	2009-04-26 02:02:30.980603500 -0700
@@ -76,6 +76,11 @@
   void (*end_run)    (GtkPrintOperation *operation,
 		      gboolean           wait,
 		      gboolean           cancelled);
+  void (*margin_adjust) (GtkPrintOperation *operation,
+		      gdouble            *top,
+		      gdouble            *bottom,
+		      gdouble            *left,
+		      gdouble            *right);
 };
 
 
--- old/gtkprintoperation-win32.c	2008-10-16 21:06:20.000000000 -0700
+++ gtkprintoperation-win32.c	2009-04-26 09:09:59.328009500 -0700
@@ -547,6 +547,55 @@
 }
 
 static void
+win32_margin_adjust (GtkPrintOperation *op,
+		   gdouble            *top,
+		   gdouble            *bottom,
+		   gdouble            *left,
+		   gdouble            *right)
+{
+  gdouble           offset_x, offset_y;
+  POINT             pt;
+  HDC               hDc;
+  GtkPrintSettings  *prt_settings;
+  const gchar       *printer_name;
+
+  /* In Windows to make the margins into margins from the edge of the paper
+   * we need to allow for the print device's non-printable area and subtract
+   * that from the margin sizes, which we do here */
+
+  prt_settings = gtk_print_operation_get_print_settings(op);
+  printer_name = gtk_print_settings_get_printer(prt_settings);
+
+  hDc = CreateDC("WINSPOOL", printer_name, NULL, NULL);
+  if (hDc)
+    {
+      pt.x = GetDeviceCaps(hDc, PHYSICALOFFSETX);
+      pt.y = GetDeviceCaps(hDc, PHYSICALOFFSETY);
+      /* Convert Windows logical units -> pixels and then -> inches */
+      LPtoDP(hDc, &pt, 1);
+      offset_x = (gdouble)pt.x / (gdouble)GetDeviceCaps(hDc, LOGPIXELSX);
+      offset_y = (gdouble)pt.y / (gdouble)GetDeviceCaps(hDc, LOGPIXELSY);
+
+      if (top)
+        {
+          if (*top > offset_y) *top -= offset_y; else *top = 0;
+        }
+      if (bottom)
+        {
+          if (*bottom > offset_y) *bottom -= offset_y; else *bottom = 0;
+        }
+      if (left)
+        {
+          if (*left > offset_x) *left -= offset_x; else *left = 0;
+        }
+      if (right)
+        {
+          if (*right > offset_x) *right -= offset_x; else *right = 0;
+        }
+    }
+}
+
+static void
 win32_poll_status (GtkPrintOperation *op)
 {
   GtkPrintOperationWin32 *op_win32 = op->priv->platform_data;
@@ -1602,6 +1651,7 @@
   op->priv->start_page = win32_start_page;
   op->priv->end_page = win32_end_page;
   op->priv->end_run = win32_end_run;
+  op->priv->margin_adjust = win32_margin_adjust;
   
  out:
   if (!*do_print && hDC != NULL)
@@ -1826,6 +1876,7 @@
   op->priv->start_page = win32_start_page;
   op->priv->end_page = win32_end_page;
   op->priv->end_run = win32_end_run;
+  op->priv->margin_adjust = win32_margin_adjust;
   
   out:
   if (!*do_print && printdlgex && printdlgex->hDC != NULL)
--- old/gtkprintoperation-unix.c	2008-10-16 21:06:20.000000000 -0700
+++ gtkprintoperation-unix.c	2009-04-26 01:55:51.574353500 -0700
@@ -444,6 +444,7 @@
 	  priv->start_page = unix_start_page;
 	  priv->end_page = unix_end_page;
 	  priv->end_run = unix_end_run;
+	  priv->margin_adjust = NULL;
 	  
 	  job = gtk_print_job_new (priv->job_name, printer, settings, page_setup);
           op_unix->job = job;
