Code

family name field on svgfonts dialog now properly saves attribute. Should do the...
[inkscape.git] / src / ui / dialog / print.cpp
index d1da361088165f2fdef43af15da9f1de1e44e109..d45f1374e96697d76fba0d3c5b8d86a7bf3c70ab 100644 (file)
 #include "unit-constants.h"
 #include "helper/png-write.h"
 #include "svg/svg-color.h"
+#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,
+draw_page (GtkPrintOperation */*operation*/,
            GtkPrintContext   *context,
-           gint               page_nr,
+           gint               /*page_nr*/,
            gpointer           user_data)
 {
     struct workaround_gtkmm *junk = (struct workaround_gtkmm*)user_data;
@@ -46,7 +98,7 @@ draw_page (GtkPrintOperation *operation,
         std::string tmp_base = "inkscape-print-png-XXXXXX";
 
         int tmp_fd;
-        if ( (tmp_fd = Glib::file_open_tmp (tmp_png, tmp_base)) >= 0) {
+        if ( (tmp_fd = Inkscape::IO::file_open_tmp (tmp_png, tmp_base)) >= 0) {
             close(tmp_fd);
 
             guint32 bgcolor = 0x00000000;
@@ -58,8 +110,8 @@ draw_page (GtkPrintOperation *operation,
 
             sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,
                 width, height,
-                (unsigned long)(width * dpi / PX_PER_IN),
-                (unsigned long)(height * dpi / PX_PER_IN),
+                (unsigned long)(width * PT_PER_IN / PX_PER_IN),
+                (unsigned long)(height * PT_PER_IN / PX_PER_IN),
                 dpi, dpi, bgcolor, NULL, NULL, true, NULL);
 
             // This doesn't seem to work:
@@ -90,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);
@@ -112,8 +184,8 @@ draw_page (GtkPrintOperation *operation,
 }
 
 static GObject*
-create_custom_widget (GtkPrintOperation *operation,
-                      gpointer           user_data) 
+create_custom_widget (GtkPrintOperation */*operation*/,
+                      gpointer           user_data)
 {
     //printf("%s\n",__FUNCTION__);
     return G_OBJECT(user_data);
@@ -121,8 +193,8 @@ create_custom_widget (GtkPrintOperation *operation,
 
 static void
 begin_print (GtkPrintOperation *operation,
-             GtkPrintContext   *context,
-             gpointer           user_data) 
+             GtkPrintContext   */*context*/,
+             gpointer           /*user_data*/)
 {
     //printf("%s\n",__FUNCTION__);
     gtk_print_operation_set_n_pages (operation, 1);
@@ -149,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;
@@ -169,9 +245,10 @@ Print::Print(SPDocument *doc, SPItem *base) :
     gtk_print_operation_set_custom_tab_label (_printop, _("Rendering"));
 }
 
-Gtk::PrintOperationResult Print::run(Gtk::PrintOperationAction, Gtk::Window&)
+Gtk::PrintOperationResult Print::run(Gtk::PrintOperationAction, Gtk::Window &parent_window)
 {
-    gtk_print_operation_run (_printop, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
+    gtk_print_operation_run (_printop, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+           parent_window.gobj(), NULL);
     return Gtk::PRINT_OPERATION_RESULT_APPLY;
 }
 
@@ -179,4 +256,3 @@ Gtk::PrintOperationResult Print::run(Gtk::PrintOperationAction, Gtk::Window&)
 } // namespace Dialog
 } // namespace UI
 } // namespace Inkscape
-