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., 59 Temple Place - Suite 330, Boston, MA
26 /*#define DEBUGGING 1 */
27 #include "debug-print.h"
33 /* Increments table_num so different procedures' output can be
38 if (subtable_num != 0)
45 /* Ejects the paper for all active devices. */
49 struct outp_driver *d;
51 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
55 /* Skip down a single line on all active devices. */
59 struct outp_driver *d;
61 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
62 if (d->page_open && d->cp_y != 0)
63 d->cp_y += d->font_height;
67 static struct outp_driver *d=0;
70 static struct som_table *t=0;
73 static unsigned flags;
75 /* Number of columns, rows. */
78 /* Number of columns or rows in left, right, top, bottom headers. */
79 static int hl, hr, ht, hb;
84 /* Table height, width. */
87 static void render_columns (void);
88 static void render_simple (void);
89 static void render_segments (void);
91 static void output_table (struct outp_driver *, struct som_table *);
93 /* Output table T to appropriate output devices. */
95 som_submit (struct som_table *t)
100 assert (entry++ == 0);
104 t->class->flags (&flags);
105 t->class->count (&nc, &nr);
106 t->class->headers (&hl, &hr, &ht, &hb);
109 if (hl + hr > nc || ht + hb > nr)
111 printf ("headers: (l,r)=(%d,%d), (t,b)=(%d,%d) in table size (%d,%d)\n",
112 hl, hr, ht, hb, nc, nr);
115 else if (hl + hr == nc)
116 printf ("warning: headers (l,r)=(%d,%d) in table width %d\n", hl, hr, nc);
117 else if (ht + hb == nr)
118 printf ("warning: headers (t,b)=(%d,%d) in table height %d\n", ht, hb, nr);
121 t->class->columns (&cs);
123 if (!(flags & SOMF_NO_TITLE))
127 struct outp_driver *d;
129 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
134 assert (--entry == 0);
138 /* Output table TABLE to driver DRIVER. */
140 output_table (struct outp_driver *driver, struct som_table *table)
145 assert (d->driver_open);
146 if (!d->page_open && !d->class->open_page (d))
148 d->device = OUTP_DEV_DISABLED;
152 if (d->class->special)
154 driver->class->submit (d, t);
158 t->class->driver (d);
159 t->class->area (&tw, &th);
161 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
162 d->cp_y += d->font_height;
164 if (cs != SOM_COL_NONE
165 && 2 * (tw + d->prop_em_width) <= d->width
166 && nr - (ht + hb) > 5)
168 else if (tw < d->width && th + d->cp_y < d->length)
174 /* Render the table into multiple columns. */
176 render_columns (void)
182 assert (cs == SOM_COL_DOWN);
183 assert (d->cp_x == 0);
185 for (y0 = ht; y0 < nr - hb; y0 = y1)
189 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
199 t->class->title (index++, 0);
200 t->class->render (0, y0, nc, y1);
202 d->cp_x += tw + 2 * d->prop_em_width;
203 if (d->cp_x + tw > d->width)
219 /* Render the table by itself on the current page. */
223 assert (d->cp_x == 0);
224 assert (tw < d->width && th + d->cp_y < d->length);
226 t->class->title (0, 0);
227 t->class->render (hl, ht, nc - hr, nr - hb);
231 /* General table breaking routine. */
233 render_segments (void)
240 assert (d->cp_x == 0);
242 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
247 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
248 if (x_index == 0 && x1 != nc - hr)
251 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
255 if (count++ != 0 && d->cp_y != 0)
256 d->cp_y += d->font_height;
258 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
259 if (y_index == 0 && y1 != nr - hb)
267 t->class->title (x_index ? x_index : y_index,
268 x_index ? y_index : 0);
269 t->class->render (x0, y0, x1, y1);