}
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)
}
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);
}
}
-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)
}
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);
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)
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
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)
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);
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)
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
#define OUTPUT_SPV_WRITER_H 1
struct page_setup;
-struct table_item_text;
struct pivot_table;
struct spv_writer;
struct text_item;
#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)
/* 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;
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. */
{
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);
#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;
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;
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);
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);
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;