+xr_fsm_draw_image (struct xr_fsm *fsm, int space)
+{
+ cairo_surface_t *image = fsm->item->image;
+ int width = cairo_image_surface_get_width (image) * XR_POINT;
+ int height = cairo_image_surface_get_height (image) * XR_POINT;
+ if (!width || !height)
+ goto error;
+
+ if (height > fsm->rp.size[V])
+ {
+ double scale = fsm->rp.size[V] / (double) height;
+ width *= scale;
+ height *= scale;
+ if (!width || !height)
+ goto error;
+
+ cairo_scale (fsm->cairo, scale, scale);
+ }
+
+ if (width > fsm->rp.size[H])
+ {
+ double scale = fsm->rp.size[H] / (double) width;
+ width *= scale;
+ height *= scale;
+ if (!width || !height)
+ goto error;
+
+ cairo_scale (fsm->cairo, scale, scale);
+ }
+
+ if (space < height)
+ return 0;
+
+ draw_image (image, fsm->cairo);
+ fsm->done = true;
+ return height;
+
+error:
+ fsm->done = true;
+ return 0;
+}
+
+static int
+xr_fsm_draw_page_break (struct xr_fsm *fsm, int space)