+static const struct render_page *
+render_pager_add_table (struct render_pager *p, struct table *table)
+{
+ struct render_page *page;
+
+ if (p->n_pages >= p->allocated_pages)
+ p->pages = x2nrealloc (p->pages, &p->allocated_pages, sizeof *p->pages);
+ page = p->pages[p->n_pages++] = render_page_create (p->params, table);
+ return page;
+}
+
+static void
+render_pager_start_page (struct render_pager *p)
+{
+ render_break_init (&p->x_break, p->pages[p->cur_page++], H);
+ render_break_init_empty (&p->y_break);
+}
+
+static void
+add_footnote_page (struct render_pager *p, const struct render_page *body)
+{
+ const struct table *table = body->table;
+ int nc = table_nc (table);
+ int nr = table_nr (table);
+ int footnote_idx = 0;
+ struct tab_table *t;
+ int x, y;
+
+ if (!body->n_footnotes)
+ return;
+
+ t = tab_create (2, body->n_footnotes);
+ for (y = 0; y < nr; y++)
+ for (x = 0; x < nc; )
+ {
+ struct table_cell cell;
+
+ table_get_cell (table, x, y, &cell);
+ if (y == cell.d[V][0])
+ {
+ size_t i;
+
+ for (i = 0; i < cell.n_contents; i++)
+ {
+ const struct cell_contents *cc = &cell.contents[i];
+ size_t j;
+
+ for (j = 0; j < cc->n_footnotes; j++)
+ {
+ const char *f = cc->footnotes[j];
+
+ tab_text (t, 0, footnote_idx, TAB_LEFT, "");
+ tab_footnote (t, 0, footnote_idx, "(none)");
+ tab_text (t, 1, footnote_idx, TAB_LEFT, f);
+ footnote_idx++;
+ }
+ }
+ }
+ x = cell.d[H][1];
+ table_cell_free (&cell);
+ }
+ render_pager_add_table (p, &t->table);
+}
+
+/* Creates and returns a new render_pager for rendering TABLE_ITEM on the
+ device with the given PARAMS. */