xr_pager_destroy() would destroy the latest cairo_t, if there was one.
Generally there wasn't, since in the common case it got destroyed by
xr_pager_run() when the fsm emptied out, but in the case of the last page
in a produced output file, xr_destroy() would call xr_pager_destroy()
after first destroying the surface_t it was drawing on. I don't think this
is an actual bug, because everything is properly reference-counted inside
Cairo (the cairo_t holds a reference on its cairo_surface_t) but I found it
confusing.
xr_pager_run (p);
}
+void
+xr_pager_finish_page (struct xr_pager *p)
+{
+ if (p->cr)
+ {
+ cairo_restore (p->cr);
+ cairo_destroy (p->cr);
+ p->cr = NULL;
+ }
+}
+
bool
xr_pager_needs_new_page (struct xr_pager *p)
{
if (p->item && (!p->cr || p->y >= p->fsm_style->size[V]))
{
- if (p->cr)
- {
- cairo_restore (p->cr);
- cairo_destroy (p->cr);
- p->cr = NULL;
- }
+ xr_pager_finish_page (p);
return true;
}
else
bool xr_pager_has_page (const struct xr_pager *);
void xr_pager_add_page (struct xr_pager *, cairo_t *);
+void xr_pager_finish_page (struct xr_pager *);
bool xr_pager_needs_new_page (struct xr_pager *);
#endif /* HAVE_CAIRO */
static void
xr_finish_page (struct xr_driver *xr)
{
+ xr_pager_finish_page (xr->pager);
+
/* For 'trim' true:
- If the destination is PDF or PostScript, set the dest surface size, copy
if (xr->pager)
xr_finish_page (xr);
+ xr_pager_destroy (xr->pager);
+
if (xr->drawing_surface && xr->drawing_surface != xr->dest_surface)
cairo_surface_destroy (xr->drawing_surface);
if (xr->dest_surface)
cairo_surface_destroy (xr->dest_surface);
}
- xr_pager_destroy (xr->pager);
xr_page_style_unref (xr->page_style);
xr_fsm_style_unref (xr->fsm_style);
free (xr);