From: Ben Pfaff Date: Tue, 29 Dec 2020 07:50:50 +0000 (-0800) Subject: table-item: Make caption into table_cell too. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c243b3761224d8f0ca299caa317a735c72f4843d;p=pspp table-item: Make caption into table_cell too. --- diff --git a/src/output/csv.c b/src/output/csv.c index b29a675053..dd1b953b5a 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -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); diff --git a/src/output/html.c b/src/output/html.c index 576b598427..9f9fc2db89 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -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, " ", "
"); - 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); diff --git a/src/output/odt.c b/src/output/odt.c index 97109cef42..9397bf1425 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -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 diff --git a/src/output/pivot-output.c b/src/output/pivot-output.c index f9f497439d..8cde929c50 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -195,37 +195,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) @@ -671,11 +640,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); diff --git a/src/output/render.c b/src/output/render.c index b3ef306251..680beb38f8 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -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 diff --git a/src/output/spv/spv-writer.h b/src/output/spv/spv-writer.h index 05604d5219..94c70f7185 100644 --- a/src/output/spv/spv-writer.h +++ b/src/output/spv/spv-writer.h @@ -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; diff --git a/src/output/table-item.c b/src/output/table-item.c index 93cbde70ed..7e8542c176 100644 --- a/src/output/table-item.c +++ b/src/output/table-item.c @@ -33,46 +33,6 @@ #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); diff --git a/src/output/table-item.h b/src/output/table-item.h index 57d18b75cc..aa41edaa3a 100644 --- a/src/output/table-item.h +++ b/src/output/table-item.h @@ -29,19 +29,6 @@ #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); diff --git a/src/output/table.c b/src/output/table.c index 5430cd5ffb..a8b7704fd2 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -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); diff --git a/src/output/tex.c b/src/output/tex.c index cd90c3ab46..b606409749 100644 --- a/src/output/tex.c +++ b/src/output/tex.c @@ -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;