-/* Return the number of columns and rows in the table into N_COLUMNS
- and N_ROWS, respectively. */
-static void
-tabi_count (struct som_entity *t_, int *n_columns, int *n_rows)
-{
- struct tab_table *t = t_->ext;
- *n_columns = t->nc;
- *n_rows = t->nr;
-}
-
-/* Return the column style for this table into STYLE. */
-static void
-tabi_columns (struct som_entity *t_, int *style)
-{
- struct tab_table *t = t_->ext;
- *style = t->col_style;
-}
-
-/* Return the number of header rows/columns on the left, right, top,
- and bottom sides into HL, HR, HT, and HB, respectively. */
-static void
-tabi_headers (struct som_entity *t_, int *hl, int *hr, int *ht, int *hb)
-{
- struct tab_table *t = t_->ext;
- *hl = t->l;
- *hr = t->r;
- *ht = t->t;
- *hb = t->b;
-}
-
-/* Return flags set for the current table into FLAGS. */
-static void
-tabi_flags (struct som_entity *t_, unsigned *flags)
-{
- struct tab_table *t = t_->ext;
- *flags = t->flags;
-}
-
-/* Returns the line style to use for spacing purposes for a rule
- of the given TYPE. */
-static enum outp_line_style
-rule_to_spacing_type (unsigned char type)
-{
- switch (type)
- {
- case TAL_0:
- return OUTP_L_NONE;
- case TAL_GAP:
- case TAL_1:
- return OUTP_L_SINGLE;
- case TAL_2:
- return OUTP_L_DOUBLE;
- default:
- NOT_REACHED ();
- }
-}
-
-static void *
-tabi_render_init (struct som_entity *t_, struct outp_driver *driver,
- int hl, int hr, int ht, int hb)
-{
- const struct tab_table *t = t_->ext;
- struct tab_rendering *r;
- int col, row;
- int i;
-
- tab_offset (t_->ext, 0, 0);
-
- r = xmalloc (sizeof *r);
- r->table = t;
- r->driver = driver;
- r->w = xnmalloc (tab_nc (t), sizeof *r->w);
- r->h = xnmalloc (tab_nr (t), sizeof *r->h);
- r->hrh = xnmalloc (tab_nr (t) + 1, sizeof *r->hrh);
- r->wrv = xnmalloc (tab_nc (t) + 1, sizeof *r->wrv);
- r->l = hl;
- r->r = hr;
- r->t = ht;
- r->b = hb;
-
- /* Figure out sizes of rules. */
- for (row = 0; row <= tab_nr (t); row++)
- {
- int width = 0;
- for (col = 0; col < tab_nc (t); col++)
- {
- unsigned char rh = t->rh[col + row * t->cf];
- int w = driver->horiz_line_width[rule_to_spacing_type (rh)];
- if (w > width)
- width = w;
- }
- r->hrh[row] = width;
- }
-
- for (col = 0; col <= tab_nc (t); col++)
- {
- int width = 0;
- for (row = 0; row < tab_nr (t); row++)
- {
- unsigned char *rv = &t->rv[col + row * (t->cf + 1)];
- int w;
- if (*rv == UCHAR_MAX)
- *rv = col != 0 && col != tab_nc (t) ? TAL_GAP : TAL_0;
- w = driver->vert_line_width[rule_to_spacing_type (*rv)];
- if (w > width)
- width = w;
- }
- r->wrv[col] = width;
- }
-
- /* Determine row heights and columns widths. */
- for (i = 0; i < tab_nr (t); i++)
- r->h[i] = -1;
- for (i = 0; i < tab_nc (t); i++)
- r->w[i] = -1;
-
- t->dim (r, t->dim_aux);
-
- for (i = 0; i < tab_nr (t); i++)
- if (r->h[i] < 0)
- error (0, 0, "height of table row %d is %d (not initialized?)",
- i, r->h[i]);
- for (i = 0; i < tab_nc (t); i++)
- if (r->w[i] < 0)
- error (0, 0, "width of table column %d is %d (not initialized?)",
- i, r->w[i]);
-
- /* Add up header sizes. */
- for (i = 0, r->wl = r->wrv[0]; i < r->l; i++)
- r->wl += r->w[i] + r->wrv[i + 1];
- for (i = 0, r->ht = r->hrh[0]; i < r->t; i++)
- r->ht += r->h[i] + r->hrh[i + 1];
- for (i = tab_nc (t) - r->r, r->wr = r->wrv[i]; i < tab_nc (t); i++)
- r->wr += r->w[i] + r->wrv[i + 1];
- for (i = tab_nr (t) - r->b, r->hb = r->hrh[i]; i < tab_nr (t); i++)
- r->hb += r->h[i] + r->hrh[i + 1];
-
- /* Title. */
- if (!(t->flags & SOMF_NO_TITLE))
- r->ht += driver->font_height;