source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: multiple fixes to -Tascii .HP rendering: * do not add an
@ 2012-07-10 19:54 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2012-07-10 19:54 UTC (permalink / raw)
  To: source

Log Message:
-----------
multiple fixes to -Tascii .HP rendering:
* do not add an excessive blank line before the block
* in literal mode, start a new line after the tag

getting this to work requires some general (print_man_node) fixes:
* in literal mode, break the output line at the end of each
input line, not just after those input lines ending in text
* but don't break it when there was no output on the line
* and adjust the margins after the .HP tag

these general fixes require an adjustment to -Tascii .TP rendering:
* set up NOBREAK mode before the body, not after the head

finally, based on all this, implement -Tman .Bl -hang in terms of .HP

OpenBSD rev. 1.84 and 1.29, respectively

Modified Files:
--------------
    mdocml:
        man_term.c
        mdoc_man.c

Revision Data
-------------
Index: mdoc_man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_man.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.30 -r1.31
--- mdoc_man.c
+++ mdoc_man.c
@@ -100,7 +100,7 @@ static	int	  pre_ux(DECL_ARGS);
 static	int	  pre_xr(DECL_ARGS);
 static	void	  print_word(const char *);
 static	void	  print_offs(const char *);
-static	void	  print_width(const char *);
+static	void	  print_width(const char *, const struct mdoc_node *);
 static	void	  print_count(int *);
 static	void	  print_node(DECL_ARGS);
 
@@ -360,22 +360,34 @@ print_offs(const char *v)
 }
 
 void
-print_width(const char *v)
+print_width(const char *v, const struct mdoc_node *child)
 {
 	char		  buf[24];
 	struct roffsu	  su;
-	size_t		  sz;
+	size_t		  sz, chsz;
+
+	/* XXX Rough estimation, might have multiple parts. */
+	chsz = (NULL != child && MDOC_TEXT == child->type) ?
+			strlen(child->string) : 0;
 
 	if (a2roffsu(v, &su, SCALE_MAX)) {
 		if (SCALE_EN == su.unit)
 			sz = su.scale;
 		else {
+			if (chsz)
+				print_word(".HP");
+			else
+				print_word(".TP");
 			print_word(v);
 			return;
 		}
 	} else
 		sz = strlen(v);
 
+	if (chsz > sz)
+		print_word(".HP");
+	else
+		print_word(".TP");
 	snprintf(buf, sizeof(buf), "%ldn", sz + 2);
 	print_word(buf);
 }
@@ -1027,8 +1039,7 @@ pre_it(DECL_ARGS)
 		case (LIST_dash):
 			/* FALLTHROUGH */
 		case (LIST_hyphen):
-			print_word(".TP");
-			print_width(bln->norm->Bl.width);
+			print_width(bln->norm->Bl.width, NULL);
 			outflags |= MMAN_nl;
 			font_push('B');
 			if (LIST_bullet == bln->norm->Bl.type)
@@ -1038,15 +1049,18 @@ pre_it(DECL_ARGS)
 			font_pop();
 			break;
 		case (LIST_enum):
-			print_word(".TP");
-			print_width(bln->norm->Bl.width);
+			print_width(bln->norm->Bl.width, NULL);
 			outflags |= MMAN_nl;
 			print_count(&bln->norm->Bl.count);
 			outflags |= MMAN_nl;
 			break;
+		case (LIST_hang):
+			print_width(bln->norm->Bl.width, n->child);
+			outflags |= MMAN_nl;
+			break;
 		default:
 			if (bln->norm->Bl.width)
-				print_width(bln->norm->Bl.width);
+				print_width(bln->norm->Bl.width, n->child);
 			break;
 		}
 		outflags |= MMAN_nl;
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -Lman_term.c -Lman_term.c -u -p -r1.129 -r1.130
--- man_term.c
+++ man_term.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -480,13 +480,16 @@ pre_HP(DECL_ARGS)
 		print_bvspace(p, n);
 		return(1);
 	case (MAN_BODY):
-		p->flags |= TERMP_NOBREAK;
-		p->flags |= TERMP_TWOSPACE;
 		break;
 	default:
 		return(0);
 	}
 
+	if ( ! (MANT_LITERAL & mt->fl)) {
+		p->flags |= TERMP_NOBREAK;
+		p->flags |= TERMP_TWOSPACE;
+	}
+
 	len = mt->lmargin[mt->lmargincur];
 	ival = -1;
 
@@ -516,9 +519,6 @@ post_HP(DECL_ARGS)
 {
 
 	switch (n->type) {
-	case (MAN_BLOCK):
-		term_flushln(p);
-		break;
 	case (MAN_BODY):
 		term_flushln(p);
 		p->flags &= ~TERMP_NOBREAK;
@@ -696,6 +696,8 @@ pre_TP(DECL_ARGS)
 	case (MAN_BODY):
 		p->offset = mt->offset + len;
 		p->rmargin = p->maxrmargin;
+		p->flags &= ~TERMP_NOBREAK;
+		p->flags &= ~TERMP_TWOSPACE;
 		break;
 	default:
 		break;
@@ -713,9 +715,6 @@ post_TP(DECL_ARGS)
 	switch (n->type) {
 	case (MAN_HEAD):
 		term_flushln(p);
-		p->flags &= ~TERMP_NOBREAK;
-		p->flags &= ~TERMP_TWOSPACE;
-		p->rmargin = p->maxrmargin;
 		break;
 	case (MAN_BODY):
 		term_newln(p);
@@ -912,29 +911,8 @@ print_man_node(DECL_ARGS)
 			term_newln(p);
 
 		term_word(p, n->string);
+		goto out;
 
-		/*
-		 * If we're in a literal context, make sure that words
-		 * togehter on the same line stay together.  This is a
-		 * POST-printing call, so we check the NEXT word.  Since
-		 * -man doesn't have nested macros, we don't need to be
-		 * more specific than this.
-		 */
-		if (MANT_LITERAL & mt->fl && ! (TERMP_NOBREAK & p->flags) &&
-				(NULL == n->next || 
-				 n->next->line > n->line)) {
-			rm = p->rmargin;
-			rmax = p->maxrmargin;
-			p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
-			p->flags |= TERMP_NOSPACE;
-			term_flushln(p);
-			p->rmargin = rm;
-			p->maxrmargin = rmax;
-		}
-
-		if (MAN_EOS & n->flags)
-			p->flags |= TERMP_SENTENCE;
-		return;
 	case (MAN_EQN):
 		term_eqn(p, n->eqn);
 		return;
@@ -966,6 +944,31 @@ print_man_node(DECL_ARGS)
 	if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
 		term_fontrepl(p, TERMFONT_NONE);
 
+out:
+	/*
+	 * If we're in a literal context, make sure that words
+	 * together on the same line stay together.  This is a
+	 * POST-printing call, so we check the NEXT word.  Since
+	 * -man doesn't have nested macros, we don't need to be
+	 * more specific than this.
+	 */
+	if (MANT_LITERAL & mt->fl && ! (TERMP_NOBREAK & p->flags) &&
+	    NULL != n->next && n->next->line > n->line) {
+		rm = p->rmargin;
+		rmax = p->maxrmargin;
+		p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
+		p->flags |= TERMP_NOSPACE;
+		if (NULL != n->string && '\0' != *n->string)
+			term_flushln(p);
+		else
+			term_newln(p);
+		if (rm < rmax && n->parent->tok == MAN_HP) {
+			p->offset = rm;
+			p->rmargin = rmax;
+		} else
+			p->rmargin = rm;
+		p->maxrmargin = rmax;
+	}
 	if (MAN_EOS & n->flags)
 		p->flags |= TERMP_SENTENCE;
 }
--
 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:[~2012-07-10 19:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-10 19:54 mdocml: multiple fixes to -Tascii .HP rendering: * do not add an 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).