table: Get rid of TAB_* for horizontal and vertical alignment.
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 26 Dec 2019 00:52:33 +0000 (00:52 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:28:10 +0000 (05:28 +0000)
Until now, either TAB_LEFT, TAB_RIGHT, etc. could be used or the
area_style mechanism could be used.  The latter has a superset of the
former's features, so this commit eliminates the former.

src/output/page-setup-item.h
src/output/render.c
src/output/table.c
src/output/table.h
tests/output/render-test.c

index a01b7763e261f2f8d57b9cb1585ca44a7c156dd8..564299ea8d9f3b32502e520a5f69fbaf7a07263c 100644 (file)
@@ -43,7 +43,7 @@ enum page_chart_size
 struct page_paragraph
   {
     char *markup;
-    int halign;                 /* TAB_LEFT, TAB_CENTER, TAB_RIGHT. */
+    enum table_halign halign;
   };
 
 struct page_heading
index e18d8451db40e018360a9bdc91b87d6bb37ac191..39cde176eeff6fa86f5c00ea100f0f426a964c96 100644 (file)
@@ -26,6 +26,7 @@
 #include "libpspp/hash-functions.h"
 #include "libpspp/hmap.h"
 #include "libpspp/pool.h"
+#include "output/pivot-table.h" /* XXX for PIVOT_AREA_FOOTER */
 #include "output/render.h"
 #include "output/table-item.h"
 #include "output/table.h"
@@ -1508,10 +1509,16 @@ add_footnote_page (struct render_pager *p, const struct table_item *item)
     return;
 
   struct table *t = table_create (1, n_footnotes, 0, 0, 0, 0);
+
+  const struct area_style *style = item->table->styles[PIVOT_AREA_FOOTER];
+  if (!style)
+    style = pivot_area_get_default_style (PIVOT_AREA_FOOTER);
+  t->styles[PIVOT_AREA_FOOTER] = area_style_clone (t->container, style);
+
   for (size_t i = 0; i < n_footnotes; i++)
     {
-      table_text_format (t, 0, i, TAB_LEFT, "%s. %s",
-                         f[i]->marker, f[i]->content);
+      table_text_format (t, 0, i, PIVOT_AREA_FOOTER << TAB_STYLE_SHIFT,
+                         "%s. %s", f[i]->marker, f[i]->content);
       if (f[i]->style)
         table_add_style (t, 0, i, f[i]->style);
     }
index 00759a00162a1d2c809303f152aaf655d201103f..b6caf598c640463f5ec5b9ccbda0d6c769333da9 100644 (file)
@@ -176,7 +176,13 @@ struct table *
 table_from_string (const char *text)
 {
   struct table *t = table_create (1, 1, 0, 0, 0, 0);
-  table_text (t, 0, 0, TAB_LEFT, text);
+  t->styles[0] = xmalloc (sizeof *t->styles[0]);
+  *t->styles[0] = (struct area_style) {
+    AREA_STYLE_INITIALIZER__,
+    .cell_style.halign = TABLE_HALIGN_LEFT,
+    .cell_style.valign = TABLE_VALIGN_TOP
+  };
+  table_text (t, 0, 0, 0 << TAB_STYLE_SHIFT, text);
   return t;
 }
 \f
@@ -745,37 +751,7 @@ table_get_cell (const struct table *t, int x, int y, struct table_cell *cell)
   cell->n_footnotes = 0;
 
   int style_idx = (opt & TAB_STYLE_MASK) >> TAB_STYLE_SHIFT;
-  const struct area_style *style = t->styles[style_idx];
-  if (style)
-    cell->style = style;
-  else
-    {
-      static const struct area_style styles[3][3] = {
-#define S(H,V) [H][V] = { AREA_STYLE_INITIALIZER__,     \
-                          .cell_style.halign = H,       \
-                          .cell_style.valign = V }
-        S(TABLE_HALIGN_LEFT, TABLE_VALIGN_TOP),
-        S(TABLE_HALIGN_LEFT, TABLE_VALIGN_CENTER),
-        S(TABLE_HALIGN_LEFT, TABLE_VALIGN_BOTTOM),
-        S(TABLE_HALIGN_CENTER, TABLE_VALIGN_TOP),
-        S(TABLE_HALIGN_CENTER, TABLE_VALIGN_CENTER),
-        S(TABLE_HALIGN_CENTER, TABLE_VALIGN_BOTTOM),
-        S(TABLE_HALIGN_RIGHT, TABLE_VALIGN_TOP),
-        S(TABLE_HALIGN_RIGHT, TABLE_VALIGN_CENTER),
-        S(TABLE_HALIGN_RIGHT, TABLE_VALIGN_BOTTOM),
-      };
-
-      enum table_halign halign
-        = ((opt & TAB_HALIGN) == TAB_LEFT ? TABLE_HALIGN_LEFT
-           : (opt & TAB_HALIGN) == TAB_CENTER ? TABLE_HALIGN_CENTER
-           : TABLE_HALIGN_RIGHT);
-      enum table_valign valign
-        = ((opt & TAB_VALIGN) == TAB_TOP ? TABLE_VALIGN_TOP
-           : (opt & TAB_VALIGN) == TAB_MIDDLE ? TABLE_VALIGN_CENTER
-           : TABLE_VALIGN_BOTTOM);
-
-      cell->style = &styles[halign][valign];
-    }
+  cell->style = t->styles[style_idx];
 
   if (opt & TAB_JOIN)
     {
@@ -801,6 +777,8 @@ table_get_cell (const struct table *t, int x, int y, struct table_cell *cell)
       cell->d[TABLE_VERT][1] = y + 1;
       cell->text = CONST_CAST (char *, cc ? cc : "");
     }
+
+  assert (cell->style);
 }
 
 /* Returns one of the TAL_* enumeration constants (declared in output/table.h)
index d7f36197164a03cf15385b3ddad95d3a1256a411..fb3ca946aa904ca849559c35208366d956c24e42 100644 (file)
@@ -177,18 +177,6 @@ enum
     TAB_STYLE_SHIFT = 5,
     TAB_STYLE_MASK = 7 << TAB_STYLE_SHIFT,
 
-    /* Horizontal alignment of cell contents. */
-    TAB_RIGHT      = 0 << 10,
-    TAB_LEFT       = 1 << 10,
-    TAB_CENTER     = 2 << 10,
-    TAB_HALIGN     = 3 << 10, /* Alignment mask. */
-
-    /* Vertical alignment of cell contents. */
-    TAB_TOP        = 0 << 12,
-    TAB_MIDDLE     = 1 << 12,
-    TAB_BOTTOM     = 2 << 12,
-    TAB_VALIGN     = 3 << 12, /* Alignment mask. */
-
     /* Internal use by tab.c only. */
     TAB_JOIN = 1 << 14,
   };
index b5b505c940c0236b988d4e9eee2796739b396a78..35400216541d52a24ad5ba2160f9835dc1ebbef2 100644 (file)
@@ -386,7 +386,6 @@ read_table (FILE *stream)
     for (c = 0; c < nc; c++)
       if (table_cell_is_empty (tab, c, r))
         {
-          unsigned int opt;
           char *new_line;
           char *text;
           int rs, cs;
@@ -412,7 +411,13 @@ read_table (FILE *stream)
               cs = 1;
             }
 
-          opt = 0;
+#define S(H) { AREA_STYLE_INITIALIZER__, .cell_style.halign = H }
+          static const struct area_style left_style = S (TABLE_HALIGN_LEFT);
+          static const struct area_style right_style = S (TABLE_HALIGN_RIGHT);
+          static const struct area_style center_style
+            = S (TABLE_HALIGN_CENTER);
+
+          const struct area_style *style = &right_style;
           while (*text && strchr ("<>^,@()|", *text))
             switch (*text++)
               {
@@ -438,18 +443,15 @@ read_table (FILE *stream)
                 break;
 
               case '(':
-                opt &= ~TAB_HALIGN;
-                opt |= TAB_LEFT;
+                style = &left_style;
                 break;
 
               case ')':
-                opt &= ~TAB_HALIGN;
-                opt |= TAB_RIGHT;
+                style = &right_style;
                 break;
 
               case '|':
-                opt &= ~TAB_HALIGN;
-                opt |= TAB_CENTER;
+                style = &center_style;
                 break;
 
               default:
@@ -464,8 +466,11 @@ read_table (FILE *stream)
 
           for (i = 0; (content = strsep (&pos, "#")) != NULL; i++)
             if (!i)
-              table_joint_text (tab, c, r, c + cs - 1, r + rs - 1, opt,
-                                content);
+              {
+                table_joint_text (tab, c, r, c + cs - 1, r + rs - 1, 0,
+                                  content);
+                table_add_style (tab, c, r, style);
+              }
             else
               {
                 char marker[2] = { 'a' + n_footnotes, '\0' };