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 tab_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. */
179 /* Bits with values (1 << TAB_FIRST_AVAILABLE) and higher are
180 not used, so they are available for subclasses to use as
182 TAB_FIRST_AVAILABLE = 5
185 /* Styles for the rules around table cells. */
188 TAL_NONE = TABLE_STROKE_NONE,
189 #define TAL_0 TAL_NONE
190 TAL_SOLID = TABLE_STROKE_SOLID,
191 #define TAL_1 TAL_SOLID
192 TAL_DASHED = TABLE_STROKE_DASHED,
193 TAL_THICK = TABLE_STROKE_THICK,
194 TAL_THIN = TABLE_STROKE_THIN,
195 TAL_DOUBLE = TABLE_STROKE_DOUBLE,
196 #define TAL_2 TAL_DOUBLE
199 /* Given line styles A and B (each one of the TAL_* enumeration constants
200 above), returns a line style that "combines" them, that is, that gives a
201 reasonable line style choice for a rule for different reasons should have
202 both styles A and B. */
203 static inline int table_rule_combine (int a, int b)
205 return a > b ? a : b;
213 n[TABLE_HORZ]: Number of columns.
214 n[TABLE_VERT]: Number of rows. */
219 Rows at the top and bottom of a table and columns at the left and right
220 edges of a table can be designated as headers. If the table must be
221 broken across more than one page for output, headers rows and columns
222 are repeated on each page.
224 h[TABLE_HORZ][0]: Left header columns.
225 h[TABLE_HORZ][1]: Right header columns.
226 h[TABLE_VERT][0]: Top header rows.
227 h[TABLE_VERT][1]: Bottom header rows. */
228 int h[TABLE_N_AXES][2];
230 /* Reference count. A table may be shared between multiple owners,
231 indicated by a reference count greater than 1. When this is the case,
232 the table must not be modified. */
236 /* Reference counting. */
237 struct table *table_ref (const struct table *);
238 void table_unref (struct table *);
239 bool table_is_shared (const struct table *);
241 /* Returns the number of columns or rows, respectively, in T. */
242 static inline int table_nc (const struct table *t)
243 { return t->n[TABLE_HORZ]; }
244 static inline int table_nr (const struct table *t)
245 { return t->n[TABLE_VERT]; }
247 /* Returns the number of left, right, top, or bottom headers, respectively, in
249 static inline int table_hl (const struct table *t)
250 { return t->h[TABLE_HORZ][0]; }
251 static inline int table_hr (const struct table *t)
252 { return t->h[TABLE_HORZ][1]; }
253 static inline int table_ht (const struct table *t)
254 { return t->h[TABLE_VERT][0]; }
255 static inline int table_hb (const struct table *t)
256 { return t->h[TABLE_VERT][1]; }
260 /* Simple kinds of tables. */
261 struct table *table_from_string (const char *);
263 #endif /* output/table.h */