gui: Configure page setup when printing in the GUI.
[pspp-builds.git] / src / ui / gui / psppire-output-window.c
index 02d4b2543fdb5f7025528a11d76c9f6f68a4f3af..2e02b4e5ec33503f8ffc08d63676bc64e6d8d30b 100644 (file)
@@ -237,6 +237,18 @@ psppire_output_submit (struct output_driver *this,
       g_free (font_name);
       pango_font_description_free (font_desc);
 
+      /* Pretend that the "page" has a reasonable width and a very big length,
+         so that most tables can be conveniently viewed on-screen with vertical
+         scrolling only.  (The length should not be increased very much because
+         it is already close enough to INT_MAX when expressed as thousands of a
+         point.) */
+      string_map_insert (&options, "paper-size", "300x200000mm");
+      string_map_insert (&options, "headers", "off");
+      string_map_insert (&options, "left-margin", "0");
+      string_map_insert (&options, "right-margin", "0");
+      string_map_insert (&options, "top-margin", "0");
+      string_map_insert (&options, "bottom-margin", "0");
+
       pod->xr = xr_driver_create (cr, &options);
 
       string_map_destroy (&options);
@@ -605,7 +617,42 @@ psppire_output_window_new (void)
 
 
 \f
+static void
+create_xr_print_driver (GtkPrintContext *context, PsppireOutputWindow *window)
+{
+  struct string_map options;
+  GtkPageSetup *page_setup;
+  double width, height;
+  double left_margin;
+  double right_margin;
+  double top_margin;
+  double bottom_margin;
+
+  page_setup = gtk_print_context_get_page_setup (context);
+  width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
+  height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
+  left_margin = gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM);
+  right_margin = gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM);
+  top_margin = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM);
+  bottom_margin = gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM);
+
+  string_map_init (&options);
+  string_map_insert_nocopy (&options, xstrdup ("paper-size"),
+                            xasprintf("%.2fx%.2fmm", width, height));
+  string_map_insert_nocopy (&options, xstrdup ("left-margin"),
+                            xasprintf ("%.2fmm", left_margin));
+  string_map_insert_nocopy (&options, xstrdup ("right-margin"),
+                            xasprintf ("%.2fmm", right_margin));
+  string_map_insert_nocopy (&options, xstrdup ("top-margin"),
+                            xasprintf ("%.2fmm", top_margin));
+  string_map_insert_nocopy (&options, xstrdup ("bottom-margin"),
+                            xasprintf ("%.2fmm", bottom_margin));
 
+  window->print_xrd =
+    xr_driver_create (gtk_print_context_get_cairo_context (context), &options);
+
+  string_map_destroy (&options);
+}
 
 static gboolean
 paginate (GtkPrintOperation *operation,
@@ -629,23 +676,16 @@ paginate (GtkPrintOperation *operation,
     }
   else
     {
-      struct string_map options = STRING_MAP_INITIALIZER (options);
       g_print ("Number of pages is %d\n", window->print_n_pages);
       gtk_print_operation_set_n_pages (operation, window->print_n_pages);
       window->print_item = 0;
 
-      //      xr_driver_destroy (window->print_xrd);
-
-      window->print_xrd =
-       xr_driver_create (gtk_print_context_get_cairo_context (context), &options);
-
-      string_map_destroy (&options);
+      create_xr_print_driver (context, window);
 
       return TRUE;
     }
 }
 
-
 static void
 begin_print (GtkPrintOperation *operation,
             GtkPrintContext   *context,
@@ -653,12 +693,8 @@ begin_print (GtkPrintOperation *operation,
 {
   g_print ("%s\n", __FUNCTION__);
 
-  struct string_map options = STRING_MAP_INITIALIZER (options);
+  create_xr_print_driver (context, window);
 
-  window->print_xrd =
-    xr_driver_create (gtk_print_context_get_cairo_context (context), &options);
-
-  string_map_destroy (&options);
   window->print_item = 0;
   window->print_n_pages = 1;
 }