pivot-table: Allow footnote marker style to change after creation.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 10 Jan 2021 02:02:50 +0000 (18:02 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 10 Jan 2021 02:03:06 +0000 (18:03 -0800)
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
src/output/html.c
src/output/odt.c
src/output/pivot-output.c
src/output/pivot-table.c
src/output/pivot-table.h
src/output/tex.c

index 90eb285dd28126e892569ec521a8167808599a2a..e427a4a5ed8ba9d4c816d9a6f849d116c6bbfdbd 100644 (file)
@@ -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
index f14386335efe63deaa16a69e17f2da76467ce07d..3f07adcfeebd1dd634d19ba55c296054a21f0e5b 100644 (file)
@@ -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, " ", "<br>");
           free (marker);
         }
index c21acea3757a1d7d820f9df3628c25e7a388cc0e..406ef14069c32b31f2d1661f24343f2b540223e7 100644 (file)
@@ -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);
index cd21e2cb195b74c81208ee90fe9860c7bb74a0ea..b49805f91612da94f2a6941828799a676a2ca80d 100644 (file)
@@ -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,
index 671544ef06906a513e8c5099827fccc2b1b7f3a4..37ea5c7a9549599b3892b7bd500acda969ce4f27 100644 (file)
@@ -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, ']');
     }
index 85aef6ab3cafa76531c87bb3bd50c875db095746..c6005d38921c683787d37987a7c6c4ed6e138013 100644 (file)
@@ -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. */
index 2d29c2aa85629affce079eb58cf146e347af703b..e832db7d2acf34061af4a58db22bcd02b4fe5d0c 100644 (file)
@@ -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, "$^{");