]> git.cameronkatri.com Git - mandoc.git/blobdiff - term.c
Minor correction: we render HTML character references hexadecimal,
[mandoc.git] / term.c
diff --git a/term.c b/term.c
index 4a2279882aa1b5043fbae9b44987c8893d7d843c..f67fcf9d959ff7fe6f9823fcdfabfcb09e72b4e4 100644 (file)
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/*     $Id: term.c,v 1.270 2017/06/14 01:31:27 schwarze Exp $ */
+/*     $Id: term.c,v 1.274 2017/07/28 14:25:48 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -129,7 +129,7 @@ term_flushln(struct termp *p)
            p->maxrmargin - p->viscol - vbl : 0;
        vis = vend = 0;
 
-       if ((p->flags && TERMP_MULTICOL) == 0)
+       if ((p->flags & TERMP_MULTICOL) == 0)
                p->tcol->col = 0;
        while (p->tcol->col < p->tcol->lastcol) {
 
@@ -526,9 +526,14 @@ term_word(struct termp *p, const char *word)
                                p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
                        continue;
                case ESCAPE_HORIZ:
+                       if (*seq == '|') {
+                               seq++;
+                               uc = -p->col;
+                       } else
+                               uc = 0;
                        if (a2roffsu(seq, &su, SCALE_EM) == NULL)
                                continue;
-                       uc = term_hspan(p, &su) / 24;
+                       uc += term_hen(p, &su);
                        if (uc > 0)
                                while (uc-- > 0)
                                        bufferc(p, ASCII_NBRSP);
@@ -547,19 +552,19 @@ term_word(struct termp *p, const char *word)
                        }
                        continue;
                case ESCAPE_HLINE:
-                       if ((seq = a2roffsu(seq, &su, SCALE_EM)) == NULL)
+                       if ((cp = a2roffsu(seq, &su, SCALE_EM)) == NULL)
                                continue;
-                       uc = term_hspan(p, &su) / 24;
+                       uc = term_hen(p, &su);
                        if (uc <= 0) {
                                if (p->tcol->rmargin <= p->tcol->offset)
                                        continue;
                                lsz = p->tcol->rmargin - p->tcol->offset;
                        } else
                                lsz = uc;
-                       if (*seq == '\0')
+                       if (*cp == seq[-1])
                                uc = -1;
-                       else if (*seq == '\\') {
-                               seq++;
+                       else if (*cp == '\\') {
+                               seq = cp + 1;
                                esc = mandoc_escape(&seq, &cp, &sz);
                                switch (esc) {
                                case ESCAPE_UNICODE:
@@ -576,7 +581,7 @@ term_word(struct termp *p, const char *word)
                                        break;
                                }
                        } else
-                               uc = *seq;
+                               uc = *cp;
                        if (uc < 0x20 || (uc > 0x7E && uc < 0xA0))
                                uc = '_';
                        if (p->enc == TERMENC_ASCII) {
@@ -966,7 +971,7 @@ term_vspan(const struct termp *p, const struct roffsu *su)
 }
 
 /*
- * Convert a scaling width to basic units, rounding down.
+ * Convert a scaling width to basic units, rounding towards 0.
  */
 int
 term_hspan(const struct termp *p, const struct roffsu *su)
@@ -974,3 +979,17 @@ term_hspan(const struct termp *p, const struct roffsu *su)
 
        return (*p->hspan)(p, su);
 }
+
+/*
+ * Convert a scaling width to basic units, rounding to closest.
+ */
+int
+term_hen(const struct termp *p, const struct roffsu *su)
+{
+       int bu;
+
+       if ((bu = (*p->hspan)(p, su)) >= 0)
+               return (bu + 11) / 24;
+       else
+               return -((-bu + 11) / 24);
+}