1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2007, 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/assertion.h>
28 /* Increments table_num so different procedures' output can be
33 if (subtable_num != 0)
40 /* Ejects the paper for all active devices. */
44 struct outp_driver *d;
46 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
50 /* Flushes output on all active devices. */
54 struct outp_driver *d;
56 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
60 /* Skip down a single line on all active devices. */
64 struct outp_driver *d;
66 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
67 if (d->page_open && d->cp_y != 0)
68 d->cp_y += d->font_height;
71 static void render_columns (struct outp_driver *, struct som_entity *);
72 static void render_simple (struct outp_driver *, struct som_entity *);
73 static void render_segments (struct outp_driver *, struct som_entity *);
75 static void output_entity (struct outp_driver *, struct som_entity *);
77 /* Output table T to appropriate output devices. */
79 som_submit (struct som_entity *t)
81 struct outp_driver *d;
86 assert (entry++ == 0);
89 if (t->type == SOM_TABLE)
95 /* Set up to render the table. */
96 t->class->flags (&flags);
97 if (!(flags & SOMF_NO_TITLE))
100 /* Do some basic error checking. */
101 t->class->count (&nc, &nr);
102 t->class->headers (&hl, &hr, &ht, &hb);
103 if (hl + hr > nc || ht + hb > nr)
105 fprintf (stderr, "headers: (l,r)=(%d,%d), (t,b)=(%d,%d) "
106 "in table size (%d,%d)\n",
107 hl, hr, ht, hb, nc, nr);
110 else if (hl + hr == nc)
111 fprintf (stderr, "warning: headers (l,r)=(%d,%d) in table width %d\n",
113 else if (ht + hb == nr)
114 fprintf (stderr, "warning: headers (t,b)=(%d,%d) in table height %d\n",
118 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
119 output_entity (d, t);
122 assert (--entry == 0);
126 /* Output entity T to driver D. */
128 output_entity (struct outp_driver *d, struct som_entity *t)
130 bool fits_width, fits_length;
138 if (d->class->special || t->type == SOM_CHART)
140 d->class->submit (d, t);
144 t->class->driver (d);
145 t->class->area (&tw, &th);
146 t->class->count (&nc, &nr);
147 t->class->headers (&hl, &hr, &ht, &hb);
148 t->class->columns (&cs);
149 t->class->flags (&flags);
151 fits_width = t->class->fits_width (d->width);
152 fits_length = t->class->fits_length (d->length);
153 if (!fits_width || !fits_length)
156 tl = fits_width ? hl : 0;
157 tr = fits_width ? hr : 0;
158 tt = fits_length ? ht : 0;
159 tb = fits_length ? hb : 0;
160 t->class->set_headers (tl, tr, tt, tb);
161 t->class->driver (d);
162 t->class->area (&tw, &th);
165 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
166 d->cp_y += d->font_height;
168 if (cs != SOM_COL_NONE
169 && 2 * (tw + d->prop_em_width) <= d->width
170 && nr - (ht + hb) > 5)
171 render_columns (d, t);
172 else if (tw < d->width && th + d->cp_y < d->length)
173 render_simple (d, t);
175 render_segments (d, t);
177 t->class->set_headers (hl, hr, ht, hb);
180 /* Render the table into multiple columns. */
182 render_columns (struct outp_driver *d, struct som_entity *t)
192 t->class->area (&tw, &th);
193 t->class->count (&nc, &nr);
194 t->class->headers (&hl, &hr, &ht, &hb);
195 t->class->columns (&cs);
197 assert (cs == SOM_COL_DOWN);
198 assert (d->cp_x == 0);
200 for (y0 = ht; y0 < nr - hb; y0 = y1)
204 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
216 t->class->title (index++, 0);
217 t->class->render (0, y0, nc, y1);
219 d->cp_x += tw + 2 * d->prop_em_width;
220 if (d->cp_x + tw > d->width)
236 /* Render the table by itself on the current page. */
238 render_simple (struct outp_driver *d, struct som_entity *t)
244 t->class->area (&tw, &th);
245 t->class->count (&nc, &nr);
246 t->class->headers (&hl, &hr, &ht, &hb);
248 assert (d->cp_x == 0);
249 assert (tw < d->width && th + d->cp_y < d->length);
251 t->class->title (0, 0);
252 t->class->render (hl, ht, nc - hr, nr - hb);
256 /* General table breaking routine. */
258 render_segments (struct outp_driver *d, struct som_entity *t)
268 assert (d->cp_x == 0);
270 t->class->count (&nc, &nr);
271 t->class->headers (&hl, &hr, &ht, &hb);
272 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
277 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
278 if (x_index == 0 && x1 != nc - hr)
281 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
285 if (count++ != 0 && d->cp_y != 0)
286 d->cp_y += d->font_height;
288 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
289 if (y_index == 0 && y1 != nr - hb)
299 t->class->title (x_index ? x_index : y_index,
300 x_index ? y_index : 0);
301 t->class->render (x0, y0, x1, y1);