]>
git.cameronkatri.com Git - mandoc.git/blob - eqn_html.c
e7393a96aa935c2e17f4318d74dce9ded7c2d0ee
1 /* $Id: eqn_html.c,v 1.13 2017/06/23 02:32:12 schwarze Exp $ */
3 * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2017 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>
33 eqn_box(struct html
*p
, const struct eqn_box
*bp
)
35 struct tag
*post
, *row
, *cell
, *t
;
36 const struct eqn_box
*child
, *parent
;
37 const unsigned char *cp
;
48 * Special handling for a matrix, which is presented to us in
49 * column order, but must be printed in row-order.
51 if (EQN_MATRIX
== bp
->type
) {
52 if (NULL
== bp
->first
)
54 if (EQN_LIST
!= bp
->first
->type
) {
55 eqn_box(p
, bp
->first
);
58 if (NULL
== (parent
= bp
->first
->first
))
60 /* Estimate the number of rows, first. */
61 if (NULL
== (child
= parent
->first
))
63 for (rows
= 0; NULL
!= child
; rows
++)
65 /* Print row-by-row. */
66 post
= print_otag(p
, TAG_MTABLE
, "");
67 for (i
= 0; i
< rows
; i
++) {
68 parent
= bp
->first
->first
;
69 row
= print_otag(p
, TAG_MTR
, "");
70 while (NULL
!= parent
) {
71 child
= parent
->first
;
72 for (j
= 0; j
< i
; j
++) {
77 cell
= print_otag(p
, TAG_MTD
, "");
79 * If we have no data for this
80 * particular cell, then print a
81 * placeholder and continue--don't puke.
84 eqn_box(p
, child
->first
);
86 parent
= parent
->next
;
95 post
= print_otag(p
, TAG_MOVER
, "");
98 post
= print_otag(p
, TAG_MSUP
, "");
101 post
= print_otag(p
, TAG_MUNDER
, "");
104 post
= print_otag(p
, TAG_MSUB
, "");
107 post
= print_otag(p
, TAG_MFRAC
, "");
110 post
= print_otag(p
, TAG_MUNDEROVER
, "");
113 post
= print_otag(p
, TAG_MSUBSUP
, "");
116 post
= print_otag(p
, TAG_MSQRT
, "");
122 if (bp
->top
|| bp
->bottom
) {
123 assert(NULL
== post
);
124 if (bp
->top
&& NULL
== bp
->bottom
)
125 post
= print_otag(p
, TAG_MOVER
, "");
126 else if (bp
->top
&& bp
->bottom
)
127 post
= print_otag(p
, TAG_MUNDEROVER
, "");
129 post
= print_otag(p
, TAG_MUNDER
, "");
132 if (EQN_PILE
== bp
->type
) {
133 assert(NULL
== post
);
134 if (bp
->first
!= NULL
&& bp
->first
->type
== EQN_LIST
)
135 post
= print_otag(p
, TAG_MTABLE
, "");
136 } else if (bp
->type
== EQN_LIST
&&
137 bp
->parent
&& bp
->parent
->type
== EQN_PILE
) {
138 assert(NULL
== post
);
139 post
= print_otag(p
, TAG_MTR
, "");
140 print_otag(p
, TAG_MTD
, "");
143 if (bp
->text
!= NULL
) {
144 assert(post
== NULL
);
146 cp
= (unsigned char *)bp
->text
;
147 if (isdigit(cp
[0]) || (cp
[0] == '.' && isdigit(cp
[1]))) {
149 while (*++cp
!= '\0') {
150 if (*cp
!= '.' && !isdigit(*cp
)) {
155 } else if (*cp
!= '\0' && isalpha(*cp
) == 0) {
157 while (*++cp
!= '\0') {
165 if (bp
->text
[0] != '\0' &&
166 (((tag
== TAG_MN
|| tag
== TAG_MO
) &&
167 font
== EQNFONT_ROMAN
) ||
168 (tag
== TAG_MI
&& font
== (bp
->text
[1] == '\0' ?
169 EQNFONT_ITALIC
: EQNFONT_ROMAN
))))
173 post
= print_otag(p
, tag
, "");
176 post
= print_otag(p
, tag
, "?", "fontstyle", "normal");
180 post
= print_otag(p
, tag
, "?", "fontweight", "bold");
183 post
= print_otag(p
, tag
, "?", "fontstyle", "italic");
188 print_text(p
, bp
->text
);
189 } else if (NULL
== post
) {
190 if (NULL
!= bp
->left
|| NULL
!= bp
->right
)
191 post
= print_otag(p
, TAG_MFENCED
, "??",
192 "open", bp
->left
== NULL
? "" : bp
->left
,
193 "close", bp
->right
== NULL
? "" : bp
->right
);
195 post
= print_otag(p
, TAG_MROW
, "");
197 print_otag(p
, TAG_MROW
, "");
200 eqn_box(p
, bp
->first
);
203 if (NULL
!= bp
->bottom
) {
204 t
= print_otag(p
, TAG_MO
, "");
205 print_text(p
, bp
->bottom
);
208 if (NULL
!= bp
->top
) {
209 t
= print_otag(p
, TAG_MO
, "");
210 print_text(p
, bp
->top
);
217 eqn_box(p
, bp
->next
);
221 print_eqn(struct html
*p
, const struct eqn
*ep
)
225 t
= print_otag(p
, TAG_MATH
, "c", "eqn");
227 p
->flags
|= HTML_NONOSPACE
;
228 eqn_box(p
, ep
->root
);
229 p
->flags
&= ~HTML_NONOSPACE
;