=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.256 retrieving revision 1.262 diff -u -p -r1.256 -r1.262 --- mandoc/term.c 2016/01/07 21:03:54 1.256 +++ mandoc/term.c 2017/06/02 19:21:23 1.262 @@ -1,7 +1,7 @@ -/* $Id: term.c,v 1.256 2016/01/07 21:03:54 schwarze Exp $ */ +/* $Id: term.c,v 1.262 2017/06/02 19:21:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010-2015 Ingo Schwarze + * Copyright (c) 2010-2017 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -141,8 +141,8 @@ term_flushln(struct termp *p) * subsequent tabs into a single huge set of spaces. */ ntab = 0; - while (i < p->col && '\t' == p->buf[i]) { - vend = (vis / p->tabwidth + 1) * p->tabwidth; + while (i < p->col && p->buf[i] == '\t') { + vend = term_tab_next(vis); vbl += vend - vis; vis = vend; ntab++; @@ -160,7 +160,7 @@ term_flushln(struct termp *p) if (' ' == p->buf[j] || '\t' == p->buf[j]) break; - /* Back over the the last printed character. */ + /* Back over the last printed character. */ if (8 == p->buf[j]) { assert(j); vend -= (*p->width)(p, p->buf[j - 1]); @@ -192,18 +192,21 @@ term_flushln(struct termp *p) vend -= vis; (*p->endline)(p); p->viscol = 0; - if (TERMP_BRIND & p->flags) { - vbl = p->rmargin; - vend += p->rmargin; - vend -= p->offset; - } else - vbl = p->offset; - /* use pending tabs on the new line */ + /* Use pending tabs on the new line. */ - if (0 < ntab) - vbl += ntab * p->tabwidth; + vbl = 0; + while (ntab--) + vbl = term_tab_next(vbl); + /* Re-establish indentation. */ + + if (p->flags & TERMP_BRIND) { + vbl += p->rmargin; + vend += p->rmargin - p->offset; + } else + vbl += p->offset; + /* * Remove the p->overstep width. * Again, if p->overstep is negative, @@ -397,10 +400,11 @@ term_fontpop(struct termp *p) void term_word(struct termp *p, const char *word) { + struct roffsu su; const char nbrsp[2] = { ASCII_NBRSP, 0 }; const char *seq, *cp; int sz, uc; - size_t ssz; + size_t csz, lsz, ssz; enum mandoc_esc esc; if ( ! (TERMP_NOSPACE & p->flags)) { @@ -485,6 +489,83 @@ term_word(struct termp *p, const char *word) else if (*word == '\0') p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE); continue; + case ESCAPE_HORIZ: + if (a2roffsu(seq, &su, SCALE_EM) == 0) + continue; + uc = term_hspan(p, &su) / 24; + if (uc > 0) + while (uc-- > 0) + bufferc(p, ASCII_NBRSP); + else if (p->col > (size_t)(-uc)) + p->col += uc; + else { + uc += p->col; + p->col = 0; + if (p->offset > (size_t)(-uc)) { + p->ti += uc; + p->offset += uc; + } else { + p->ti -= p->offset; + p->offset = 0; + } + } + continue; + case ESCAPE_HLINE: + if (a2roffsu(seq, &su, SCALE_EM) == 0) + continue; + uc = term_hspan(p, &su) / 24; + if (uc <= 0) { + if (p->rmargin <= p->offset) + continue; + lsz = p->rmargin - p->offset; + } else + lsz = uc; + while (sz && + strchr(" %&()*+-./0123456789:<=>", *seq)) { + seq++; + sz--; + } + if (sz && strchr("cifMmnPpuv", *seq)) { + seq++; + sz--; + } + if (sz == 0) + uc = -1; + else if (*seq == '\\') { + seq++; + esc = mandoc_escape(&seq, &cp, &sz); + switch (esc) { + case ESCAPE_UNICODE: + uc = mchars_num2uc(cp + 1, sz - 1); + break; + case ESCAPE_NUMBERED: + uc = mchars_num2char(cp, sz); + break; + case ESCAPE_SPECIAL: + uc = mchars_spec2cp(cp, sz); + break; + default: + uc = -1; + break; + } + } else + uc = *seq; + if (uc < 0x20 || (uc > 0x7E && uc < 0xA0)) + uc = '_'; + if (p->enc == TERMENC_ASCII) { + cp = ascii_uc2str(uc); + csz = term_strlen(p, cp); + ssz = strlen(cp); + } else + csz = (*p->width)(p, uc); + while (lsz >= csz) { + if (p->enc == TERMENC_ASCII) + encode(p, cp, ssz); + else + encode1(p, uc); + lsz -= csz; + } + continue; case ESCAPE_SKIPCHAR: p->flags |= TERMP_BACKAFTER; continue; @@ -504,7 +585,9 @@ term_word(struct termp *p, const char *word) } } /* Trim trailing backspace/blank pair. */ - if (p->col > 2 && p->buf[p->col - 1] == ' ') + if (p->col > 2 && + (p->buf[p->col - 1] == ' ' || + p->buf[p->col - 1] == '\t')) p->col -= 2; continue; default: @@ -568,7 +651,7 @@ encode1(struct termp *p, int c) p->fontq[p->fonti] : TERMFONT_NONE; if (p->flags & TERMP_BACKBEFORE) { - if (p->buf[p->col - 1] == ' ') + if (p->buf[p->col - 1] == ' ' || p->buf[p->col - 1] == '\t') p->col--; else p->buf[p->col++] = 8; @@ -604,8 +687,20 @@ encode(struct termp *p, const char *word, size_t sz) if (ASCII_HYPH == word[i] || isgraph((unsigned char)word[i])) encode1(p, word[i]); - else + else { p->buf[p->col++] = word[i]; + + /* + * Postpone the effect of \z while handling + * an overstrike sequence from ascii_uc2str(). + */ + + if (word[i] == '\b' && + (p->flags & TERMP_BACKBEFORE)) { + p->flags &= ~TERMP_BACKBEFORE; + p->flags |= TERMP_BACKAFTER; + } + } } }