+/* render_pager. */
+
+struct render_pager
+ {
+ int width;
+ struct render_break x_break;
+ struct render_break y_break;
+ };
+
+/* Creates and returns a new render_pager for breaking PAGE into smaller
+ chunks. Takes ownership of PAGE. */
+struct render_pager *
+render_pager_create (struct render_page *page)
+{
+ struct render_pager *p = xmalloc (sizeof *p);
+ p->width = page->params->size[H];
+ render_break_init (&p->x_break, page, H);
+ render_break_init_empty (&p->y_break);
+ return p;
+}
+
+/* Destroys P. */
+void
+render_pager_destroy (struct render_pager *p)
+{
+ if (p)
+ {
+ render_break_destroy (&p->x_break);
+ render_break_destroy (&p->y_break);
+ free (p);
+ }
+}
+
+/* Returns true if P has content remaining to render, false if rendering is
+ done. */
+bool
+render_pager_has_next (const struct render_pager *p_)
+{
+ struct render_pager *p = CONST_CAST (struct render_pager *, p_);
+
+ while (!render_break_has_next (&p->y_break))
+ {
+ render_break_destroy (&p->y_break);
+ if (render_break_has_next (&p->x_break))
+ {
+ struct render_page *x_slice;
+
+ x_slice = render_break_next (&p->x_break, p->width);
+ render_break_init (&p->y_break, x_slice, V);
+ }
+ else
+ {
+ render_break_init_empty (&p->y_break);
+ return false;
+ }
+ }
+ return true;
+}
+
+/* Returns the next render_page from P to render in a space that has vertical
+ size SPACE and the horizontal size as specified in render_params passed to
+ render_page_create(). The caller takes ownership of the returned
+ render_page. If no content remains to render, or if SPACE is too small to
+ render anything, returns NULL. */
+struct render_page *
+render_pager_next (struct render_pager *p, int space)
+{
+ return (render_pager_has_next (p)
+ ? render_break_next (&p->y_break, space)
+ : NULL);
+}
+\f