From b9aea813e643c3badd9a9fe7a8b396088b30c96e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 9 Dec 2018 12:46:17 -0800 Subject: [PATCH] table: Get rid of TAL_GAP. This is only necessary in pathological cases. Those cases don't really come up in normal usage and as PSPP shifts toward pivot tables they won't come up at all. --- src/language/dictionary/split-file.c | 2 -- src/language/dictionary/sys-file-info.c | 3 +-- src/language/stats/crosstabs.q | 2 -- src/language/stats/frequencies.c | 1 - src/language/stats/t-test-indep.c | 1 - src/language/stats/t-test-one-sample.c | 1 - src/language/stats/t-test-paired.c | 1 - src/output/ascii.c | 1 + src/output/cairo.c | 1 + src/output/html.c | 8 ++++---- src/output/render.c | 14 ++++++++++++-- src/output/render.h | 2 ++ src/output/tab.c | 9 ++++----- src/output/table-casereader.c | 2 +- src/output/table.h | 1 - tests/output/render.at | 20 ++++++++++---------- 16 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/language/dictionary/split-file.c b/src/language/dictionary/split-file.c index 34949c5d15..fda5cfd00c 100644 --- a/src/language/dictionary/split-file.c +++ b/src/language/dictionary/split-file.c @@ -77,8 +77,6 @@ output_split_file_values (const struct dataset *ds, const struct ccase *c) return; t = tab_create (3, split_cnt + 1); - tab_vline (t, TAL_GAP, 1, 0, split_cnt); - tab_vline (t, TAL_GAP, 2, 0, split_cnt); tab_text (t, 0, 0, TAB_NONE, _("Variable")); tab_text (t, 1, 0, TAB_LEFT, _("Value")); tab_text (t, 2, 0, TAB_LEFT, _("Label")); diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index b0c35ec0ce..8f0a4c2b69 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -173,8 +173,7 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) t = tab_create (2, 11 + (info.product_ext != NULL)); r = 0; - tab_vline (t, TAL_GAP, 1, 0, 8); - + tab_text (t, 0, r, TAB_LEFT, _("File:")); tab_text (t, 1, r++, TAB_LEFT, fh_get_file_name (h)); diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 08a182a456..c2f34c2df2 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -1446,8 +1446,6 @@ submit (struct pivot_table *pt, struct tab_table *t) tab_box (t, TAL_2, TAL_2, -1, -1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1); tab_box (t, -1, -1, -1, TAL_1, tab_l (t), tab_t (t) - 1, tab_nc (t) - 1, tab_nr (t) - 1); - tab_box (t, -1, -1, -1, TAL_GAP, 0, tab_t (t), tab_l (t) - 1, - tab_nr (t) - 1); tab_vline (t, TAL_2, tab_l (t), 0, tab_nr (t) - 1); tab_submit (t); diff --git a/src/language/stats/frequencies.c b/src/language/stats/frequencies.c index 0a1a060d26..ff29b6600a 100644 --- a/src/language/stats/frequencies.c +++ b/src/language/stats/frequencies.c @@ -1588,7 +1588,6 @@ dump_statistics (const struct frq_proc *frq, const struct var_freqs *vf, tab_box (t, TAL_1, TAL_1, -1, -1 , 0 , 0 , 2, tab_nr(t) - 1) ; tab_vline (t, TAL_1 , 2, 0, tab_nr(t) - 1); - tab_vline (t, TAL_GAP , 1, 0, tab_nr(t) - 1 ) ; for (i = 0; i < FRQ_ST_count; i++) { diff --git a/src/language/stats/t-test-indep.c b/src/language/stats/t-test-indep.c index a2e0d4d355..e4e4243308 100644 --- a/src/language/stats/t-test-indep.c +++ b/src/language/stats/t-test-indep.c @@ -205,7 +205,6 @@ indep_summary (const struct tt *tt, struct indep_samples *is, const struct pair_ tab_box (t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols - 1, rows - 1); tab_hline (t, TAL_2, 0, cols - 1, 1); - tab_vline (t, TAL_GAP, 1, 0, rows - 1); tab_title (t, _("Group Statistics")); tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, var_to_string (is->gvar)); tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("N")); diff --git a/src/language/stats/t-test-one-sample.c b/src/language/stats/t-test-one-sample.c index 73356e4e87..fdcef55937 100644 --- a/src/language/stats/t-test-one-sample.c +++ b/src/language/stats/t-test-one-sample.c @@ -90,7 +90,6 @@ one_sample_test (const struct tt *tt, const struct one_samp *os) _("%g%% Confidence Interval of the Difference"), tt->confidence * 100.0); - tab_vline (t, TAL_GAP, 6, 1, 1); tab_hline (t, TAL_1, 5, 6, 2); tab_text (t, 1, 2, TAB_CENTER | TAT_TITLE, _("t")); tab_text (t, 2, 2, TAB_CENTER | TAT_TITLE, _("df")); diff --git a/src/language/stats/t-test-paired.c b/src/language/stats/t-test-paired.c index 94e7a8c409..4935e9a8cb 100644 --- a/src/language/stats/t-test-paired.c +++ b/src/language/stats/t-test-paired.c @@ -300,7 +300,6 @@ paired_test (const struct tt *tt, const struct paired_samp *os) _("%g%% Confidence Interval of the Difference"), tt->confidence * 100.0); - tab_vline (t, TAL_GAP, 6, 1, 1); tab_hline (t, TAL_1, 5, 6, 2); tab_text (t, 7, 2, TAB_CENTER | TAT_TITLE, _("t")); tab_text (t, 8, 2, TAB_CENTER | TAT_TITLE, _("df")); diff --git a/src/output/ascii.c b/src/output/ascii.c index ae5e25bef4..f53feeaa91 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -449,6 +449,7 @@ ascii_output_table_item (struct ascii_driver *a, } for (i = 0; i < TABLE_N_AXES; i++) params.min_break[i] = a->min_break[i]; + params.supports_margins = false; if (a->file == NULL && !ascii_open_page (a)) return; diff --git a/src/output/cairo.c b/src/output/cairo.c index 404d9a8fd2..3b87aeb64d 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -400,6 +400,7 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo) for (i = 0; i < TABLE_N_AXES; i++) xr->params->min_break[i] = xr->min_break[i]; + xr->params->supports_margins = true; } cairo_set_source_rgb (xr->cairo, xr->fg.red, xr->fg.green, xr->fg.blue); diff --git a/src/output/html.c b/src/output/html.c index 6dc2ffe737..6e5181d7da 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -497,24 +497,24 @@ html_output_table (struct html_driver *html, const struct table_item *item) n_borders = 0; top = table_get_rule (t, TABLE_VERT, x, y); - if (top > TAL_GAP) + if (top > TAL_0) put_border (html->file, n_borders++, top, "top"); if (y + rowspan == table_nr (t)) { bottom = table_get_rule (t, TABLE_VERT, x, y + rowspan); - if (bottom > TAL_GAP) + if (bottom > TAL_0) put_border (html->file, n_borders++, bottom, "bottom"); } left = table_get_rule (t, TABLE_HORZ, x, y); - if (left > TAL_GAP) + if (left > TAL_0) put_border (html->file, n_borders++, left, "left"); if (x + colspan == table_nc (t)) { right = table_get_rule (t, TABLE_HORZ, x + colspan, y); - if (right > TAL_GAP) + if (right > TAL_0) put_border (html->file, n_borders++, right, "right"); } diff --git a/src/output/render.c b/src/output/render.c index 1dc8f2e281..6c7f3bca51 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -515,7 +515,6 @@ rule_to_render_type (unsigned char type) switch (type) { case TAL_0: - case TAL_GAP: return RENDER_LINE_NONE; case TAL_1: return RENDER_LINE_SINGLE; @@ -544,10 +543,21 @@ measure_rule (const struct render_params *params, const struct table *table, for (d[b] = 0; d[b] < table->n[b]; d[b]++) rules |= 1u << table_get_rule (table, a, d[H], d[V]); + /* Turn off TAL_NONE because it has width 0 and we needn't bother. However, + if the device doesn't support margins, make sure that there is at least a + small gap between cells (but we don't need any at the left or right edge + of the table). */ + if (rules & (1u << TAL_0)) + { + rules &= ~(1u << TAL_0); + if (z > 0 && z < table->n[a] && !params->supports_margins && a == H) + rules |= 1u << TAL_1; + } + /* Calculate maximum width of the rules that are present. */ width = 0; if (rules & (1u << TAL_1) - || (z > 0 && z < table->n[a] && rules & (1u << TAL_GAP))) + || (z > 0 && z < table->n[a] && rules & (1u << TAL_0))) width = params->line_widths[a][RENDER_LINE_SINGLE]; if (rules & (1u << TAL_2)) width = MAX (width, params->line_widths[a][RENDER_LINE_DOUBLE]); diff --git a/src/output/render.h b/src/output/render.h index ed5bb1eaf4..d1f085fb2c 100644 --- a/src/output/render.h +++ b/src/output/render.h @@ -128,6 +128,8 @@ struct render_params across two pages. (Joined cells may always be broken at join points.) */ int min_break[TABLE_N_AXES]; + + bool supports_margins; }; /* An iterator for breaking render_pages into smaller chunks. */ diff --git a/src/output/tab.c b/src/output/tab.c index 78bde01e5d..af43d6c2bc 100644 --- a/src/output/tab.c +++ b/src/output/tab.c @@ -99,13 +99,12 @@ tab_create (int nc, int nr) memset (t->ct, 0, nc * nr); t->rh = pool_nmalloc (t->container, nc, nr + 1); - memset (t->rh, 0, nc * (nr + 1)); + memset (t->rh, TAL_0, nc * (nr + 1)); t->rv = pool_nmalloc (t->container, nr, nc + 1); - memset (t->fmtmap, 0, sizeof (*t->fmtmap) * n_RC); - - memset (t->rv, TAL_GAP, nr * (nc + 1)); + memset (t->rv, TAL_0, nr * (nc + 1)); + memset (t->fmtmap, 0, sizeof (*t->fmtmap) * n_RC); t->fmtmap[RC_PVALUE] = ugly[RC_PVALUE]; t->fmtmap[RC_INTEGER] = ugly[RC_INTEGER]; t->fmtmap[RC_OTHER] = *settings_get_format (); @@ -204,7 +203,7 @@ tab_realloc (struct tab_table *t, int nc, int nr) { memset (&t->rh[nc * (tab_nr (t) + 1)], TAL_0, (nr - tab_nr (t)) * nc); - memset (&t->rv[(nc + 1) * tab_nr (t)], TAL_GAP, + memset (&t->rv[(nc + 1) * tab_nr (t)], TAL_0, (nr - tab_nr (t)) * (nc + 1)); } } diff --git a/src/output/table-casereader.c b/src/output/table-casereader.c index 36f74f20c4..5acb1a928d 100644 --- a/src/output/table-casereader.c +++ b/src/output/table-casereader.c @@ -148,7 +148,7 @@ table_casereader_get_rule (const struct table *t, enum table_axis axis, if (axis == TABLE_VERT) return tc->heading != NULL && y == 1 ? TAL_1 : TAL_0; else - return TAL_GAP; + return TAL_0; } static const struct table_class table_casereader_class = diff --git a/src/output/table.h b/src/output/table.h index 09e5041a3e..d93c69e38c 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -68,7 +68,6 @@ enum enum { TAL_0, /* No line. */ - TAL_GAP, /* Spacing but no line. */ TAL_1, /* Single line. */ TAL_2, /* Double line. */ N_LINES diff --git a/tests/output/render.at b/tests/output/render.at index e1d6fcea36..3a12da4c2c 100644 --- a/tests/output/render.at +++ b/tests/output/render.at @@ -401,11 +401,11 @@ AT_DATA([input], [2 2 1*2 hij\nklm\nnop ]) AT_CHECK([render-test input], [0], [dnl -abc -def -hij -klm -nop + abc + def + hij + klm + nop ]) AT_CLEANUP @@ -2775,10 +2775,10 @@ AT_DATA([input], [dnl 1*2 @shorter ]) AT_CHECK([render-test --width=30 --length=15 input], [0], [dnl -+-------------------+ -|A long text string.| -+-------------------+ -| shorter| -+-------------------+ ++--------------------+ +| A long text string.| ++--------------------+ +| shorter| ++--------------------+ ]) AT_CLEANUP -- 2.30.2