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
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)
147 bool fits_width, fits_length;
150 assert (d->driver_open);
151 if (!d->page_open && !d->class->open_page (d))
153 d->device = OUTP_DEV_DISABLED;
157 if (d->class->special || entity->type == SOM_CHART)
159 driver->class->submit (d, entity);
165 t->class->driver (d);
166 t->class->area (&tw, &th);
167 fits_width = t->class->fits_width (d->width);
168 fits_length = t->class->fits_length (d->length);
169 if (!fits_width || !fits_length)
172 tl = fits_width ? hl : 0;
173 tr = fits_width ? hr : 0;
174 tt = fits_length ? ht : 0;
175 tb = fits_length ? hb : 0;
176 t->class->set_headers (tl, tr, tt, tb);
177 t->class->driver (d);
178 t->class->area (&tw, &th);
181 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
182 d->cp_y += d->font_height;
184 if (cs != SOM_COL_NONE
185 && 2 * (tw + d->prop_em_width) <= d->width
186 && nr - (ht + hb) > 5)
188 else if (tw < d->width && th + d->cp_y < d->length)
193 t->class->set_headers (hl, hr, ht, hb);
196 /* Render the table into multiple columns. */
198 render_columns (void)
204 assert (cs == SOM_COL_DOWN);
205 assert (d->cp_x == 0);
207 for (y0 = ht; y0 < nr - hb; y0 = y1)
211 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
221 t->class->title (index++, 0);
222 t->class->render (0, y0, nc, y1);
224 d->cp_x += tw + 2 * d->prop_em_width;
225 if (d->cp_x + tw > d->width)
241 /* Render the table by itself on the current page. */
245 assert (d->cp_x == 0);
246 assert (tw < d->width && th + d->cp_y < d->length);
248 t->class->title (0, 0);
249 t->class->render (hl, ht, nc - hr, nr - hb);
253 /* General table breaking routine. */
255 render_segments (void)
262 assert (d->cp_x == 0);
264 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
269 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
270 if (x_index == 0 && x1 != nc - hr)
273 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
277 if (count++ != 0 && d->cp_y != 0)
278 d->cp_y += d->font_height;
280 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
281 if (y_index == 0 && y1 != nr - hb)
289 t->class->title (x_index ? x_index : y_index,
290 x_index ? y_index : 0);
291 t->class->render (x0, y0, x1, y1);