]> git.cameronkatri.com Git - mandoc.git/blob - tbl_html.c
style message about missing .Fn markup; inspired by mdoclint
[mandoc.git] / tbl_html.c
1 /* $Id: tbl_html.c,v 1.21 2017/06/08 18:11:22 schwarze Exp $ */
2 /*
3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "mandoc.h"
28 #include "out.h"
29 #include "html.h"
30
31 static void html_tblopen(struct html *, const struct tbl_span *);
32 static size_t html_tbl_len(size_t, void *);
33 static size_t html_tbl_strlen(const char *, void *);
34 static size_t html_tbl_sulen(const struct roffsu *, void *);
35
36
37 static size_t
38 html_tbl_len(size_t sz, void *arg)
39 {
40 return sz;
41 }
42
43 static size_t
44 html_tbl_strlen(const char *p, void *arg)
45 {
46 return strlen(p);
47 }
48
49 static size_t
50 html_tbl_sulen(const struct roffsu *su, void *arg)
51 {
52 switch (su->unit) {
53 case SCALE_FS: /* 2^16 basic units */
54 return su->scale * 65536.0 / 24.0;
55 case SCALE_IN: /* 10 characters per inch */
56 return su->scale * 10.0;
57 case SCALE_CM: /* 2.54 cm per inch */
58 return su->scale * 10.0 / 2.54;
59 case SCALE_PC: /* 6 pica per inch */
60 case SCALE_VS:
61 return su->scale * 10.0 / 6.0;
62 case SCALE_EN:
63 case SCALE_EM:
64 return su->scale;
65 case SCALE_PT: /* 12 points per pica */
66 return su->scale * 10.0 / 6.0 / 12.0;
67 case SCALE_BU: /* 24 basic units per character */
68 return su->scale / 24.0;
69 case SCALE_MM: /* 1/1000 inch */
70 return su->scale / 100.0;
71 default:
72 abort();
73 }
74 }
75
76 static void
77 html_tblopen(struct html *h, const struct tbl_span *sp)
78 {
79 struct tag *t;
80 int ic;
81
82 if (h->tbl.cols == NULL) {
83 h->tbl.len = html_tbl_len;
84 h->tbl.slen = html_tbl_strlen;
85 h->tbl.sulen = html_tbl_sulen;
86 tblcalc(&h->tbl, sp, 0);
87 }
88
89 assert(NULL == h->tblt);
90 h->tblt = print_otag(h, TAG_TABLE, "c", "tbl");
91
92 t = print_otag(h, TAG_COLGROUP, "");
93 for (ic = 0; ic < sp->opts->cols; ic++)
94 print_otag(h, TAG_COL, "shw", h->tbl.cols[ic].width);
95 print_tagq(h, t);
96 }
97
98 void
99 print_tblclose(struct html *h)
100 {
101
102 assert(h->tblt);
103 print_tagq(h, h->tblt);
104 h->tblt = NULL;
105 }
106
107 void
108 print_tbl(struct html *h, const struct tbl_span *sp)
109 {
110 const struct tbl_dat *dp;
111 struct tag *tt;
112 int ic;
113
114 /* Inhibit printing of spaces: we do padding ourselves. */
115
116 if (h->tblt == NULL)
117 html_tblopen(h, sp);
118
119 assert(h->tblt);
120
121 h->flags |= HTML_NONOSPACE;
122 h->flags |= HTML_NOSPACE;
123
124 tt = print_otag(h, TAG_TR, "");
125
126 switch (sp->pos) {
127 case TBL_SPAN_HORIZ:
128 case TBL_SPAN_DHORIZ:
129 print_otag(h, TAG_TD, "?", "colspan", "0");
130 break;
131 default:
132 dp = sp->first;
133 for (ic = 0; ic < sp->opts->cols; ic++) {
134 print_stagq(h, tt);
135 print_otag(h, TAG_TD, "");
136
137 if (dp == NULL || dp->layout->col > ic)
138 continue;
139 if (dp->layout->pos != TBL_CELL_DOWN)
140 if (dp->string != NULL)
141 print_text(h, dp->string);
142 dp = dp->next;
143 }
144 break;
145 }
146
147 print_tagq(h, tt);
148
149 h->flags &= ~HTML_NONOSPACE;
150
151 if (sp->next == NULL) {
152 assert(h->tbl.cols);
153 free(h->tbl.cols);
154 h->tbl.cols = NULL;
155 print_tblclose(h);
156 }
157
158 }