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 #include "debug-print.h"
32 /* Increments table_num so different procedures' output can be
37 if (subtable_num != 0)
44 /* Ejects the paper for all active devices. */
48 struct outp_driver *d;
50 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
54 /* Skip down a single line on all active devices. */
58 struct outp_driver *d;
60 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
61 if (d->page_open && d->cp_y != 0)
62 d->cp_y += d->font_height;
66 static struct outp_driver *d=0;
69 static struct som_table *t=0;
72 static unsigned flags;
74 /* Number of columns, rows. */
77 /* Number of columns or rows in left, right, top, bottom headers. */
78 static int hl, hr, ht, hb;
83 /* Table height, width. */
86 static void render_columns (void);
87 static void render_simple (void);
88 static void render_segments (void);
90 static void output_table (struct outp_driver *, struct som_table *);
92 /* Output table T to appropriate output devices. */
94 som_submit (struct som_table *t)
99 assert (entry++ == 0);
103 t->class->flags (&flags);
104 t->class->count (&nc, &nr);
105 t->class->headers (&hl, &hr, &ht, &hb);
108 if (hl + hr > nc || ht + hb > nr)
110 printf ("headers: (l,r)=(%d,%d), (t,b)=(%d,%d) in table size (%d,%d)\n",
111 hl, hr, ht, hb, nc, nr);
114 else if (hl + hr == nc)
115 printf ("warning: headers (l,r)=(%d,%d) in table width %d\n", hl, hr, nc);
116 else if (ht + hb == nr)
117 printf ("warning: headers (t,b)=(%d,%d) in table height %d\n", ht, hb, nr);
120 t->class->columns (&cs);
122 if (!(flags & SOMF_NO_TITLE))
126 struct outp_driver *d;
128 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
133 assert (--entry == 0);
137 /* Output table TABLE to driver DRIVER. */
139 output_table (struct outp_driver *driver, struct som_table *table)
144 assert (d->driver_open);
145 if (!d->page_open && !d->class->open_page (d))
147 d->device = OUTP_DEV_DISABLED;
151 if (d->class->special)
153 driver->class->submit (d, t);
157 t->class->driver (d);
158 t->class->area (&tw, &th);
160 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
161 d->cp_y += d->font_height;
163 if (cs != SOM_COL_NONE
164 && 2 * (tw + d->prop_em_width) <= d->width
165 && nr - (ht + hb) > 5)
167 else if (tw < d->width && th + d->cp_y < d->length)
173 /* Render the table into multiple columns. */
175 render_columns (void)
181 assert (cs == SOM_COL_DOWN);
182 assert (d->cp_x == 0);
184 for (y0 = ht; y0 < nr - hb; y0 = y1)
188 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
198 t->class->title (index++, 0);
199 t->class->render (0, y0, nc, y1);
201 d->cp_x += tw + 2 * d->prop_em_width;
202 if (d->cp_x + tw > d->width)
218 /* Render the table by itself on the current page. */
222 assert (d->cp_x == 0);
223 assert (tw < d->width && th + d->cp_y < d->length);
225 t->class->title (0, 0);
226 t->class->render (hl, ht, nc - hr, nr - hb);
230 /* General table breaking routine. */
232 render_segments (void)
239 assert (d->cp_x == 0);
241 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
246 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
247 if (x_index == 0 && x1 != nc - hr)
250 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
254 if (count++ != 0 && d->cp_y != 0)
255 d->cp_y += d->font_height;
257 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
258 if (y_index == 0 && y1 != nr - hb)
266 t->class->title (x_index ? x_index : y_index,
267 x_index ? y_index : 0);
268 t->class->render (x0, y0, x1, y1);