1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009, 2010, 2011, 2014 Free Software Foundation, Inc.
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.
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.
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/>. */
17 #ifndef OUTPUT_RENDER_H
18 #define OUTPUT_RENDER_H 1
22 #include "output/table-provider.h"
26 enum render_line_style
28 RENDER_LINE_NONE, /* No line. */
29 RENDER_LINE_SINGLE, /* Single line. */
30 RENDER_LINE_DOUBLE, /* Double line. */
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);
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,
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
55 Optional. If NULL, the rendering engine assumes that all breakpoints
57 int (*adjust_break) (void *aux, const struct table_cell *cell,
58 int width, int height);
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]).
64 STYLES is interpreted this way:
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]);
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]);
80 /* Auxiliary data passed to each of the above functions. */
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];
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];
92 /* Width of different kinds of lines. */
93 int line_widths[TABLE_N_AXES][RENDER_N_LINES];
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
98 int min_break[TABLE_N_AXES];
101 /* A "page" of content that is ready to be rendered.
103 A page's size is not limited to the size passed in as part of render_params.
104 Use render_break (see below) to break a too-big 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 *);
109 struct render_page *render_page_ref (const struct render_page *);
110 void render_page_unref (struct render_page *);
112 int render_page_get_size (const struct render_page *, enum table_axis);
113 void render_page_draw (const struct render_page *);
114 void render_page_draw_region (const struct render_page *,
115 int x, int y, int w, int h);
117 int render_page_get_best_breakpoint (const struct render_page *, int height);
119 /* An iterator for breaking render_pages into smaller chunks. */
122 struct render_page *page; /* Page being broken up. */
123 enum table_axis axis; /* Axis along which 'page' is being broken. */
124 int z; /* Next cell along 'axis'. */
125 int pixel; /* Pixel offset within cell 'z' (usually 0). */
126 int hw; /* Width of headers of 'page' along 'axis'. */
129 void render_break_init (struct render_break *, struct render_page *,
131 void render_break_init_empty (struct render_break *);
132 void render_break_destroy (struct render_break *);
134 bool render_break_has_next (const struct render_break *);
135 int render_break_next_size (const struct render_break *);
136 struct render_page *render_break_next (struct render_break *, int size);
138 #endif /* output/render.h */