summaryrefslogtreecommitdiffstats
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
commit497337adb4cbff663bffd46a9081e56a5ae7874e (patch)
treedf13807a3827ad67bfd2f574b5e880b584d0691e
parent1146ced33c4a59a115f352a3cd7c07344c04e746 (diff)
downloadmandoc-497337adb4cbff663bffd46a9081e56a5ae7874e.tar.gz
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.h2
-rw-r--r--mdoc_term.c15
-rw-r--r--mdoc_validate.c2
3 files changed, 15 insertions, 4 deletions
diff --git a/mdoc.h b/mdoc.h
index 43ab3b5c..f2341a47 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -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 7ca42a50..e05b9f96 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -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 6aaddaa8..c8596140 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -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;