+
+ free (breaks);
+
+ return y;
+}
+
+static int
+ascii_layout_subtable (struct ascii_driver *a,
+ const struct cell_contents *contents,
+ int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2] UNUSED,
+ int *widthp)
+{
+ struct render_params params;
+ struct render_pager *p;
+ int r[TABLE_N_AXES][2];
+ int width, height;
+ int i;
+
+ params.draw_line = ascii_draw_line;
+ params.measure_cell_width = ascii_measure_cell_width;
+ params.measure_cell_height = ascii_measure_cell_height;
+ params.adjust_break = NULL;
+ params.draw_cell = ascii_draw_cell,
+ params.aux = a;
+ params.size[H] = bb[TABLE_HORZ][1] - bb[TABLE_HORZ][0];
+ params.size[V] = bb[TABLE_VERT][1] - bb[TABLE_VERT][0];
+ params.font_size[H] = 1;
+ params.font_size[V] = 1;
+ for (i = 0; i < RENDER_N_LINES; i++)
+ {
+ int width = i == RENDER_LINE_NONE ? 0 : 1;
+ params.line_widths[H][i] = width;
+ params.line_widths[V][i] = width;
+ }
+
+ p = render_pager_create (¶ms, contents->table);
+ width = render_pager_get_size (p, TABLE_HORZ);
+ height = render_pager_get_size (p, TABLE_VERT);
+
+ /* r = intersect(bb, clip) - bb. */
+ for (i = 0; i < TABLE_N_AXES; i++)
+ {
+ r[i][0] = MAX (bb[i][0], clip[i][0]) - bb[i][0];
+ r[i][1] = MIN (bb[i][1], clip[i][1]) - bb[i][0];
+ }
+
+ if (r[H][0] < r[H][1] && r[V][0] < r[V][1])
+ {
+ unsigned int alignment = contents->options & TAB_ALIGNMENT;
+ int save_x = a->x;
+
+ a->x += bb[TABLE_HORZ][0];
+ if (alignment == TAB_RIGHT)
+ a->x += params.size[H] - width;
+ else if (alignment == TAB_CENTER)
+ a->x += (params.size[H] - width) / 2;
+ a->y += bb[TABLE_VERT][0];
+ render_pager_draw (p);
+ a->y -= bb[TABLE_VERT][0];
+ a->x = save_x;
+ }
+ render_pager_destroy (p);
+
+ if (width > *widthp)
+ *widthp = width;
+ return bb[V][0] + height;
+}
+
+static void
+ascii_layout_cell (struct ascii_driver *a, const struct table_cell *cell,
+ int bb_[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
+ int *widthp, int *heightp)
+{
+ int bb[TABLE_N_AXES][2];
+ size_t i;
+
+ *widthp = 0;
+ *heightp = 0;
+
+ memcpy (bb, bb_, sizeof bb);
+ for (i = 0; i < cell->n_contents && bb[V][0] < bb[V][1]; i++)
+ {
+ const struct cell_contents *contents = &cell->contents[i];
+
+ /* Put a blank line between contents. */
+ if (i > 0)
+ {
+ bb[V][0]++;
+ if (bb[V][0] >= bb[V][1])
+ break;
+ }
+
+ if (contents->text)
+ bb[V][0] = ascii_layout_cell_text (a, contents, bb, clip, widthp);
+ else
+ bb[V][0] = ascii_layout_subtable (a, contents, bb, clip, widthp);
+ }
+ *heightp = bb[V][0] - bb_[V][0];
+}
+
+void
+ascii_test_write (struct output_driver *driver,
+ const char *s, int x, int y, unsigned int options)
+{
+ struct ascii_driver *a = ascii_driver_cast (driver);
+ struct cell_contents contents;
+ struct table_cell cell;
+ int bb[TABLE_N_AXES][2];
+ int width, height;
+
+ if (a->file == NULL && !ascii_open_page (a))
+ return;
+ a->y = 0;
+
+ contents.options = options | TAB_LEFT;
+ contents.text = CONST_CAST (char *, s);
+ contents.table = NULL;
+
+ memset (&cell, 0, sizeof cell);
+ cell.contents = &contents;
+ cell.n_contents = 1;
+
+ bb[TABLE_HORZ][0] = x;
+ bb[TABLE_HORZ][1] = a->width;
+ bb[TABLE_VERT][0] = y;
+ bb[TABLE_VERT][1] = a->length;
+
+ ascii_layout_cell (a, &cell, bb, bb, &width, &height);
+
+ a->y = 1;
+}
+
+void
+ascii_test_set_length (struct output_driver *driver, int y, int length)
+{
+ struct ascii_driver *a = ascii_driver_cast (driver);
+
+ if (a->file == NULL && !ascii_open_page (a))
+ return;
+
+ if (y < 0 || y >= a->length)
+ return;
+ u8_line_set_length (&a->lines[y], length);