output: Break struct pivot_table_look out of struct pivot_table.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 30 Oct 2020 07:02:43 +0000 (00:02 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 30 Oct 2020 07:02:43 +0000 (00:02 -0700)
19 files changed:
src/language/stats/crosstabs.q
src/language/stats/examine.c
src/language/stats/factor.c
src/language/stats/means.c
src/language/stats/oneway.c
src/language/stats/rank.c
src/language/stats/roc.c
src/output/pivot-output.c
src/output/pivot-table.c
src/output/pivot-table.h
src/output/spv/spv-legacy-decoder.c
src/output/spv/spv-legacy-decoder.h
src/output/spv/spv-light-decoder.c
src/output/spv/spv-table-look.c
src/output/spv/spv-table-look.h
src/output/spv/spv-writer.c
src/output/spv/spv.c
src/output/spv/spv.h
utilities/pspp-output.c

index e8739bc1bf438d2616fcbde50c8986bbeae77912..a66ee7798f2e4a4b0cdf6caec1f3c7494fa31cdd 100644 (file)
@@ -1247,7 +1247,7 @@ create_crosstab_table (struct crosstabs_proc *proc, struct crosstabulation *xt,
     pivot_value_new_user_text_nocopy (ds_steal_cstr (&title)),
     "Crosstabulation");
   pivot_table_set_weight_format (table, &proc->weight_format);
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   struct pivot_dimension *statistics = pivot_dimension_create (
     table, PIVOT_AXIS_ROW, N_("Statistics"));
@@ -1287,7 +1287,7 @@ create_chisq_table (struct crosstabulation *xt)
 {
   struct pivot_table *chisq = pivot_table_create (N_("Chi-Square Tests"));
   pivot_table_set_weight_format (chisq, &xt->weight_format);
-  chisq->omit_empty = true;
+  chisq->look.omit_empty = true;
 
   pivot_dimension_create (
     chisq, PIVOT_AXIS_ROW, N_("Statistics"),
@@ -1318,7 +1318,7 @@ create_sym_table (struct crosstabulation *xt)
 {
   struct pivot_table *sym = pivot_table_create (N_("Symmetric Measures"));
   pivot_table_set_weight_format (sym, &xt->weight_format);
-  sym->omit_empty = true;
+  sym->look.omit_empty = true;
 
   pivot_dimension_create (
     sym, PIVOT_AXIS_COLUMN, N_("Values"),
@@ -1358,7 +1358,7 @@ create_risk_table (struct crosstabulation *xt,
 {
   struct pivot_table *risk = pivot_table_create (N_("Risk Estimate"));
   pivot_table_set_weight_format (risk, &xt->weight_format);
-  risk->omit_empty = true;
+  risk->look.omit_empty = true;
 
   struct pivot_dimension *values = pivot_dimension_create (
     risk, PIVOT_AXIS_COLUMN, N_("Values"),
@@ -1405,7 +1405,7 @@ create_direct_table (struct crosstabulation *xt)
 {
   struct pivot_table *direct = pivot_table_create (N_("Directional Measures"));
   pivot_table_set_weight_format (direct, &xt->weight_format);
-  direct->omit_empty = true;
+  direct->look.omit_empty = true;
 
   pivot_dimension_create (
     direct, PIVOT_AXIS_COLUMN, N_("Values"),
index 50e55178281e3135e70b938dad6911b17f74c586..1fe24e132f8221035faef89f1bc1d23dab10e070 100644 (file)
@@ -589,7 +589,7 @@ static void
 percentiles_report (const struct examine *cmd, int iact_idx)
 {
   struct pivot_table *table = pivot_table_create (N_("Percentiles"));
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   struct pivot_dimension *percentiles = pivot_dimension_create (
     table, PIVOT_AXIS_COLUMN, N_("Percentiles"));
@@ -667,7 +667,7 @@ static void
 normality_report (const struct examine *cmd, int iact_idx)
 {
   struct pivot_table *table = pivot_table_create (N_("Tests of Normality"));
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   struct pivot_dimension *test =
     pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Shapiro-Wilk"),
@@ -733,7 +733,7 @@ static void
 descriptives_report (const struct examine *cmd, int iact_idx)
 {
   struct pivot_table *table = pivot_table_create (N_("Descriptives"));
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Aspect"),
                           N_("Statistic"), N_("Std. Error"));
@@ -830,7 +830,7 @@ static void
 extremes_report (const struct examine *cmd, int iact_idx)
 {
   struct pivot_table *table = pivot_table_create (N_("Extreme Values"));
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   struct pivot_dimension *statistics = pivot_dimension_create (
     table, PIVOT_AXIS_COLUMN, N_("Statistics"));
@@ -919,7 +919,7 @@ summary_report (const struct examine *cmd, int iact_idx)
 {
   struct pivot_table *table = pivot_table_create (
     N_("Case Processing Summary"));
-  table->omit_empty = true;
+  table->look.omit_empty = true;
   pivot_table_set_weight_var (table, dict_get_weight (cmd->dict));
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
index 6ebb0cd0c3b28a71a87833e6e6a1b1bccadb556c..bdfc9ae290c8b29549eff6a9d7b33e5a76daafa4 100644 (file)
@@ -1750,7 +1750,7 @@ show_explained_variance (const struct cmd_factor * factor,
 
   struct pivot_table *table = pivot_table_create (
     N_("Total Variance Explained"));
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
                           N_("Total"), PIVOT_RC_OTHER,
index 3c1c28973e3639e1238a2777d3d560fe3c586295..27a2457052243ce71b896cabd7d722570cf08b74 100644 (file)
@@ -751,7 +751,7 @@ means_shipout_single (const struct mtable *mt, const struct means *means,
                      const struct workspace *ws)
 {
   struct pivot_table *pt = pivot_table_create (N_("Report"));
-  pt->omit_empty = true;
+  pt->look.omit_empty = true;
 
   struct pivot_dimension *dim_cells =
     pivot_dimension_create (pt, PIVOT_AXIS_COLUMN, N_("Statistics"));
@@ -793,7 +793,7 @@ means_shipout_multivar (const struct mtable *mt, const struct means *means,
     }
 
   struct pivot_table *pt = pivot_table_create (ds_cstr (&dss));
-  pt->omit_empty = true;
+  pt->look.omit_empty = true;
   ds_destroy (&dss);
 
   struct pivot_dimension *dim_cells =
index 3665211a1c64aa61ee953a9603a2fafeef047ead..9b88ed1707eada8a8cbb1afec5b2d79505e6cf22 100644 (file)
@@ -1367,7 +1367,7 @@ show_comparisons (const struct oneway_spec *cmd, const struct oneway_workspace *
                                         _("Multiple Comparisons (%s)"),
                                         var_to_string (cmd->vars[v]))),
     "Multiple Comparisons");
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   struct pivot_dimension *statistics = pivot_dimension_create (
     table, PIVOT_AXIS_COLUMN, N_("Statistics"),
index 48eda85474c5e995f3768b0d1d088220aae44abc..857d6f5dff552c6f53aa74e5bb3c26364b440e1f 100644 (file)
@@ -823,7 +823,7 @@ cmd_rank (struct lexer *lexer, struct dataset *ds)
     {
       struct pivot_table *table = pivot_table_create (
         N_("Variables Created by RANK"));
-      table->omit_empty = true;
+      table->look.omit_empty = true;
 
       pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("New Variable"),
                               N_("New Variable"), N_("Function"),
index 16a6d72cb96769ad7175dc77243e775db617b4b9..5f8da6df55e04f0ea0e3b07677513fc55fe31891 100644 (file)
@@ -1062,7 +1062,7 @@ show_coords (struct roc_state *rs, const struct cmd_roc *roc)
 {
   struct pivot_table *table = pivot_table_create (
     N_("Coordinates of the Curve"));
-  table->omit_empty = true;
+  table->look.omit_empty = true;
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
                           N_("Positive if greater than or equal to"),
index 1e27c84192633ecafc6d131ae0707f515ed801f6..8ca3601cfcbaf0882dbd903ad2fa47929712bcce 100644 (file)
@@ -312,9 +312,9 @@ pivot_table_submit_layer (const struct pivot_table *pt,
 
   size_t body[TABLE_N_AXES];
   size_t *column_enumeration = pivot_table_enumerate_axis (
-    pt, PIVOT_AXIS_COLUMN, layer_indexes, pt->omit_empty, &body[H]);
+    pt, PIVOT_AXIS_COLUMN, layer_indexes, pt->look.omit_empty, &body[H]);
   size_t *row_enumeration = pivot_table_enumerate_axis (
-    pt, PIVOT_AXIS_ROW, layer_indexes, pt->omit_empty, &body[V]);
+    pt, PIVOT_AXIS_ROW, layer_indexes, pt->look.omit_empty, &body[V]);
 
   int stub[TABLE_N_AXES] = {
     [H] = pt->axes[PIVOT_AXIS_ROW].label_depth,
@@ -326,11 +326,11 @@ pivot_table_submit_layer (const struct pivot_table *pt,
 
   for (size_t i = 0; i < PIVOT_N_AREAS; i++)
     table->styles[i] = table_area_style_override (
-      table->container, &pt->areas[i], NULL, NULL);
+      table->container, &pt->look.areas[i], NULL, NULL);
 
   for (size_t i = 0; i < PIVOT_N_BORDERS; i++)
     {
-      const struct table_border_style *in = &pt->borders[i];
+      const struct table_border_style *in = &pt->look.borders[i];
       table->rule_colors[i] = pool_alloc (table->container,
                                           sizeof *table->rule_colors[i]);
       struct cell_color *out = table->rule_colors[i];
@@ -355,7 +355,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
       footnotes[i] = table_create_footnote (
         table, i, content, marker,
         table_area_style_override (table->container,
-                                   &pt->areas[PIVOT_AREA_FOOTER],
+                                   &pt->look.areas[PIVOT_AREA_FOOTER],
                                    pf->content->cell_style,
                                    pf->content->font_style));
       free (marker);
@@ -364,29 +364,29 @@ pivot_table_submit_layer (const struct pivot_table *pt,
 
   compose_headings (table,
                     &pt->axes[PIVOT_AXIS_COLUMN], H, &pt->axes[PIVOT_AXIS_ROW],
-                    pt->borders,
+                    pt->look.borders,
                     PIVOT_BORDER_DIM_COL_HORZ,
                     PIVOT_BORDER_DIM_COL_VERT,
                     PIVOT_BORDER_CAT_COL_HORZ,
                     PIVOT_BORDER_CAT_COL_VERT,
                     column_enumeration, body[H],
-                    &pt->areas[PIVOT_AREA_COLUMN_LABELS],
+                    &pt->look.areas[PIVOT_AREA_COLUMN_LABELS],
                     PIVOT_AREA_COLUMN_LABELS,
-                    &pt->areas[PIVOT_AREA_CORNER], footnotes,
+                    &pt->look.areas[PIVOT_AREA_CORNER], footnotes,
                     pt->show_values, pt->show_variables,
                     pt->rotate_inner_column_labels, false);
 
   compose_headings (table,
                     &pt->axes[PIVOT_AXIS_ROW], V, &pt->axes[PIVOT_AXIS_COLUMN],
-                    pt->borders,
+                    pt->look.borders,
                     PIVOT_BORDER_DIM_ROW_VERT,
                     PIVOT_BORDER_DIM_ROW_HORZ,
                     PIVOT_BORDER_CAT_ROW_VERT,
                     PIVOT_BORDER_CAT_ROW_HORZ,
                     row_enumeration, body[V],
-                    &pt->areas[PIVOT_AREA_ROW_LABELS],
+                    &pt->look.areas[PIVOT_AREA_ROW_LABELS],
                     PIVOT_AREA_ROW_LABELS,
-                    &pt->areas[PIVOT_AREA_CORNER], footnotes,
+                    &pt->look.areas[PIVOT_AREA_CORNER], footnotes,
                     pt->show_values, pt->show_variables,
                     false, pt->rotate_outer_row_labels);
 
@@ -405,7 +405,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
           fill_cell (table,
                      x + stub[H], y + stub[V],
                      x + stub[H], y + stub[V],
-                     &pt->areas[PIVOT_AREA_DATA], PIVOT_AREA_DATA,
+                     &pt->look.areas[PIVOT_AREA_DATA], PIVOT_AREA_DATA,
                      value, footnotes,
                      pt->show_values, pt->show_variables, false);
 
@@ -418,32 +418,32 @@ pivot_table_submit_layer (const struct pivot_table *pt,
 
   if (pt->corner_text && stub[H] && stub[V])
     fill_cell (table, 0, 0, stub[H] - 1, stub[V] - 1,
-               &pt->areas[PIVOT_AREA_CORNER], PIVOT_AREA_CORNER,
+               &pt->look.areas[PIVOT_AREA_CORNER], PIVOT_AREA_CORNER,
                pt->corner_text, footnotes,
                pt->show_values, pt->show_variables, false);
 
   if (table_nc (table) && table_nr (table))
     {
       table_hline (
-        table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_TOP),
+        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_TOP),
         0, table_nc (table) - 1, 0);
       table_hline (
-        table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_BOTTOM),
+        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_BOTTOM),
         0, table_nc (table) - 1, table_nr (table));
       table_vline (
-        table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_LEFT),
+        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_LEFT),
         0, 0, table_nr (table) - 1);
       table_vline (
-        table, get_table_rule (pt->borders, PIVOT_BORDER_INNER_RIGHT),
+        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_RIGHT),
         table_nc (table), 0, table_nr (table) - 1);
 
       if (stub[V])
         table_hline (
-          table, get_table_rule (pt->borders, PIVOT_BORDER_DATA_TOP),
+          table, get_table_rule (pt->look.borders, PIVOT_BORDER_DATA_TOP),
           0, table_nc (table) - 1, stub[V]);
       if (stub[H])
         table_vline (
-          table, get_table_rule (pt->borders, PIVOT_BORDER_DATA_LEFT),
+          table, get_table_rule (pt->look.borders, PIVOT_BORDER_DATA_LEFT),
           stub[H], 0, table_nr (table) - 1);
 
     }
@@ -455,7 +455,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
   if (pt->title)
     {
       struct table_item_text *title = pivot_value_to_table_item_text (
-        pt->title, &pt->areas[PIVOT_AREA_TITLE], footnotes,
+        pt->title, &pt->look.areas[PIVOT_AREA_TITLE], footnotes,
         pt->show_values, pt->show_variables);
       table_item_set_title (ti, title);
       table_item_text_destroy (title);
@@ -472,7 +472,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
             {
               layers = xzalloc (sizeof *layers);
               layers->style = table_area_style_override (
-                NULL, &pt->areas[PIVOT_AREA_LAYERS], NULL, NULL);
+                NULL, &pt->look.areas[PIVOT_AREA_LAYERS], NULL, NULL);
               layers->layers = xnmalloc (layer_axis->n_dimensions,
                                          sizeof *layers->layers);
             }
@@ -504,7 +504,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
   if (pt->caption && pt->show_caption)
     {
       struct table_item_text *caption = pivot_value_to_table_item_text (
-        pt->caption, &pt->areas[PIVOT_AREA_CAPTION], footnotes,
+        pt->caption, &pt->look.areas[PIVOT_AREA_CAPTION], footnotes,
         pt->show_values, pt->show_variables);
       table_item_set_caption (ti, caption);
       table_item_text_destroy (caption);
@@ -525,13 +525,13 @@ pivot_table_submit (struct pivot_table *pt)
   if (pt->decimal == '.' || pt->decimal == ',')
     settings_set_decimal_char (pt->decimal);
 
-  if (pt->print_all_layers)
+  if (pt->look.print_all_layers)
     {
       size_t *layer_indexes;
 
       PIVOT_AXIS_FOR_EACH (layer_indexes, &pt->axes[PIVOT_AXIS_LAYER])
         {
-          if (pt->paginate_layers)
+          if (pt->look.paginate_layers)
             text_item_submit (text_item_create (TEXT_ITEM_EJECT_PAGE, ""));
           pivot_table_submit_layer (pt, layer_indexes);
         }
index 3e7fb8ca137a8aecadd60008e02e077b04336b8e..b30961dacb31d01ab35420a44aa3bd1a32bb6a0f 100644 (file)
@@ -193,6 +193,80 @@ pivot_table_sizing_uninit (struct pivot_table_sizing *sizing)
     }
 }
 \f
+/* Pivot table looks. */
+
+void
+pivot_table_look_init (struct pivot_table_look *look)
+{
+  memset (look, 0, sizeof *look);
+
+  look->omit_empty = false;
+  look->row_labels_in_corner = true;
+  look->width_ranges[TABLE_HORZ][0] = 50;
+  look->width_ranges[TABLE_HORZ][1] = 72;
+  look->width_ranges[TABLE_VERT][0] = 36;
+  look->width_ranges[TABLE_VERT][1] = 120;
+
+  for (size_t i = 0; i < PIVOT_N_AREAS; i++)
+    table_area_style_copy (NULL, &look->areas[i],
+                           pivot_area_get_default_style (i));
+
+  static const enum table_stroke default_strokes[PIVOT_N_BORDERS] = {
+    [PIVOT_BORDER_TITLE]        = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_OUTER_LEFT]   = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_OUTER_TOP]    = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_OUTER_RIGHT]  = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_OUTER_BOTTOM] = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_INNER_LEFT]   = TABLE_STROKE_THICK,
+    [PIVOT_BORDER_INNER_TOP]    = TABLE_STROKE_THICK,
+    [PIVOT_BORDER_INNER_RIGHT]  = TABLE_STROKE_THICK,
+    [PIVOT_BORDER_INNER_BOTTOM] = TABLE_STROKE_THICK,
+    [PIVOT_BORDER_DATA_LEFT]    = TABLE_STROKE_THICK,
+    [PIVOT_BORDER_DATA_TOP]     = TABLE_STROKE_THICK,
+    [PIVOT_BORDER_DIM_ROW_HORZ] = TABLE_STROKE_SOLID,
+    [PIVOT_BORDER_DIM_ROW_VERT] = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_DIM_COL_HORZ] = TABLE_STROKE_SOLID,
+    [PIVOT_BORDER_DIM_COL_VERT] = TABLE_STROKE_SOLID,
+    [PIVOT_BORDER_CAT_ROW_HORZ] = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_CAT_ROW_VERT] = TABLE_STROKE_NONE,
+    [PIVOT_BORDER_CAT_COL_HORZ] = TABLE_STROKE_SOLID,
+    [PIVOT_BORDER_CAT_COL_VERT] = TABLE_STROKE_SOLID,
+  };
+  for (size_t i = 0; i < PIVOT_N_BORDERS; i++)
+    look->borders[i] = (struct table_border_style) {
+      .stroke = default_strokes[i],
+      .color = CELL_COLOR_BLACK,
+    };
+}
+
+void
+pivot_table_look_uninit (struct pivot_table_look *look)
+{
+  free (look->name);
+
+  for (size_t i = 0; i < PIVOT_N_AREAS; i++)
+    table_area_style_uninit (&look->areas[i]);
+
+  free (look->continuation);
+}
+
+static char *
+xstrdup_if_nonempty (const char *s)
+{
+  return s && s[0] ? xstrdup (s) : NULL;
+}
+
+void
+pivot_table_look_copy (struct pivot_table_look *dst,
+                       const struct pivot_table_look *src)
+{
+  *dst = *src;
+  dst->name = xstrdup_if_nonempty (src->name);
+  for (size_t i = 0; i < PIVOT_N_AREAS; i++)
+    table_area_style_copy (NULL, &dst->areas[i], &src->areas[i]);
+  dst->continuation = xstrdup_if_nonempty (src->continuation);
+}
+\f
 /* Axes. */
 
 /* Returns the name of AXIS_TYPE. */
@@ -707,44 +781,8 @@ pivot_table_create__ (struct pivot_value *title, const char *subtype)
   table->subtype = subtype ? pivot_value_new_text (subtype) : NULL;
   table->command_c = output_get_command_name ();
 
-  table->sizing[TABLE_HORZ].range[0] = 50;
-  table->sizing[TABLE_HORZ].range[1] = 72;
-  table->sizing[TABLE_VERT].range[0] = 36;
-  table->sizing[TABLE_VERT].range[1] = 120;
-
-  for (size_t i = 0; i < PIVOT_N_AREAS; i++)
-    table_area_style_copy (NULL, &table->areas[i],
-                           pivot_area_get_default_style (i));
+  pivot_table_look_init (&table->look);
 
-  /* Set default border styles. */
-  static const enum table_stroke default_strokes[PIVOT_N_BORDERS] = {
-    [PIVOT_BORDER_TITLE]        = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_OUTER_LEFT]   = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_OUTER_TOP]    = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_OUTER_RIGHT]  = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_OUTER_BOTTOM] = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_INNER_LEFT]   = TABLE_STROKE_THICK,
-    [PIVOT_BORDER_INNER_TOP]    = TABLE_STROKE_THICK,
-    [PIVOT_BORDER_INNER_RIGHT]  = TABLE_STROKE_THICK,
-    [PIVOT_BORDER_INNER_BOTTOM] = TABLE_STROKE_THICK,
-    [PIVOT_BORDER_DATA_LEFT]    = TABLE_STROKE_THICK,
-    [PIVOT_BORDER_DATA_TOP]     = TABLE_STROKE_THICK,
-    [PIVOT_BORDER_DIM_ROW_HORZ] = TABLE_STROKE_SOLID,
-    [PIVOT_BORDER_DIM_ROW_VERT] = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_DIM_COL_HORZ] = TABLE_STROKE_SOLID,
-    [PIVOT_BORDER_DIM_COL_VERT] = TABLE_STROKE_SOLID,
-    [PIVOT_BORDER_CAT_ROW_HORZ] = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_CAT_ROW_VERT] = TABLE_STROKE_NONE,
-    [PIVOT_BORDER_CAT_COL_HORZ] = TABLE_STROKE_SOLID,
-    [PIVOT_BORDER_CAT_COL_VERT] = TABLE_STROKE_SOLID,
-  };
-  for (size_t i = 0; i < PIVOT_N_BORDERS; i++)
-    table->borders[i] = (struct table_border_style) {
-      .stroke = default_strokes[i],
-      .color = CELL_COLOR_BLACK,
-    };
-
-  table->row_labels_in_corner = true;
   hmap_init (&table->cells);
 
   return table;
@@ -793,13 +831,11 @@ pivot_table_unref (struct pivot_table *table)
     return;
 
   free (table->current_layer);
-  free (table->table_look);
+  pivot_table_look_uninit (&table->look);
 
   for (int i = 0; i < TABLE_N_AXES; i++)
     pivot_table_sizing_uninit (&table->sizing[i]);
 
-  free (table->continuation);
-
   for (int i = 0; i < sizeof table->ccs / sizeof *table->ccs; i++)
     free (table->ccs[i]);
 
@@ -820,9 +856,6 @@ pivot_table_unref (struct pivot_table *table)
   pivot_value_destroy (table->corner_text);
   pivot_value_destroy (table->caption);
 
-  for (size_t i = 0; i < PIVOT_N_AREAS; i++)
-    table_area_style_uninit (&table->areas[i]);
-
   for (size_t i = 0; i < table->n_dimensions; i++)
     pivot_dimension_destroy (table->dimensions[i]);
   free (table->dimensions);
@@ -851,6 +884,20 @@ pivot_table_is_shared (const struct pivot_table *table)
   return table->ref_cnt > 1;
 }
 
+const struct pivot_table_look *
+pivot_table_get_look (const struct pivot_table *table)
+{
+  return &table->look;
+}
+
+void
+pivot_table_set_look (struct pivot_table *table,
+                      const struct pivot_table_look *look)
+{
+  pivot_table_look_uninit (&table->look);
+  pivot_table_look_copy (&table->look, look);
+}
+
 /* Sets the format used for PIVOT_RC_COUNT cells to the one used for variable
    WV, which should be the weight variable for the dictionary whose data or
    statistics are being put into TABLE.
@@ -1056,7 +1103,7 @@ pivot_table_create_footnote__ (struct pivot_table *table, size_t idx,
           struct pivot_footnote *f = xmalloc (sizeof *f);
           f->idx = table->n_footnotes;
           f->marker = pivot_make_default_footnote_marker (
-            f->idx, table->show_numeric_markers);
+            f->idx, table->look.show_numeric_markers);
           f->content = NULL;
           f->show = true;
 
@@ -1275,7 +1322,7 @@ pivot_table_assign_label_depth (struct pivot_table *table)
 {
   pivot_axis_assign_label_depth (table, PIVOT_AXIS_COLUMN, false);
   if (pivot_axis_assign_label_depth (
-        table, PIVOT_AXIS_ROW, (table->row_labels_in_corner
+        table, PIVOT_AXIS_ROW, (table->look.row_labels_in_corner
                                 && !table->corner_text))
       && table->axes[PIVOT_AXIS_COLUMN].label_depth == 0)
     table->axes[PIVOT_AXIS_COLUMN].label_depth = 1;
@@ -1436,11 +1483,13 @@ free_headings (const struct pivot_axis *axis, char ***headings)
 }
 
 static void
-pivot_table_sizing_dump (const char *name, const struct pivot_table_sizing *s,
+pivot_table_sizing_dump (const char *name,
+                         const int width_ranges[2],
+                         const struct pivot_table_sizing *s,
                          int indentation)
 {
   indent (indentation);
-  printf ("%ss: min=%d, max=%d\n", name, s->range[0], s->range[1]);
+  printf ("%ss: min=%d, max=%d\n", name, width_ranges[0], width_ranges[1]);
   if (s->n_widths)
     {
       indent (indentation + 1);
@@ -1484,7 +1533,7 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
   pivot_table_dump_string (table->dataset, "dataset", indentation);
   pivot_table_dump_string (table->datafile, "datafile", indentation);
   pivot_table_dump_string (table->notes, "notes", indentation);
-  pivot_table_dump_string (table->table_look, "table-look", indentation);
+  pivot_table_dump_string (table->look.name, "table-look", indentation);
   if (table->date)
     {
       indent (indentation);
@@ -1497,20 +1546,21 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
 
   indent (indentation);
   printf ("sizing:\n");
-  pivot_table_sizing_dump ("column", &table->sizing[TABLE_HORZ],
-                           indentation + 1);
-  pivot_table_sizing_dump ("row", &table->sizing[TABLE_VERT],
-                           indentation + 1);
+  pivot_table_sizing_dump ("column", table->look.width_ranges[TABLE_HORZ],
+                           &table->sizing[TABLE_HORZ], indentation + 1);
+  pivot_table_sizing_dump ("row", table->look.width_ranges[TABLE_VERT],
+                           &table->sizing[TABLE_VERT], indentation + 1);
 
   indent (indentation);
   printf ("areas:\n");
   for (enum pivot_area area = 0; area < PIVOT_N_AREAS; area++)
-    table_area_style_dump (area, &table->areas[area], indentation + 1);
+    table_area_style_dump (area, &table->look.areas[area], indentation + 1);
 
   indent (indentation);
   printf ("borders:\n");
   for (enum pivot_border border = 0; border < PIVOT_N_BORDERS; border++)
-    table_border_style_dump (border, &table->borders[border], indentation + 1);
+    table_border_style_dump (border, &table->look.borders[border],
+                             indentation + 1);
 
   for (size_t i = 0; i < table->n_dimensions; i++)
     pivot_dimension_dump (table->dimensions[i], indentation);
@@ -1579,9 +1629,9 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
       putchar ('\n');
 
       size_t *column_enumeration = pivot_table_enumerate_axis (
-        table, PIVOT_AXIS_COLUMN, layer_indexes, table->omit_empty, NULL);
+        table, PIVOT_AXIS_COLUMN, layer_indexes, table->look.omit_empty, NULL);
       size_t *row_enumeration = pivot_table_enumerate_axis (
-        table, PIVOT_AXIS_ROW, layer_indexes, table->omit_empty, NULL);
+        table, PIVOT_AXIS_ROW, layer_indexes, table->look.omit_empty, NULL);
 
       char ***column_headings = compose_headings (
         &table->axes[PIVOT_AXIS_COLUMN], column_enumeration,
@@ -2121,12 +2171,6 @@ pivot_value_new_text_format (const char *format, ...)
   return value;
 }
 
-static char *
-xstrdup_if_nonempty (const char *s)
-{
-  return s && s[0] ? xstrdup (s) : NULL;
-}
-
 /* Returns a new pivot_value that represents X.
 
    The format to use for X is unspecified.  Usually the easiest way to specify
index b6f746e6bf17703d9c838e9358583a1c3e9353c5..cc61377fc29818160b438e8866ca001873d51af0 100644 (file)
@@ -154,9 +154,6 @@ void pivot_border_get_default_style (enum pivot_border,
    heights. */
 struct pivot_table_sizing
   {
-    /* Minimum and maximum column width, in 1/96" units. */
-    int range[2];
-
     /* Specific column widths, in 1/96" units. */
     int *widths;
     size_t n_widths;
@@ -372,6 +369,42 @@ void pivot_category_destroy (struct pivot_category *);
 
 bool pivot_result_class_change (const char *, const struct fmt_spec *);
 \f
+/* Styling for a pivot table.
+
+   The division between this and the style information in struct pivot_table
+   seems fairly arbitrary.  The ultimate reason for the division is simply
+   because that's how SPSS documentation and file formats do it. */
+struct pivot_table_look
+  {
+    char *name;                 /* May be null. */
+
+    /* General properties. */
+    bool omit_empty;
+    bool row_labels_in_corner;
+    int width_ranges[TABLE_N_AXES][2];      /* In 1/96" units. */
+
+    /* Footnote display settings. */
+    bool show_numeric_markers;
+    bool footnote_marker_superscripts;
+
+    /* Styles. */
+    struct table_area_style areas[PIVOT_N_AREAS];
+    struct table_border_style borders[PIVOT_N_BORDERS];
+
+    /* Print settings. */
+    bool print_all_layers;
+    bool paginate_layers;
+    bool shrink_to_fit[TABLE_N_AXES];
+    bool top_continuation, bottom_continuation;
+    char *continuation;
+    size_t n_orphan_lines;
+  };
+
+void pivot_table_look_init (struct pivot_table_look *);
+void pivot_table_look_uninit (struct pivot_table_look *);
+void pivot_table_look_copy (struct pivot_table_look *,
+                            const struct pivot_table_look *);
+\f
 /* A pivot table.  See the top of this file for more information. */
 struct pivot_table
   {
@@ -380,35 +413,23 @@ struct pivot_table
        the pivot_table must not be modified. */
     int ref_cnt;
 
+    /* Styling. */
+    struct pivot_table_look look;
+
     /* Display settings. */
     bool rotate_inner_column_labels;
     bool rotate_outer_row_labels;
-    bool row_labels_in_corner;
     bool show_grid_lines;
     bool show_caption;
-    bool omit_empty;       /* Omit empty rows and columns? */
     size_t *current_layer; /* axis[PIVOT_AXIS_LAYER].n_dimensions elements. */
-    char *table_look;      /* May be NULL. */
     enum settings_value_show show_values;
     enum settings_value_show show_variables;
     struct fmt_spec weight_format;
 
-    /* Footnote display settings. */
-    bool show_numeric_markers;
-    bool footnote_marker_superscripts;
-
     /* Column and row sizing and page breaks.
        sizing[TABLE_HORZ] is for columns, sizing[TABLE_VERT] is for rows. */
     struct pivot_table_sizing sizing[TABLE_N_AXES];
 
-    /* Print settings. */
-    bool print_all_layers;
-    bool paginate_layers;
-    bool shrink_to_fit[TABLE_N_AXES];
-    bool top_continuation, bottom_continuation;
-    char *continuation;
-    size_t n_orphan_lines;
-
     /* Format settings. */
     int epoch;
     char decimal;               /* Usually ',' or '.'. */
@@ -438,10 +459,6 @@ struct pivot_table
     struct pivot_value *caption;
     char *notes;
 
-    /* Styles. */
-    struct table_area_style areas[PIVOT_N_AREAS];
-    struct table_border_style borders[PIVOT_N_BORDERS];
-
     /* Dimensions. */
     struct pivot_dimension **dimensions;
     size_t n_dimensions;
@@ -463,6 +480,12 @@ struct pivot_table *pivot_table_ref (const struct pivot_table *);
 void pivot_table_unref (struct pivot_table *);
 bool pivot_table_is_shared (const struct pivot_table *);
 
+/* Styling. */
+const struct pivot_table_look *pivot_table_get_look (
+  const struct pivot_table *);
+void pivot_table_set_look (struct pivot_table *,
+                           const struct pivot_table_look *);
+
 /* Format of PIVOT_RC_COUNT cells. */
 void pivot_table_set_weight_var (struct pivot_table *,
                                  const struct variable *);
index 0c0f954797aa80c0eb14129d696acf914da5b7ad..09924cf8e0453d6c6e3b6637165221d3db01fa30 100644 (file)
@@ -671,12 +671,12 @@ decode_label_frame (struct pivot_table *table,
   if (lf->label->purpose == SPVDX_PURPOSE_TITLE)
     {
       target = &table->title;
-      area = &table->areas[PIVOT_AREA_TITLE];
+      area = &table->look.areas[PIVOT_AREA_TITLE];
     }
   else if (lf->label->purpose == SPVDX_PURPOSE_SUB_TITLE)
     {
       target = &table->caption;
-      area = &table->areas[PIVOT_AREA_CAPTION];
+      area = &table->look.areas[PIVOT_AREA_CAPTION];
     }
   else if (lf->label->purpose == SPVDX_PURPOSE_FOOTNOTE)
     {
@@ -684,7 +684,7 @@ decode_label_frame (struct pivot_table *table,
           && lf->label->text[0]->uses_reference != INT_MIN)
         {
           target = NULL;
-          area = &table->areas[PIVOT_AREA_FOOTER];
+          area = &table->look.areas[PIVOT_AREA_FOOTER];
         }
       else
         return NULL;
@@ -692,7 +692,7 @@ decode_label_frame (struct pivot_table *table,
   else if (lf->label->purpose == SPVDX_PURPOSE_LAYER)
     {
       target = NULL;
-      area = &table->areas[PIVOT_AREA_LAYERS];
+      area = &table->look.areas[PIVOT_AREA_LAYERS];
     }
   else
     return NULL;
@@ -1079,11 +1079,12 @@ add_dimension (struct spv_series **series, size_t n,
     = find_facet_level (v, base_facet_level + n);
   if (fl)
     {
-      struct table_area_style *area = (axis_type == PIVOT_AXIS_COLUMN
-                                       ? &table->areas[PIVOT_AREA_COLUMN_LABELS]
-                                       : axis_type == PIVOT_AXIS_ROW
-                                       ? &table->areas[PIVOT_AREA_ROW_LABELS]
-                                       : NULL);
+      struct table_area_style *area
+        = (axis_type == PIVOT_AXIS_COLUMN
+           ? &table->look.areas[PIVOT_AREA_COLUMN_LABELS]
+           : axis_type == PIVOT_AXIS_ROW
+           ? &table->look.areas[PIVOT_AREA_ROW_LABELS]
+           : NULL);
       if (area && fl->axis->label)
         {
           table_area_style_uninit (area);
@@ -1100,7 +1101,7 @@ add_dimension (struct spv_series **series, size_t n,
         decode_spvdx_style_incremental (
           fl2->axis->major_ticks->style,
           fl2->axis->major_ticks->tick_frame_style,
-          &table->areas[PIVOT_AREA_ROW_LABELS]);
+          &table->look.areas[PIVOT_AREA_ROW_LABELS]);
     }
 
   const struct spvdx_facet_level *fl3 = find_facet_level (v, base_facet_level);
@@ -1493,9 +1494,9 @@ decode_set_cell_properties__ (struct pivot_table *table,
       /* Sets alt_fg_color and alt_bg_color. */
       struct table_area_style area;
       decode_spvdx_style (labeling, graph, &area);
-      table->areas[PIVOT_AREA_DATA].font_style.fg[1]
+      table->look.areas[PIVOT_AREA_DATA].font_style.fg[1]
         = area.font_style.fg[0];
-      table->areas[PIVOT_AREA_DATA].font_style.bg[1]
+      table->look.areas[PIVOT_AREA_DATA].font_style.bg[1]
         = area.font_style.bg[0];
       table_area_style_uninit (&area);
     }
@@ -1531,8 +1532,8 @@ decode_set_cell_properties__ (struct pivot_table *table,
             {
               const struct table_area_style *base_area_style
                 = (c->dimension->axis_type == PIVOT_AXIS_ROW
-                   ? &table->areas[PIVOT_AREA_ROW_LABELS]
-                   : &table->areas[PIVOT_AREA_COLUMN_LABELS]);
+                   ? &table->look.areas[PIVOT_AREA_ROW_LABELS]
+                   : &table->look.areas[PIVOT_AREA_COLUMN_LABELS]);
               apply_styles_to_value (table, c->name, set_format,
                                      base_area_style, major_ticks, frame);
             }
@@ -1625,7 +1626,7 @@ decode_set_cell_properties__ (struct pivot_table *table,
                 goto skip;
             }
           apply_styles_to_value (table, cell->value, set_format,
-                                 &table->areas[PIVOT_AREA_DATA],
+                                 &table->look.areas[PIVOT_AREA_DATA],
                                  labeling, interval);
 
         skip: ;
@@ -1696,7 +1697,7 @@ decode_set_cell_properties (struct pivot_table *table, struct hmap *series_map,
               struct pivot_cell *cell;
               HMAP_FOR_EACH (cell, struct pivot_cell, hmap_node, &table->cells)
                 apply_styles_to_value (table, cell->value, set_format,
-                                       &table->areas[PIVOT_AREA_DATA],
+                                       &table->look.areas[PIVOT_AREA_DATA],
                                        NULL, NULL);
             }
         }
@@ -1755,11 +1756,11 @@ format_map_destroy (struct hmap *format_map)
 
 char * WARN_UNUSED_RESULT
 decode_spvdx_table (const struct spvdx_visualization *v, const char *subtype,
-                    const struct spv_table_look *look,
+                    const struct pivot_table_look *look,
                     struct spv_data *data, struct pivot_table **outp)
 {
   struct pivot_table *table = pivot_table_create__ (NULL, subtype);
-  spv_table_look_install (look, table);
+  pivot_table_set_look (table, look);
 
   struct hmap series_map = HMAP_INITIALIZER (series_map);
   struct hmap format_map = HMAP_INITIALIZER (format_map);
@@ -1777,8 +1778,8 @@ decode_spvdx_table (const struct spvdx_visualization *v, const char *subtype,
                   &min_width, &max_width, &n)
           && v->graph->cell_style->width[n] == '\0')
         {
-          table->sizing[TABLE_HORZ].range[0] = min_width;
-          table->sizing[TABLE_HORZ].range[1] = max_width;
+          table->look.width_ranges[TABLE_HORZ][0] = min_width;
+          table->look.width_ranges[TABLE_HORZ][1] = max_width;
         }
     }
 
@@ -1844,10 +1845,10 @@ decode_spvdx_table (const struct spvdx_visualization *v, const char *subtype,
       }
   if (v->graph->interval->labeling->style)
     {
-      table_area_style_uninit (&table->areas[PIVOT_AREA_DATA]);
+      table_area_style_uninit (&table->look.areas[PIVOT_AREA_DATA]);
       decode_spvdx_style (v->graph->interval->labeling->style,
                           v->graph->cell_style,
-                          &table->areas[PIVOT_AREA_DATA]);
+                          &table->look.areas[PIVOT_AREA_DATA]);
     }
 
   /* Decode all of the sourceVariable and derivedVariable  */
index 2cf9d6b10f68e2890bf8cb01b57defdf84f732b7..0b88811a6842717dc08d7cc7576ab284d7b87c24 100644 (file)
 struct pivot_table;
 struct spvdx_visualization;
 struct spv_data;
-struct spv_table_look;
+struct pivot_table_look;
 
 char *decode_spvdx_table (const struct spvdx_visualization *,
                           const char *subtype,
-                          const struct spv_table_look *,
+                          const struct pivot_table_look *,
                           struct spv_data *,
                           struct pivot_table **outp)
   WARN_UNUSED_RESULT;
index a09ac5ba242080b89ab5705c633caadea8afc7e0..a352106434ceb67885fd8e385f018e3bfc2dd9fc 100644 (file)
@@ -679,7 +679,7 @@ decode_spvlb_border (const struct spvlb_border *in, struct pivot_table *table)
   if (in->border_type >= PIVOT_N_BORDERS)
     return xasprintf ("bad border type %"PRIu32, in->border_type);
 
-  struct table_border_style *out = &table->borders[in->border_type];
+  struct table_border_style *out = &table->look.borders[in->border_type];
   out->color = decode_spvlb_color_u32 (in->color);
   return decode_spvlb_stroke (in->stroke_type, &out->stroke);
 }
@@ -839,14 +839,14 @@ decode_spvlb_table (const struct spvlb_table *in, struct pivot_table **outp)
     }
 
   /* Display settings. */
-  out->show_numeric_markers = !in->ts->show_alphabetic_markers;
+  out->look.show_numeric_markers = !in->ts->show_alphabetic_markers;
   out->rotate_inner_column_labels = in->header->rotate_inner_column_labels;
   out->rotate_outer_row_labels = in->header->rotate_outer_row_labels;
-  out->row_labels_in_corner = in->ts->show_row_labels_in_corner;
+  out->look.row_labels_in_corner = in->ts->show_row_labels_in_corner;
   out->show_grid_lines = in->borders->show_grid_lines;
   out->show_caption = true;
-  out->footnote_marker_superscripts = in->ts->footnote_marker_superscripts;
-  out->omit_empty = in->ts->omit_empty;
+  out->look.footnote_marker_superscripts = in->ts->footnote_marker_superscripts;
+  out->look.omit_empty = in->ts->omit_empty;
 
   const struct spvlb_x1 *x1 = in->formats->x1;
   if (x1)
@@ -862,10 +862,10 @@ decode_spvlb_table (const struct spvlb_table *in, struct pivot_table **outp)
     }
 
   /* Column and row display settings. */
-  out->sizing[TABLE_VERT].range[0] = in->header->min_row_height;
-  out->sizing[TABLE_VERT].range[1] = in->header->max_row_height;
-  out->sizing[TABLE_HORZ].range[0] = in->header->min_col_width;
-  out->sizing[TABLE_HORZ].range[1] = in->header->max_col_width;
+  out->look.width_ranges[TABLE_VERT][0] = in->header->min_row_height;
+  out->look.width_ranges[TABLE_VERT][1] = in->header->max_row_height;
+  out->look.width_ranges[TABLE_HORZ][0] = in->header->min_col_width;
+  out->look.width_ranges[TABLE_HORZ][1] = in->header->max_col_width;
 
   convert_widths (in->formats->widths, in->formats->n_widths,
                   &out->sizing[TABLE_HORZ].widths,
@@ -892,17 +892,17 @@ decode_spvlb_table (const struct spvlb_table *in, struct pivot_table **outp)
                  &out->sizing[TABLE_HORZ].n_keeps);
 
   out->notes = to_utf8_if_nonempty (in->ts->notes, encoding);
-  out->table_look = to_utf8_if_nonempty (in->ts->table_look, encoding);
+  out->look.name = to_utf8_if_nonempty (in->ts->table_look, encoding);
 
   /* Print settings. */
-  out->print_all_layers = in->ps->all_layers;
-  out->paginate_layers = in->ps->paginate_layers;
-  out->shrink_to_fit[TABLE_HORZ] = in->ps->fit_width;
-  out->shrink_to_fit[TABLE_VERT] = in->ps->fit_length;
-  out->top_continuation = in->ps->top_continuation;
-  out->bottom_continuation = in->ps->bottom_continuation;
-  out->continuation = xstrdup (in->ps->continuation_string);
-  out->n_orphan_lines = in->ps->n_orphan_lines;
+  out->look.print_all_layers = in->ps->all_layers;
+  out->look.paginate_layers = in->ps->paginate_layers;
+  out->look.shrink_to_fit[TABLE_HORZ] = in->ps->fit_width;
+  out->look.shrink_to_fit[TABLE_VERT] = in->ps->fit_length;
+  out->look.top_continuation = in->ps->top_continuation;
+  out->look.bottom_continuation = in->ps->bottom_continuation;
+  out->look.continuation = xstrdup (in->ps->continuation_string);
+  out->look.n_orphan_lines = in->ps->n_orphan_lines;
 
   /* Format settings. */
   out->epoch = in->formats->y0->epoch;
@@ -990,7 +990,7 @@ decode_spvlb_table (const struct spvlb_table *in, struct pivot_table **outp)
   /* Styles. */
   for (size_t i = 0; i < PIVOT_N_AREAS; i++)
     {
-      error = decode_spvlb_area (in->areas->areas[i], &out->areas[i],
+      error = decode_spvlb_area (in->areas->areas[i], &out->look.areas[i],
                                  encoding);
       if (error)
         goto error;
index c9945b000c6dd5239fda002db95a764cebfdddef..03850bb433c56c8c4629b7d9d9a376521623cd5d 100644 (file)
@@ -25,6 +25,8 @@
 #include <string.h>
 
 #include "output/spv/structure-xml-parser.h"
+#include "output/pivot-table.h"
+#include "output/table.h"
 
 #include "gl/read-file.h"
 #include "gl/xalloc.h"
@@ -121,9 +123,9 @@ pivot_border_from_name (const char *name)
 
 char * WARN_UNUSED_RESULT
 spv_table_look_decode (const struct spvsx_table_properties *in,
-                       struct spv_table_look **outp)
+                       struct pivot_table_look **outp)
 {
-  struct spv_table_look *out = xzalloc (sizeof *out);
+  struct pivot_table_look *out = xzalloc (sizeof *out);
   char *error = NULL;
 
   out->name = in->name ? xstrdup (in->name) : NULL;
@@ -260,8 +262,8 @@ spv_table_look_decode (const struct spvsx_table_properties *in,
   const struct spvsx_printing_properties *pp = in->printing_properties;
   out->print_all_layers = pp->print_all_layers > 0;
   out->paginate_layers = pp->print_each_layer_on_separate_page > 0;
-  out->shrink_to_width = pp->rescale_wide_table_to_fit_page > 0;
-  out->shrink_to_length = pp->rescale_long_table_to_fit_page > 0;
+  out->shrink_to_fit[TABLE_HORZ] = pp->rescale_wide_table_to_fit_page > 0;
+  out->shrink_to_fit[TABLE_VERT] = pp->rescale_long_table_to_fit_page > 0;
   out->top_continuation = pp->continuation_text_at_top > 0;
   out->bottom_continuation = pp->continuation_text_at_bottom > 0;
   out->continuation = xstrdup (pp->continuation_text
@@ -272,13 +274,14 @@ spv_table_look_decode (const struct spvsx_table_properties *in,
   return NULL;
 
 error:
-  spv_table_look_destroy (out);
+  pivot_table_look_uninit (out);
+  free (out);
   *outp = NULL;
   return error;
 }
 
 char * WARN_UNUSED_RESULT
-spv_table_look_read (const char *filename, struct spv_table_look **outp)
+spv_table_look_read (const char *filename, struct pivot_table_look **outp)
 {
   *outp = NULL;
 
@@ -362,7 +365,7 @@ end_elem (xmlTextWriter *xml)
 }
 
 char * WARN_UNUSED_RESULT
-spv_table_look_write (const char *filename, const struct spv_table_look *look)
+spv_table_look_write (const char *filename, const struct pivot_table_look *look)
 {
   FILE *file = fopen (filename, "w");
   if (!file)
@@ -476,8 +479,10 @@ spv_table_look_write (const char *filename, const struct spv_table_look *look)
 
   start_elem (xml, "printingProperties");
   write_attr_bool (xml, "printAllLayers", look->print_all_layers);
-  write_attr_bool (xml, "rescaleLongTableToFitPage", look->shrink_to_length);
-  write_attr_bool (xml, "rescaleWideTableToFitPage", look->shrink_to_width);
+  write_attr_bool (xml, "rescaleLongTableToFitPage",
+                   look->shrink_to_fit[TABLE_HORZ]);
+  write_attr_bool (xml, "rescaleWideTableToFitPage",
+                   look->shrink_to_fit[TABLE_VERT]);
   write_attr_format (xml, "windowOrphanLines", "%zu", look->n_orphan_lines);
   if (look->continuation && look->continuation[0]
       && (look->top_continuation || look->bottom_continuation))
@@ -504,87 +509,3 @@ spv_table_look_write (const char *filename, const struct spv_table_look *look)
 
   return NULL;
 }
-
-void
-spv_table_look_destroy (struct spv_table_look *look)
-{
-  if (look)
-    {
-      free (look->name);
-      for (size_t i = 0; i < PIVOT_N_AREAS; i++)
-        table_area_style_uninit (&look->areas[i]);
-      free (look->continuation);
-      free (look);
-    }
-}
-
-void
-spv_table_look_install (const struct spv_table_look *look,
-                        struct pivot_table *table)
-{
-  free (table->table_look);
-  if (look->name)
-    table->table_look = xstrdup (look->name);
-
-  table->omit_empty = look->omit_empty;
-
-  for (enum table_axis axis = 0; axis < TABLE_N_AXES; axis++)
-    for (int i = 0; i < 2; i++)
-      if (look->width_ranges[axis][i] > 0)
-        table->sizing[axis].range[i] = look->width_ranges[axis][i];
-  table->row_labels_in_corner = look->row_labels_in_corner;
-
-  table->footnote_marker_superscripts = look->footnote_marker_superscripts;
-  table->show_numeric_markers = look->show_numeric_markers;
-
-  for (size_t i = 0; i < PIVOT_N_AREAS; i++)
-    {
-      table_area_style_uninit (&table->areas[i]);
-      table_area_style_copy (NULL, &table->areas[i], &look->areas[i]);
-    }
-  for (size_t i = 0; i < PIVOT_N_BORDERS; i++)
-    table->borders[i] = look->borders[i];
-
-  table->print_all_layers = look->print_all_layers;
-  table->paginate_layers = look->paginate_layers;
-  table->shrink_to_fit[TABLE_HORZ] = look->shrink_to_width;
-  table->shrink_to_fit[TABLE_VERT] = look->shrink_to_length;
-  table->top_continuation = look->top_continuation;
-  table->bottom_continuation = look->bottom_continuation;
-  table->continuation = xstrdup (look->continuation);
-  table->n_orphan_lines = look->n_orphan_lines;
-}
-
-struct spv_table_look *
-spv_table_look_get (const struct pivot_table *table)
-{
-  struct spv_table_look *look = xzalloc (sizeof *look);
-
-  look->name = table->table_look ? xstrdup (table->table_look) : NULL;
-
-  look->omit_empty = table->omit_empty;
-
-  for (enum table_axis axis = 0; axis < TABLE_N_AXES; axis++)
-    for (int i = 0; i < 2; i++)
-      look->width_ranges[axis][i] = table->sizing[axis].range[i];
-  look->row_labels_in_corner = table->row_labels_in_corner;
-
-  look->footnote_marker_superscripts = table->footnote_marker_superscripts;
-  look->show_numeric_markers = table->show_numeric_markers;
-
-  for (size_t i = 0; i < PIVOT_N_AREAS; i++)
-    table_area_style_copy (NULL, &look->areas[i], &table->areas[i]);
-  for (size_t i = 0; i < PIVOT_N_BORDERS; i++)
-    look->borders[i] = table->borders[i];
-
-  look->print_all_layers = table->print_all_layers;
-  look->paginate_layers = table->paginate_layers;
-  look->shrink_to_width = table->shrink_to_fit[TABLE_HORZ];
-  look->shrink_to_length = table->shrink_to_fit[TABLE_VERT];
-  look->top_continuation = table->top_continuation;
-  look->bottom_continuation = table->bottom_continuation;
-  look->continuation = xstrdup (table->continuation);
-  look->n_orphan_lines = table->n_orphan_lines;
-
-  return look;
-}
index 76d6efb03ab6a58bc6ca9661e48567baaa76d27e..59fe420dc4e8f97398094da048b4aa30adb8b0ca 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef OUTPUT_SPV_TABLE_LOOK_H
 #define OUTPUT_SPV_TABLE_LOOK_H 1
 
-/* TableLook decoder.
+/* TableLook file decoder.
 
    A TableLook specifies styles for tables and other aspects of output.  They
    exist standalone as .stt files as well as embedded in structure XML, in
 
 #include <stdbool.h>
 #include "libpspp/compiler.h"
-#include "output/pivot-table.h"
-#include "output/table.h"
 
+struct pivot_table_look;
 struct spvsx_table_properties;
 
-struct spv_table_look
-  {
-    char *name;                 /* May be null. */
-
-    /* General properties. */
-    bool omit_empty;
-    int width_ranges[TABLE_N_AXES][2];      /* In 1/96" units. */
-    bool row_labels_in_corner;
-
-    /* Footnote display settings. */
-    bool show_numeric_markers;
-    bool footnote_marker_superscripts;
-
-    /* Styles. */
-    struct table_area_style areas[PIVOT_N_AREAS];
-    struct table_border_style borders[PIVOT_N_BORDERS];
-
-    /* Print settings. */
-    bool print_all_layers;
-    bool paginate_layers;
-    bool shrink_to_width;
-    bool shrink_to_length;
-    bool top_continuation, bottom_continuation;
-    char *continuation;
-    size_t n_orphan_lines;
-  };
-
-void spv_table_look_destroy (struct spv_table_look *);
-
 char *spv_table_look_decode (const struct spvsx_table_properties *,
-                             struct spv_table_look **)
+                             struct pivot_table_look **)
   WARN_UNUSED_RESULT;
-char *spv_table_look_read (const char *, struct spv_table_look **)
+char *spv_table_look_read (const char *, struct pivot_table_look **)
   WARN_UNUSED_RESULT;
-char *spv_table_look_write (const char *, const struct spv_table_look *)
+char *spv_table_look_write (const char *, const struct pivot_table_look *)
   WARN_UNUSED_RESULT;
 
-void spv_table_look_install (const struct spv_table_look *,
-                             struct pivot_table *);
-struct spv_table_look *spv_table_look_get (const struct pivot_table *);
-
 #endif /* output/spv/spv-table-look.h */
index db8d03dfbffee47f320e29b6db962895b9a829db..4883ebf5ba36477cff3fa7bcf90a696a93a74d5f 100644 (file)
@@ -770,10 +770,10 @@ put_light_table (struct buf *buf, uint64_t table_id,
   put_bool (buf, table->rotate_outer_row_labels);
   put_bool (buf, true);
   put_u32 (buf, 0x15);
-  put_u32 (buf, table->sizing[H].range[0]);
-  put_u32 (buf, table->sizing[H].range[1]);
-  put_u32 (buf, table->sizing[V].range[0]);
-  put_u32 (buf, table->sizing[V].range[1]);
+  put_u32 (buf, table->look.width_ranges[H][0]);
+  put_u32 (buf, table->look.width_ranges[H][1]);
+  put_u32 (buf, table->look.width_ranges[V][0]);
+  put_u32 (buf, table->look.width_ranges[V][1]);
   put_u64 (buf, table_id);
 
   /* Titles. */
@@ -795,7 +795,7 @@ put_light_table (struct buf *buf, uint64_t table_id,
   /* Areas. */
   for (size_t i = 0; i < PIVOT_N_AREAS; i++)
     {
-      const struct table_area_style *a = &table->areas[i];
+      const struct table_area_style *a = &table->look.areas[i];
       put_byte (buf, i + 1);
       put_byte (buf, 0x31);
       put_string (buf, (a->font_style.typeface
@@ -838,7 +838,7 @@ put_light_table (struct buf *buf, uint64_t table_id,
   put_be32 (buf, PIVOT_N_BORDERS);
   for (size_t i = 0; i < PIVOT_N_BORDERS; i++)
     {
-      const struct table_border_style *b = &table->borders[i];
+      const struct table_border_style *b = &table->look.borders[i];
       put_be32 (buf, i);
       put_be32 (buf, (b->stroke == TABLE_STROKE_NONE ? 0
                       : b->stroke == TABLE_STROKE_SOLID ? 1
@@ -858,14 +858,14 @@ put_light_table (struct buf *buf, uint64_t table_id,
   /* Print Settings. */
   uint32_t ps_start = start_count (buf);
   put_be32 (buf, 1);
-  put_bool (buf, table->print_all_layers);
-  put_bool (buf, table->paginate_layers);
-  put_bool (buf, table->shrink_to_fit[H]);
-  put_bool (buf, table->shrink_to_fit[V]);
-  put_bool (buf, table->top_continuation);
-  put_bool (buf, table->bottom_continuation);
-  put_be32 (buf, table->n_orphan_lines);
-  put_bestring (buf, table->continuation);
+  put_bool (buf, table->look.print_all_layers);
+  put_bool (buf, table->look.paginate_layers);
+  put_bool (buf, table->look.shrink_to_fit[H]);
+  put_bool (buf, table->look.shrink_to_fit[V]);
+  put_bool (buf, table->look.top_continuation);
+  put_bool (buf, table->look.bottom_continuation);
+  put_be32 (buf, table->look.n_orphan_lines);
+  put_bestring (buf, table->look.continuation);
   end_count_u32 (buf, ps_start);
 
   /* Table Settings. */
@@ -873,10 +873,10 @@ put_light_table (struct buf *buf, uint64_t table_id,
   put_be32 (buf, 1);
   put_be32 (buf, 4);
   put_be32 (buf, 0);            /* XXX current_layer */
-  put_bool (buf, table->omit_empty);
-  put_bool (buf, table->row_labels_in_corner);
-  put_bool (buf, !table->show_numeric_markers);
-  put_bool (buf, table->footnote_marker_superscripts);
+  put_bool (buf, table->look.omit_empty);
+  put_bool (buf, table->look.row_labels_in_corner);
+  put_bool (buf, !table->look.show_numeric_markers);
+  put_bool (buf, table->look.footnote_marker_superscripts);
   put_byte (buf, 0);
   uint32_t keep_start = start_count (buf);
   put_be32 (buf, 0);            /* n-row-breaks */
@@ -887,7 +887,7 @@ put_light_table (struct buf *buf, uint64_t table_id,
   put_be32 (buf, 0);            /* n-column-point-keeps */
   end_count_be32 (buf, keep_start);
   put_bestring (buf, table->notes);
-  put_bestring (buf, table->table_look);
+  put_bestring (buf, table->look.name);
   for (size_t i = 0; i < 82; i++)
     put_byte (buf, 0);
   end_count_u32 (buf, ts_start);
index 398ca59951557246319c514d6b093530cc14f92b..5f537edfc84da8a6e6482ce55be4bc142ad7315f 100644 (file)
@@ -260,7 +260,11 @@ spv_item_destroy (struct spv_item *item)
       free (item->children);
 
       pivot_table_unref (item->table);
-      spv_table_look_destroy (item->table_look);
+      if (item->table_look)
+        {
+          pivot_table_look_uninit (item->table_look);
+          free (item->table_look);
+        }
       free (item->bin_member);
       free (item->xml_member);
       free (item->subtype);
@@ -1189,14 +1193,14 @@ spv_close (struct spv_reader *spv)
 
 void
 spv_item_set_table_look (struct spv_item *item,
-                         const struct spv_table_look *look)
+                         const struct pivot_table_look *look)
 {
   /* If this is a table, install the table look in it.
 
      (We can't just set item->table_look because light tables ignore it and
      legacy tables sometimes override it.) */
   if (spv_item_is_table (item))
-    spv_table_look_install (look, spv_item_get_table (item));
+    pivot_table_set_look (spv_item_get_table (item), look);
 
   for (size_t i = 0; i < item->n_children; i++)
     spv_item_set_table_look (item->children[i], look);
index 1753cdaabd3dd99c55a63b236649ee7e89af0863..21d19a6615b9d6b8dbd93eb470a4b1a228dac540 100644 (file)
@@ -130,7 +130,7 @@ struct spv_item
 
     /* SPV_ITEM_TABLE only. */
     struct pivot_table *table;    /* NULL if not yet loaded. */
-    struct spv_table_look *table_look;
+    struct pivot_table_look *table_look;
     char *bin_member;
     char *xml_member;
     char *subtype;
@@ -198,7 +198,7 @@ char *spv_item_get_legacy_table (const struct spv_item *, struct _xmlDoc **)
   WARN_UNUSED_RESULT;
 
 void spv_item_set_table_look (struct spv_item *,
-                              const struct spv_table_look *);
+                              const struct pivot_table_look *);
 
 char *spv_decode_fmt_spec (uint32_t u32, struct fmt_spec *) WARN_UNUSED_RESULT;
 
index 4b9710a020bc1c3c24ddb7a08e22f8e60c511fb3..256a6e257519d517b17e8a502445387082c8fe8f 100644 (file)
@@ -77,7 +77,7 @@ static bool raw;
 static bool force;
 
 /* --table-look: TableLook to replace table style for conversion. */
-static struct spv_table_look *table_look;
+static struct pivot_table_look *table_look;
 
 /* Number of warnings issued. */
 static size_t n_warnings;
@@ -355,11 +355,9 @@ run_get_table_look (int argc UNUSED, char **argv)
   if (!table)
     error (1, 0, "%s: no tables found", argv[1]);
 
-  struct spv_table_look *look = spv_table_look_get (table);
-  err = spv_table_look_write (argv[2], look);
+  err = spv_table_look_write (argv[2], pivot_table_get_look (table));
   if (err)
     error (1, 0, "%s", err);
-  spv_table_look_destroy (look);
 
   spv_close (spv);
 }
@@ -793,7 +791,11 @@ main (int argc, char **argv)
 
   c->run (argc, argv);
 
-  spv_table_look_destroy (table_look);
+  if (table_look)
+    {
+      pivot_table_look_uninit (table_look);
+      free (table_look);
+    }
   i18n_done ();
 
   return n_warnings ? EXIT_FAILURE : EXIT_SUCCESS;
@@ -923,7 +925,12 @@ parse_members (const char *arg)
 static void
 parse_table_look (const char *arg)
 {
-  spv_table_look_destroy (table_look);
+  if (table_look)
+    {
+      pivot_table_look_uninit (table_look);
+      free (table_look);
+    }
+
   char *error_s = spv_table_look_read (arg, &table_look);
   if (error_s)
     error (1, 0, "%s", error_s);