aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-07-29 13:58:18 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-07-29 13:58:18 +0000
commitdbf0764647f6b56bbb229562292e5a01705778af (patch)
tree05de7efb36208710968732fad5d2c15f6949e99a /mdoc_term.c
parent09d8ae540417e00bfa6ee4c17de85c9f9d89a570 (diff)
downloadmandoc-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.
Diffstat (limited to 'mdoc_term.c')
-rw-r--r--mdoc_term.c17
1 files changed, 14 insertions, 3 deletions
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