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
27 /*#define DEBUGGING 1 */
28 #include "debug-print.h"
34 /* Increments table_num so different procedures' output can be
39 if (subtable_num != 0)
46 /* Ejects the paper for all active devices. */
50 struct outp_driver *d;
52 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
56 /* Skip down a single line on all active devices. */
60 struct outp_driver *d;
62 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
63 if (d->page_open && d->cp_y != 0)
64 d->cp_y += d->font_height;
68 static struct outp_driver *d=0;
71 static struct som_table *t=0;
74 static unsigned flags;
76 /* Number of columns, rows. */
79 /* Number of columns or rows in left, right, top, bottom headers. */
80 static int hl, hr, ht, hb;
85 /* Table height, width. */
88 static void render_columns (void);
89 static void render_simple (void);
90 static void render_segments (void);
92 static void output_table (struct outp_driver *, struct som_table *);
94 /* Output table T to appropriate output devices. */
96 som_submit (struct som_table *t)
101 assert (entry++ == 0);
105 t->class->flags (&flags);
106 t->class->count (&nc, &nr);
107 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))
128 struct outp_driver *d;
130 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
135 assert (--entry == 0);
139 /* Output table TABLE to driver DRIVER. */
141 output_table (struct outp_driver *driver, struct som_table *table)
146 assert (d->driver_open);
147 if (!d->page_open && !d->class->open_page (d))
149 d->device = OUTP_DEV_DISABLED;
153 if (d->class->special)
155 driver->class->submit (d, t);
159 t->class->driver (d);
160 t->class->area (&tw, &th);
162 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
163 d->cp_y += d->font_height;
165 if (cs != SOM_COL_NONE
166 && 2 * (tw + d->prop_em_width) <= d->width
167 && nr - (ht + hb) > 5)
169 else if (tw < d->width && th + d->cp_y < d->length)
175 /* Render the table into multiple columns. */
177 render_columns (void)
183 assert (cs == SOM_COL_DOWN);
184 assert (d->cp_x == 0);
186 for (y0 = ht; y0 < nr - hb; y0 = y1)
190 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
200 t->class->title (index++, 0);
201 t->class->render (0, y0, nc, y1);
203 d->cp_x += tw + 2 * d->prop_em_width;
204 if (d->cp_x + tw > d->width)
220 /* Render the table by itself on the current page. */
224 assert (d->cp_x == 0);
225 assert (tw < d->width && th + d->cp_y < d->length);
227 t->class->title (0, 0);
228 t->class->render (hl, ht, nc - hr, nr - hb);
232 /* General table breaking routine. */
234 render_segments (void)
241 assert (d->cp_x == 0);
243 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
248 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
249 if (x_index == 0 && x1 != nc - hr)
252 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
256 if (count++ != 0 && d->cp_y != 0)
257 d->cp_y += d->font_height;
259 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
260 if (y_index == 0 && y1 != nr - hb)
268 t->class->title (x_index ? x_index : y_index,
269 x_index ? y_index : 0);
270 t->class->render (x0, y0, x1, y1);