Nothing ever changes the number of rows or columns in a table after
initializing it anymore, so the more complicated interface is not needed.
struct tab_table *t;
t = pool_create_container (struct tab_table, container);
struct tab_table *t;
t = pool_create_container (struct tab_table, container);
- table_init (&t->table, &tab_table_class);
- table_set_nc (&t->table, nc);
- table_set_nr (&t->table, nr);
+ table_init (&t->table, &tab_table_class, nc, nr);
t->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc);
t->ct = pool_calloc (t->container, nr * nc, sizeof *t->ct);
t->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc);
t->ct = pool_calloc (t->container, nr * nc, sizeof *t->ct);
{
int y;
for (y = y1; y <= y2; y++)
{
int y;
for (y = y1; y <= y2; y++)
- t->rv[x + (t->cf + 1) * y] = style;
+ t->rv[x + (tab_nc (t) + 1) * y] = style;
{
int x;
for (x = x1; x <= x2; x++)
{
int x;
for (x = x1; x <= x2; x++)
- t->rh[x + t->cf * y] = style;
+ t->rh[x + tab_nc (t) * y] = style;
int x;
for (x = x1; x <= x2; x++)
{
int x;
for (x = x1; x <= x2; x++)
{
- t->rh[x + t->cf * y1] = f_h;
- t->rh[x + t->cf * (y2 + 1)] = f_h;
+ t->rh[x + tab_nc (t) * y1] = f_h;
+ t->rh[x + tab_nc (t) * (y2 + 1)] = f_h;
int y;
for (y = y1; y <= y2; y++)
{
int y;
for (y = y1; y <= y2; y++)
{
- t->rv[x1 + (t->cf + 1) * y] = f_v;
- t->rv[(x2 + 1) + (t->cf + 1) * y] = f_v;
+ t->rv[x1 + (tab_nc (t) + 1) * y] = f_v;
+ t->rv[(x2 + 1) + (tab_nc (t) + 1) * y] = f_v;
int x;
for (x = x1; x <= x2; x++)
int x;
for (x = x1; x <= x2; x++)
- t->rh[x + t->cf * y] = i_h;
+ t->rh[x + tab_nc (t) * y] = i_h;
int y;
for (y = y1; y <= y2; y++)
int y;
for (y = y1; y <= y2; y++)
- t->rv[x + (t->cf + 1) * y] = i_v;
+ t->rv[x + (tab_nc (t) + 1) * y] = i_v;
- table->cc[c + r * table->cf] = text;
- table->ct[c + r * table->cf] = opt;
+ table->cc[c + r * tab_nc (table)] = text;
+ table->ct[c + r * tab_nc (table)] = opt;
}
/* Sets cell (C,R) in TABLE, with options OPT, to have text value
}
/* Sets cell (C,R) in TABLE, with options OPT, to have text value
- void **cc = &table->cc[x1 + y1 * table->cf];
- unsigned short *ct = &table->ct[x1 + y1 * table->cf];
- const int ofs = table->cf - (x2 - x1);
+ void **cc = &table->cc[x1 + y1 * tab_nc (table)];
+ unsigned short *ct = &table->ct[x1 + y1 * tab_nc (table)];
+ const int ofs = tab_nc (table) - (x2 - x1);
tab_add_footnote (struct tab_table *table, int x, int y,
const struct footnote *f)
{
tab_add_footnote (struct tab_table *table, int x, int y,
const struct footnote *f)
{
- int index = x + y * table->cf;
+ int index = x + y * tab_nc (table);
unsigned short opt = table->ct[index];
struct tab_joined_cell *j;
unsigned short opt = table->ct[index];
struct tab_joined_cell *j;
tab_add_style (struct tab_table *table, int x, int y,
const struct area_style *style)
{
tab_add_style (struct tab_table *table, int x, int y,
const struct area_style *style)
{
- int index = x + y * table->cf;
+ int index = x + y * tab_nc (table);
unsigned short opt = table->ct[index];
struct tab_joined_cell *j;
unsigned short opt = table->ct[index];
struct tab_joined_cell *j;
bool
tab_cell_is_empty (const struct tab_table *table, int c, int r)
{
bool
tab_cell_is_empty (const struct tab_table *table, int c, int r)
{
- return table->cc[c + r * table->cf] == NULL;
+ return table->cc[c + r * tab_nc (table)] == NULL;
struct table_cell *cell)
{
const struct tab_table *t = tab_cast (table);
struct table_cell *cell)
{
const struct tab_table *t = tab_cast (table);
- int index = x + y * t->cf;
+ int index = x + y * tab_nc (t);
unsigned short opt = t->ct[index];
const void *cc = t->cc[index];
unsigned short opt = t->ct[index];
const void *cc = t->cc[index];
{
const struct tab_table *t = tab_cast (table);
uint8_t raw = (axis == TABLE_VERT
{
const struct tab_table *t = tab_cast (table);
uint8_t raw = (axis == TABLE_VERT
- ? t->rh[x + t->cf * y] : t->rv[x + (t->cf + 1) * y]);
+ ? t->rh[x + tab_nc (t) * y]
+ : t->rv[x + (tab_nc (t) + 1) * y]);
struct cell_color *p = t->rule_colors[(raw & TAB_RULE_STYLE_MASK)
>> TAB_RULE_STYLE_SHIFT];
if (p)
struct cell_color *p = t->rule_colors[(raw & TAB_RULE_STYLE_MASK)
>> TAB_RULE_STYLE_SHIFT];
if (p)
struct table table;
struct pool *container;
struct table table;
struct pool *container;
- /* Table title and caption, or null. */
- int cf; /* Column factor for indexing purposes. */
-
/* Table contents.
Each array element in cc[] is ordinarily a "char *" pointer to a
/* Table contents.
Each array element in cc[] is ordinarily a "char *" pointer to a
struct cell_color *color);
};
struct cell_color *color);
};
-void table_init (struct table *, const struct table_class *);
-
-/* Table class implementations can call these functions or just set the
- table's n[] and h[][] members directly. */
-void table_set_nc (struct table *, int nc);
-void table_set_nr (struct table *, int nr);
+void table_init (struct table *, const struct table_class *, int nc, int nr);
\f
/* For use primarily by output drivers. */
\f
/* For use primarily by output drivers. */
/* Initializes TABLE as a table of the specified CLASS, initially with a
reference count of 1.
/* Initializes TABLE as a table of the specified CLASS, initially with a
reference count of 1.
- TABLE initially has 0 rows and columns and no headers. The table
- implementation should update the numbers of rows and columns. The table
+ TABLE initially has NR rows and NC columns and no headers. The table
implementation (or its client) may update the header rows and columns.
A table is an abstract class, that is, a plain struct table is not useful on
its own. Thus, this function is normally called from the initialization
function of some subclass of table. */
void
implementation (or its client) may update the header rows and columns.
A table is an abstract class, that is, a plain struct table is not useful on
its own. Thus, this function is normally called from the initialization
function of some subclass of table. */
void
-table_init (struct table *table, const struct table_class *class)
+table_init (struct table *table, const struct table_class *class,
+ int nc, int nr)
- table->n[TABLE_HORZ] = table->n[TABLE_VERT] = 0;
+ table->n[TABLE_HORZ] = nc;
+ table->n[TABLE_VERT] = nr;
table->h[TABLE_HORZ][0] = table->h[TABLE_HORZ][1] = 0;
table->h[TABLE_VERT][0] = table->h[TABLE_VERT][1] = 0;
table->ref_cnt = 1;
}
table->h[TABLE_HORZ][0] = table->h[TABLE_HORZ][1] = 0;
table->h[TABLE_VERT][0] = table->h[TABLE_VERT][1] = 0;
table->ref_cnt = 1;
}
-
-/* Sets the number of columns in TABLE to NC. */
-void
-table_set_nc (struct table *table, int nc)
-{
- assert (!table_is_shared (table));
- table->n[TABLE_HORZ] = nc;
-}
-
-/* Sets the number of rows in TABLE to NR. */
-void
-table_set_nr (struct table *table, int nr)
-{
- assert (!table_is_shared (table));
- table->n[TABLE_VERT] = nr;
-}
\f
struct area_style *
area_style_clone (struct pool *pool, const struct area_style *old)
\f
struct area_style *
area_style_clone (struct pool *pool, const struct area_style *old)