+ /* 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 = bb[V][0] + extents.y + extents.height;
+ if (bottom < bb[V][1])
+ {
+ if (brk && clip[H][0] != clip[H][1])
+ best = bottom;
+ if (brk)
+ *brk = bottom;
+ }
+ else
+ break;
+ }
+ while (pango_layout_iter_next_line (iter));
+ pango_layout_iter_free (iter);
+
+ /* If enabled, draws a green line across the chosen breakpoint, which can
+ be useful for debugging issues with breaking. */
+ if (0)
+ {
+ if (best && !xr->nest)
+ {
+ cairo_save (xr->cairo);
+ cairo_set_source_rgb (xr->cairo, 0, 1, 0);
+ dump_line (xr, -xr->left_margin, best,
+ xr->width + xr->right_margin, best,
+ RENDER_LINE_SINGLE);
+ cairo_restore (xr->cairo);
+ }
+ }
+ }
+
+ pango_layout_set_attributes (font->layout, NULL);
+
+ if (font == &local_font)
+ {
+ g_object_unref (G_OBJECT (font->layout));
+ pango_font_description_free (font->desc);
+ }
+
+ return bb[V][0] + h;
+}
+
+static void
+xr_layout_cell (struct xr_driver *xr, const struct table_cell *cell,
+ 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];
+ }
+
+ bb[V][0] = xr_layout_cell_text (xr, contents, cell->style, bb, clip,
+ width, brk);