summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/usr.bin/mandoc/tbl/Makefile6
-rw-r--r--regress/usr.bin/mandoc/tbl/layout_center.in98
-rw-r--r--regress/usr.bin/mandoc/tbl/layout_center.out_ascii65
-rw-r--r--share/man/man7/tbl.75
-rw-r--r--usr.bin/mandoc/tbl_term.c22
5 files changed, 187 insertions, 9 deletions
diff --git a/regress/usr.bin/mandoc/tbl/Makefile b/regress/usr.bin/mandoc/tbl/Makefile
index 865c0b65cd7..af6f4361f88 100644
--- a/regress/usr.bin/mandoc/tbl/Makefile
+++ b/regress/usr.bin/mandoc/tbl/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.10 2015/01/28 02:23:33 schwarze Exp $
+# $OpenBSD: Makefile,v 1.11 2015/01/28 04:18:31 schwarze Exp $
-REGRESS_TARGETS = blankline center expand fonts layout macro misalign
-REGRESS_TARGETS += nested numbers opt span vert
+REGRESS_TARGETS = blankline center expand fonts layout layout_center
+REGRESS_TARGETS += macro misalign nested numbers opt span vert
LINT_TARGETS = layout macro nested opt
# groff-1.22.3 defect:
diff --git a/regress/usr.bin/mandoc/tbl/layout_center.in b/regress/usr.bin/mandoc/tbl/layout_center.in
new file mode 100644
index 00000000000..7c05202c848
--- /dev/null
+++ b/regress/usr.bin/mandoc/tbl/layout_center.in
@@ -0,0 +1,98 @@
+.TH TBL-LAYOUT_CENTER 1 "January 28, 2015" OpenBSD
+.SH NAME
+tbl-layout_center \- center a table as a whole
+.SH DESCRIPTION
+normal text
+.TS
+center; l.
+12345678901234567890123456789012345678901234567890123456789012345678901\
+234567890123456
+.TE
+.TS
+center; l.
+12345678901234567890123456789012345678901234567890123456789012345678901\
+23456789012345
+.TE
+.TS
+center; l.
+12345678901234567890123456789012345678901234567890123456789012345678901\
+2345678901234
+.TE
+.TS
+center; l.
+12345678901234567890123456789012345678901234567890123456789012345678901234
+.TE
+.TS
+center; l.
+1234567890123456789012345678901234567890123456789012345678901234567890123
+.TE
+.TS
+center; l.
+123456789012345678901234567890123456789012345678901234567890123456789012
+.TE
+.TS
+center; l.
+12345678901234567890123456789012345678901234567890123456789012345678901
+.TE
+.TS
+center; l.
+1234567890123456789012345678901234567890123456789012345678901234567890
+.TE
+.TS
+center; l.
+123456789012345678901234567890123456789012345678901234567890123456789
+.TE
+.TS
+center; l.
+12345678901234567890123456789012345678901234567890123456789012345678
+.TE
+.TS
+center; l|.
+_
+txt
+.TE
+.TS
+center; l|.
+_
+text
+.TE
+.TS
+center; |l.
+_
+txt
+.TE
+.TS
+center; |l.
+_
+text
+.TE
+.TS
+center; |l|.
+_
+txt
+.TE
+.TS
+center; |l|.
+_
+text
+.TE
+.TS
+center tab(:); |l||l|.
+_
+txt:text
+.TE
+.TS
+center tab(:); |l||l|.
+_
+text:text
+.TE
+.TS
+center box; l.
+txt
+.TE
+.PP
+normal text
+.TS
+center box; l.
+text
+.TE
diff --git a/regress/usr.bin/mandoc/tbl/layout_center.out_ascii b/regress/usr.bin/mandoc/tbl/layout_center.out_ascii
new file mode 100644
index 00000000000..8df45eec70b
--- /dev/null
+++ b/regress/usr.bin/mandoc/tbl/layout_center.out_ascii
@@ -0,0 +1,65 @@
+TBL-LAYOUT_CENTER(1) General Commands Manual TBL-LAYOUT_CENTER(1)
+
+
+
+NNAAMMEE
+ tbl-layout_center - center a table as a whole
+
+DDEESSCCRRIIPPTTIIOONN
+ normal text
+
+12345678901234567890123456789012345678901234567890123456789012345678901234567890123456
+
+1234567890123456789012345678901234567890123456789012345678901234567890123456789012345
+
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234
+
+ 12345678901234567890123456789012345678901234567890123456789012345678901234
+
+ 1234567890123456789012345678901234567890123456789012345678901234567890123
+
+ 123456789012345678901234567890123456789012345678901234567890123456789012
+
+ 12345678901234567890123456789012345678901234567890123456789012345678901
+
+ 1234567890123456789012345678901234567890123456789012345678901234567890
+
+ 123456789012345678901234567890123456789012345678901234567890123456789
+
+ 12345678901234567890123456789012345678901234567890123456789012345678
+
+ ----+
+ txt |
+
+ -----+
+ text |
+
+ +----
+ |txt
+
+ +-----
+ |text
+
+ +----+
+ |txt |
+
+ +-----+
+ |text |
+
+ +----++-----+
+ |txt ||text |
+
+ +-----++-----+
+ |text ||text |
+
+ +----+
+ |txt |
+ +----+
+ normal text
+
+ +-----+
+ |text |
+ +-----+
+
+
+OpenBSD January 28, 2015 TBL-LAYOUT_CENTER(1)
diff --git a/share/man/man7/tbl.7 b/share/man/man7/tbl.7
index 19a10015851..8c214606be2 100644
--- a/share/man/man7/tbl.7
+++ b/share/man/man7/tbl.7
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tbl.7,v 1.12 2015/01/26 18:41:45 schwarze Exp $
+.\" $OpenBSD: tbl.7,v 1.13 2015/01/28 04:18:31 schwarze Exp $
.\"
.\" Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 26 2015 $
+.Dd $Mdocdate: January 28 2015 $
.Dt TBL 7
.Os
.Sh NAME
@@ -152,7 +152,6 @@ For GNU compatibility, this may also be invoked with
.Cm frame .
.It Cm center
Center the table instead of left-adjusting it.
-Currently ignored.
For GNU compatibility, this may also be invoked with
.Cm centre .
.It Cm decimalpoint
diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c
index 8cb646aa13a..5dd8384c6e4 100644
--- a/usr.bin/mandoc/tbl_term.c
+++ b/usr.bin/mandoc/tbl_term.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tbl_term.c,v 1.21 2015/01/27 05:20:30 schwarze Exp $ */
+/* $OpenBSD: tbl_term.c,v 1.22 2015/01/28 04:18:31 schwarze Exp $ */
/*
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -61,8 +61,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;
@@ -88,6 +89,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)
@@ -187,12 +203,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;
-
}
/*