From f919c4f6194066290f88e4852016428832d01aa1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 26 Dec 2019 00:52:33 +0000 Subject: [PATCH] table: Get rid of TAB_* for horizontal and vertical alignment. 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 | 2 +- src/output/render.c | 11 ++++++++-- src/output/table.c | 42 +++++++++--------------------------- src/output/table.h | 12 ----------- tests/output/render-test.c | 25 ++++++++++++--------- 5 files changed, 35 insertions(+), 57 deletions(-) diff --git a/src/output/page-setup-item.h b/src/output/page-setup-item.h index a01b7763e2..564299ea8d 100644 --- a/src/output/page-setup-item.h +++ b/src/output/page-setup-item.h @@ -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 diff --git a/src/output/render.c b/src/output/render.c index e18d8451db..39cde176ee 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -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); } diff --git a/src/output/table.c b/src/output/table.c index 00759a0016..b6caf598c6 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -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; } @@ -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) diff --git a/src/output/table.h b/src/output/table.h index d7f3619716..fb3ca946aa 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -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, }; diff --git a/tests/output/render-test.c b/tests/output/render-test.c index b5b505c940..3540021654 100644 --- a/tests/output/render-test.c +++ b/tests/output/render-test.c @@ -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 = ¢er_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' }; -- 2.30.2