diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-06-14 17:50:45 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-06-14 17:50:45 +0000 |
commit | 80ac93be26e104b44e59db20f822b3f1b3727034 (patch) | |
tree | ac6ead0756eed56a0f66ab9975b9b840171f3032 /usr.bin/mandoc/term.c | |
parent | da25b5189535e7811c024d84f0c57bf36591811b (diff) |
improve rounding rules for scaling units
in horizontal orientation in the terminal formatter
Diffstat (limited to 'usr.bin/mandoc/term.c')
-rw-r--r-- | usr.bin/mandoc/term.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index e6aebdc379a..9c93a3a90a5 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.130 2017/06/14 01:31:19 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.131 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -526,7 +526,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); @@ -547,7 +547,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; @@ -964,7 +964,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) @@ -972,3 +972,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); +} |