+static void html_tblopen(struct html *, const struct tbl_span *);
+static size_t html_tbl_len(size_t, void *);
+static size_t html_tbl_strlen(const char *, void *);
+static size_t html_tbl_sulen(const struct roffsu *, void *);
+
+
+static size_t
+html_tbl_len(size_t sz, void *arg)
+{
+ return sz;
+}
+
+static size_t
+html_tbl_strlen(const char *p, void *arg)
+{
+ return strlen(p);
+}
+
+static size_t
+html_tbl_sulen(const struct roffsu *su, void *arg)
+{
+ if (su->scale < 0.0)
+ return 0;
+
+ switch (su->unit) {
+ case SCALE_FS: /* 2^16 basic units */
+ return su->scale * 65536.0 / 24.0;
+ case SCALE_IN: /* 10 characters per inch */
+ return su->scale * 10.0;
+ case SCALE_CM: /* 2.54 cm per inch */
+ return su->scale * 10.0 / 2.54;
+ case SCALE_PC: /* 6 pica per inch */
+ case SCALE_VS:
+ return su->scale * 10.0 / 6.0;
+ case SCALE_EN:
+ case SCALE_EM:
+ return su->scale;
+ case SCALE_PT: /* 12 points per pica */
+ return su->scale * 10.0 / 6.0 / 12.0;
+ case SCALE_BU: /* 24 basic units per character */
+ return su->scale / 24.0;
+ case SCALE_MM: /* 1/1000 inch */
+ return su->scale / 100.0;
+ default:
+ abort();
+ }
+}
+
+static void
+html_tblopen(struct html *h, const struct tbl_span *sp)
+{
+ html_close_paragraph(h);
+ if (h->tbl.cols == NULL) {
+ h->tbl.len = html_tbl_len;
+ h->tbl.slen = html_tbl_strlen;
+ h->tbl.sulen = html_tbl_sulen;
+ tblcalc(&h->tbl, sp, 0, 0);
+ }
+ assert(NULL == h->tblt);
+ h->tblt = print_otag(h, TAG_TABLE, "c?ss", "tbl",
+ "border",
+ sp->opts->opts & TBL_OPT_ALLBOX ? "1" : NULL,
+ "border-style",
+ sp->opts->opts & TBL_OPT_DBOX ? "double" :
+ sp->opts->opts & TBL_OPT_BOX ? "solid" : NULL,
+ "border-top-style",
+ sp->pos == TBL_SPAN_DHORIZ ? "double" :
+ sp->pos == TBL_SPAN_HORIZ ? "solid" : NULL);
+}
+
+void
+print_tblclose(struct html *h)
+{
+
+ assert(h->tblt);
+ print_tagq(h, h->tblt);
+ h->tblt = NULL;
+}
+