From: schwarze Date: Thu, 1 Jun 2017 19:05:15 +0000 (+0000) Subject: Minimal implementation of the \h (horizontal motion) escape sequence. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8e935ceab83e2fb72e4e27e9ef21243319f2df5c;p=openbsd Minimal implementation of the \h (horizontal motion) escape sequence. Good enough to cope with the average DocBook insanity. --- diff --git a/regress/usr.bin/mandoc/roff/esc/h.in b/regress/usr.bin/mandoc/roff/esc/h.in index 31fbb4e2940..4bc1953e993 100644 --- a/regress/usr.bin/mandoc/roff/esc/h.in +++ b/regress/usr.bin/mandoc/roff/esc/h.in @@ -7,11 +7,11 @@ .Sh DESCRIPTION simple: >\h'0'< .br -escape only: >\h'\w'\&''< +escape only: >\h'\w'\&'M'< .br escape at the end: >\h'0+\w'\&''< .br -escape at the beginning: >\h'\w'\&'+0'< +escape at the beginning: >\h'\w'\&'M+0'< .br escape in the middle: >\h'0+\w'\&'+0'< .br diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7 index 4054e4e59bf..352da642a5a 100644 --- a/share/man/man7/roff.7 +++ b/share/man/man7/roff.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: roff.7,v 1.60 2017/05/08 15:33:43 schwarze Exp $ +.\" $OpenBSD: roff.7,v 1.61 2017/06/01 19:05:15 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons .\" Copyright (c) 2010,2011,2013-2015,2017 Ingo Schwarze @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 8 2017 $ +.Dd $Mdocdate: June 1 2017 $ .Dt ROFF 7 .Os .Sh NAME @@ -1923,9 +1923,10 @@ and .Ss \eH\(aq Ns Oo +|- Oc Ns Ar number Ns \(aq Set the height of the current font; ignored by .Xr mandoc 1 . -.Ss \eh\(aq Ns Ar number Ns \(aq -Horizontal motion; ignored by -.Xr mandoc 1 . +.Ss \eh\(aq Ns Ar width Ns \(aq +Horizontal motion relative to the current position. +The default scaling unit is +.Cm m . .Ss \ek[ Ns Ar name ] Mark horizontal input place in register; ignored by .Xr mandoc 1 . diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index 75ad6fcae30..012d6bd16bd 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.c,v 1.66 2015/11/12 22:43:30 schwarze Exp $ */ +/* $OpenBSD: mandoc.c,v 1.67 2017/06/01 19:05:15 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2011-2015 Ingo Schwarze @@ -173,7 +173,7 @@ mandoc_escape(const char **end, const char **start, int *sz) ++*end; return ESCAPE_ERROR; } - gly = ESCAPE_IGNORE; + gly = (*start)[-1] == 'h' ? ESCAPE_HORIZ : ESCAPE_IGNORE; term = **start; *start = ++*end; break; diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 00bdd948f54..7a682b17aa4 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.161 2017/06/01 15:24:41 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.162 2017/06/01 19:05:15 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -411,6 +411,7 @@ enum mandoc_esc { ESCAPE_NUMBERED, /* a numbered glyph */ ESCAPE_UNICODE, /* a unicode codepoint */ ESCAPE_NOSPACE, /* suppress space if the last on a line */ + ESCAPE_HORIZ, /* horizontal movement */ ESCAPE_SKIPCHAR, /* skip the next character */ ESCAPE_OVERSTRIKE /* overstrike all chars in the argument */ }; diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 40cd82da914..122179a2fa9 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.257 2017/05/30 16:31:25 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.258 2017/06/01 19:05:15 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -405,7 +405,8 @@ print_mdoc_node(DECL_ARGS) if (NODE_EOS & n->flags) p->flags |= TERMP_SENTENCE; - p->offset = offset; + if (n->type != ROFFT_TEXT) + p->offset = offset; p->rmargin = rmargin; } diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index 2a4a44f41fa..adc17542848 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.120 2017/05/07 17:30:58 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.121 2017/06/01 19:05:15 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -398,6 +398,7 @@ 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; @@ -486,6 +487,27 @@ 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_SKIPCHAR: p->flags |= TERMP_BACKAFTER; continue;