+xr_layout_cell (struct xr_driver *xr, const struct table_cell *cell,
+ int footnote_idx,
+ int bb_[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
+ int *width, int *height, int *brk)
+{
+ int bb[TABLE_N_AXES][2];
+ size_t i;
+
+ *width = 0;
+ *height = 0;
+ if (brk)
+ *brk = 0;
+
+ memcpy (bb, bb_, sizeof bb);
+
+ /* If enabled, draws a blue rectangle around the cell extents, which can be
+ useful for debugging layout. */
+ if (0)
+ {
+ if (clip[H][0] != clip[H][1])
+ {
+ int offset = (xr->nest) * XR_POINT;
+
+ cairo_save (xr->cairo);
+ cairo_set_source_rgb (xr->cairo, 0, 0, 1);
+ dump_rectangle (xr,
+ bb[H][0] + offset, bb[V][0] + offset,
+ bb[H][1] - offset, bb[V][1] - offset);
+ cairo_restore (xr->cairo);
+ }
+ }
+
+ for (i = 0; i < cell->n_contents && bb[V][0] < bb[V][1]; i++)
+ {
+ const struct cell_contents *contents = &cell->contents[i];
+
+ if (brk)
+ *brk = bb[V][0];
+ if (i > 0)
+ {
+ bb[V][0] += xr->char_height / 2;
+ if (bb[V][0] >= bb[V][1])
+ break;
+ if (brk)
+ *brk = bb[V][0];
+ }
+
+ if (contents->text)
+ bb[V][0] = xr_layout_cell_text (xr, contents, footnote_idx, bb, clip,
+ bb[V][0], width, brk);
+ else
+ bb[V][0] = xr_layout_cell_subtable (xr, contents, footnote_idx,
+ bb, clip, width, brk);
+ footnote_idx += contents->n_footnotes;
+ }
+ *height = bb[V][0] - bb_[V][0];
+}
+\f
+struct output_driver_factory pdf_driver_factory =
+ { "pdf", "pspp.pdf", xr_pdf_create };
+struct output_driver_factory ps_driver_factory =
+ { "ps", "pspp.ps", xr_ps_create };
+struct output_driver_factory svg_driver_factory =
+ { "svg", "pspp.svg", xr_svg_create };
+
+static const struct output_driver_class cairo_driver_class =
+{
+ "cairo",
+ xr_destroy,
+ xr_submit,
+ xr_flush,
+};
+\f
+/* GUI rendering helpers. */
+
+struct xr_rendering
+ {
+ struct output_item *item;
+
+ /* Table items. */
+ struct render_pager *p;
+ struct xr_driver *xr;
+ };
+
+#define CHART_WIDTH 500
+#define CHART_HEIGHT 375
+
+
+
+struct xr_driver *
+xr_driver_create (cairo_t *cairo, struct string_map *options)
+{
+ struct xr_driver *xr = xr_allocate ("cairo", 0, options);
+ if (!xr_set_cairo (xr, cairo))
+ {
+ output_driver_destroy (&xr->driver);
+ return NULL;
+ }
+ return xr;
+}
+
+/* Destroy XR, which should have been created with xr_driver_create(). Any
+ cairo_t added to XR is not destroyed, because it is owned by the client. */
+void
+xr_driver_destroy (struct xr_driver *xr)
+{
+ if (xr != NULL)
+ {
+ xr->cairo = NULL;
+ output_driver_destroy (&xr->driver);
+ }
+}
+
+static struct xr_rendering *
+xr_rendering_create_text (struct xr_driver *xr, const char *text, cairo_t *cr)
+{
+ struct table_item *table_item;
+ struct xr_rendering *r;
+
+ table_item = table_item_create (table_from_string (TAB_LEFT, text), NULL);
+ r = xr_rendering_create (xr, &table_item->output_item, cr);
+ table_item_unref (table_item);
+
+ return r;
+}
+
+void
+xr_rendering_apply_options (struct xr_rendering *xr, struct string_map *o)
+{
+ if (is_table_item (xr->item))
+ apply_options (xr->xr, o);
+}
+
+struct xr_rendering *
+xr_rendering_create (struct xr_driver *xr, const struct output_item *item,
+ cairo_t *cr)