diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2017-06-02 19:21:23 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2017-06-02 19:21:23 +0000 |
commit | bfb452504d8b3a8d83033a92009dcdba6370788c (patch) | |
tree | 8f12de603ba3eae6da0c83f0cac8c59ede05373a /term.c | |
parent | 341cc10aaf00ff009f89041f23ec4e6e6519285e (diff) | |
download | mandoc-bfb452504d8b3a8d83033a92009dcdba6370788c.tar.gz |
Partial implementation of \h (horizontal line drawing function).
A full implementation would require access to output device properties
and state variables (both only available after the main parser has
finalized the parse tree) before numerical expansions in the roff
preprocessor (i.e., before the main parser is even started).
Not trying to pull that stunt right now because the static-width
implementation committed here is sufficient for tcl-style manual pages
and already more complicated than i would have suspected.
Diffstat (limited to 'term.c')
-rw-r--r-- | term.c | 58 |
1 files changed, 57 insertions, 1 deletions
@@ -404,7 +404,7 @@ term_word(struct termp *p, const char *word) 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)) { @@ -510,6 +510,62 @@ term_word(struct termp *p, const char *word) } } 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; |