free (style);
}
}
-
-struct footnote *
-footnote_clone (const struct footnote *old)
-{
- struct footnote *new = xmalloc (sizeof *new);
- *new = (struct footnote) {
- .idx = old->idx,
- .content = old->content ? xstrdup (old->content) : NULL,
- .marker = old->marker ? xstrdup (old->marker) : NULL,
- .style = old->style ? table_area_style_clone (NULL, old->style) : NULL,
- };
- return new;
-}
-
-void
-footnote_destroy (struct footnote *f)
-{
- if (f)
- {
- free (f->content);
- free (f->marker);
- if (f->style)
- {
- table_area_style_uninit (f->style);
- free (f->style);
- }
- free (f);
- }
-}
-
-struct table_cell *
-table_cell_clone (const struct table_cell *old)
-{
- struct table_cell *new = xmalloc (sizeof *new);
- *new = *old;
- new->text = xstrdup (new->text);
-
- if (old->n_subscripts)
- {
- new->subscripts = xnmalloc (old->n_subscripts, sizeof *new->subscripts);
- for (size_t i = 0; i < old->n_subscripts; i++)
- new->subscripts[i] = xstrdup (old->subscripts[i]);
- }
- else
- new->subscripts = NULL;
-
- if (old->n_footnotes)
- {
- new->footnotes = xnmalloc (old->n_footnotes, sizeof *new->footnotes);
- for (size_t i = 0; i < old->n_footnotes; i++)
- new->footnotes[i] = footnote_clone (old->footnotes[i]);
- }
- else
- new->footnotes = NULL;
-
- if (old->style)
- new->style = table_area_style_clone (NULL, old->style);
-
- return new;
-}
-
-void
-table_cell_destroy (struct table_cell *cell)
-{
- if (!cell)
- return;
-
- free (cell->text);
- for (size_t i = 0; i < cell->n_subscripts; i++)
- free (cell->subscripts[i]);
- free (cell->subscripts);
- for (size_t i = 0; i < cell->n_footnotes; i++)
- footnote_destroy (cell->footnotes[i]);
- free (cell->footnotes);
- if (cell->style)
- {
- table_area_style_uninit (cell->style);
- free (cell->style);
- }
- free (cell);
-}
-
-void
-table_cell_format_footnote_markers (const struct table_cell *cell,
- struct string *s)
-{
- for (size_t i = 0; i < cell->n_footnotes; i++)
- {
- if (i)
- ds_put_byte (s, ',');
- ds_put_cstr (s, cell->footnotes[i]->marker);
- }
-}
\f
const char *
table_halign_to_string (enum table_halign halign)
cell->subscripts[i] = pool_strdup (table->container, subscripts[i]);
}
-/* Create a footnote in TABLE with MARKER (e.g. "a") as its marker and CONTENT
- as its content. The footnote will be styled as STYLE, which is mandatory.
- IDX must uniquely identify the footnote within TABLE.
-
- Returns the new footnote. The return value is the only way to get to the
- footnote later, so it is important for the caller to remember it. */
-struct footnote *
-table_create_footnote (struct table *table, size_t idx, const char *content,
- const char *marker, struct table_area_style *style)
-{
- assert (style);
-
- struct footnote *f = pool_alloc (table->container, sizeof *f);
- f->idx = idx;
- f->content = pool_strdup (table->container, content);
- f->marker = pool_strdup (table->container, marker);
- f->style = style;
- return f;
-}
-
-/* Attaches a reference to footnote F to the cell at column X, row Y in
- TABLE. */
+/* Attaches a reference to the NF footnotes at F to the cell at column X, row Y
+ in TABLE. */
void
-table_add_footnote (struct table *table, int x, int y, struct footnote *f)
+table_add_footnotes (struct table *table, int x, int y,
+ struct pivot_footnote **f, size_t nf)
{
- assert (f->style);
-
struct table_cell *cell = get_joined_cell (table, x, y);
cell->footnotes = pool_realloc (
table->container, cell->footnotes,
- (cell->n_footnotes + 1) * sizeof *cell->footnotes);
+ (cell->n_footnotes + nf) * sizeof *cell->footnotes);
- cell->footnotes[cell->n_footnotes++] = f;
+ for (size_t i = 0; i < nf; i++)
+ cell->footnotes[cell->n_footnotes++] = f[i];
}
/* Overrides the style for column X, row Y in TABLE with STYLE.