From abc77034fd0bf89464c491ca3b573f6c3ab17648 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 9 Jan 2021 18:02:50 -0800 Subject: [PATCH] pivot-table: Allow footnote marker style to change after creation. Footnote markers can be set as numeric or alphabetic. Until now, the code for this has only honored this setting at the time the footnote was added. With this commit, changes in this setting are also honored after adding it. --- src/output/cairo-fsm.c | 3 +-- src/output/html.c | 3 ++- src/output/odt.c | 2 +- src/output/pivot-output.c | 2 +- src/output/pivot-table.c | 43 +++++++++++++++++++++++++-------------- src/output/pivot-table.h | 6 ++++++ src/output/tex.c | 4 ++-- 7 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/output/cairo-fsm.c b/src/output/cairo-fsm.c index 90eb285dd2..e427a4a5ed 100644 --- a/src/output/cairo-fsm.c +++ b/src/output/cairo-fsm.c @@ -767,8 +767,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell, ds_put_byte (&body, ','); size_t idx = value->footnote_indexes[i]; - const struct pivot_footnote *f = pt->footnotes[idx]; - pivot_value_format (f->marker, pt, &body); + pivot_footnote_format_marker (pt->footnotes[idx], 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 f14386335e..3f07adcfee 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -593,7 +593,8 @@ html_put_table_cell (struct html_driver *html, const struct pivot_table *pt, size_t idx = cell->value->footnote_indexes[i]; const struct pivot_footnote *f = pt->footnotes[idx]; - char *marker = pivot_value_to_string (f->marker, pt); + + char *marker = pivot_footnote_marker_string (f, pt); escape_string (html->file, marker, " ", "
"); free (marker); } diff --git a/src/output/odt.c b/src/output/odt.c index c21acea375..406ef14069 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -427,7 +427,7 @@ write_footnotes (struct odt_driver *odt, xmlTextWriterWriteAttribute (odt->content_wtr, _xml("text:style-name"), _xml("superscript")); const struct pivot_footnote *f = pt->footnotes[footnote_indexes[i]]; - char *s = pivot_value_to_string (f->marker, pt); + 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 cd21e2cb19..b49805f916 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -635,7 +635,7 @@ pivot_output (const struct pivot_table *pt, for (size_t i = 0; i < nf; i++) { struct string s = DS_EMPTY_INITIALIZER; - pivot_value_format (f[i]->marker, pt, &s); + pivot_footnote_format_marker (f[i], pt, &s); ds_put_cstr (&s, ". "); pivot_value_format (f[i]->content, pt, &s); fill_cell_owned (footnotes, 0, i, 0, i, PIVOT_AREA_FOOTER, &s, diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 671544ef06..37ea5c7a95 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -1505,15 +1505,30 @@ pivot_table_create_footnote (struct pivot_table *table, NULL, content); } -static struct pivot_value * -pivot_make_default_footnote_marker (int idx, bool show_numeric_markers) -{ - char text[INT_BUFSIZE_BOUND (size_t)]; - if (show_numeric_markers) - snprintf (text, sizeof text, "%d", idx + 1); +void +pivot_footnote_format_marker (const struct pivot_footnote *f, + const struct pivot_table *pt, + struct string *s) +{ + if (f->marker) + pivot_value_format_body (f->marker, pt, s); + else if (pt->look->show_numeric_markers) + ds_put_format (s, "%zu", f->idx + 1); else - str_format_26adic (idx + 1, false, text, sizeof text); - return pivot_value_new_user_text (text, -1); + { + char text[INT_BUFSIZE_BOUND (size_t)]; + str_format_26adic (f->idx + 1, false, text, sizeof text); + ds_put_cstr (s, text); + } +} + +char * +pivot_footnote_marker_string (const struct pivot_footnote *f, + const struct pivot_table *pt) +{ + struct string s = DS_EMPTY_INITIALIZER; + pivot_footnote_format_marker (f, pt, &s); + return ds_steal_cstr (&s); } /* Creates or modifies a footnote in TABLE with 0-based number IDX (and creates @@ -1533,12 +1548,10 @@ pivot_table_create_footnote__ (struct pivot_table *table, size_t idx, while (idx >= table->n_footnotes) { struct pivot_footnote *f = xmalloc (sizeof *f); - f->idx = table->n_footnotes; - f->marker = pivot_make_default_footnote_marker ( - f->idx, table->look->show_numeric_markers); - f->content = NULL; - f->show = true; - + *f = (struct pivot_footnote) { + .idx = table->n_footnotes, + .show = true, + }; table->footnotes[table->n_footnotes++] = f; } } @@ -2410,7 +2423,7 @@ pivot_value_format (const struct pivot_value *value, size_t idx = value->footnote_indexes[i]; const struct pivot_footnote *f = pt->footnotes[idx]; - pivot_value_format (f->marker, pt, out); + pivot_footnote_format_marker (f, pt, out); ds_put_byte (out, ']'); } diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h index 85aef6ab3c..c6005d3892 100644 --- a/src/output/pivot-table.h +++ b/src/output/pivot-table.h @@ -553,6 +553,12 @@ struct pivot_footnote *pivot_table_create_footnote__ ( struct pivot_table *, size_t idx, struct pivot_value *marker, struct pivot_value *content); +void pivot_footnote_format_marker (const struct pivot_footnote *, + const struct pivot_table *, + struct string *); +char *pivot_footnote_marker_string (const struct pivot_footnote *, + const struct pivot_table *); + void pivot_footnote_destroy (struct pivot_footnote *); /* Internals. */ diff --git a/src/output/tex.c b/src/output/tex.c index 2d29c2aa85..e832db7d2a 100644 --- a/src/output/tex.c +++ b/src/output/tex.c @@ -394,7 +394,7 @@ tex_put_footnote_markers (struct tex_driver *tex, for (size_t i = 0; i < n_footnotes; i++) { const struct pivot_footnote *f = pt->footnotes[footnote_indexes[i]]; - char *marker = pivot_value_to_string (f->marker, pt); + char *marker = pivot_footnote_marker_string (f, pt); tex_escape_string (tex, marker, true); free (marker); } @@ -562,7 +562,7 @@ tex_output_table_layer (struct tex_driver *tex, const struct pivot_table *pt, for (int i = 0; i < n_footnotes; ++i) { - char *marker = pivot_value_to_string (footnotes[i]->marker, pt); + char *marker = pivot_footnote_marker_string (footnotes[i], pt); char *content = pivot_value_to_string (footnotes[i]->content, pt); shipout (&tex->token_list, "$^{"); -- 2.30.2