aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-06-14 17:51:15 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-06-14 17:51:15 +0000
commitd687586337f23b878d3678fc908d2c30b540a058 (patch)
tree4690c1992cd85292996a523727c3307ab8f10c45 /term.c
parent98b1f2affc51ab2505cc48390d8ea926eaac9e03 (diff)
downloadmandoc-d687586337f23b878d3678fc908d2c30b540a058.tar.gz
mandoc-d687586337f23b878d3678fc908d2c30b540a058.tar.zst
mandoc-d687586337f23b878d3678fc908d2c30b540a058.zip
improve rounding rules for scaling units
in horizontal orientation in the terminal formatter
Diffstat (limited to 'term.c')
-rw-r--r--term.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/term.c b/term.c
index 4a227988..e0308dd9 100644
--- 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.271 2017/06/14 17:51:15 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -528,7 +528,7 @@ term_word(struct termp *p, const char *word)
case ESCAPE_HORIZ:
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);
@@ -549,7 +549,7 @@ term_word(struct termp *p, const char *word)
case ESCAPE_HLINE:
if ((seq = 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;
@@ -966,7 +966,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 +974,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);
+}