aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tbl_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-01-28 04:19:35 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-01-28 04:19:35 +0000
commitc49d930f6dcda366d67ac4b3bad9cc05ac3bc954 (patch)
tree5fc35cc20f43686438c1a794c5a82369b1693490 /tbl_term.c
parentbbe823a0b9a444fa14623b68d2c3f0c1dfe0219e (diff)
downloadmandoc-c49d930f6dcda366d67ac4b3bad9cc05ac3bc954.tar.gz
mandoc-c49d930f6dcda366d67ac4b3bad9cc05ac3bc954.tar.zst
mandoc-c49d930f6dcda366d67ac4b3bad9cc05ac3bc954.zip
implement the tbl(7) "center" layout option
Diffstat (limited to 'tbl_term.c')
-rw-r--r--tbl_term.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/tbl_term.c b/tbl_term.c
index e9497dd2..9b6aea36 100644
--- a/tbl_term.c
+++ b/tbl_term.c
@@ -1,4 +1,4 @@
-/* $Id: tbl_term.c,v 1.33 2015/01/27 05:21:45 schwarze Exp $ */
+/* $Id: tbl_term.c,v 1.34 2015/01/28 04:19:35 schwarze Exp $ */
/*
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -63,8 +63,9 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
const struct tbl_head *hp;
const struct tbl_cell *cp;
const struct tbl_dat *dp;
+ static size_t offset;
+ size_t rmargin, maxrmargin, tsz;
int horiz, spans, vert;
- size_t rmargin, maxrmargin;
rmargin = tp->rmargin;
maxrmargin = tp->maxrmargin;
@@ -90,6 +91,21 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
tblcalc(&tp->tbl, sp, rmargin - tp->offset);
+ /* Center the table as a whole. */
+
+ offset = tp->offset;
+ if (sp->opts->opts & TBL_OPT_CENTRE) {
+ tsz = sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX)
+ ? 2 : !!sp->opts->lvert + !!sp->opts->rvert;
+ for (hp = sp->head; hp != NULL; hp = hp->next)
+ tsz += tp->tbl.cols[hp->ident].width + 3;
+ tsz -= 3;
+ if (offset + tsz > rmargin)
+ tsz -= 1;
+ tp->offset = (offset + rmargin > tsz) ?
+ (offset + rmargin - tsz) / 2 : 0;
+ }
+
/* Horizontal frame at the start of boxed tables. */
if (sp->opts->opts & TBL_OPT_DBOX)
@@ -189,12 +205,12 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
assert(tp->tbl.cols);
free(tp->tbl.cols);
tp->tbl.cols = NULL;
+ tp->offset = offset;
}
tp->flags &= ~TERMP_NONOSPACE;
tp->rmargin = rmargin;
tp->maxrmargin = maxrmargin;
-
}
/*