cairo: Avoid using cairo_t for a destroyed cairo_surface_t.
[pspp] / src / output / cairo-pager.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2014, 2020 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef OUTPUT_CAIRO_PAGER_H
18 #define OUTPUT_CAIRO_PAGER_H 1
19
20 #include <stdbool.h>
21
22 #ifdef HAVE_CAIRO
23
24 /* Cairo output driver paginater. */
25
26 #include <cairo/cairo.h>
27 #include <pango/pango-font.h>
28 #include "output/cairo-fsm.h"
29 #include "output/page-setup-item.h"
30 #include "output/table.h"
31
32 struct xr_page_style
33   {
34     int ref_cnt;
35
36     int margins[TABLE_N_AXES][2];    /* Margins. */
37
38     struct page_heading headings[2]; /* Top and bottom headings. */
39
40     int initial_page_number;
41     int object_spacing;
42   };
43 struct xr_page_style *xr_page_style_ref (const struct xr_page_style *);
44 struct xr_page_style *xr_page_style_unshare (struct xr_page_style *);
45 void xr_page_style_unref (struct xr_page_style *);
46 bool xr_page_style_equals (const struct xr_page_style *,
47                            const struct xr_page_style *);
48 struct xr_page_style *xr_page_style_default (void);
49
50 static inline int
51 xr_page_style_paper_size (const struct xr_page_style *ps,
52                           const struct xr_fsm_style *fs, enum table_axis a)
53 {
54   return fs->size[a] + ps->margins[a][0] + ps->margins[a][1];
55 }
56
57 struct xr_pager *xr_pager_create (const struct xr_page_style *,
58                                   const struct xr_fsm_style *);
59 void xr_pager_destroy (struct xr_pager *);
60
61 bool xr_pager_has_item (const struct xr_pager *);
62 void xr_pager_add_item (struct xr_pager *, const struct output_item *);
63
64 bool xr_pager_has_page (const struct xr_pager *);
65 void xr_pager_add_page (struct xr_pager *, cairo_t *);
66 void xr_pager_finish_page (struct xr_pager *);
67 bool xr_pager_needs_new_page (struct xr_pager *);
68
69 #endif  /* HAVE_CAIRO */
70
71 #endif /* output/cairo-pager.h */