1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <libpspp/assertion.h>
31 /* Increments table_num so different procedures' output can be
36 if (subtable_num != 0)
43 /* Ejects the paper for all active devices. */
47 struct outp_driver *d;
49 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
53 /* Skip down a single line on all active devices. */
57 struct outp_driver *d;
59 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
60 if (d->page_open && d->cp_y != 0)
61 d->cp_y += d->font_height;
65 static struct outp_driver *d = 0;
68 static struct som_entity *t = 0;
71 static unsigned flags;
73 /* Number of columns, rows. */
76 /* Number of columns or rows in left, right, top, bottom headers. */
77 static int hl, hr, ht, hb;
82 /* Table height, width. */
85 static void render_columns (void);
86 static void render_simple (void);
87 static void render_segments (void);
89 static void output_entity (struct outp_driver *, struct som_entity *);
91 /* Output table T to appropriate output devices. */
93 som_submit (struct som_entity *t)
98 assert (entry++ == 0);
101 if ( t->type == SOM_TABLE)
104 t->class->flags (&flags);
105 t->class->count (&nc, &nr);
106 t->class->headers (&hl, &hr, &ht, &hb);
110 if (hl + hr > nc || ht + hb > nr)
112 printf ("headers: (l,r)=(%d,%d), (t,b)=(%d,%d) in table size (%d,%d)\n",
113 hl, hr, ht, hb, nc, nr);
116 else if (hl + hr == nc)
117 printf ("warning: headers (l,r)=(%d,%d) in table width %d\n", hl, hr, nc);
118 else if (ht + hb == nr)
119 printf ("warning: headers (t,b)=(%d,%d) in table height %d\n", ht, hb, nr);
122 t->class->columns (&cs);
124 if (!(flags & SOMF_NO_TITLE))
130 struct outp_driver *d;
132 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
133 output_entity (d, t);
138 assert (--entry == 0);
142 /* Output entity ENTITY to driver DRIVER. */
144 output_entity (struct outp_driver *driver, struct som_entity *entity)
146 bool fits_width, fits_length;
150 if (d->class->special || entity->type == SOM_CHART)
152 driver->class->submit (d, entity);
158 t->class->driver (d);
159 t->class->area (&tw, &th);
160 fits_width = t->class->fits_width (d->width);
161 fits_length = t->class->fits_length (d->length);
162 if (!fits_width || !fits_length)
165 tl = fits_width ? hl : 0;
166 tr = fits_width ? hr : 0;
167 tt = fits_length ? ht : 0;
168 tb = fits_length ? hb : 0;
169 t->class->set_headers (tl, tr, tt, tb);
170 t->class->driver (d);
171 t->class->area (&tw, &th);
174 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
175 d->cp_y += d->font_height;
177 if (cs != SOM_COL_NONE
178 && 2 * (tw + d->prop_em_width) <= d->width
179 && nr - (ht + hb) > 5)
181 else if (tw < d->width && th + d->cp_y < d->length)
186 t->class->set_headers (hl, hr, ht, hb);
189 /* Render the table into multiple columns. */
191 render_columns (void)
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. */
240 assert (d->cp_x == 0);
241 assert (tw < d->width && th + d->cp_y < d->length);
243 t->class->title (0, 0);
244 t->class->render (hl, ht, nc - hr, nr - hb);
248 /* General table breaking routine. */
250 render_segments (void)
257 assert (d->cp_x == 0);
259 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
264 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
265 if (x_index == 0 && x1 != nc - hr)
268 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
272 if (count++ != 0 && d->cp_y != 0)
273 d->cp_y += d->font_height;
275 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
276 if (y_index == 0 && y1 != nr - hb)
286 t->class->title (x_index ? x_index : y_index,
287 x_index ? y_index : 0);
288 t->class->render (x0, y0, x1, y1);