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 /* Parameters for rendering a table_item to a device.
32 The rendering code assumes that larger 'x' is to the right and larger 'y'
33 toward the bottom of the page.
35 The rendering code assumes that the table being rendered has its upper left
36 corner at (0,0) in device coordinates. This is usually not the case from
37 the driver's perspective, so the driver should expect to apply its own
38 offset to coordinates passed to callback functions.
42 /* Functional parameters and auxiliary data to pass to them. */
43 const struct render_ops *ops;
46 /* Page size to try to fit the rendering into. Some tables will, of
47 course, overflow this size. */
48 int size[TABLE_N_AXES];
50 /* Nominal size of a character in the most common font:
51 font_size[TABLE_HORZ]: Em width.
52 font_size[TABLE_VERT]: Line spacing. */
53 int font_size[TABLE_N_AXES];
55 /* Width of different kinds of lines. */
56 const int *line_widths; /* RENDER_N_LINES members. */
58 /* 1/96" of an inch (1px) in the rendering unit. Currently used only for
59 column width ranges (as specified in width_ranges in struct
60 pivot_table_look). Set to 0 to disable this feature. */
63 /* Minimum cell width or height before allowing the cell to be broken
64 across two pages. (Joined cells may always be broken at join
66 int min_break[TABLE_N_AXES];
68 /* True if the driver supports cell margins. (If false, the rendering
69 engine will insert a small space betweeen adjacent cells that don't have
70 an intervening rule.) */
71 bool supports_margins;
73 /* True if the local language has a right-to-left direction, otherwise
74 false. (Use render_direction_rtl() to find out.) */
77 /* True if the table is being rendered for printing (as opposed to
78 on-screen display). */
84 /* Measures CELL's width. Stores in *MIN_WIDTH the minimum width required
85 to avoid splitting a single word across multiple lines (normally, this
86 is the width of the longest word in the cell) and in *MAX_WIDTH the
87 minimum width required to avoid line breaks other than at new-lines.
89 void (*measure_cell_width) (void *aux, const struct table_cell *cell,
90 int *min_width, int *max_width);
92 /* Returns the height required to render CELL given a width of WIDTH. */
93 int (*measure_cell_height) (void *aux, const struct table_cell *cell,
96 /* Given that there is space measuring WIDTH by HEIGHT to render CELL,
97 where HEIGHT is insufficient to render the entire height of the cell,
98 returns the largest height less than HEIGHT at which it is appropriate
99 to break the cell. For example, if breaking at the specified HEIGHT
100 would break in the middle of a line of text, the return value would be
101 just sufficiently less that the breakpoint would be between lines of
104 Optional. If NULL, the rendering engine assumes that all breakpoints
106 int (*adjust_break) (void *aux, const struct table_cell *cell,
107 int width, int height);
109 /* Draws a generalized intersection of lines in the rectangle whose
110 top-left corner is (BB[TABLE_HORZ][0], BB[TABLE_VERT][0]) and whose
111 bottom-right corner is (BB[TABLE_HORZ][1], BB[TABLE_VERT][1]).
113 STYLES is interpreted this way:
115 STYLES[TABLE_HORZ][0]: style of line from top of BB to its center.
116 STYLES[TABLE_HORZ][1]: style of line from bottom of BB to its center.
117 STYLES[TABLE_VERT][0]: style of line from left of BB to its center.
118 STYLES[TABLE_VERT][1]: style of line from right of BB to its center. */
119 void (*draw_line) (void *aux, int bb[TABLE_N_AXES][2],
120 const struct table_border_style styles[TABLE_N_AXES][2]);
122 /* Draws CELL within bounding box BB. CLIP is the same as BB (the common
123 case) or a subregion enclosed by BB. In the latter case only the part
124 of the cell that lies within CLIP should actually be drawn, although BB
125 should used to determine the layout of the cell.
127 The text in the cell needs to be vertically offset VALIGN_OFFSET units
128 from the top of the bounding box. This handles vertical alignment with
129 the cell. (The caller doesn't just reduce the bounding box size because
130 that would prevent the implementation from filling the entire cell with
131 the background color.) The implementation must handle horizontal
133 void (*draw_cell) (void *aux, const struct table_cell *cell, int color_idx,
134 int bb[TABLE_N_AXES][2], int valign_offset,
135 int spill[TABLE_N_AXES][2],
136 int clip[TABLE_N_AXES][2]);
138 /* Scales all output by FACTOR, e.g. a FACTOR of 0.5 would cause everything
139 subsequent to be drawn half-size. FACTOR will be greater than 0 and
140 less than or equal to 1.
142 Optional. If NULL, the rendering engine won't try to scale output. */
143 void (*scale) (void *aux, double factor);
146 /* An iterator for breaking render_pages into smaller chunks. */
147 struct render_pager *render_pager_create (const struct render_params *,
148 const struct pivot_table *,
149 const size_t *layer_indexes);
150 void render_pager_destroy (struct render_pager *);
152 bool render_pager_has_next (const struct render_pager *);
153 int render_pager_draw_next (struct render_pager *, int space);
155 void render_pager_draw (const struct render_pager *);
156 void render_pager_draw_region (const struct render_pager *,
157 int x, int y, int w, int h);
159 int render_pager_get_size (const struct render_pager *, enum table_axis);
160 int render_pager_get_best_breakpoint (const struct render_pager *, int height);
162 bool render_direction_rtl (void);
165 #endif /* output/render.h */