=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.248 retrieving revision 1.253 diff -u -p -r1.248 -r1.253 --- mandoc/term.c 2015/04/29 18:35:00 1.248 +++ mandoc/term.c 2015/10/12 00:08:16 1.253 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.248 2015/04/29 18:35:00 schwarze Exp $ */ +/* $Id: term.c,v 1.253 2015/10/12 00:08:16 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -78,6 +78,8 @@ term_end(struct termp *p) * the next column. However, if less than p->trailspace blanks, * which can be 0, 1, or 2, remain to the right margin, the line * will be broken. + * - TERMP_BRTRSP: Consider trailing whitespace significant + * when deciding whether the chunk fits or not. * - TERMP_BRIND: If the chunk does not fit and the output line has * to be broken, start the next line at the right margin instead * of at the offset. Used together with TERMP_NOBREAK for the tags @@ -291,6 +293,10 @@ term_flushln(struct termp *p) } else if (TERMP_DANGLE & p->flags) return; + /* Trailing whitespace is significant in some columns. */ + if (vis && vbl && (TERMP_BRTRSP & p->flags)) + vis += vbl; + /* If the column was overrun, break the line. */ if (maxvis < vis + p->trailspace * (*p->width)(p, ' ')) { (*p->endline)(p); @@ -468,7 +474,6 @@ term_word(struct termp *p, const char *word) term_fontrepl(p, TERMFONT_BI); continue; case ESCAPE_FONT: - /* FALLTHROUGH */ case ESCAPE_FONTROMAN: term_fontrepl(p, TERMFONT_NONE); continue; @@ -499,6 +504,9 @@ term_word(struct termp *p, const char *word) p->flags |= TERMP_BACKBEFORE; } } + /* Trim trailing backspace/blank pair. */ + if (p->col > 2 && p->buf[p->col - 1] == ' ') + p->col -= 2; continue; default: continue; @@ -561,7 +569,10 @@ encode1(struct termp *p, int c) p->fontq[p->fonti] : TERMFONT_NONE; if (p->flags & TERMP_BACKBEFORE) { - p->buf[p->col++] = 8; + if (p->buf[p->col - 1] == ' ') + p->col--; + else + p->buf[p->col++] = 8; p->flags &= ~TERMP_BACKBEFORE; } if (TERMFONT_UNDER == f || TERMFONT_BI == f) { @@ -632,7 +643,7 @@ size_t term_len(const struct termp *p, size_t sz) { - return((*p->width)(p, ' ') * sz); + return (*p->width)(p, ' ') * sz; } static size_t @@ -641,9 +652,9 @@ cond_width(const struct termp *p, int c, int *skip) if (*skip) { (*skip) = 0; - return(0); + return 0; } else - return((*p->width)(p, c)); + return (*p->width)(p, c); } size_t @@ -759,15 +770,13 @@ term_strlen(const struct termp *p, const char *cp) case ASCII_HYPH: sz += cond_width(p, '-', &skip); cp++; - /* FALLTHROUGH */ - case ASCII_BREAK: break; default: break; } } - return(sz); + return sz; } int @@ -799,7 +808,6 @@ term_vspan(const struct termp *p, const struct roffsu r = su->scale / 12.0; break; case SCALE_EN: - /* FALLTHROUGH */ case SCALE_EM: r = su->scale * 0.6; break; @@ -808,10 +816,9 @@ term_vspan(const struct termp *p, const struct roffsu break; default: abort(); - /* NOTREACHED */ } ri = r > 0.0 ? r + 0.4995 : r - 0.4995; - return(ri < 66 ? ri : 1); + return ri < 66 ? ri : 1; } /* @@ -821,5 +828,5 @@ int term_hspan(const struct termp *p, const struct roffsu *su) { - return((*p->hspan)(p, su)); + return (*p->hspan)(p, su); }