+ int ofs[TABLE_N_AXES] = { 0, 0 };
+ size_t start_page = SIZE_MAX;
+
+ while (render_pager_has_next (p))
+ {
+ struct render_page *page;
+
+ if (start_page == p->cur_page)
+ break;
+ start_page = p->cur_page;
+
+ page = render_break_next (&p->y_break, space - ofs[V]);
+ if (!page)
+ break;
+
+ render_page_draw (page, ofs);
+ ofs[V] += render_page_get_size (page, V);
+ render_page_unref (page);
+ }
+ return ofs[V];
+}
+
+/* Draws all of P's content. */
+void
+render_pager_draw (const struct render_pager *p)
+{
+ render_pager_draw_region (p, 0, 0, INT_MAX, INT_MAX);
+}
+
+/* Draws the region of P's content that lies in the region (X,Y)-(X+W,Y+H).
+ Some extra content might be drawn; the device should perform clipping as
+ necessary. */
+void
+render_pager_draw_region (const struct render_pager *p,
+ int x, int y, int w, int h)
+{
+ int ofs[TABLE_N_AXES] = { 0, 0 };
+ int clip[TABLE_N_AXES][2];
+ size_t i;
+
+ clip[H][0] = x;
+ clip[H][1] = x + w;
+ for (i = 0; i < p->n_pages; i++)
+ {
+ const struct render_page *page = p->pages[i];
+ int size = render_page_get_size (page, V);
+
+ clip[V][0] = MAX (y, ofs[V]) - ofs[V];
+ clip[V][1] = MIN (y + h, ofs[V] + size) - ofs[V];
+ if (clip[V][1] > clip[V][0])
+ render_page_draw_region (page, ofs, clip);
+
+ ofs[V] += size;
+ }
+}
+
+/* Returns the size of P's content along AXIS; i.e. the content's width if AXIS
+ is TABLE_HORZ and its length if AXIS is TABLE_VERT. */
+int
+render_pager_get_size (const struct render_pager *p, enum table_axis axis)
+{
+ int size = 0;
+ size_t i;
+
+ for (i = 0; i < p->n_pages; i++)
+ {
+ int subsize = render_page_get_size (p->pages[i], axis);
+ size = axis == H ? MAX (size, subsize) : size + subsize;
+ }
+
+ return size;
+}
+
+int
+render_pager_get_best_breakpoint (const struct render_pager *p, int height)
+{
+ int y = 0;
+ size_t i;
+
+ for (i = 0; i < p->n_pages; i++)
+ {
+ int size = render_page_get_size (p->pages[i], V);
+ if (y + size >= height)
+ return render_page_get_best_breakpoint (p->pages[i], height - y) + y;
+ y += size;
+ }
+
+ return height;