source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Partial implementation of .Bd -centered.
@ 2014-07-29 13:58 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-07-29 13:58 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        mdoc.h
        mdoc_term.c
        mdoc_validate.c

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.230
retrieving revision 1.231
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.230 -r1.231
--- mdoc_validate.c
+++ 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;
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.271
retrieving revision 1.272
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.271 -r1.272
--- mdoc_term.c
+++ 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
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.130
retrieving revision 1.131
diff -Lmdoc.h -Lmdoc.h -u -p -r1.130 -r1.131
--- mdoc.h
+++ 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 */
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-07-29 13:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-29 13:58 mdocml: Partial implementation of .Bd -centered schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).