work
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 10 Feb 2019 00:00:45 +0000 (16:00 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 10 Feb 2019 00:00:45 +0000 (16:00 -0800)
12 files changed:
src/output/ascii.c
src/output/cairo.c
src/output/pivot-output.c
src/output/pivot-table.c
src/output/render.c
src/output/render.h
src/output/tab.c
src/output/table-item.h
src/output/table-provider.h
src/output/table.c
src/output/table.h
src/output/text-item.c

index 6f8644ba3f299b117bbf844783bc49d757d85f88..7833ed0ac5e34907f90ff8b0d6a630ccc61905b7 100644 (file)
@@ -44,6 +44,7 @@
 #include "output/driver-provider.h"
 #include "output/message-item.h"
 #include "output/options.h"
+#include "output/pivot-table.h"
 #include "output/render.h"
 #include "output/table-item.h"
 #include "output/text-item.h"
@@ -460,8 +461,9 @@ ascii_output_table_item_unref (struct ascii_driver *a,
 static void
 ascii_output_text (struct ascii_driver *a, const char *text)
 {
-  ascii_output_table_item_unref (
-    a, table_item_create (table_from_string (text), NULL, NULL));
+  struct pivot_table *pt = pivot_table_create_for_text (
+    NULL, pivot_value_new_user_text (text, -1));
+  ascii_output_table_item_unref (a, table_item_create (pt));
 }
 
 static void
index 4794fe25e1ec8b0a8264e3ad795b9bb2b6d4c7fb..80bca382a7f3159a9b8561e9ab54695c416ed431 100644 (file)
@@ -43,6 +43,7 @@
 #include "output/message-item.h"
 #include "output/options.h"
 #include "output/page-setup-item.h"
+#include "output/pivot-table.h"
 #include "output/render.h"
 #include "output/table-item.h"
 #include "output/table.h"
@@ -1582,11 +1583,11 @@ xr_driver_destroy (struct xr_driver *xr)
 static struct xr_rendering *
 xr_rendering_create_text (struct xr_driver *xr, const char *text, cairo_t *cr)
 {
-  struct table_item *table_item;
-  struct xr_rendering *r;
-
-  table_item = table_item_create (table_from_string (text), NULL, NULL);
-  r = xr_rendering_create (xr, &table_item->output_item, cr);
+  struct pivot_table *pt = pivot_table_create_for_text (
+    NULL, pivot_value_new_user_text (text, -1));
+  struct table_item *table_item = table_item_create (pt);
+  struct xr_rendering *r = xr_rendering_create (xr, &table_item->output_item,
+                                                cr);
   table_item_unref (table_item);
 
   return r;
index 69a6f7fec640f5caa4272e43ea94996fb77b3b19..08db3a0781f375fb9022c739eeeb23bba8aa7091 100644 (file)
@@ -488,29 +488,13 @@ pivot_table_submit_layer (const struct pivot_table *pt,
 }
 
 void
-pivot_table_submit (struct pivot_table *pt)
+pivot_table_flatten (const struct pivot_table *pt)
 {
-  pivot_table_assign_label_depth (CONST_CAST (struct pivot_table *, pt));
-
   int old_decimal = settings_get_decimal_char (FMT_COMMA);
   if (pt->decimal == '.' || pt->decimal == ',')
     settings_set_decimal_char (pt->decimal);
 
-  if (pt->print_all_layers)
-    {
-      size_t *layer_indexes;
-
-      PIVOT_AXIS_FOR_EACH (layer_indexes, &pt->axes[PIVOT_AXIS_LAYER])
-        {
-          if (pt->paginate_layers)
-            text_item_submit (text_item_create (TEXT_ITEM_EJECT_PAGE, ""));
-          pivot_table_submit_layer (pt, layer_indexes);
-        }
-    }
-  else
-    pivot_table_submit_layer (pt, pt->current_layer);
+  pivot_table_submit_layer (pt, pt->current_layer);
 
   settings_set_decimal_char (old_decimal);
-
-  pivot_table_destroy (pt);
 }
index 2adcf62634d32a3385a513cd85e344b9870a0d77..96821170eff043db82a47e88004d19f2ba84747c 100644 (file)
@@ -696,9 +696,7 @@ pivot_table_create__ (struct pivot_value *title)
 }
 
 /* Creates and returns a new pivot table with the given TITLE and a single cell
-   with the given CONTENT.
-
-   This is really just for error handling. */
+   with the given CONTENT. */
 struct pivot_table *
 pivot_table_create_for_text (struct pivot_value *title,
                              struct pivot_value *content)
@@ -1202,12 +1200,14 @@ pivot_table_assign_label_depth (struct pivot_table *table)
     table->axes[PIVOT_AXIS_COLUMN].label_depth = 1;
   pivot_axis_assign_label_depth (table, PIVOT_AXIS_LAYER, false);
 }
-\f
-/* Footnotes. */
 
+void
+pivot_table_submit (struct pivot_table *pt)
+{
+  pivot_table_assign_label_depth (CONST_CAST (struct pivot_table *, pt));
+  table_item_submit (table_item_create (pt));
 \f
-\f
-static void
+  static void
 indent (int indentation)
 {
   for (int i = 0; i < indentation * 2; i++)
index 4c98ad0fd9e6335334d7a4607847a2445b57ba53..0fad329ee47aaf03849bd4adf85a3df7e32e2e08 100644 (file)
@@ -1552,7 +1552,7 @@ add_text_page (struct render_pager *p, const struct table_item_text *t,
    device with the given PARAMS. */
 struct render_pager *
 render_pager_create (const struct render_params *params,
-                     const struct table_item *table_item)
+                     const struct pivot_table *pt)
 {
   const struct table *table = table_item_get_table (table_item);
 
index c10f23716060924897da482dc106128fbd5cdcf3..31046e98fe97dffc5f67a2f5be7607640b81ffbc 100644 (file)
@@ -21,7 +21,7 @@
 #include <stddef.h>
 #include "output/table-provider.h"
 
-struct table_item;
+struct pivot_table;
 
 enum render_line_style
   {
@@ -34,7 +34,7 @@ enum render_line_style
     RENDER_N_LINES
   };
 
-/* Parameters for rendering a table_item to a device.
+/* Parameters for rendering a pivot table to a device.
 
 
    Coordinate system
@@ -137,7 +137,7 @@ struct render_params
 
 /* An iterator for breaking render_pages into smaller chunks. */
 struct render_pager *render_pager_create (const struct render_params *,
-                                          const struct table_item *);
+                                          const struct pivot_table *);
 void render_pager_destroy (struct render_pager *);
 
 bool render_pager_has_next (const struct render_pager *);
index bf1f4671e54e551650eeace59bc64dfb38e9699d..19f7072dd0f23e49ef7d00b1c1e7b7a0a1b4ca66 100644 (file)
@@ -484,7 +484,6 @@ tab_get_cell (const struct table *table, int x, int y,
 
   cell->options = opt;
   cell->n_footnotes = 0;
-  cell->destructor = NULL;
 
   int style_idx = (opt & TAB_STYLE_MASK) >> TAB_STYLE_SHIFT;
   const struct area_style *style = t->styles[style_idx];
index b7866a3c9b565f95fe996d62d562c604aab4d14e..8d62421ea18ccda2290101d73dc914da68d3fcb5 100644 (file)
 /* Table items.
 
    A table item is a subclass of an output item (see output-item.h) that
-   contains a table (see table.h) and some formatting properties.  Currently
-   the formatting properties are an optional title (a brief description
-   typically displayed above the table) and an optional caption (a more verbose
-   description typically displayed below the table). */
+   contains a pivot table (see pivot-table.h). */
 
 #include "libpspp/compiler.h"
 #include "output/output-item.h"
-#include "output/table.h"
 
-/* Title or caption in a table item. */
-struct table_item_text
-  {
-    char *content;
-    const struct footnote **footnotes;
-    size_t n_footnotes;
-    struct area_style *style;
-  };
-
-struct table_item_text *table_item_text_create (const char *);
-struct table_item_text *table_item_text_clone (const struct table_item_text *);
-void table_item_text_destroy (struct table_item_text *);
-
-/* A table item.
-
-   The members of struct table_item should not be accessed directly.  Use one
-   of the accessor functions defined below. */
+/* A table item. */
 struct table_item
   {
     struct output_item output_item;  /* Superclass. */
-    struct table *table;             /* The table to be rendered. */
-    struct table_item_text *title;   /* Null if there is no title. */
-    struct table_item_text *layers;  /* Null if there is no layer info. */
-    struct table_item_text *caption; /* Null if there is no caption. */
+    struct pivot_table *table;       /* The table to be rendered. */
   };
 
-struct table_item *table_item_create (struct table *, const char *title,
-                                      const char *caption);
-
-const struct table *table_item_get_table (const struct table_item *);
-
-const struct table_item_text *table_item_get_title (const struct table_item *);
-void table_item_set_title (struct table_item *,
-                           const struct table_item_text *);
-
-const struct table_item_text *table_item_get_layers (
-  const struct table_item *);
-void table_item_set_layers (struct table_item *,
-                           const struct table_item_text *);
-
-const struct table_item_text *table_item_get_caption (
-  const struct table_item *);
-void table_item_set_caption (struct table_item *,
-                             const struct table_item_text *);
+struct table_item *table_item_create (struct pivot_table *);
 \f
 /* This boilerplate for table_item, a subclass of output_item, was
    autogenerated by mk-class-boilerplate. */
index 5df00458ed8a13d239ad1ea5c5ab019e1a775299..d4822d01a122f085951c39eba636af454c441676 100644 (file)
@@ -61,10 +61,6 @@ struct table_cell
     size_t n_footnotes;
 
     const struct area_style *style;
-
-    /* Called to free the cell's data, if nonnull. */
-    void (*destructor) (void *destructor_aux);
-    void *destructor_aux;
   };
 
 void table_cell_free (struct table_cell *);
@@ -100,18 +96,12 @@ table_cell_is_joined (const struct table_cell *cell)
 
 struct table_class
   {
-    /* Frees TABLE.
-
-       The table class may assume that any cells that were retrieved by calling
-       the 'get_cell' function have been freed (by calling their destructors)
-       before this function is called. */
+    /* Frees TABLE. */
     void (*destroy) (struct table *table);
 
     /* Initializes CELL with the contents of the table cell at column X and row
-       Y within TABLE.  All members of CELL must be initialized, except that if
-       'destructor' is set to a null pointer, then 'destructor_aux' need not be
-       initialized.  The 'contents' member of CELL must be set to a nonnull
-       value.
+       Y within TABLE.  All members of CELL must be initialized.  The
+       'contents' member of CELL must be set to a nonnull value.
 
        The table class must allow any number of cells in the table to be
        retrieved simultaneously; that is, TABLE must not assume that a given
index 8f717ead5679359b4f5c8529811e7b731d9c307d..18b822ba70c5c7c4405e3f28f54c7d2c752e3daa 100644 (file)
@@ -298,16 +298,6 @@ table_collect_footnotes (const struct table_item *item,
   return n;
 }
 \f
-/* Returns a table that contains a single cell, whose contents are the
-   left-aligned TEXT.  */
-struct table *
-table_from_string (const char *text)
-{
-  struct tab_table *t = tab_create (1, 1);
-  tab_text (t, 0, 0, TAB_LEFT, text);
-  return &t->table;
-}
-\f
 const char *
 table_halign_to_string (enum table_halign halign)
 {
index 5331aa34388d97f0d534ddf6bf8fc3a462db30d5..1229e9062f82051b94fc5a9ceb48a26675bcecca 100644 (file)
@@ -262,10 +262,5 @@ void table_set_hl (struct table *, int hl);
 void table_set_hr (struct table *, int hr);
 void table_set_ht (struct table *, int ht);
 void table_set_hb (struct table *, int hb);
-\f
-/* Table classes. */
-
-/* Simple kinds of tables. */
-struct table *table_from_string (const char *);
 
 #endif /* output/table.h */
index 2aba955eb33e240cecc377d3cdea90a40928546e..eb3155affc948926f32b093bec2278c4553ee4d9 100644 (file)
@@ -97,27 +97,24 @@ text_item_submit (struct text_item *item)
 struct table_item *
 text_item_to_table_item (struct text_item *text_item)
 {
-  struct tab_table *tab = tab_create (1, 1);
+  struct pivot_value *text = pivot_value_new_user_text (
+    text_item_get_text (text_item), -1);
 
-  struct area_style *style = pool_alloc (tab->container, sizeof *style);
-  *style = (struct area_style) AREA_STYLE_INITIALIZER;
-  struct font_style *font_style = &style->font_style;
+  struct font_style *font_style = xmalloc (sizeof *font_style);
   if (text_item->typeface)
-    font_style->typeface = pool_strdup (tab->container, text_item->typeface);
+    font_style->typeface = xstrdup (tab->container, text_item->typeface);
+  else if (text_item->type == TEXT_ITEM_SYNTAX
+           || text_item->type == TEXT_ITEM_LOG)
+    font_style->typeface = xstrdup ("Monospace");
   font_style->size = text_item->size;
   font_style->bold = text_item->bold;
   font_style->italic = text_item->italic;
   font_style->underline = text_item->underline;
   font_style->markup = text_item->markup;
-  tab->styles[0] = style;
-
-  int opts = TAB_LEFT;
-  if (text_item->markup)
-    opts |= TAB_MARKUP;
-  if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
-    opts |= TAB_FIX;
-  tab_text (tab, 0, 0, opts, text_item_get_text (text_item));
-  struct table_item *table_item = table_item_create (&tab->table, NULL, NULL);
+  text->font_style = font_style;
+
+  struct table_item *table_item = table_item_create (
+    pivot_table_create_for_text (NULL, text));
   text_item_unref (text_item);
   return table_item;
 }