-static int
-get_layout_height (PangoLayout *layout)
-{
- int w, h;
- pango_layout_get_size (layout, &w, &h);
- return h;
-}
-
-static int
-xr_render_page_heading (cairo_t *cairo, const PangoFontDescription *font,
- const struct page_heading *ph, int page_number,
- int width, bool draw, int base_y)
-{
- PangoLayout *layout = pango_cairo_create_layout (cairo);
- pango_layout_set_font_description (layout, font);
-
- int y = 0;
- for (size_t i = 0; i < ph->n; i++)
- {
- const struct page_paragraph *pp = &ph->paragraphs[i];
-
- char *markup = output_driver_substitute_heading_vars (pp->markup,
- page_number);
- pango_layout_set_markup (layout, markup, -1);
- free (markup);
-
- pango_layout_set_alignment (
- layout,
- (pp->halign == TABLE_HALIGN_LEFT ? PANGO_ALIGN_LEFT
- : pp->halign == TABLE_HALIGN_CENTER ? PANGO_ALIGN_CENTER
- : pp->halign == TABLE_HALIGN_MIXED ? PANGO_ALIGN_LEFT
- : PANGO_ALIGN_RIGHT));
- pango_layout_set_width (layout, xr_to_pango (width));
- if (draw)
- {
- cairo_save (cairo);
- cairo_translate (cairo, 0, xr_to_pt (y + base_y));
- pango_cairo_show_layout (cairo, layout);
- cairo_restore (cairo);
- }
-
- y += pango_to_xr (get_layout_height (layout));
- }
-
- g_object_unref (G_OBJECT (layout));
-
- return y;
-}
-
-static int
-xr_measure_headings (cairo_surface_t *surface,
- const PangoFontDescription *font,
- const struct page_heading headings[2],
- int width, int object_spacing, int height[2])
-{
- cairo_t *cairo = cairo_create (surface);
- int total = 0;
- for (int i = 0; i < 2; i++)
- {
- int h = xr_render_page_heading (cairo, font, &headings[i], -1,
- width, false, 0);
-
- /* If the top heading is nonempty, add some space below it. */
- if (h && i == 0)
- h += object_spacing;
-
- if (height)
- height[i] = h;
- total += h;
- }
- cairo_destroy (cairo);
- return total;
-}
-
-static bool
-xr_check_fonts (cairo_surface_t *surface,
- PangoFontDescription *fonts[XR_N_FONTS],
- int usable_width, int usable_length)
-{
- cairo_t *cairo = cairo_create (surface);
- int char_width, char_height;
- xr_measure_fonts (cairo, fonts, &char_width, &char_height);
- cairo_destroy (cairo);
-
- bool ok = true;
- enum { MIN_WIDTH = 3, MIN_LENGTH = 3 };
- if (usable_width / char_width < MIN_WIDTH)
- {
- msg (ME, _("The defined page is not wide enough to hold at least %d "
- "characters in the default font. In fact, there's only "
- "room for %d characters."),
- MIN_WIDTH, usable_width / char_width);
- ok = false;
- }
- if (usable_length / char_height < MIN_LENGTH)
- {
- msg (ME, _("The defined page is not long enough to hold at least %d "
- "lines in the default font. In fact, there's only "
- "room for %d lines."),
- MIN_LENGTH, usable_length / char_height);
- ok = false;
- }
- return ok;
-}
-
-static void
-xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
-{
- xr->cairo = cairo;
-
- cairo_set_line_width (xr->cairo, xr_to_pt (XR_LINE_WIDTH));
-
- xr_measure_fonts (xr->cairo, xr->fonts, &xr->char_width, &xr->char_height);