From b0095a770753743c2ece0f095b914220c7ae47fb Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 10 Jul 2012 19:54:11 +0000 Subject: 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 --- mdoc_man.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'mdoc_man.c') diff --git a/mdoc_man.c b/mdoc_man.c index 98984238..1c84958f 100644 --- a/mdoc_man.c +++ b/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; -- cgit