7ed828f515d61b24d7c5153cde9dc831dd7d44fe
[pspp] / src / output / cairo.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010 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_H
18 #define OUTPUT_CAIRO_H 1
19
20 #include <stdbool.h>
21
22 #ifdef HAVE_CAIRO
23
24 #include <cairo/cairo.h>
25
26 struct chart_item;
27 struct output_item;
28 struct string_map;
29
30 /* Creating and destroying Cairo output drivers. */
31 struct xr_driver *xr_driver_create (cairo_t *, struct string_map *options);
32 void xr_driver_destroy (struct xr_driver *);
33
34
35 /* Functions for rendering a single output item to a Cairo context.
36    Output items are never broken across multiple pages.
37    Used by PSPPIRE to render in the GUI. */
38 struct xr_rendering *xr_rendering_create (struct xr_driver *,
39                                           const struct output_item *,
40                                           cairo_t *);
41
42 void xr_rendering_apply_options (struct xr_rendering *, struct string_map *o);
43 void xr_rendering_measure (struct xr_rendering *, int *w, int *h);
44 void xr_rendering_draw (struct xr_rendering *, cairo_t *,
45                         int x, int y, int w, int h);
46
47 /* Functions for rendering a series of output items to a series of Cairo
48    contexts, with pagination, possibly including headers.
49
50    The intended usage pattern is this:
51
52      * Create an xr_driver with xr_driver_create().  The cairo_t passed in must
53        accurately reflect the properties of the output (e.g. for the purpose of
54        page size and font selection) but need not be used for rendering.
55
56      * Call xr_driver_next_page() to set up the first real output page's
57        cairo_t.  (You can skip this step if the cairo_t passed to
58        xr_driver_create() can be used.)
59
60      * Then, for each output_item:
61
62        - Pass the output item to xr_driver_output_item().  As much output as
63          fits will be rendered on the current page.
64
65        - Then, as long as xr_driver_need_new_page() returns true, obtain a new
66          page for rendering and pass it to xr_driver_next_page().  As much
67          output as fits on the new page will be rendered on it.
68
69      * When you're done, destroy the output driver with xr_driver_destroy().
70
71    These functions may also be used for counting pages without actually
72    rendering output.  Follow the same steps, except pass NULL as the cairo_t to
73    xr_driver_next_page().  (But xr_driver_create() still needs a valid cairo_t
74    for page setup.)
75
76    (If the cairo_t that you pass to xr_driver_create() won't remain valid, be
77    sure to clear it out one way or another before calling xr_driver_destroy(),
78    so that xr_driver_destroy() won't destroy it itself.)
79 */
80 void xr_driver_next_page (struct xr_driver *, cairo_t *);
81 void xr_driver_output_item (struct xr_driver *, const struct output_item *);
82 bool xr_driver_need_new_page (const struct xr_driver *);
83 bool xr_driver_is_page_blank (const struct xr_driver *);
84
85 struct xr_color
86 {
87   double red;
88   double green;
89   double blue;
90 };
91
92 struct output_driver;
93 struct string_map;
94
95 void parse_color (struct output_driver *d, struct string_map *options,
96                   const char *key, const char *default_value,
97                   struct xr_color *color);
98
99
100 /* Render charts with Cairo. */
101 char *xr_draw_png_chart (const struct chart_item *,
102                          const char *file_name_template, int number,
103                          const struct xr_color *fg,
104                          const struct xr_color *bg);
105
106
107 #endif  /* HAVE_CAIRO */
108
109 #endif /* output/cairo.h */