diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2014-07-29 13:58:18 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2014-07-29 13:58:18 +0000 |
commit | dbf0764647f6b56bbb229562292e5a01705778af (patch) | |
tree | 05de7efb36208710968732fad5d2c15f6949e99a | |
parent | 09d8ae540417e00bfa6ee4c17de85c9f9d89a570 (diff) | |
download | mandoc-dbf0764647f6b56bbb229562292e5a01705778af.tar.gz mandoc-dbf0764647f6b56bbb229562292e5a01705778af.tar.zst mandoc-dbf0764647f6b56bbb229562292e5a01705778af.zip |
Partial implementation of .Bd -centered.
In groff, .Bd -centered operates in fill mode, which is relatively
hard to implement, while this implementation operates in non-fill
mode so far. As long as you pay attention that your lines do not
overflow, it works. To make sure that rendering is the same for
mandoc and groff, it is recommended to insert .br between lines
for now. This implementation will need improvement later.
-rw-r--r-- | mdoc.h | 4 | ||||
-rw-r--r-- | mdoc_term.c | 17 | ||||
-rw-r--r-- | mdoc_validate.c | 4 |
3 files changed, 18 insertions, 7 deletions
@@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.130 2014/07/02 03:48:07 schwarze Exp $ */ +/* $Id: mdoc.h,v 1.131 2014/07/29 13:58:18 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -280,7 +280,7 @@ enum mdoc_list { enum mdoc_disp { DISP__NONE = 0, - DISP_centred, /* -centered */ + DISP_centered, /* -centered */ DISP_ragged, /* -ragged */ DISP_unfilled, /* -unfilled */ DISP_filled, /* -filled */ diff --git a/mdoc_term.c b/mdoc_term.c index 4629e43a..a7f5b36d 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.271 2014/07/07 15:03:43 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.272 2014/07/29 13:58:18 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -1571,7 +1571,7 @@ termp_fa_pre(DECL_ARGS) static int termp_bd_pre(DECL_ARGS) { - size_t tabwidth, rm, rmax; + size_t tabwidth, lm, len, rm, rmax; struct mdoc_node *nn; if (MDOC_BLOCK == n->type) { @@ -1592,18 +1592,29 @@ termp_bd_pre(DECL_ARGS) */ if (DISP_literal != n->norm->Bd.type && - DISP_unfilled != n->norm->Bd.type) + DISP_unfilled != n->norm->Bd.type && + DISP_centered != n->norm->Bd.type) return(1); tabwidth = p->tabwidth; if (DISP_literal == n->norm->Bd.type) p->tabwidth = term_len(p, 8); + lm = p->offset; rm = p->rmargin; rmax = p->maxrmargin; p->rmargin = p->maxrmargin = TERM_MAXMARGIN; for (nn = n->child; nn; nn = nn->next) { + if (DISP_centered == n->norm->Bd.type) { + if (MDOC_TEXT == nn->type) { + len = term_strlen(p, nn->string); + p->offset = len >= rm ? 0 : + lm + len >= rm ? rm - len : + (lm + rm - len) / 2; + } else + p->offset = lm; + } print_mdoc_node(p, pair, meta, nn); /* * If the printed node flushes its own line, then we diff --git a/mdoc_validate.c b/mdoc_validate.c index 9e52365a..a122ac3b 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.230 2014/07/07 16:12:20 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.231 2014/07/29 13:58:18 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -802,7 +802,7 @@ pre_bd(PRE_ARGS) switch (argv->arg) { case MDOC_Centred: - dt = DISP_centred; + dt = DISP_centered; break; case MDOC_Ragged: dt = DISP_ragged; |