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_entity *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_entity (struct outp_driver *, struct som_entity *);
92 /* Output table T to appropriate output devices. */
94 som_submit (struct som_entity *t)
99 assert (entry++ == 0);
102 if ( t->type == SOM_TABLE)
105 t->class->flags (&flags);
106 t->class->count (&nc, &nr);
107 t->class->headers (&hl, &hr, &ht, &hb);
111 if (hl + hr > nc || ht + hb > nr)
113 printf ("headers: (l,r)=(%d,%d), (t,b)=(%d,%d) in table size (%d,%d)\n",
114 hl, hr, ht, hb, nc, nr);
117 else if (hl + hr == nc)
118 printf ("warning: headers (l,r)=(%d,%d) in table width %d\n", hl, hr, nc);
119 else if (ht + hb == nr)
120 printf ("warning: headers (t,b)=(%d,%d) in table height %d\n", ht, hb, nr);
123 t->class->columns (&cs);
125 if (!(flags & SOMF_NO_TITLE))
131 struct outp_driver *d;
133 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
134 output_entity (d, t);
139 assert (--entry == 0);
143 /* Output entity ENTITY to driver DRIVER. */
145 output_entity (struct outp_driver *driver, struct som_entity *entity)
149 assert (d->driver_open);
150 if (!d->page_open && !d->class->open_page (d))
152 d->device = OUTP_DEV_DISABLED;
156 if (d->class->special || entity->type == SOM_CHART)
158 driver->class->submit (d, entity);
164 t->class->driver (d);
165 t->class->area (&tw, &th);
167 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
168 d->cp_y += d->font_height;
170 if (cs != SOM_COL_NONE
171 && 2 * (tw + d->prop_em_width) <= d->width
172 && nr - (ht + hb) > 5)
174 else if (tw < d->width && th + d->cp_y < d->length)
180 /* Render the table into multiple columns. */
182 render_columns (void)
188 assert (cs == SOM_COL_DOWN);
189 assert (d->cp_x == 0);
191 for (y0 = ht; y0 < nr - hb; y0 = y1)
195 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
205 t->class->title (index++, 0);
206 t->class->render (0, y0, nc, y1);
208 d->cp_x += tw + 2 * d->prop_em_width;
209 if (d->cp_x + tw > d->width)
225 /* Render the table by itself on the current page. */
229 assert (d->cp_x == 0);
230 assert (tw < d->width && th + d->cp_y < d->length);
232 t->class->title (0, 0);
233 t->class->render (hl, ht, nc - hr, nr - hb);
237 /* General table breaking routine. */
239 render_segments (void)
246 assert (d->cp_x == 0);
248 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
253 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
254 if (x_index == 0 && x1 != nc - hr)
257 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
261 if (count++ != 0 && d->cp_y != 0)
262 d->cp_y += d->font_height;
264 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
265 if (y_index == 0 && y1 != nr - hb)
273 t->class->title (x_index ? x_index : y_index,
274 x_index ? y_index : 0);
275 t->class->render (x0, y0, x1, y1);