+ /* XXX doesn't do well with very large captions */
+ struct table_cell cell;
+ ascii_init_caption_cell (caption, &cell);
+ caption_height = ascii_measure_cell_height (a, &cell, a->width);
+ }
+ else
+ caption_height = 0;
+
+ params.draw_line = ascii_draw_line;
+ params.measure_cell_width = ascii_measure_cell_width;
+ params.measure_cell_height = ascii_measure_cell_height;
+ params.draw_cell = ascii_draw_cell,
+ params.aux = a;
+ params.size[H] = a->width;
+ params.size[V] = a->length - caption_height;
+ 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;
+ }
+
+ if (a->file == NULL)
+ ascii_open_page (a);
+
+ page = render_page_create (¶ms, table_item_get_table (table_item));
+ for (render_break_init (&x_break, page, H);
+ render_break_has_next (&x_break); )
+ {
+ struct render_page *x_slice;
+ struct render_break y_break;
+
+ x_slice = render_break_next (&x_break, a->width);
+ for (render_break_init (&y_break, x_slice, V);
+ render_break_has_next (&y_break); )
+ {
+ struct render_page *y_slice;
+ int space;
+
+ if (a->y > 0)
+ a->y++;
+
+ space = a->length - a->y - caption_height;
+ if (render_break_next_size (&y_break) > space)
+ {
+ assert (a->y > 0);
+ ascii_close_page (a);
+ ascii_open_page (a);
+ continue;
+ }
+
+ y_slice = render_break_next (&y_break, space);
+ if (caption_height)
+ {
+ struct table_cell cell;
+ int bb[TABLE_N_AXES][2];
+
+ ascii_init_caption_cell (caption, &cell);
+ bb[H][0] = 0;
+ bb[H][1] = a->width;
+ bb[V][0] = 0;
+ bb[V][1] = caption_height;
+ ascii_draw_cell (a, &cell, bb, bb);
+ a->y += caption_height;
+ caption_height = 0;
+ }
+ render_page_draw (y_slice);
+ a->y += render_page_get_size (y_slice, V);
+ render_page_unref (y_slice);
+ }
+ render_break_destroy (&y_break);
+ }
+ render_break_destroy (&x_break);
+ }
+ else if (is_chart_item (output_item) && a->chart_file_name != NULL)
+ {
+ struct chart_item *chart_item = to_chart_item (output_item);
+ char *file_name;
+
+ file_name = xr_draw_png_chart (chart_item, a->chart_file_name,
+ a->chart_cnt++);
+ if (file_name != NULL)
+ {
+ struct text_item *text_item;
+
+ text_item = text_item_create_format (
+ TEXT_ITEM_PARAGRAPH, _("See %s for a chart."), file_name);
+
+ ascii_submit (driver, &text_item->output_item);
+ text_item_unref (text_item);
+ free (file_name);
+ }
+ }
+ else if (is_text_item (output_item))
+ {
+ const struct text_item *text_item = to_text_item (output_item);
+ enum text_item_type type = text_item_get_type (text_item);
+ const char *text = text_item_get_text (text_item);
+
+ switch (type)
+ {
+ case TEXT_ITEM_TITLE:
+ free (a->title);
+ a->title = xstrdup (text);
+ break;
+
+ case TEXT_ITEM_SUBTITLE:
+ free (a->subtitle);
+ a->subtitle = xstrdup (text);
+ break;
+
+ case TEXT_ITEM_COMMAND_CLOSE:
+ break;
+
+ case TEXT_ITEM_BLANK_LINE:
+ if (a->y > 0)
+ a->y++;
+ break;
+
+ case TEXT_ITEM_EJECT_PAGE:
+ if (a->y > 0)
+ ascii_close_page (a);
+ break;
+
+ default:
+ {
+ struct table_item *item;
+
+ item = table_item_create (table_from_string (0, text), NULL);
+ ascii_submit (&a->driver, &item->output_item);
+ table_item_unref (item);
+ }
+ break;