+ if (c->alpha != 255)
+ printf ("rgba(%d, %d, %d, %d)", c->r, c->g, c->b, c->alpha);
+ else
+ printf ("#%02"PRIx8"%02"PRIx8"%02"PRIx8, c->r, c->g, c->b);
+}
+
+void
+font_style_dump (const struct font_style *f)
+{
+ printf ("%s %dpx ", f->typeface, f->size);
+ cell_color_dump (&f->fg[0]);
+ putchar ('/');
+ cell_color_dump (&f->bg[0]);
+ if (!cell_color_equal (&f->fg[0], &f->fg[1])
+ || !cell_color_equal (&f->bg[0], &f->bg[1]))
+ {
+ printf (" alt=");
+ cell_color_dump (&f->fg[1]);
+ putchar ('/');
+ cell_color_dump (&f->bg[1]);
+ }
+ if (f->bold)
+ fputs (" bold", stdout);
+ if (f->italic)
+ fputs (" italic", stdout);
+ if (f->underline)
+ fputs (" underline", stdout);
+}
+
+bool
+font_style_equal (const struct font_style *a, const struct font_style *b)
+{
+ return (a->bold == b->bold
+ && a->italic == b->italic
+ && a->underline == b->underline
+ && a->markup == b->markup
+ && cell_color_equal (&a->fg[0], &b->fg[0])
+ && cell_color_equal (&a->fg[1], &b->fg[1])
+ && cell_color_equal (&a->bg[0], &b->bg[0])
+ && cell_color_equal (&a->bg[1], &b->bg[1])
+ && !strcmp (a->typeface ? a->typeface : "",
+ b->typeface ? b->typeface : "")
+ && a->size == b->size);
+}
+
+void
+cell_style_dump (const struct cell_style *c)
+{
+ fputs (table_halign_to_string (c->halign), stdout);
+ if (c->halign == TABLE_HALIGN_DECIMAL)
+ printf ("(%.2gpx)", c->decimal_offset);
+ printf (" %s", table_valign_to_string (c->valign));
+ printf (" %d,%d,%d,%dpx",
+ c->margin[TABLE_HORZ][0], c->margin[TABLE_HORZ][1],
+ c->margin[TABLE_VERT][0], c->margin[TABLE_VERT][1]);
+}
+\f
+
+static const bool debugging = true;
+
+/* Creates and returns a new table with NC columns and NR rows and initially no
+ header rows or columns.
+
+ Sets the number of header rows on each side of TABLE to HL on the
+ left, HR on the right, HT on the top, HB on the bottom. Header rows
+ are repeated when a table is broken across multiple columns or
+ multiple pages.
+
+ The table's cells are initially empty. */
+struct table *
+table_create (int nc, int nr, int hl, int hr, int ht, int hb)
+{
+ struct table *t;
+
+ t = pool_create_container (struct table, container);
+ t->n[TABLE_HORZ] = nc;
+ t->n[TABLE_VERT] = nr;
+ t->h[TABLE_HORZ][0] = hl;
+ t->h[TABLE_HORZ][1] = hr;
+ t->h[TABLE_VERT][0] = ht;
+ t->h[TABLE_VERT][1] = hb;
+ t->ref_cnt = 1;
+
+ t->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc);
+ t->ct = pool_calloc (t->container, nr * nc, sizeof *t->ct);
+
+ t->rh = pool_nmalloc (t->container, nc, nr + 1);
+ memset (t->rh, TABLE_STROKE_NONE, nc * (nr + 1));
+
+ t->rv = pool_nmalloc (t->container, nr, nc + 1);
+ memset (t->rv, TABLE_STROKE_NONE, nr * (nc + 1));
+
+ memset (t->styles, 0, sizeof t->styles);
+ memset (t->rule_colors, 0, sizeof t->rule_colors);
+
+ return t;