1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997, 1998, 1999, 2000, 2009, 2013, 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_TABLE_H
18 #define OUTPUT_TABLE_H 1
22 . A table is a rectangular grid of cells. Cells can be joined to form larger
23 cells. Rows and columns can be separated by rules of various types. Rows
24 at the top and bottom of a table and columns at the left and right edges of
25 a table can be designated as headers, which means that if the table must be
26 broken across more than one page, those rows or columns are repeated on each
29 Every table is an instance of a particular table class that is responsible
30 for keeping track of cell data. By far the most common table class is
31 struct table (see output/tab.h). This header also declares some other
32 kinds of table classes, near the end of the file.
34 A table is not itself an output_item, and thus a table cannot by itself be
35 used for output, but they can be embedded inside struct table_item (see
36 table-item.h) for that purpose. */
50 Many table-related declarations use 2-element arrays in place of "x" and "y"
51 variables. This reduces code duplication significantly, because much table
52 code treats rows and columns the same way.
54 A lot of code that uses these enumerations assumes that the two values are 0
55 and 1, so don't change them to other values. */
60 #define TABLE_N_AXES 2
65 uint8_t alpha, r, g, b;
68 #define CELL_COLOR(r, g, b) { 255, r, g, b }
69 #define CELL_COLOR_BLACK CELL_COLOR (0, 0, 0)
70 #define CELL_COLOR_WHITE CELL_COLOR (255, 255, 255)
73 cell_color_equal (const struct cell_color *a, const struct cell_color *b)
75 return a->alpha == b->alpha && a->r == b->r && a->g == b->g && a->b == b->b;
78 void cell_color_dump (const struct cell_color *);
91 const char *table_stroke_to_string (enum table_stroke);
93 struct table_border_style
95 enum table_stroke stroke;
96 struct cell_color color;
99 #define TABLE_BORDER_STYLE_INITIALIZER { TABLE_STROKE_SOLID, CELL_COLOR_BLACK }
110 const char *table_halign_to_string (enum table_halign);
119 const char *table_valign_to_string (enum table_valign);
123 enum table_halign halign;
124 enum table_valign valign;
125 double decimal_offset; /* In 1/96" units. */
126 char decimal_char; /* Either '.' or ','. */
127 int margin[TABLE_N_AXES][2]; /* In 1/96" units. */
130 #define CELL_STYLE_INITIALIZER { CELL_STYLE_INITIALIZER__ }
131 #define CELL_STYLE_INITIALIZER__ \
132 .margin = { [TABLE_HORZ][0] = 8, [TABLE_HORZ][1] = 11, \
133 [TABLE_VERT][0] = 1, [TABLE_VERT][1] = 1 }
135 void cell_style_dump (const struct cell_style *);
139 bool bold, italic, underline, markup;
140 struct cell_color fg[2], bg[2];
145 #define FONT_STYLE_INITIALIZER { FONT_STYLE_INITIALIZER__ }
146 #define FONT_STYLE_INITIALIZER__ \
147 .fg = { [0] = CELL_COLOR_BLACK, [1] = CELL_COLOR_BLACK}, \
148 .bg = { [0] = CELL_COLOR_WHITE, [1] = CELL_COLOR_WHITE},
150 void font_style_copy (struct font_style *, const struct font_style *);
151 void font_style_uninit (struct font_style *);
152 void font_style_dump (const struct font_style *);
156 struct cell_style cell_style;
157 struct font_style font_style;
160 #define AREA_STYLE_INITIALIZER { AREA_STYLE_INITIALIZER__ }
161 #define AREA_STYLE_INITIALIZER__ \
162 .cell_style = CELL_STYLE_INITIALIZER, \
163 .font_style = FONT_STYLE_INITIALIZER
165 struct area_style *area_style_clone (struct pool *, const struct area_style *);
166 void area_style_copy (struct area_style *, const struct area_style *);
167 void area_style_uninit (struct area_style *);
168 void area_style_free (struct area_style *);
170 /* Properties of a table cell. */
174 TAB_FIX = 1 << 1, /* Use fixed font. */
175 TAB_MARKUP = 1 << 2, /* Text contains Pango markup. */
176 TAB_NUMERIC = 1 << 3, /* Cell contents are numeric. */
177 TAB_ROTATE = 1 << 4, /* Rotate cell contents 90 degrees. */
180 TAB_STYLE_MASK = 7 << TAB_STYLE_SHIFT,
182 /* Horizontal alignment of cell contents. */
185 TAB_CENTER = 2 << 10,
186 TAB_HALIGN = 3 << 10, /* Alignment mask. */
188 /* Vertical alignment of cell contents. */
190 TAB_MIDDLE = 1 << 12,
191 TAB_BOTTOM = 2 << 12,
192 TAB_VALIGN = 3 << 12, /* Alignment mask. */
194 /* Internal use by tab.c only. */
198 /* Styles for the rules around table cells. */
201 TAL_NONE = TABLE_STROKE_NONE,
202 #define TAL_0 TAL_NONE
203 TAL_SOLID = TABLE_STROKE_SOLID,
204 #define TAL_1 TAL_SOLID
205 TAL_DASHED = TABLE_STROKE_DASHED,
206 TAL_THICK = TABLE_STROKE_THICK,
207 TAL_THIN = TABLE_STROKE_THIN,
208 TAL_DOUBLE = TABLE_STROKE_DOUBLE,
209 #define TAL_2 TAL_DOUBLE
212 /* Given line styles A and B (each one of the TAL_* enumeration constants
213 above), returns a line style that "combines" them, that is, that gives a
214 reasonable line style choice for a rule for different reasons should have
215 both styles A and B. */
216 static inline int table_rule_combine (int a, int b)
218 return a > b ? a : b;
224 struct pool *container;
228 n[TABLE_HORZ]: Number of columns.
229 n[TABLE_VERT]: Number of rows. */
234 Rows at the top and bottom of a table and columns at the left and right
235 edges of a table can be designated as headers. If the table must be
236 broken across more than one page for output, headers rows and columns
237 are repeated on each page.
239 h[TABLE_HORZ][0]: Left header columns.
240 h[TABLE_HORZ][1]: Right header columns.
241 h[TABLE_VERT][0]: Top header rows.
242 h[TABLE_VERT][1]: Bottom header rows. */
243 int h[TABLE_N_AXES][2];
245 /* Reference count. A table may be shared between multiple owners,
246 indicated by a reference count greater than 1. When this is the case,
247 the table must not be modified. */
252 Each array element in cc[] is ordinarily a "char *" pointer to a
253 string. If TAB_JOIN (defined in tab.c) is set in ct[] for the element,
254 however, it is a joined cell and the corresponding element of cc[]
255 points to a struct tab_joined_cell. */
256 void **cc; /* Cell contents; void *[nr][nc]. */
257 unsigned short *ct; /* Cell types; unsigned short[nr][nc]. */
258 struct area_style *styles[8];
261 unsigned char *rh; /* Horiz rules; unsigned char[nr+1][nc]. */
262 unsigned char *rv; /* Vert rules; unsigned char[nr][nc+1]. */
263 struct cell_color *rule_colors[32];
266 /* Reference counting. */
267 struct table *table_ref (const struct table *);
268 void table_unref (struct table *);
269 bool table_is_shared (const struct table *);
271 /* Returns the number of columns or rows, respectively, in T. */
272 static inline int table_nc (const struct table *t)
273 { return t->n[TABLE_HORZ]; }
274 static inline int table_nr (const struct table *t)
275 { return t->n[TABLE_VERT]; }
277 /* Returns the number of left, right, top, or bottom headers, respectively, in
279 static inline int table_hl (const struct table *t)
280 { return t->h[TABLE_HORZ][0]; }
281 static inline int table_hr (const struct table *t)
282 { return t->h[TABLE_HORZ][1]; }
283 static inline int table_ht (const struct table *t)
284 { return t->h[TABLE_VERT][0]; }
285 static inline int table_hb (const struct table *t)
286 { return t->h[TABLE_VERT][1]; }
290 /* Simple kinds of tables. */
291 struct table *table_from_string (const char *);
293 #endif /* output/table.h */