=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/tbl_term.c,v retrieving revision 1.21 retrieving revision 1.22 diff -c -r1.21 -r1.22 *** src/usr.bin/mandoc/tbl_term.c 2015/01/27 05:20:30 1.21 --- src/usr.bin/mandoc/tbl_term.c 2015/01/28 04:18:31 1.22 *************** *** 1,4 **** ! /* $OpenBSD: tbl_term.c,v 1.21 2015/01/27 05:20:30 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: tbl_term.c,v 1.22 2015/01/28 04:18:31 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze *************** *** 61,68 **** const struct tbl_head *hp; const struct tbl_cell *cp; const struct tbl_dat *dp; int horiz, spans, vert; - size_t rmargin, maxrmargin; rmargin = tp->rmargin; maxrmargin = tp->maxrmargin; --- 61,69 ---- 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; rmargin = tp->rmargin; maxrmargin = tp->maxrmargin; *************** *** 88,93 **** --- 89,109 ---- 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) *************** *** 187,198 **** assert(tp->tbl.cols); free(tp->tbl.cols); tp->tbl.cols = NULL; } tp->flags &= ~TERMP_NONOSPACE; tp->rmargin = rmargin; tp->maxrmargin = maxrmargin; - } /* --- 203,214 ---- 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; } /*