927009e9cbf0e32dca8c1ddbc154f49133c5e634
[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;
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     /* Given that there is space measuring WIDTH by HEIGHT to render CELL,
48        where HEIGHT is insufficient to render the entire height of the cell,
49        returns the largest height less than HEIGHT at which it is appropriate
50        to break the cell.  For example, if breaking at the specified HEIGHT
51        would break in the middle of a line of text, the return value would be
52        just sufficiently less that the breakpoint would be between lines of
53        text.
54
55        Optional.  If NULL, the rendering engine assumes that all breakpoints
56        are acceptable. */
57     int (*adjust_break) (void *aux, const struct table_cell *cell,
58                          int width, int height);
59
60     /* Draws a generalized intersection of lines in the rectangle whose
61        top-left corner is (BB[TABLE_HORZ][0], BB[TABLE_VERT][0]) and whose
62        bottom-right corner is (BB[TABLE_HORZ][1], BB[TABLE_VERT][1]).
63
64        STYLES is interpreted this way:
65
66        STYLES[TABLE_HORZ][0]: style of line from top of BB to its center.
67        STYLES[TABLE_HORZ][1]: style of line from bottom of BB to its center.
68        STYLES[TABLE_VERT][0]: style of line from left of BB to its center.
69        STYLES[TABLE_VERT][1]: style of line from right of BB to its center. */
70     void (*draw_line) (void *aux, int bb[TABLE_N_AXES][2],
71                        enum render_line_style styles[TABLE_N_AXES][2]);
72
73     /* Draws CELL within bounding box BB.  CLIP is the same as BB (the common
74        case) or a subregion enclosed by BB.  In the latter case only the part
75        of the cell that lies within CLIP should actually be drawn, although BB
76        should used to determine the layout of the cell. */
77     void (*draw_cell) (void *aux, const struct table_cell *cell,
78                        int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2]);
79
80     /* Auxiliary data passed to each of the above functions. */
81     void *aux;
82
83     /* Page size to try to fit the rendering into.  Some tables will, of
84        course, overflow this size. */
85     int size[TABLE_N_AXES];
86
87     /* Nominal size of a character in the most common font:
88        font_size[TABLE_HORZ]: Em width.
89        font_size[TABLE_VERT]: Line spacing. */
90     int font_size[TABLE_N_AXES];
91
92     /* Width of different kinds of lines. */
93     int line_widths[TABLE_N_AXES][RENDER_N_LINES];
94
95     /* Minimum cell width or height before allowing the cell to be broken
96        across two pages.  (Joined cells may always be broken at join
97        points.) */
98     int min_break[TABLE_N_AXES];
99   };
100 \f
101 /* A "page" of content that is ready to be rendered.
102
103    A page's size is not limited to the size passed in as part of render_params.
104    Use render_pager (see below) to break a render_page into smaller
105    render_pages that will fit in the available space. */
106 struct render_page *render_page_create (const struct render_params *,
107                                         const struct table *);
108
109 struct render_page *render_page_ref (const struct render_page *);
110 void render_page_unref (struct render_page *);
111 \f
112 /* An iterator for breaking render_pages into smaller chunks. */
113
114 struct render_pager *render_pager_create (struct render_page *);
115 void render_pager_destroy (struct render_pager *);
116
117 bool render_pager_has_next (const struct render_pager *);
118 int render_pager_draw_next (struct render_pager *, int space);
119
120 void render_pager_draw (const struct render_pager *);
121 void render_pager_draw_region (const struct render_pager *,
122                                int x, int y, int w, int h);
123 int render_pager_get_size (const struct render_pager *, enum table_axis);
124 int render_pager_get_best_breakpoint (const struct render_pager *, int height);
125
126 #endif /* output/render.h */