+ if (clip[H][1] != INT_MAX || clip[V][1] != INT_MAX)
+ {
+ double x0 = xr_to_pt (clip[H][0] + xr->x);
+ double y0 = xr_to_pt (clip[V][0] + xr->y);
+ double x1 = xr_to_pt (clip[H][1] + xr->x);
+ double y1 = xr_to_pt (clip[V][1] + xr->y);
+
+ cairo_rectangle (xr->cairo, x0, y0, x1 - x0, y1 - y0);
+ cairo_clip (xr->cairo);
+ }
+}
+
+static int
+xr_layout_cell_text (struct xr_driver *xr,
+ const struct cell_contents *contents,
+ int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
+ int y, int *widthp, int *brk)
+{
+ unsigned int options = contents->options;
+ struct xr_font *font;
+ int w, h;
+
+ font = (options & TAB_FIX ? &xr->fonts[XR_FONT_FIXED]
+ : options & TAB_EMPH ? &xr->fonts[XR_FONT_EMPHASIS]
+ : &xr->fonts[XR_FONT_PROPORTIONAL]);
+
+ pango_layout_set_text (font->layout, contents->text, -1);
+
+ pango_layout_set_alignment (
+ font->layout,
+ ((options & TAB_ALIGNMENT) == TAB_RIGHT ? PANGO_ALIGN_RIGHT
+ : (options & TAB_ALIGNMENT) == TAB_LEFT ? PANGO_ALIGN_LEFT
+ : PANGO_ALIGN_CENTER));
+ pango_layout_set_width (
+ font->layout,
+ bb[H][1] == INT_MAX ? -1 : xr_to_pango (bb[H][1] - bb[H][0]));
+ pango_layout_set_wrap (font->layout, PANGO_WRAP_WORD);
+
+ if (clip[H][0] != clip[H][1])
+ {
+ cairo_save (xr->cairo);
+ xr_clip (xr, clip);
+ cairo_translate (xr->cairo,
+ xr_to_pt (bb[H][0] + xr->x),
+ xr_to_pt (y + xr->y));
+ pango_cairo_show_layout (xr->cairo, font->layout);
+
+ /* If enabled, this draws a blue rectangle around the extents of each
+ line of text, which can be rather useful for debugging layout
+ issues. */
+ if (0)
+ {
+ PangoLayoutIter *iter;
+ iter = pango_layout_get_iter (font->layout);
+ do
+ {
+ PangoRectangle extents;
+
+ pango_layout_iter_get_line_extents (iter, &extents, NULL);
+ cairo_save (xr->cairo);
+ cairo_set_source_rgb (xr->cairo, 1, 0, 0);
+ dump_rectangle (xr,
+ pango_to_xr (extents.x) - xr->x,
+ pango_to_xr (extents.y) - xr->y,
+ pango_to_xr (extents.x + extents.width) - xr->x,
+ pango_to_xr (extents.y + extents.height) - xr->y);
+ cairo_restore (xr->cairo);
+ }
+ while (pango_layout_iter_next_line (iter));
+ pango_layout_iter_free (iter);
+ }
+
+ cairo_restore (xr->cairo);
+ }
+
+ pango_layout_get_size (font->layout, &w, &h);
+ w = pango_to_xr (w);
+ h = pango_to_xr (h);
+ if (w > *widthp)
+ *widthp = w;
+ if (y + h >= bb[V][1])
+ {
+ PangoLayoutIter *iter;
+ int best UNUSED = 0;
+
+ /* Choose a breakpoint between lines instead of in the middle of one. */
+ iter = pango_layout_get_iter (font->layout);
+ do
+ {
+ PangoRectangle extents;
+ int y0, y1;
+ int bottom;
+
+ pango_layout_iter_get_line_extents (iter, NULL, &extents);
+ pango_layout_iter_get_line_yrange (iter, &y0, &y1);
+ extents.x = pango_to_xr (extents.x);
+ extents.y = pango_to_xr (y0);
+ extents.width = pango_to_xr (extents.width);
+ extents.height = pango_to_xr (y1 - y0);
+ bottom = y + extents.y + extents.height;
+ if (bottom < bb[V][1])
+ {
+ if (brk && clip[H][0] != clip[H][1])
+ best = bottom;
+ *brk = bottom;
+ }
+ else
+ break;
+ }
+ while (pango_layout_iter_next_line (iter));