output: Render pivot tables monolithically.
[pspp] / src / output / spv-driver.c
index 935b2fb9f7071d0362532e5e429e9c0450c87d20..900a047af5f2a3fb921aaf75b191868df5d09460 100644 (file)
 
 #include "data/file-handle-def.h"
 #include "libpspp/cast.h"
-#include "output/group-item.h"
-#include "output/page-setup-item.h"
-#include "output/table-item.h"
-#include "output/text-item.h"
+#include "output/cairo-chart.h"
+#include "output/output-item.h"
+#include "output/page-setup.h"
 #include "output/spv/spv-writer.h"
 
 #include "gl/xalloc.h"
@@ -51,30 +50,32 @@ spv_driver_cast (struct output_driver *driver)
 
 static struct output_driver *
 spv_create (struct file_handle *fh, enum settings_output_devices device_type,
-             struct string_map *o UNUSED)
+            struct driver_options *o)
 {
-  struct output_driver *d;
-  struct spv_driver *spv;
-
-  spv = xzalloc (sizeof *spv);
-  d = &spv->driver;
-  spv->handle = fh;
-  output_driver_init (&spv->driver, &spv_driver_class, fh_get_file_name (fh),
-                      device_type);
-
-  char *error = spv_writer_open (fh_get_file_name (fh), &spv->writer);
-  if (spv->writer == NULL)
+  struct spv_writer *writer;
+  char *error = spv_writer_open (fh_get_file_name (fh), &writer);
+  if (!writer)
     {
       msg (ME, "%s", error);
-      goto error;
+      free (error);
+      return NULL;
     }
 
-  return d;
-
- error:
-  fh_unref (fh);
-  output_driver_destroy (d);
-  return NULL;
+  struct page_setup *ps = page_setup_parse (o);
+  spv_writer_set_page_setup (writer, ps);
+  page_setup_destroy (ps);
+
+  struct spv_driver *spv = xmalloc (sizeof *spv);
+  *spv = (struct spv_driver) {
+    .driver = {
+      .class = &spv_driver_class,
+      .name = xstrdup (fh_get_file_name (fh)),
+      .device_type = device_type,
+    },
+    .handle = fh,
+    .writer = writer,
+  };
+  return &spv->driver;
 }
 
 static void
@@ -91,28 +92,20 @@ spv_destroy (struct output_driver *driver)
 
 static void
 spv_submit (struct output_driver *driver,
-             const struct output_item *output_item)
+            const struct output_item *output_item)
 {
   struct spv_driver *spv = spv_driver_cast (driver);
 
-  if (is_group_open_item (output_item))
-    spv_writer_open_heading (spv->writer,
-                             to_group_open_item (output_item)->command_name,
-                             to_group_open_item (output_item)->command_name);
-  else if (is_group_close_item (output_item))
-    spv_writer_close_heading (spv->writer);
-  else if (is_table_item (output_item))
-    {
-      const struct table_item *table_item = to_table_item (output_item);
-      if (table_item->pt)
-        spv_writer_put_table (spv->writer, table_item->pt);
-    }
-  else if (is_text_item (output_item))
-    spv_writer_put_text (spv->writer, to_text_item (output_item),
-                         output_get_command_name ());
-  else if (is_page_setup_item (output_item))
-    spv_writer_set_page_setup (spv->writer,
-                               to_page_setup_item (output_item)->page_setup);
+  spv_writer_write (spv->writer, output_item);
+}
+
+static void
+spv_setup (struct output_driver *driver,
+           const struct page_setup *ps)
+{
+  struct spv_driver *spv = spv_driver_cast (driver);
+
+  spv_writer_set_page_setup (spv->writer, ps);
 }
 
 struct output_driver_factory spv_driver_factory =
@@ -120,8 +113,10 @@ struct output_driver_factory spv_driver_factory =
 
 static const struct output_driver_class spv_driver_class =
   {
-    "spv",
-    spv_destroy,
-    spv_submit,
-    NULL,
+    .name = "spv",
+    .destroy = spv_destroy,
+    .submit = spv_submit,
+    .setup = spv_setup,
+    .handles_show = true,
+    .handles_groups = true,
   };