Make caption into table_cell too.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 29 Dec 2020 07:50:50 +0000 (23:50 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 31 Dec 2020 03:58:11 +0000 (19:58 -0800)
src/output/csv.c
src/output/html.c
src/output/odt.c
src/output/pivot-output.c
src/output/render.c
src/output/spv/spv-writer.h
src/output/table-item.c
src/output/table-item.h
src/output/table.c
src/output/tex.c

index b29a6750538ac87fab0ccec4db1467ed714fbdad..dd1b953b5a34242f43b02c7d05e0b28f1b17a813 100644 (file)
@@ -182,24 +182,7 @@ csv_format_footnotes (struct footnote **f, size_t n, struct string *s)
 }
 
 static void
-csv_output_table_item_text (struct csv_driver *csv,
-                            const struct table_item_text *text,
-                            const char *leader)
-{
-  if (!text)
-    return;
-
-  struct string s = DS_EMPTY_INITIALIZER;
-  ds_put_format (&s, "%s: %s", leader, text->content);
-  csv_format_footnotes (text->footnotes, text->n_footnotes, &s);
-  csv_output_field (csv, ds_cstr (&s));
-  ds_destroy (&s);
-  putc ('\n', csv->file);
-}
-
-static void
-csv_output_table_cell (struct csv_driver *csv,
-                       const struct table_cell *cell,
+csv_output_table_cell (struct csv_driver *csv, const struct table_cell *cell,
                        const char *leader)
 {
   if (!cell)
@@ -274,8 +257,8 @@ csv_submit (struct output_driver *driver,
         }
 
       if (csv->captions)
-        csv_output_table_item_text (csv, table_item_get_caption (table_item),
-                                    "Caption");
+        csv_output_table_cell (csv, table_item_get_caption (table_item),
+                               "Caption");
 
       struct footnote **f;
       size_t n_footnotes = table_collect_footnotes (table_item, &f);
index 576b598427de831a4f8b4a09101d0ee6fa833fc5..9f9fc2db89df9804650921c282ddb5a650f58978 100644 (file)
@@ -513,14 +513,6 @@ html_put_footnote_markers (struct html_driver *html,
     }
 }
 
-static void
-html_put_table_item_text (struct html_driver *html,
-                          const struct table_item_text *text)
-{
-  escape_string (html->file, text->content, " ", "<br>");
-  html_put_footnote_markers (html, text->footnotes, text->n_footnotes);
-}
-
 static void
 html_put_table_cell_text (struct html_driver *html,
                           const struct table_cell *cell)
@@ -674,11 +666,11 @@ html_output_table (struct html_driver *html, const struct table_item *item)
     }
   fputs (">\n", html->file);
 
-  const struct table_item_text *caption = table_item_get_caption (item);
+  const struct table_cell *caption = table_item_get_caption (item);
   if (caption)
     {
       put_tfoot (html, t, &tfoot);
-      html_put_table_item_text (html, caption);
+      html_put_table_cell (html, t, caption, "span", false);
     }
   struct footnote **f;
   size_t n_footnotes = table_collect_footnotes (item, &f);
index 97109cef4276a4bbd830c2fd9b4a6a79f1aa9016..9397bf142574359aca5cd7439214c693a8de2ebe 100644 (file)
@@ -426,22 +426,6 @@ write_footnote (struct odt_driver *odt, const struct footnote *f)
   xmlTextWriterEndElement (odt->content_wtr);
 }
 
-static void
-write_table_item_text (struct odt_driver *odt,
-                       const struct table_item_text *text)
-{
-  if (!text)
-    return;
-
-  xmlTextWriterStartElement (odt->content_wtr, _xml("text:h"));
-  xmlTextWriterWriteFormatAttribute (odt->content_wtr,
-                                     _xml("text:outline-level"), "%d", 2);
-  xmlTextWriterWriteString (odt->content_wtr, _xml (text->content));
-  for (size_t i = 0; i < text->n_footnotes; i++)
-    write_footnote (odt, text->footnotes[i]);
-  xmlTextWriterEndElement (odt->content_wtr);
-}
-
 static void
 write_table_item_cell (struct odt_driver *odt,
                        const struct table_cell *cell)
@@ -576,7 +560,7 @@ write_table (struct odt_driver *odt, const struct table_item *item)
   xmlTextWriterEndElement (odt->content_wtr); /* table */
 
   /* Write a caption for the table */
-  write_table_item_text (odt, table_item_get_caption (item));
+  write_table_item_cell (odt, table_item_get_caption (item));
 }
 
 static void
index f633c7d60fd3ac75828abedeac1a8f6192c0d73f..e8cacabad72107c1a4d08faf04ce568488129927 100644 (file)
@@ -193,37 +193,6 @@ pivot_value_to_table_cell (const struct pivot_value *value,
   return cell;
 }
 
-static struct table_item_text *
-pivot_value_to_table_item_text (const struct pivot_value *value,
-                                const struct table_area_style *area,
-                                struct footnote **footnotes,
-                                enum settings_value_show show_values,
-                                enum settings_value_show show_variables)
-{
-  if (!value)
-    return NULL;
-
-  struct string s = DS_EMPTY_INITIALIZER;
-  pivot_value_format_body (value, show_values, show_variables, &s);
-
-  struct table_item_text *text = xmalloc (sizeof *text);
-  *text = (struct table_item_text) {
-    .content = ds_steal_cstr (&s),
-    .footnotes = xnmalloc (value->n_footnotes, sizeof *text->footnotes),
-    .style = table_area_style_override (
-      NULL, area, value->cell_style, value->font_style, false),
-  };
-
-  for (size_t i = 0; i < value->n_footnotes; i++)
-    {
-      struct footnote *f = footnotes[value->footnotes[i]->idx];
-      if (f)
-        text->footnotes[text->n_footnotes++] = f;
-    }
-
-  return text;
-}
-
 static int
 get_table_rule (const struct table_border_style *styles,
                 enum pivot_border style_idx)
@@ -566,11 +535,11 @@ pivot_table_submit_layer (const struct pivot_table *pt,
 
   if (pt->caption && pt->show_caption)
     {
-      struct table_item_text *caption = pivot_value_to_table_item_text (
-        pt->caption, &pt->look->areas[PIVOT_AREA_CAPTION], footnotes,
-        pt->show_values, pt->show_variables);
+      struct table_cell *caption = pivot_value_to_table_cell (
+        pt->caption, &pt->look->areas[PIVOT_AREA_CAPTION], PIVOT_AREA_CAPTION,
+        footnotes, pt->show_values, pt->show_variables);
       table_item_set_caption (ti, caption);
-      table_item_text_destroy (caption);
+      table_cell_destroy (caption);
     }
 
   free (footnotes);
index b3ef3062511c9daec499e335cab93d032001848e..680beb38f86d69b18d8ddeb6812c8cf4d862bac4 100644 (file)
@@ -1551,22 +1551,6 @@ add_table_cell_page (struct render_pager *p, const struct table_cell *cell,
   render_pager_add_table (p, tab, min_width);
 }
 
-static void
-add_text_page (struct render_pager *p, const struct table_item_text *t,
-               int min_width)
-{
-  if (!t)
-    return;
-
-  struct table *tab = table_create (1, 1, 0, 0, 0, 0);
-  table_text (tab, 0, 0, 0, t->content);
-  for (size_t i = 0; i < t->n_footnotes; i++)
-    table_add_footnote (tab, 0, 0, t->footnotes[i]);
-  if (t->style)
-    tab->styles[0] = table_area_style_clone (tab->container, t->style);
-  render_pager_add_table (p, tab, min_width);
-}
-
 static void
 add_layers_page (struct render_pager *p,
                  const struct table_item_layers *layers, int min_width)
@@ -1624,7 +1608,7 @@ render_pager_create (const struct render_params *params,
   add_table_cell_page (p, table_item_get_title (table_item), body_width);
   add_layers_page (p, table_item_get_layers (table_item), body_width);
   render_pager_add_table (p, table_ref (table_item_get_table (table_item)), 0);
-  add_text_page (p, table_item_get_caption (table_item), 0);
+  add_table_cell_page (p, table_item_get_caption (table_item), 0);
   add_footnote_page (p, table_item);
 
   /* If we're shrinking tables to fit the page length, then adjust the scale
index 05604d521980baf3c7a857efc7fc0754fff95ca3..94c70f718503900aa0ea64bb91fc4c69fa6d0f08 100644 (file)
@@ -18,7 +18,6 @@
 #define OUTPUT_SPV_WRITER_H 1
 
 struct page_setup;
-struct table_item_text;
 struct pivot_table;
 struct spv_writer;
 struct text_item;
index 93cbde70ed64f8f214d4388a3b5211ddf4ad665d..7e8542c176b8ec778ad55a5f1ea75a00803cd66e 100644 (file)
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
-struct table_item_text *
-table_item_text_create (const char *content)
-{
-  if (!content)
-    return NULL;
-
-  struct table_item_text *text = xmalloc (sizeof *text);
-  *text = (struct table_item_text) { .content = xstrdup (content) };
-  return text;
-}
-
-struct table_item_text *
-table_item_text_clone (const struct table_item_text *old)
-{
-  if (!old)
-    return NULL;
-
-  struct table_item_text *new = xmalloc (sizeof *new);
-  *new = (struct table_item_text) {
-    .content = xstrdup (old->content),
-    .footnotes = xmemdup (old->footnotes,
-                          old->n_footnotes * sizeof *old->footnotes),
-    .n_footnotes = old->n_footnotes,
-    .style = table_area_style_clone (NULL, old->style),
-  };
-  return new;
-}
-
-void
-table_item_text_destroy (struct table_item_text *text)
-{
-  if (text)
-    {
-      free (text->content);
-      free (text->footnotes);
-      table_area_style_free (text->style);
-      free (text);
-    }
-}
-
 void
 table_item_layer_copy (struct table_item_layer *dst,
                        const struct table_item_layer *src)
@@ -188,7 +148,7 @@ table_item_set_layers (struct table_item *item,
 
 /* Returns ITEM's caption, which is a null pointer if no caption has been
    set. */
-const struct table_item_text *
+const struct table_cell *
 table_item_get_caption (const struct table_item *item)
 {
   return item->caption;
@@ -201,11 +161,11 @@ table_item_get_caption (const struct table_item *item)
    This function may only be used on a table_item that is unshared. */
 void
 table_item_set_caption (struct table_item *item,
-                        const struct table_item_text *caption)
+                        const struct table_cell *caption)
 {
   assert (!table_item_is_shared (item));
-  table_item_text_destroy (item->caption);
-  item->caption = table_item_text_clone (caption);
+  table_cell_destroy (item->caption);
+  item->caption = table_cell_clone (caption);
 }
 
 /* Returns ITEM's notes, which is a null pointer if ITEM has no notes. */
@@ -250,7 +210,7 @@ table_item_destroy (struct output_item *output_item)
 {
   struct table_item *item = to_table_item (output_item);
   table_cell_destroy (item->title);
-  table_item_text_destroy (item->caption);
+  table_cell_destroy (item->caption);
   table_item_layers_destroy (item->layers);
   free (item->notes);
   pivot_table_unref (item->pt);
index 57d18b75cc28c26c32e0d2c5580fbe372111998d..aa41edaa3afbbd948835a88122baa7a867ef9717 100644 (file)
 #include "output/output-item.h"
 #include "output/table.h"
 
-/* Title or caption in a table item. */
-struct table_item_text
-  {
-    char *content;
-    struct footnote **footnotes;
-    size_t n_footnotes;
-    struct table_area_style *style;
-  };
-
-struct table_item_text *table_item_text_create (const char *);
-struct table_item_text *table_item_text_clone (const struct table_item_text *);
-void table_item_text_destroy (struct table_item_text *);
-
 struct table_item_layer
   {
     char *content;
@@ -73,7 +60,7 @@ struct table_item
     struct output_item output_item;   /* Superclass. */
     struct table *table;              /* The table to be rendered. */
     struct table_cell *title;         /* Null if there is no title. */
-    struct table_item_text *caption;  /* Null if there is no caption. */
+    struct table_cell *caption;       /* Null if there is no caption. */
     struct table_item_layers *layers; /* Null if there is no layer info. */
     char *notes;                      /* Shown as tooltip. */
     struct pivot_table *pt;
@@ -91,10 +78,8 @@ const struct table_item_layers *table_item_get_layers (
 void table_item_set_layers (struct table_item *,
                            const struct table_item_layers *);
 
-const struct table_item_text *table_item_get_caption (
-  const struct table_item *);
-void table_item_set_caption (struct table_item *,
-                             const struct table_item_text *);
+const struct table_cell *table_item_get_caption (const struct table_item *);
+void table_item_set_caption (struct table_item *, const struct table_cell *);
 
 const char *table_item_get_notes (const struct table_item *);
 void table_item_set_notes (struct table_item *, const char *notes);
index 2bd71cb1b8c99e84653e520c748214eb708e6e8b..90e9491a39ed71e572e2020130e1b95e1843f39a 100644 (file)
@@ -241,7 +241,7 @@ table_collect_footnotes (const struct table_item *item,
                                    footnotes, &allocated, &n);
     }
 
-  const struct table_item_text *caption = table_item_get_caption (item);
+  const struct table_cell *caption = table_item_get_caption (item);
   if (caption)
     footnotes = add_footnotes (caption->footnotes, caption->n_footnotes,
                                footnotes, &allocated, &n);
index cd90c3ab468855bedf7fce436954e00f8a9ad72c..b6064097495b9006684f4e88764aeb4dc429bed0 100644 (file)
@@ -410,11 +410,11 @@ tex_output_table (struct tex_driver *tex, const struct table_item *item)
 
   shipout (&tex->token_list, "\n{\\parindent=0pt\n");
 
-  const struct table_item_text *caption = table_item_get_caption (item);
+  const struct table_cell *caption = table_item_get_caption (item);
   if (caption)
     {
       shipout (&tex->token_list, "{\\sl ");
-      tex_escape_string (tex, caption->content, false);
+      tex_escape_string (tex, caption->text, false);
       shipout (&tex->token_list, "}\n\n");
     }
   struct footnote **f;