From: schwarze Date: Fri, 8 Aug 2014 15:03:24 +0000 (+0000) Subject: Partial implementation of .Bd -centered. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2065e47a4f71d5392cafbd7d2c0cfacce9c053fa;p=openbsd 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. --- diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h index caa51ecc62d..6d5bff6c10c 100644 --- a/usr.bin/mandoc/mdoc.h +++ b/usr.bin/mandoc/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.54 2014/07/02 03:47:07 schwarze Exp $ */ +/* $Id: mdoc.h,v 1.55 2014/08/08 15:03:24 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * @@ -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/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index db74c881e83..d586f34584b 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.173 2014/07/07 15:03:24 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.174 2014/08/08 15:03:24 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze @@ -1567,7 +1567,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) { @@ -1588,18 +1588,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/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 1b200521324..1ca1e8e3432 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.148 2014/07/07 16:12:06 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.149 2014/08/08 15:03:25 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -798,7 +798,7 @@ pre_bd(PRE_ARGS) switch (argv->arg) { case MDOC_Centred: - dt = DISP_centred; + dt = DISP_centered; break; case MDOC_Ragged: dt = DISP_ragged;