1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include <libpspp/assertion.h>
28 /* Increments table_num so different procedures' output can be
33 if (subtable_num != 0)
40 /* Ejects the paper for all active devices. */
44 struct outp_driver *d;
46 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
50 /* Skip down a single line on all active devices. */
54 struct outp_driver *d;
56 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
57 if (d->page_open && d->cp_y != 0)
58 d->cp_y += d->font_height;
62 static struct outp_driver *d = 0;
65 static struct som_entity *t = 0;
68 static unsigned flags;
70 /* Number of columns, rows. */
73 /* Number of columns or rows in left, right, top, bottom headers. */
74 static int hl, hr, ht, hb;
79 /* Table height, width. */
82 static void render_columns (void);
83 static void render_simple (void);
84 static void render_segments (void);
86 static void output_entity (struct outp_driver *, struct som_entity *);
88 /* Output table T to appropriate output devices. */
90 som_submit (struct som_entity *t)
95 assert (entry++ == 0);
98 if ( t->type == SOM_TABLE)
101 t->class->flags (&flags);
102 t->class->count (&nc, &nr);
103 t->class->headers (&hl, &hr, &ht, &hb);
107 if (hl + hr > nc || ht + hb > nr)
109 printf ("headers: (l,r)=(%d,%d), (t,b)=(%d,%d) in table size (%d,%d)\n",
110 hl, hr, ht, hb, nc, nr);
113 else if (hl + hr == nc)
114 printf ("warning: headers (l,r)=(%d,%d) in table width %d\n", hl, hr, nc);
115 else if (ht + hb == nr)
116 printf ("warning: headers (t,b)=(%d,%d) in table height %d\n", ht, hb, nr);
119 t->class->columns (&cs);
121 if (!(flags & SOMF_NO_TITLE))
127 struct outp_driver *d;
129 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
130 output_entity (d, t);
135 assert (--entry == 0);
139 /* Output entity ENTITY to driver DRIVER. */
141 output_entity (struct outp_driver *driver, struct som_entity *entity)
143 bool fits_width, fits_length;
147 if (d->class->special || entity->type == SOM_CHART)
149 driver->class->submit (d, entity);
155 t->class->driver (d);
156 t->class->area (&tw, &th);
157 fits_width = t->class->fits_width (d->width);
158 fits_length = t->class->fits_length (d->length);
159 if (!fits_width || !fits_length)
162 tl = fits_width ? hl : 0;
163 tr = fits_width ? hr : 0;
164 tt = fits_length ? ht : 0;
165 tb = fits_length ? hb : 0;
166 t->class->set_headers (tl, tr, tt, tb);
167 t->class->driver (d);
168 t->class->area (&tw, &th);
171 if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0)
172 d->cp_y += d->font_height;
174 if (cs != SOM_COL_NONE
175 && 2 * (tw + d->prop_em_width) <= d->width
176 && nr - (ht + hb) > 5)
178 else if (tw < d->width && th + d->cp_y < d->length)
183 t->class->set_headers (hl, hr, ht, hb);
186 /* Render the table into multiple columns. */
188 render_columns (void)
194 assert (cs == SOM_COL_DOWN);
195 assert (d->cp_x == 0);
197 for (y0 = ht; y0 < nr - hb; y0 = y1)
201 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
213 t->class->title (index++, 0);
214 t->class->render (0, y0, nc, y1);
216 d->cp_x += tw + 2 * d->prop_em_width;
217 if (d->cp_x + tw > d->width)
233 /* Render the table by itself on the current page. */
237 assert (d->cp_x == 0);
238 assert (tw < d->width && th + d->cp_y < d->length);
240 t->class->title (0, 0);
241 t->class->render (hl, ht, nc - hr, nr - hb);
245 /* General table breaking routine. */
247 render_segments (void)
254 assert (d->cp_x == 0);
256 for (x_index = 0, x0 = hl; x0 < nc - hr; x0 = x1, x_index++)
261 t->class->cumulate (SOM_COLUMNS, x0, &x1, d->width, NULL);
262 if (x_index == 0 && x1 != nc - hr)
265 for (y_index = 0, y0 = ht; y0 < nr - hb; y0 = y1, y_index++)
269 if (count++ != 0 && d->cp_y != 0)
270 d->cp_y += d->font_height;
272 t->class->cumulate (SOM_ROWS, y0, &y1, d->length - d->cp_y, &len);
273 if (y_index == 0 && y1 != nr - hb)
283 t->class->title (x_index ? x_index : y_index,
284 x_index ? y_index : 0);
285 t->class->render (x0, y0, x1, y1);