-
-/* Set the title of table T to TITLE, which is formatted as if
- passed to printf(). */
-void
-tab_title (struct tab_table *t, const char *title, ...)
-{
- va_list args;
-
- assert (t != NULL && title != NULL);
- va_start (args, title);
- t->title = xvasprintf (title, args);
- va_end (args);
-}
-
-/* Set DIM_FUNC, which will be passed auxiliary data AUX, as the
- dimension function for table T.
-
- DIM_FUNC must not assume that it is called from the same
- context as tab_dim; for example, table T might be kept in
- memory and, thus, DIM_FUNC might be called after the currently
- running command completes. If it is non-null, FREE_FUNC is
- called when the table is destroyed, to allow any data
- allocated for use by DIM_FUNC to be freed. */
-void
-tab_dim (struct tab_table *t,
- tab_dim_func *dim_func, tab_dim_free_func *free_func, void *aux)
-{
- assert (t->dim == NULL);
- t->dim = dim_func;
- t->dim_free = free_func;
- t->dim_aux = aux;
-}
-
-/* Returns the natural width of column C in table T for driver D, that
- is, the smallest width necessary to display all its cells without
- wrapping. The width will be no larger than the page width minus
- left and right rule widths. */
-int
-tab_natural_width (const struct tab_rendering *r, int col)
-{
- const struct tab_table *t = r->table;
- int width, row, max_width;
-
- assert (col >= 0 && col < t->nc);
-
- width = 0;
- for (row = 0; row < t->nr; row++)
- {
- struct outp_text text;
- unsigned char opt = t->ct[col + row * t->cf];
- int w;
-
- if (opt & (TAB_JOIN | TAB_EMPTY))
- continue;
-
- text.string = t->cc[col + row * t->cf];
- text.justification = OUTP_LEFT;
- text.font = options_to_font (opt);
- text.h = text.v = INT_MAX;
-
- r->driver->class->text_metrics (r->driver, &text, &w, NULL);
- if (w > width)
- width = w;
- }
-
- if (width == 0)
- {
- /* FIXME: This is an ugly kluge to compensate for the fact
- that we don't let joined cells contribute to column
- widths. */
- width = r->driver->prop_em_width * 8;
- }
-
- max_width = r->driver->width - r->wrv[0] - r->wrv[t->nc];
- return MIN (width, max_width);
-}
-
-/* Returns the natural height of row R in table T for driver D, that
- is, the minimum height necessary to display the information in the
- cell at the widths set for each column. */
-int
-tab_natural_height (const struct tab_rendering *r, int row)
-{
- const struct tab_table *t = r->table;
- int height, col;
-
- assert (row >= 0 && row < t->nr);
-
- height = r->driver->font_height;
- for (col = 0; col < t->nc; col++)
- {
- struct outp_text text;
- unsigned char opt = t->ct[col + row * t->cf];
- int h;
-
- if (opt & (TAB_JOIN | TAB_EMPTY))
- continue;
-
- text.string = t->cc[col + row * t->cf];
- text.justification = OUTP_LEFT;
- text.font = options_to_font (opt);
- text.h = r->w[col];
- text.v = INT_MAX;
- r->driver->class->text_metrics (r->driver, &text, NULL, &h);
-
- if (h > height)
- height = h;
- }
-
- return height;
-}
-
-/* Callback function to set all columns and rows to their natural
- dimensions. Not really meant to be called directly. */
-void
-tab_natural_dimensions (struct tab_rendering *r, void *aux UNUSED)
-{
- const struct tab_table *t = r->table;
- int i;
-
- for (i = 0; i < t->nc; i++)
- r->w[i] = tab_natural_width (r, i);
-
- for (i = 0; i < t->nr; i++)
- r->h[i] = tab_natural_height (r, i);
-}
-