From d55fbbb4fda554d02c93dd46c6fa66128060e6f0 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 9 Jan 2021 18:27:36 -0800 Subject: [PATCH] pivot-table: Implement hiding footnotes. --- doc/dev/spv-file-format.texi | 1 + src/output/cairo-fsm.c | 14 +++++++++----- src/output/html.c | 19 +++++++++++-------- src/output/odt.c | 18 +++++++++++------- src/output/pivot-output.c | 2 +- src/output/spv/spv-writer.c | 7 ++++--- src/output/tex.c | 17 +++++++++++------ tests/output/pivot-table-test.c | 3 ++- tests/output/pivot-table.at | 15 +++++++++++++++ 9 files changed, 65 insertions(+), 31 deletions(-) diff --git a/doc/dev/spv-file-format.texi b/doc/dev/spv-file-format.texi index 723550a372..54decbcf52 100644 --- a/doc/dev/spv-file-format.texi +++ b/doc/dev/spv-file-format.texi @@ -1101,6 +1101,7 @@ reference other footnotes, but in practice this doesn't work. @code{show} is a 32-bit signed integer. It is positive to show the footnote or negative to hide it. Its magnitude is often 1, and in other cases tends to be the number of references to the footnote. +It is safe to write 1 to show a footnote and -1 to hide it. @node SPV Light Member Areas @subsection Areas diff --git a/src/output/cairo-fsm.c b/src/output/cairo-fsm.c index e427a4a5ed..2df3975434 100644 --- a/src/output/cairo-fsm.c +++ b/src/output/cairo-fsm.c @@ -761,13 +761,17 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell, } size_t footnote_ofs = ds_length (&body); + size_t n_footnotes = 0; for (size_t i = 0; i < value->n_footnotes; i++) { - if (i) - ds_put_byte (&body, ','); - - size_t idx = value->footnote_indexes[i]; - pivot_footnote_format_marker (pt->footnotes[idx], pt, &body); + const struct pivot_footnote *f + = pt->footnotes[value->footnote_indexes[i]]; + if (f->show) + { + if (n_footnotes++) + ds_put_byte (&body, ','); + pivot_footnote_format_marker (f, pt, &body); + } } /* Allow footnote markers to occupy the right margin. That way, numbers diff --git a/src/output/html.c b/src/output/html.c index 3f07adcfee..644ef49eba 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -586,17 +586,20 @@ html_put_table_cell (struct html_driver *html, const struct pivot_table *pt, if (cell->value->n_footnotes > 0) { fputs ("", html->file); + size_t n_footnotes = 0; for (size_t i = 0; i < cell->value->n_footnotes; i++) { - if (i > 0) - putc (',', html->file); - - size_t idx = cell->value->footnote_indexes[i]; - const struct pivot_footnote *f = pt->footnotes[idx]; + const struct pivot_footnote *f + = pt->footnotes[cell->value->footnote_indexes[i]]; + if (f->show) + { + if (n_footnotes++ > 0) + putc (',', html->file); - char *marker = pivot_footnote_marker_string (f, pt); - escape_string (html->file, marker, " ", "
"); - free (marker); + char *marker = pivot_footnote_marker_string (f, pt); + escape_string (html->file, marker, " ", "
"); + free (marker); + } } fputs ("
", html->file); } diff --git a/src/output/odt.c b/src/output/odt.c index 406ef14069..4a87815548 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -423,14 +423,18 @@ write_footnotes (struct odt_driver *odt, { for (size_t i = 0; i < n_footnotes; i++) { - xmlTextWriterStartElement (odt->content_wtr, _xml("text:span")); - xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:style-name"), - _xml("superscript")); const struct pivot_footnote *f = pt->footnotes[footnote_indexes[i]]; - char *s = pivot_footnote_marker_string (f, pt); - write_xml_with_line_breaks (odt, s); - free (s); - xmlTextWriterEndElement (odt->content_wtr); + if (f->show) + { + xmlTextWriterStartElement (odt->content_wtr, _xml("text:span")); + xmlTextWriterWriteAttribute (odt->content_wtr, + _xml("text:style-name"), + _xml("superscript")); + char *s = pivot_footnote_marker_string (f, pt); + write_xml_with_line_breaks (odt, s); + free (s); + xmlTextWriterEndElement (odt->content_wtr); + } } } diff --git a/src/output/pivot-output.c b/src/output/pivot-output.c index b49805f916..0efba3e34b 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -401,7 +401,7 @@ add_references (const struct pivot_table *pt, const struct table *table, size_t idx = cell.value->footnote_indexes[i]; assert (idx < pt->n_footnotes); - if (!refs[idx]) + if (!refs[idx] && pt->footnotes[idx]->show) { refs[idx] = true; (*n_refs)++; diff --git a/src/output/spv/spv-writer.c b/src/output/spv/spv-writer.c index c8cb28e375..58cb308fad 100644 --- a/src/output/spv/spv-writer.c +++ b/src/output/spv/spv-writer.c @@ -857,9 +857,10 @@ put_light_table (struct buf *buf, uint64_t table_id, put_u32 (buf, table->n_footnotes); for (size_t i = 0; i < table->n_footnotes; i++) { - put_value (buf, table->footnotes[i]->content); - put_optional_value (buf, table->footnotes[i]->marker); - put_u32 (buf, 0); + const struct pivot_footnote *f = table->footnotes[i]; + put_value (buf, f->content); + put_optional_value (buf, f->marker); + put_u32 (buf, f->show ? 1 : -1); } /* Areas. */ diff --git a/src/output/tex.c b/src/output/tex.c index e832db7d2a..c5591011f8 100644 --- a/src/output/tex.c +++ b/src/output/tex.c @@ -389,16 +389,21 @@ tex_put_footnote_markers (struct tex_driver *tex, const size_t *footnote_indexes, size_t n_footnotes) { - if (n_footnotes > 0) - shipout (&tex->token_list, "$^{"); + size_t n_visible = 0; for (size_t i = 0; i < n_footnotes; i++) { const struct pivot_footnote *f = pt->footnotes[footnote_indexes[i]]; - char *marker = pivot_footnote_marker_string (f, pt); - tex_escape_string (tex, marker, true); - free (marker); + if (f->show) + { + if (!n_visible++) + shipout (&tex->token_list, "$^{"); + + char *marker = pivot_footnote_marker_string (f, pt); + tex_escape_string (tex, marker, true); + free (marker); + } } - if (n_footnotes > 0) + if (n_visible) shipout (&tex->token_list, "}$"); } diff --git a/tests/output/pivot-table-test.c b/tests/output/pivot-table-test.c index 04f3eb2401..976abcd0d0 100644 --- a/tests/output/pivot-table-test.c +++ b/tests/output/pivot-table-test.c @@ -934,7 +934,8 @@ read_footnote (struct lexer *lexer, struct pivot_table *pt) else marker = NULL; - pivot_table_create_footnote__ (pt, idx, marker, content); + bool show = !lex_match_id (lexer, "HIDE"); + pivot_table_create_footnote__ (pt, idx, marker, content)->show = show; } static void diff --git a/tests/output/pivot-table.at b/tests/output/pivot-table.at index 7f09330a15..5e45563d66 100644 --- a/tests/output/pivot-table.at +++ b/tests/output/pivot-table.at @@ -471,6 +471,9 @@ AT_DATA([pivot.txt], [[ /display /title "Pivot Table with Numeric Superscript Footnotes"[footnote 0] /look marker=numeric level=super +/display +/title "Hidden Footnote"[footnote 0] +/footnote[0] "First footnote" marker="*" hide ]]) AT_CHECK([pivot-table-test --table-look $srcdir/output/look.stt pivot.txt --box unicode], [0], [[Pivot Table with Alphabetic Subscript Footnotes[*] @@ -524,6 +527,18 @@ Pivot Table with Numeric Superscript Footnotes[*] Caption[*] *. First footnote 2. Second footnote + +Hidden Footnote[*] +╭────────────┬──────────────────╮ +│ │ A[*] │ +│ ├───────┬──────────┤ +│Corner[*][2]│ B[2] │ C[*][2] │ +├────────────┼───────┼──────────┤ +│D[2] E[*] │ .00│ 1.00[*]│ +│ F[*][2]│2.00[2]│3.00[*][2]│ +╰────────────┴───────┴──────────╯ +Caption[*] +2. Second footnote ]]) AT_CLEANUP -- 2.30.2