Code

Fixing as per discussion in LP # 179988
authorozmikepittman <ozmikepittman@users.sourceforge.net>
Fri, 28 Mar 2008 00:22:17 +0000 (00:22 +0000)
committerozmikepittman <ozmikepittman@users.sourceforge.net>
Fri, 28 Mar 2008 00:22:17 +0000 (00:22 +0000)
src/ui/dialog/print.cpp

index 9b6cc754324564daab645147b351b8c6ce257cd1..d45f1374e96697d76fba0d3c5b8d86a7bf3c70ab 100644 (file)
 #include "io/sys.h"
 
 
+
+#ifdef WIN32
+#include <windows.h>
+#include <commdlg.h>
+#include <cairo.h>
+#include <cairo-win32.h>
+
+
+
+static cairo_surface_t *
+_cairo_win32_printing_surface_create (HDC hdc)
+{
+    int x, y, x_dpi, y_dpi, x_off, y_off, depth;
+    XFORM xform;
+    cairo_surface_t *surface;
+
+    x = GetDeviceCaps (hdc, HORZRES);
+    y = GetDeviceCaps (hdc, VERTRES);
+
+    x_dpi = GetDeviceCaps (hdc, LOGPIXELSX);
+    y_dpi = GetDeviceCaps (hdc, LOGPIXELSY);
+
+    x_off = GetDeviceCaps (hdc, PHYSICALOFFSETX);
+    y_off = GetDeviceCaps (hdc, PHYSICALOFFSETY);
+
+    depth = GetDeviceCaps(hdc, BITSPIXEL);
+
+    SetGraphicsMode (hdc, GM_ADVANCED);
+    xform.eM11 = x_dpi/72.0;
+    xform.eM12 = 0;
+    xform.eM21 = 0;
+    xform.eM22 = y_dpi/72.0;
+    xform.eDx = -x_off;
+    xform.eDy = -y_off;
+    SetWorldTransform (hdc, &xform);
+
+    surface = cairo_win32_printing_surface_create (hdc);
+    
+    /**
+               Read fallback dpi from device capabilities. Was a workaround for a bug patched
+               in cairo 1.5.14. Without this, fallback defaults to 300dpi, which is quite acceptable.
+               Going higher can cause spool size and memory problems.
+       */
+    // cairo_surface_set_fallback_resolution (surface, x_dpi, y_dpi);
+
+    return surface;
+}
+#endif
+
+
+
 static void
 draw_page (GtkPrintOperation */*operation*/,
            GtkPrintContext   *context,
@@ -91,8 +142,28 @@ draw_page (GtkPrintOperation */*operation*/,
         // Render as vectors
         Inkscape::Extension::Internal::CairoRenderer renderer;
         Inkscape::Extension::Internal::CairoRenderContext *ctx = renderer.createContext();
-        bool ret = ctx->setSurfaceTarget (cairo_get_target (gtk_print_context_get_cairo_context (context)), true);
-        if (ret) {
+
+        // ctx->setPSLevel(CAIRO_PS_LEVEL_3);
+        ctx->setTextToPath(false);
+        ctx->setFilterToBitmap(true);
+        ctx->setBitmapResolution(72);
+
+        cairo_t *cr = gtk_print_context_get_cairo_context (context);
+        cairo_surface_t *surface = cairo_get_target(cr);
+
+
+/**
+       Call cairo_win32_printing_surface directly as a workaround until GTK uses this call.
+       When GTK uses cairo_win32_printing_surface this automatically reverts.
+*/
+#ifdef WIN32
+        if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_WIN32) {
+        HDC dc = cairo_win32_surface_get_dc (surface);
+        surface = _cairo_win32_printing_surface_create (dc);
+        }
+#endif
+
+        bool ret = ctx->setSurfaceTarget (surface, true);        if (ret) {
             ret = renderer.setupDocument (ctx, junk->_doc);
             if (ret) {
                 renderer.renderItem(ctx, junk->_base);
@@ -150,13 +221,17 @@ Print::Print(SPDocument *doc, SPItem *base) :
     gtk_print_operation_set_job_name (_printop, title.c_str());
 
     // set up paper size to match the document size
+    gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);
     GtkPageSetup *page_setup = gtk_page_setup_new();
     gdouble doc_width = sp_document_width(_doc) * PT_PER_PX;
     gdouble doc_height = sp_document_height(_doc) * PT_PER_PX;
     GtkPaperSize *paper_size = gtk_paper_size_new_custom("custom", "custom",
                                 doc_width, doc_height, GTK_UNIT_POINTS);
     gtk_page_setup_set_paper_size (page_setup, paper_size);
+#ifndef WIN32
     gtk_print_operation_set_default_page_setup (_printop, page_setup);
+#endif
+    gtk_print_operation_set_use_full_page (_printop, TRUE);
 
     // set up signals
     _workaround._doc = _doc;
@@ -181,4 +256,3 @@ Gtk::PrintOperationResult Print::run(Gtk::PrintOperationAction, Gtk::Window &par
 } // namespace Dialog
 } // namespace UI
 } // namespace Inkscape
-