2017-01-21 13:01:39 +00:00
|
|
|
/* $Id: eqn_html.c,v 1.11 2017/01/17 01:47:51 schwarze Exp $ */
|
2012-10-18 09:55:16 +00:00
|
|
|
/*
|
2014-12-02 07:34:06 +00:00
|
|
|
* Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
|
2017-01-21 13:01:39 +00:00
|
|
|
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
|
2012-10-18 09:55:16 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
2014-12-02 07:34:06 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "mandoc.h"
|
|
|
|
#include "out.h"
|
|
|
|
#include "html.h"
|
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
static void
|
|
|
|
eqn_box(struct html *p, const struct eqn_box *bp)
|
|
|
|
{
|
|
|
|
struct tag *post, *row, *cell, *t;
|
|
|
|
const struct eqn_box *child, *parent;
|
|
|
|
size_t i, j, rows;
|
|
|
|
|
|
|
|
if (NULL == bp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
post = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special handling for a matrix, which is presented to us in
|
|
|
|
* column order, but must be printed in row-order.
|
|
|
|
*/
|
|
|
|
if (EQN_MATRIX == bp->type) {
|
|
|
|
if (NULL == bp->first)
|
|
|
|
goto out;
|
|
|
|
if (EQN_LIST != bp->first->type) {
|
|
|
|
eqn_box(p, bp->first);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (NULL == (parent = bp->first->first))
|
|
|
|
goto out;
|
|
|
|
/* Estimate the number of rows, first. */
|
|
|
|
if (NULL == (child = parent->first))
|
|
|
|
goto out;
|
|
|
|
for (rows = 0; NULL != child; rows++)
|
|
|
|
child = child->next;
|
|
|
|
/* Print row-by-row. */
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MTABLE, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
parent = bp->first->first;
|
2017-01-21 13:01:39 +00:00
|
|
|
row = print_otag(p, TAG_MTR, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
while (NULL != parent) {
|
|
|
|
child = parent->first;
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
if (NULL == child)
|
|
|
|
break;
|
|
|
|
child = child->next;
|
|
|
|
}
|
2017-01-21 13:01:39 +00:00
|
|
|
cell = print_otag(p, TAG_MTD, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
/*
|
|
|
|
* If we have no data for this
|
|
|
|
* particular cell, then print a
|
|
|
|
* placeholder and continue--don't puke.
|
|
|
|
*/
|
|
|
|
if (NULL != child)
|
|
|
|
eqn_box(p, child->first);
|
|
|
|
print_tagq(p, cell);
|
|
|
|
parent = parent->next;
|
|
|
|
}
|
|
|
|
print_tagq(p, row);
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (bp->pos) {
|
|
|
|
case (EQNPOS_TO):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MOVER, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
case (EQNPOS_SUP):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MSUP, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
case (EQNPOS_FROM):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MUNDER, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
case (EQNPOS_SUB):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MSUB, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
case (EQNPOS_OVER):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MFRAC, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
case (EQNPOS_FROMTO):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MUNDEROVER, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
case (EQNPOS_SUBSUP):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MSUBSUP, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
case (EQNPOS_SQRT):
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MSQRT, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bp->top || bp->bottom) {
|
|
|
|
assert(NULL == post);
|
|
|
|
if (bp->top && NULL == bp->bottom)
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MOVER, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
else if (bp->top && bp->bottom)
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MUNDEROVER, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
else if (bp->bottom)
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MUNDER, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EQN_PILE == bp->type) {
|
|
|
|
assert(NULL == post);
|
|
|
|
if (bp->first != NULL && bp->first->type == EQN_LIST)
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MTABLE, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
} else if (bp->type == EQN_LIST &&
|
|
|
|
bp->parent && bp->parent->type == EQN_PILE) {
|
|
|
|
assert(NULL == post);
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MTR, "");
|
|
|
|
print_otag(p, TAG_MTD, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != bp->text) {
|
|
|
|
assert(NULL == post);
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MI, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
print_text(p, bp->text);
|
|
|
|
} else if (NULL == post) {
|
2017-01-21 13:01:39 +00:00
|
|
|
if (NULL != bp->left || NULL != bp->right)
|
|
|
|
post = print_otag(p, TAG_MFENCED, "??",
|
|
|
|
"open", bp->left == NULL ? "" : bp->left,
|
|
|
|
"close", bp->right == NULL ? "" : bp->right);
|
2014-12-02 07:34:06 +00:00
|
|
|
if (NULL == post)
|
2017-01-21 13:01:39 +00:00
|
|
|
post = print_otag(p, TAG_MROW, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
else
|
2017-01-21 13:01:39 +00:00
|
|
|
print_otag(p, TAG_MROW, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
eqn_box(p, bp->first);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (NULL != bp->bottom) {
|
2017-01-21 13:01:39 +00:00
|
|
|
t = print_otag(p, TAG_MO, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
print_text(p, bp->bottom);
|
|
|
|
print_tagq(p, t);
|
|
|
|
}
|
|
|
|
if (NULL != bp->top) {
|
2017-01-21 13:01:39 +00:00
|
|
|
t = print_otag(p, TAG_MO, "");
|
2014-12-02 07:34:06 +00:00
|
|
|
print_text(p, bp->top);
|
|
|
|
print_tagq(p, t);
|
|
|
|
}
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
if (NULL != post)
|
|
|
|
print_tagq(p, post);
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2014-12-02 07:34:06 +00:00
|
|
|
eqn_box(p, bp->next);
|
|
|
|
}
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
void
|
|
|
|
print_eqn(struct html *p, const struct eqn *ep)
|
|
|
|
{
|
|
|
|
struct tag *t;
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
t = print_otag(p, TAG_MATH, "c", "eqn");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
p->flags |= HTML_NONOSPACE;
|
|
|
|
eqn_box(p, ep->root);
|
|
|
|
p->flags &= ~HTML_NONOSPACE;
|
|
|
|
|
|
|
|
print_tagq(p, t);
|
|
|
|
}
|