output: Refactor Cairo output driver to make printing via GTK+ practical.
[pspp-builds.git] / src / ui / gui / psppire-output-window.c
index ebca5533ddfc8f5d3db601e9e4adf2abeab8145b..440df86a4545c565f2167e3b5d0f3da77fa5d2c8 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009  Free Software Foundation
+   Copyright (C) 2008, 2009, 2010  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -216,7 +216,29 @@ psppire_output_submit (struct output_driver *this,
 
   cr = gdk_cairo_create (GTK_WIDGET (pod->viewer)->window);
   if (pod->xr == NULL)
-    pod->xr = xr_create_driver (cr);
+    {
+      const GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (viewer));
+      struct string_map options = STRING_MAP_INITIALIZER (options);
+      PangoFontDescription *font_desc;
+      char *font_name;
+
+      /* Use GTK+ default font as proportional font. */
+      font_name = pango_font_description_to_string (style->font_desc);
+      string_map_insert (&options, "prop-font", font_name);
+      g_free (font_name);
+
+      /* Derived emphasized font from proportional font. */
+      font_desc = pango_font_description_copy (style->font_desc);
+      pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC);
+      font_name = pango_font_description_to_string (font_desc);
+      string_map_insert (&options, "emph-font", font_name);
+      g_free (font_name);
+      pango_font_description_free (font_desc);
+
+      pod->xr = xr_driver_create (cr, &options);
+
+      string_map_destroy (&options);
+    }
 
   r = xr_rendering_create (pod->xr, item, cr);
   if (r == NULL)
@@ -301,7 +323,6 @@ done:
 static struct output_driver_class psppire_output_class =
   {
     "PSPPIRE",                  /* name */
-    NULL,                       /* create */
     NULL,                       /* destroy */
     psppire_output_submit,      /* submit */
     NULL,                       /* flush */
@@ -315,7 +336,8 @@ psppire_output_window_setup (void)
 
   pod = xzalloc (sizeof *pod);
   d = &pod->driver;
-  output_driver_init (d, &psppire_output_class, "PSPPIRE", 0);
+  output_driver_init (d, &psppire_output_class, "PSPPIRE",
+                      SETTINGS_DEVICE_UNFILTERED);
   output_driver_register (d);
 }
 \f
@@ -387,12 +409,13 @@ add_filter (GtkFileChooser *chooser, const char *name, const char *pattern)
 
 static void
 export_output (PsppireOutputWindow *window, struct string_map *options,
-               const char *class_name)
+               const char *format)
 {
   struct output_driver *driver;
   size_t i;
 
-  driver = output_driver_create (class_name, options);
+  string_map_insert (options, "format", format);
+  driver = output_driver_create (options);
   if (driver == NULL)
     return;
 
@@ -449,29 +472,25 @@ psppire_output_window_export (PsppireOutputWindow *window)
       string_map_insert (&options, "output-file", filename);
       if (filter == pdf_filter)
         {
-          string_map_insert (&options, "output-type", "pdf");
-          export_output (window, &options, "cairo");
+          export_output (window, &options, "pdf");
         }
       else if (filter == html_filter)
         export_output (window, &options, "html");
       else if (filter == odt_filter)
-        export_output (window, &options, "odf");
+        export_output (window, &options, "odt");
       else if (filter == txt_filter)
         {
           string_map_insert (&options, "headers", "false");
           string_map_insert (&options, "paginate", "false");
           string_map_insert (&options, "squeeze", "true");
           string_map_insert (&options, "emphasis", "none");
-          string_map_insert (&options, "chart-type", "none");
+          string_map_insert (&options, "charts", "none");
           string_map_insert (&options, "top-margin", "0");
           string_map_insert (&options, "bottom-margin", "0");
-          export_output (window, &options, "ascii");
+          export_output (window, &options, "txt");
         }
       else if (filter == ps_filter)
-        {
-          string_map_insert (&options, "output-type", "ps");
-          export_output (window, &options, "cairo");
-        }
+        export_output (window, &options, "ps");
       else if (filter == csv_filter)
         export_output (window, &options, "csv");
       else