f6035cf0ab52fae1c16c55d9acdc383bf3be4a02
[pspp-builds.git] / src / output / render.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_RENDER_H
18 #define OUTPUT_RENDER_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <output/table-provider.h>
23
24 struct table;
25
26 enum render_line_style
27   {
28     RENDER_LINE_NONE,           /* No line. */
29     RENDER_LINE_SINGLE,         /* Single line. */
30     RENDER_LINE_DOUBLE,         /* Double line. */
31     RENDER_N_LINES
32   };
33
34 struct render_params
35   {
36     /* Measures CELL's width.  Stores in *MIN_WIDTH the minimum width required
37        to avoid splitting a single word across multiple lines (normally, this
38        is the width of the longest word in the cell) and in *MAX_WIDTH the
39        minimum width required to avoid line breaks other than at new-lines. */
40     void (*measure_cell_width) (void *aux, const struct table_cell *cell,
41                                 int *min_width, int *max_width);
42
43     /* Returns the height required to render CELL given a width of WIDTH. */
44     int (*measure_cell_height) (void *aux, const struct table_cell *cell,
45                                 int width);
46
47     /* Draws a generalized intersection of lines in the rectangle whose
48        top-left corner is (BB[TABLE_HORZ][0], BB[TABLE_VERT][0]) and whose
49        bottom-right corner is (BB[TABLE_HORZ][1], BB[TABLE_VERT][1]).
50
51        STYLES is interpreted this way:
52
53        STYLES[TABLE_HORZ][0]: style of line from top of BB to its center.
54        STYLES[TABLE_HORZ][1]: style of line from bottom of BB to its center.
55        STYLES[TABLE_VERT][0]: style of line from left of BB to its center.
56        STYLES[TABLE_VERT][1]: style of line from right of BB to its center. */
57     void (*draw_line) (void *aux, int bb[TABLE_N_AXES][2],
58                        enum render_line_style styles[TABLE_N_AXES][2]);
59
60     /* Draws CELL within bounding box BB.  CLIP is the same as BB (the common
61        case) or a subregion enclosed by BB.  In the latter case only the part
62        of the cell that lies within CLIP should actually be drawn, although BB
63        should used to determine the layout of the cell. */
64     void (*draw_cell) (void *aux, const struct table_cell *cell,
65                        int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2]);
66
67     /* Auxiliary data passed to each of the above functions. */
68     void *aux;
69
70     /* Page size to try to fit the rendering into.  Some tables will, of
71        course, overflow this size. */
72     int size[TABLE_N_AXES];
73
74     /* Nominal size of a character in the most common font:
75        font_size[TABLE_HORZ]: Em width.
76        font_size[TABLE_VERT]: Line spacing. */
77     int font_size[TABLE_N_AXES];
78
79     /* Width of different kinds of lines. */
80     int line_widths[TABLE_N_AXES][RENDER_N_LINES];
81   };
82 \f
83 /* A "page" of content that is ready to be rendered.
84
85    A page's size is not limited to the size passed in as part of render_params.
86    Use render_break (see below) to break a too-big render_page into smaller
87    render_pages that will fit in the available space. */
88 struct render_page *render_page_create (const struct render_params *,
89                                         const struct table *);
90
91 struct render_page *render_page_ref (const struct render_page *);
92 void render_page_unref (struct render_page *);
93
94 int render_page_get_size (const struct render_page *, enum table_axis);
95 void render_page_draw (const struct render_page *);
96 void render_page_draw_region (const struct render_page *,
97                               int x, int y, int w, int h);
98 \f
99 /* An iterator for breaking render_pages into smaller chunks. */
100 struct render_break
101   {
102     struct render_page *page;   /* Page being broken up. */
103     enum table_axis axis;       /* Axis along which 'page' is being broken. */
104     int cell;                   /* Next cell. */
105     int pixel;                  /* Pixel offset within 'cell' (usually 0). */
106     int hw;                     /* Width of headers of 'page' along 'axis'. */
107   };
108
109 void render_break_init (struct render_break *, struct render_page *,
110                         enum table_axis);
111 void render_break_init_empty (struct render_break *);
112 void render_break_destroy (struct render_break *);
113
114 bool render_break_has_next (const struct render_break *);
115 int render_break_next_size (const struct render_break *);
116 struct render_page *render_break_next (struct render_break *, int size);
117
118 #endif /* output/render.h */