output: Add footnote support.
[pspp] / src / output / render.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011, 2014 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_item;
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 /* Parameters for rendering a table_item to a device.
35
36
37    Coordinate system
38    =================
39
40    The rendering code assumes that larger 'x' is to the right and larger 'y'
41    toward the bottom of the page.
42
43    The rendering code assumes that the table being rendered has its upper left
44    corner at (0,0) in device coordinates.  This is usually not the case from
45    the driver's perspective, so the driver should expect to apply its own
46    offset to coordinates passed to callback functions.
47
48
49    Callback functions
50    ==================
51
52    For each of the callback functions, AUX is passed as the 'aux' member of the
53    render_params structure.
54
55    The device is expected to transform numerical footnote index numbers into
56    footnote markers.  The existing drivers use str_format_26adic() to transform
57    index 0 to "a", index 1 to "b", and so on.  The FOOTNOTE_IDX supplied to
58    each function is the footnote index number for the first footnote in the
59    cell.  If a cell contains more than one footnote, then the additional
60    footnote indexes increase sequentially, e.g. the second footnote has index
61    FOOTNOTE_IDX + 1.
62 */
63 struct render_params
64   {
65     /* Measures CELL's width.  Stores in *MIN_WIDTH the minimum width required
66        to avoid splitting a single word across multiple lines (normally, this
67        is the width of the longest word in the cell) and in *MAX_WIDTH the
68        minimum width required to avoid line breaks other than at new-lines.
69        */
70     void (*measure_cell_width) (void *aux, const struct table_cell *cell,
71                                 int footnote_idx,
72                                 int *min_width, int *max_width);
73
74     /* Returns the height required to render CELL given a width of WIDTH. */
75     int (*measure_cell_height) (void *aux, const struct table_cell *cell,
76                                 int footnote_idx, int width);
77
78     /* Given that there is space measuring WIDTH by HEIGHT to render CELL,
79        where HEIGHT is insufficient to render the entire height of the cell,
80        returns the largest height less than HEIGHT at which it is appropriate
81        to break the cell.  For example, if breaking at the specified HEIGHT
82        would break in the middle of a line of text, the return value would be
83        just sufficiently less that the breakpoint would be between lines of
84        text.
85
86        Optional.  If NULL, the rendering engine assumes that all breakpoints
87        are acceptable. */
88     int (*adjust_break) (void *aux, const struct table_cell *cell,
89                          int footnote_idx, int width, int height);
90
91     /* Draws a generalized intersection of lines in the rectangle whose
92        top-left corner is (BB[TABLE_HORZ][0], BB[TABLE_VERT][0]) and whose
93        bottom-right corner is (BB[TABLE_HORZ][1], BB[TABLE_VERT][1]).
94
95        STYLES is interpreted this way:
96
97        STYLES[TABLE_HORZ][0]: style of line from top of BB to its center.
98        STYLES[TABLE_HORZ][1]: style of line from bottom of BB to its center.
99        STYLES[TABLE_VERT][0]: style of line from left of BB to its center.
100        STYLES[TABLE_VERT][1]: style of line from right of BB to its center. */
101     void (*draw_line) (void *aux, int bb[TABLE_N_AXES][2],
102                        enum render_line_style styles[TABLE_N_AXES][2]);
103
104     /* Draws CELL within bounding box BB.  CLIP is the same as BB (the common
105        case) or a subregion enclosed by BB.  In the latter case only the part
106        of the cell that lies within CLIP should actually be drawn, although BB
107        should used to determine the layout of the cell. */
108     void (*draw_cell) (void *aux, const struct table_cell *cell,
109                        int footnote_idx,
110                        int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2]);
111
112     /* Auxiliary data passed to each of the above functions. */
113     void *aux;
114
115     /* Page size to try to fit the rendering into.  Some tables will, of
116        course, overflow this size. */
117     int size[TABLE_N_AXES];
118
119     /* Nominal size of a character in the most common font:
120        font_size[TABLE_HORZ]: Em width.
121        font_size[TABLE_VERT]: Line spacing. */
122     int font_size[TABLE_N_AXES];
123
124     /* Width of different kinds of lines. */
125     int line_widths[TABLE_N_AXES][RENDER_N_LINES];
126
127     /* Minimum cell width or height before allowing the cell to be broken
128        across two pages.  (Joined cells may always be broken at join
129        points.) */
130     int min_break[TABLE_N_AXES];
131   };
132 \f
133 \f
134 /* An iterator for breaking render_pages into smaller chunks. */
135 struct render_pager *render_pager_create (const struct render_params *,
136                                           const struct table_item *);
137 void render_pager_destroy (struct render_pager *);
138
139 bool render_pager_has_next (const struct render_pager *);
140 int render_pager_draw_next (struct render_pager *, int space);
141
142 void render_pager_draw (const struct render_pager *);
143 void render_pager_draw_region (const struct render_pager *,
144                                int x, int y, int w, int h);
145
146 int render_pager_get_size (const struct render_pager *, enum table_axis);
147 int render_pager_get_best_breakpoint (const struct render_pager *, int height);
148
149 #endif /* output/render.h */