+
+/* Renders PAGE, by calling the 'draw_line' and 'draw_cell' functions from the
+ render_params provided to render_page_create(). */
+void
+render_page_draw (const struct render_page *page)
+{
+ int bb[TABLE_N_AXES][2];
+
+ bb[H][0] = 0;
+ bb[H][1] = page->n[H] * 2 + 1;
+ bb[V][0] = 0;
+ bb[V][1] = page->n[V] * 2 + 1;
+
+ render_page_draw_cells (page, bb);
+}
+
+/* Returns the greatest value i, 0 <= i < n, such that cp[i] <= x0. */
+static int
+get_clip_min_extent (int x0, const int cp[], int n)
+{
+ int low, high, best;
+
+ low = 0;
+ high = n;
+ best = 0;
+ while (low < high)
+ {
+ int middle = low + (high - low) / 2;
+
+ if (cp[middle] <= x0)
+ {
+ best = middle;
+ low = middle + 1;
+ }
+ else
+ high = middle;
+ }
+
+ return best;
+}
+
+/* Returns the least value i, 0 <= i < n, such that cp[i + 1] >= x1. */
+static int
+get_clip_max_extent (int x1, const int cp[], int n)
+{
+ int low, high, best;
+
+ low = 0;
+ high = n;
+ best = n;
+ while (low < high)
+ {
+ int middle = low + (high - low) / 2;
+
+ if (cp[middle] >= x1)
+ best = high = middle;
+ else
+ low = middle + 1;
+ }
+
+ return best;
+}
+
+/* Renders the cells of PAGE that intersect (X,Y)-(X+W,Y+H), by calling the
+ 'draw_line' and 'draw_cell' functions from the render_params provided to
+ render_page_create(). */
+void
+render_page_draw_region (const struct render_page *page,
+ int x, int y, int w, int h)
+{
+ int bb[TABLE_N_AXES][2];
+
+ bb[H][0] = get_clip_min_extent (x, page->cp[H], page->n[H] * 2 + 1);
+ bb[H][1] = get_clip_max_extent (x + w, page->cp[H], page->n[H] * 2 + 1);
+ bb[V][0] = get_clip_min_extent (y, page->cp[V], page->n[V] * 2 + 1);
+ bb[V][1] = get_clip_max_extent (y + h, page->cp[V], page->n[V] * 2 + 1);
+
+ render_page_draw_cells (page, bb);
+}