Revert "work toward getting rid of struct table in table_item"
[pspp] / src / output / pivot-output.c
index 8ca3601cfcbaf0882dbd903ad2fa47929712bcce..ae12c4dea391e51358a97de2ca85df32fa040c24 100644 (file)
@@ -24,6 +24,7 @@
 #include "libpspp/assertion.h"
 #include "libpspp/pool.h"
 #include "output/table.h"
+#include "output/page-eject-item.h"
 #include "output/table-item.h"
 #include "output/text-item.h"
 #include "output/table-provider.h"
@@ -57,7 +58,8 @@ static struct table_area_style *
 table_area_style_override (struct pool *pool,
                            const struct table_area_style *in,
                            const struct cell_style *cell_,
-                           const struct font_style *font_)
+                           const struct font_style *font_,
+                           bool rotate_label)
 {
   const struct cell_style *cell = cell_ ? cell_ : &in->cell_style;
   const struct font_style *font = font_ ? font_ : &in->font_style;
@@ -66,8 +68,8 @@ table_area_style_override (struct pool *pool,
                             ? pool_alloc (pool, sizeof *out)
                             : xmalloc (sizeof *out));
   *out = (struct table_area_style) {
-    .cell_style.halign = cell->halign,
-    .cell_style.valign = cell->valign,
+    .cell_style.halign = rotate_label ? TABLE_HALIGN_CENTER : cell->halign,
+    .cell_style.valign = rotate_label ? TABLE_VALIGN_CENTER : cell->valign,
     .cell_style.decimal_offset = cell->decimal_offset,
     .cell_style.margin[H][0] = cell->margin[H][0],
     .cell_style.margin[H][1] = cell->margin[H][1],
@@ -116,11 +118,12 @@ fill_cell (struct table *t, int x1, int y1, int x2, int y2,
 
   if (value)
     {
-      if (value->cell_style || value->font_style)
+      if (value->cell_style || value->font_style || rotate_label)
         table_add_style (t, x1, y1,
                          table_area_style_override (t->container, style,
                                                     value->cell_style,
-                                                    value->font_style));
+                                                    value->font_style,
+                                                    rotate_label));
 
       for (size_t i = 0; i < value->n_footnotes; i++)
         {
@@ -153,7 +156,7 @@ pivot_value_to_table_item_text (const struct pivot_value *value,
     .content = ds_steal_cstr (&s),
     .footnotes = xnmalloc (value->n_footnotes, sizeof *text->footnotes),
     .style = table_area_style_override (
-      NULL, area, value->cell_style, value->font_style),
+      NULL, area, value->cell_style, value->font_style, false),
   };
 
   for (size_t i = 0; i < value->n_footnotes; i++)
@@ -286,7 +289,7 @@ compose_headings (struct table *t,
       if (d->root->show_label_in_corner && a_ofs > 0)
         {
           int bb[TABLE_N_AXES][2];
-          bb[a][0] = a_ofs - 1;
+          bb[a][0] = 0;
           bb[a][1] = a_ofs - 1;
           bb[b][0] = bottom_row - d->label_depth + 1;
           bb[b][1] = bottom_row;
@@ -312,9 +315,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->look.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->look.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 +329,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->look.areas[i], NULL, NULL);
+      table->container, &pt->look->areas[i], NULL, NULL, false);
 
   for (size_t i = 0; i < PIVOT_N_BORDERS; i++)
     {
-      const struct table_border_style *in = &pt->look.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,40 +358,41 @@ 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->look.areas[PIVOT_AREA_FOOTER],
+                                   &pt->look->areas[PIVOT_AREA_FOOTER],
                                    pf->content->cell_style,
-                                   pf->content->font_style));
+                                   pf->content->font_style,
+                                   false));
       free (marker);
       free (content);
     }
 
   compose_headings (table,
                     &pt->axes[PIVOT_AXIS_COLUMN], H, &pt->axes[PIVOT_AXIS_ROW],
-                    pt->look.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->look.areas[PIVOT_AREA_COLUMN_LABELS],
+                    &pt->look->areas[PIVOT_AREA_COLUMN_LABELS],
                     PIVOT_AREA_COLUMN_LABELS,
-                    &pt->look.areas[PIVOT_AREA_CORNER], footnotes,
+                    &pt->look->areas[PIVOT_AREA_CORNER], footnotes,
                     pt->show_values, pt->show_variables,
-                    pt->rotate_inner_column_labels, false);
+                    pt->rotate_outer_row_labels, false);
 
   compose_headings (table,
                     &pt->axes[PIVOT_AXIS_ROW], V, &pt->axes[PIVOT_AXIS_COLUMN],
-                    pt->look.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->look.areas[PIVOT_AREA_ROW_LABELS],
+                    &pt->look->areas[PIVOT_AREA_ROW_LABELS],
                     PIVOT_AREA_ROW_LABELS,
-                    &pt->look.areas[PIVOT_AREA_CORNER], footnotes,
+                    &pt->look->areas[PIVOT_AREA_CORNER], footnotes,
                     pt->show_values, pt->show_variables,
-                    false, pt->rotate_outer_row_labels);
+                    false, pt->rotate_inner_column_labels);
 
   size_t *dindexes = XCALLOC (pt->n_dimensions, size_t);
   size_t y = 0;
@@ -405,7 +409,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->look.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);
 
@@ -416,46 +420,47 @@ pivot_table_submit_layer (const struct pivot_table *pt,
     }
   free (dindexes);
 
-  if (pt->corner_text && stub[H] && stub[V])
+  if ((pt->corner_text || !pt->look->row_labels_in_corner)
+      && stub[H] && stub[V])
     fill_cell (table, 0, 0, stub[H] - 1, stub[V] - 1,
-               &pt->look.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))
+  if (table->n[H] && table->n[V])
     {
       table_hline (
-        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_TOP),
-        0, table_nc (table) - 1, 0);
+        table, get_table_rule (pt->look->borders, PIVOT_BORDER_INNER_TOP),
+        0, table->n[H] - 1, 0);
       table_hline (
-        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_BOTTOM),
-        0, table_nc (table) - 1, table_nr (table));
+        table, get_table_rule (pt->look->borders, PIVOT_BORDER_INNER_BOTTOM),
+        0, table->n[H] - 1, table->n[V]);
       table_vline (
-        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_LEFT),
-        0, 0, table_nr (table) - 1);
+        table, get_table_rule (pt->look->borders, PIVOT_BORDER_INNER_LEFT),
+        0, 0, table->n[V] - 1);
       table_vline (
-        table, get_table_rule (pt->look.borders, PIVOT_BORDER_INNER_RIGHT),
-        table_nc (table), 0, table_nr (table) - 1);
+        table, get_table_rule (pt->look->borders, PIVOT_BORDER_INNER_RIGHT),
+        table->n[H], 0, table->n[V] - 1);
 
       if (stub[V])
         table_hline (
-          table, get_table_rule (pt->look.borders, PIVOT_BORDER_DATA_TOP),
-          0, table_nc (table) - 1, stub[V]);
+          table, get_table_rule (pt->look->borders, PIVOT_BORDER_DATA_TOP),
+          0, table->n[H] - 1, stub[V]);
       if (stub[H])
         table_vline (
-          table, get_table_rule (pt->look.borders, PIVOT_BORDER_DATA_LEFT),
-          stub[H], 0, table_nr (table) - 1);
+          table, get_table_rule (pt->look->borders, PIVOT_BORDER_DATA_LEFT),
+          stub[H], 0, table->n[V] - 1);
 
     }
   free (column_enumeration);
   free (row_enumeration);
 
-  struct table_item *ti = table_item_create (table, NULL, NULL);
+  struct table_item *ti = table_item_create (table, NULL, NULL, pt->notes);
 
   if (pt->title)
     {
       struct table_item_text *title = pivot_value_to_table_item_text (
-        pt->title, &pt->look.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 +477,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
             {
               layers = xzalloc (sizeof *layers);
               layers->style = table_area_style_override (
-                NULL, &pt->look.areas[PIVOT_AREA_LAYERS], NULL, NULL);
+                NULL, &pt->look->areas[PIVOT_AREA_LAYERS], NULL, NULL, false);
               layers->layers = xnmalloc (layer_axis->n_dimensions,
                                          sizeof *layers->layers);
             }
@@ -504,7 +509,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->look.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,14 +530,14 @@ pivot_table_submit (struct pivot_table *pt)
   if (pt->decimal == '.' || pt->decimal == ',')
     settings_set_decimal_char (pt->decimal);
 
-  if (pt->look.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->look.paginate_layers)
-            text_item_submit (text_item_create (TEXT_ITEM_EJECT_PAGE, ""));
+          if (pt->look->paginate_layers)
+            page_eject_item_submit (page_eject_item_create ());
           pivot_table_submit_layer (pt, layer_indexes);
         }
     }