]>
git.cameronkatri.com Git - mandoc.git/blob - tbl_html.c
1 /* $Id: tbl_html.c,v 1.28 2018/11/26 01:51:46 schwarze Exp $ */
3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
20 #include <sys/types.h>
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 *);
38 html_tbl_len(size_t sz
, void *arg
)
44 html_tbl_strlen(const char *p
, void *arg
)
50 html_tbl_sulen(const struct roffsu
*su
, void *arg
)
56 case SCALE_FS
: /* 2^16 basic units */
57 return su
->scale
* 65536.0 / 24.0;
58 case SCALE_IN
: /* 10 characters per inch */
59 return su
->scale
* 10.0;
60 case SCALE_CM
: /* 2.54 cm per inch */
61 return su
->scale
* 10.0 / 2.54;
62 case SCALE_PC
: /* 6 pica per inch */
64 return su
->scale
* 10.0 / 6.0;
68 case SCALE_PT
: /* 12 points per pica */
69 return su
->scale
* 10.0 / 6.0 / 12.0;
70 case SCALE_BU
: /* 24 basic units per character */
71 return su
->scale
/ 24.0;
72 case SCALE_MM
: /* 1/1000 inch */
73 return su
->scale
/ 100.0;
80 html_tblopen(struct html
*h
, const struct tbl_span
*sp
)
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, 0);
88 assert(NULL
== h
->tblt
);
89 h
->tblt
= print_otag(h
, TAG_TABLE
, "c", "tbl");
93 print_tblclose(struct html
*h
)
97 print_tagq(h
, h
->tblt
);
102 print_tbl(struct html
*h
, const struct tbl_span
*sp
)
104 const struct tbl_dat
*dp
;
106 const char *hspans
, *vspans
, *halign
, *valign
;
107 char hbuf
[4], vbuf
[4];
109 /* Inhibit printing of spaces: we do padding ourselves. */
116 h
->flags
|= HTML_NONOSPACE
;
117 h
->flags
|= HTML_NOSPACE
;
119 tt
= print_otag(h
, TAG_TR
, "");
123 case TBL_SPAN_DHORIZ
:
124 print_otag(h
, TAG_TD
, "?", "colspan", "0");
127 for (dp
= sp
->first
; dp
!= NULL
; dp
= dp
->next
) {
131 * Do not generate <td> elements for continuations
132 * of spanned cells. Larger <td> elements covering
133 * this space were already generated earlier.
136 if (dp
->layout
->pos
== TBL_CELL_SPAN
||
137 dp
->layout
->pos
== TBL_CELL_DOWN
||
138 (dp
->string
!= NULL
&&
139 strcmp(dp
->string
, "\\^") == 0))
142 /* Determine the attribute values. */
144 if (dp
->hspans
> 0) {
145 (void)snprintf(hbuf
, sizeof(hbuf
),
146 "%d", dp
->hspans
+ 1);
150 if (dp
->vspans
> 0) {
151 (void)snprintf(vbuf
, sizeof(vbuf
),
152 "%d", dp
->vspans
+ 1);
157 switch (dp
->layout
->pos
) {
158 case TBL_CELL_CENTRE
:
162 case TBL_CELL_NUMBER
:
169 if (dp
->layout
->flags
& TBL_CELL_TALIGN
)
171 else if (dp
->layout
->flags
& TBL_CELL_BALIGN
)
176 /* Print the element and the attributes. */
178 print_otag(h
, TAG_TD
, "??ss",
179 "colspan", hspans
, "rowspan", vspans
,
180 "vertical-align", valign
,
181 "text-align", halign
);
182 if (dp
->string
!= NULL
)
183 print_text(h
, dp
->string
);
190 h
->flags
&= ~HTML_NONOSPACE
;
192 if (sp
->next
== NULL
) {