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
30 /* Increments table_num so different procedures' output can be
35 if (subtable_num != 0)
42 /* Ejects the paper for all active devices. */
46 struct outp_driver *d;
48 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
52 /* Skip down a single line on all active devices. */
56 struct outp_driver *d;
58 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
59 if (d->page_open && d->cp_y != 0)
60 d->cp_y += d->font_height;
64 static struct outp_driver *d=0;
67 static struct som_entity *t=0;
70 static unsigned flags;
72 /* Number of columns, rows. */
75 /* Number of columns or rows in left, right, top, bottom headers. */
76 static int hl, hr, ht, hb;
81 /* Table height, width. */
84 static void render_columns (void);
85 static void render_simple (void);
86 static void render_segments (void);
88 static void output_entity (struct outp_driver *, struct som_entity *);
90 /* Output table T to appropriate output devices. */
92 som_submit (struct som_entity *t)
97 assert (entry++ == 0);
100 if ( t->type == SOM_TABLE)
103 t->class->flags (&flags);
104 t->class->count (&nc, &nr);
105 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))
129 struct outp_driver *d;
131 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
132 output_entity (d, t);
137 assert (--entry == 0);
141 /* Output entity ENTITY to driver DRIVER. */
143 output_entity (struct outp_driver *driver, struct som_entity *entity)
145 bool fits_width, fits_length;
149 if (d->class->special || entity->type == SOM_CHART)
151 driver->class->submit (d, entity);
157 t->class->driver (d);
158 t->class->area (&tw, &th);
159 fits_width = t->class->fits_width (d->width);
160 fits_length = t->class->fits_length (d->length);
161 if (!fits_width || !fits_length)
164 tl = fits_width ? hl : 0;
165 tr = fits_width ? hr : 0;
166 tt = fits_length ? ht : 0;
167 tb = fits_length ? hb : 0;
168 t->class->set_headers (tl, tr, tt, tb);
169 t->class->driver (d);
170 t->class->area (&tw, &th);
173 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
174 d->cp_y += d->font_height;
176 if (cs != SOM_COL_NONE
177 && 2 * (tw + d->prop_em_width) <= d->width
178 && nr - (ht + hb) > 5)
180 else if (tw < d->width && th + d->cp_y < d->length)
185 t->class->set_headers (hl, hr, ht, hb);
188 /* Render the table into multiple columns. */
190 render_columns (void)
196 assert (cs == SOM_COL_DOWN);
197 assert (d->cp_x == 0);
199 for (y0 = ht; y0 < nr - hb; y0 = y1)
203 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
215 t->class->title (index++, 0);
216 t->class->render (0, y0, nc, y1);
218 d->cp_x += tw + 2 * d->prop_em_width;
219 if (d->cp_x + tw > d->width)
235 /* Render the table by itself on the current page. */
239 assert (d->cp_x == 0);
240 assert (tw < d->width && th + d->cp_y < d->length);
242 t->class->title (0, 0);
243 t->class->render (hl, ht, nc - hr, nr - hb);
247 /* General table breaking routine. */
249 render_segments (void)
256 assert (d->cp_x == 0);
258 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
263 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
264 if (x_index == 0 && x1 != nc - hr)
267 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
271 if (count++ != 0 && d->cp_y != 0)
272 d->cp_y += d->font_height;
274 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
275 if (y_index == 0 && y1 != nr - hb)
285 t->class->title (x_index ? x_index : y_index,
286 x_index ? y_index : 0);
287 t->class->render (x0, y0, x1, y1);