1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2009 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/>. */
21 #include <libpspp/str.h>
28 TAB_ALIGN_MASK = 03, /* Alignment mask. */
29 TAB_RIGHT = 00, /* Right justify. */
30 TAB_LEFT = 01, /* Left justify. */
31 TAB_CENTER = 02, /* Center. */
34 TAB_JOIN = 004, /* Joined cell. */
35 TAB_EMPTY = 010, /* Empty cell. */
38 TAB_EMPH = 020, /* Emphasize cell contents. */
39 TAB_FIX = 040, /* Use fixed font. */
45 TAL_0 = 0, /* No line. */
46 TAL_1 = 1, /* Single line. */
47 TAL_2 = 2, /* Double line. */
48 TAL_GAP = 3, /* Spacing but no line. */
49 TAL_COUNT, /* Number of line styles. */
52 /* Column styles. Must correspond to SOM_COL_*. */
55 TAB_COL_NONE, /* No columns. */
56 TAB_COL_DOWN /* Columns down first. */
60 struct tab_joined_cell
64 struct substring contents;
71 typedef void tab_dim_func (struct tab_rendering *, void *aux);
72 typedef void tab_dim_free_func (void *aux);
77 struct pool *container;
78 int ref_cnt; /* Reference count. */
81 int col_style; /* Columns: One of TAB_COL_*. */
82 char *title; /* Table title. */
83 unsigned flags; /* SOMF_*. */
84 int nc, nr; /* Number of columns, rows. */
85 int cf; /* Column factor for indexing purposes. */
86 int l, r, t, b; /* Number of header rows on each side. */
87 struct substring *cc; /* Cell contents; substring *[nr][nc]. */
88 unsigned char *ct; /* Cell types; unsigned char[nr][nc]. */
89 unsigned char *rh; /* Horiz rules; unsigned char[nr+1][nc]. */
90 unsigned char *rv; /* Vert rules; unsigned char[nr][nc+1]. */
92 /* Calculating row and column dimensions. */
93 tab_dim_func *dim; /* Calculates cell widths and heights. */
94 tab_dim_free_func *dim_free; /* Frees space allocated for dim function. */
95 void *dim_aux; /* Auxiliary data for dim function. */
98 int col_ofs, row_ofs; /* X and Y offsets. */
101 /* Number of rows or columns in TABLE. */
102 static inline int tab_nr (const struct tab_table *table) { return table->nr; }
103 static inline int tab_nc (const struct tab_table *table) { return table->nc; }
105 /* Number of left/right/top/bottom header columns/rows in TABLE. */
106 static inline int tab_l (const struct tab_table *table) { return table->l; }
107 static inline int tab_r (const struct tab_table *table) { return table->r; }
108 static inline int tab_t (const struct tab_table *table) { return table->t; }
109 static inline int tab_b (const struct tab_table *table) { return table->b; }
113 const struct tab_table *table;
114 struct outp_driver *driver;
116 int *w; /* Column widths; [nc]. */
117 int *h; /* Row heights; [nr]. */
118 int *hrh; /* Heights of horizontal rules; [nr+1]. */
119 int *wrv; /* Widths of vertical rules; [nc+1]. */
121 /* These fields would be redundant with those in struct tab_table, except
122 that a table will be rendered with fewer header rows or columns than
123 requested when we are pressed for space. */
124 int l, r, t, b; /* Number of header rows/columns. */
125 int wl, wr, ht, hb; /* Width/height of header rows/columns. */
129 struct tab_table *tab_create (int nc, int nr);
130 void tab_destroy (struct tab_table *);
131 void tab_ref (struct tab_table *);
132 void tab_resize (struct tab_table *, int nc, int nr);
133 void tab_realloc (struct tab_table *, int nc, int nr);
134 void tab_headers (struct tab_table *, int l, int r, int t, int b);
135 void tab_columns (struct tab_table *, int style);
136 void tab_title (struct tab_table *, const char *, ...)
137 PRINTF_FORMAT (2, 3);
138 void tab_flags (struct tab_table *, unsigned);
139 void tab_submit (struct tab_table *);
142 tab_dim_func tab_natural_dimensions;
143 int tab_natural_width (const struct tab_rendering *, int c);
144 int tab_natural_height (const struct tab_rendering *, int r);
145 void tab_dim (struct tab_table *,
146 tab_dim_func *, tab_dim_free_func *, void *aux);
149 void tab_hline (struct tab_table *, int style, int x1, int x2, int y);
150 void tab_vline (struct tab_table *, int style, int x, int y1, int y2);
151 void tab_box (struct tab_table *, int f_h, int f_v, int i_h, int i_v,
152 int x1, int y1, int x2, int y2);
154 /* Text options, passed in the `opt' argument. */
157 TAT_NONE = 0, /* No options. */
158 TAT_TITLE = 0x0200 | TAB_EMPH, /* Title attributes. */
159 TAT_NOWRAP = 0x0800 /* No text wrap (tab_output_text() only). */
166 void tab_value (struct tab_table *, int c, int r, unsigned char opt,
167 const union value *, const struct dictionary *dict,
168 const struct fmt_spec *);
170 void tab_fixed (struct tab_table *, int c, int r, unsigned char opt,
171 double v, int w, int d);
173 void tab_double (struct tab_table *, int c, int r, unsigned char opt,
174 double v, const struct fmt_spec *);
176 void tab_text (struct tab_table *, int c, int r, unsigned opt, const char *);
177 void tab_text_format (struct tab_table *, int c, int r, unsigned opt,
179 PRINTF_FORMAT (5, 6);
181 void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2,
182 unsigned opt, const char *);
183 void tab_joint_text_format (struct tab_table *, int x1, int y1, int x2, int y2,
184 unsigned opt, const char *, ...)
185 PRINTF_FORMAT (7, 8);
188 void tab_offset (struct tab_table *, int col, int row);
189 void tab_next_row (struct tab_table *);
191 /* Current row/column offset. */
192 #define tab_row(TABLE) ((TABLE)->row_ofs)
193 #define tab_col(TABLE) ((TABLE)->col_ofs)
196 void tab_output_text (int options, const char *string);
197 void tab_output_text_format (int options, const char *, ...)
198 PRINTF_FORMAT (2, 3);