From 7d063611b969f452817ccde2096cc19404ce4413 Mon Sep 17 00:00:00 2001 From: schwarze Date: Tue, 10 Aug 2021 12:36:42 +0000 Subject: [PATCH] Support two-character font names (BI, CW, CR, CB, CI) in the tbl(7) layout font modifier. Get rid of the TBL_CELL_BOLD and TBL_CELL_ITALIC flags and use the usual ESCAPE_FONT* enum mandoc_esc members from mandoc.h instead, which simplifies and unifies some code. While here, also support CB and CI in roff(7) \f escape sequences and in roff(7) .ft requests for all output modes. Using those is certainly not recommended because portability is limited even with groff, but supporting them makes some existing third-party manual pages look better, in particular in HTML output mode. Bug-compatible with groff as far as i'm aware, except that i consider font names starting with the '\n' (ASCII 0x0a line feed) character so insane that i decided to not support them. Missing feature reported by nabijaczleweli dot xyz in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=992002. I used none of the code from the initial patch submitted by nabijaczleweli, but some of their ideas. Final patch tested by them, too. --- regress/usr.bin/mandoc/roff/esc/f.out_html | 2 +- .../usr.bin/mandoc/roff/ft/badargs.out_html | 7 ++- regress/usr.bin/mandoc/tbl/mod/Makefile | 11 ++-- regress/usr.bin/mandoc/tbl/mod/badfont.in | 12 ++-- .../usr.bin/mandoc/tbl/mod/badfont.out_ascii | 13 +++-- .../usr.bin/mandoc/tbl/mod/badfont.out_lint | 5 +- regress/usr.bin/mandoc/tbl/mod/font-eol.in | 13 +++++ .../usr.bin/mandoc/tbl/mod/font-eol.out_ascii | 13 +++++ .../usr.bin/mandoc/tbl/mod/font-eol.out_lint | 1 + regress/usr.bin/mandoc/tbl/mod/font.out_lint | 1 - share/man/man7/tbl.7 | 9 +-- usr.bin/mandoc/html.c | 22 ++++++-- usr.bin/mandoc/man_validate.c | 6 +- usr.bin/mandoc/mandoc.c | 10 ++-- usr.bin/mandoc/mandoc.h | 6 +- usr.bin/mandoc/mdoc_markdown.c | 6 +- usr.bin/mandoc/out.c | 4 +- usr.bin/mandoc/roff.c | 6 +- usr.bin/mandoc/roff_term.c | 6 +- usr.bin/mandoc/tbl.h | 7 +-- usr.bin/mandoc/tbl_data.c | 3 +- usr.bin/mandoc/tbl_html.c | 7 +-- usr.bin/mandoc/tbl_layout.c | 56 +++++++++---------- usr.bin/mandoc/tbl_term.c | 26 +++++++-- usr.bin/mandoc/term.c | 6 +- usr.bin/mandoc/tree.c | 26 +++++++-- 26 files changed, 185 insertions(+), 99 deletions(-) create mode 100644 regress/usr.bin/mandoc/tbl/mod/font-eol.in create mode 100644 regress/usr.bin/mandoc/tbl/mod/font-eol.out_ascii create mode 100644 regress/usr.bin/mandoc/tbl/mod/font-eol.out_lint diff --git a/regress/usr.bin/mandoc/roff/esc/f.out_html b/regress/usr.bin/mandoc/roff/esc/f.out_html index 887175f66fd..30f5c7e16be 100644 --- a/regress/usr.bin/mandoc/roff/esc/f.out_html +++ b/regress/usr.bin/mandoc/roff/esc/f.out_html @@ -1,4 +1,4 @@ numbers: bolditalicbolditalicroman letters: bolditalicbackbolditalicroman multiletter: boldemptyitalicbackbolditalicroman -typewriter: romanboldromanitalicroman +typewriter: romanboldromanitalicroman diff --git a/regress/usr.bin/mandoc/roff/ft/badargs.out_html b/regress/usr.bin/mandoc/roff/ft/badargs.out_html index a332e3a2fe4..686ca47600c 100644 --- a/regress/usr.bin/mandoc/roff/ft/badargs.out_html +++ b/regress/usr.bin/mandoc/roff/ft/badargs.out_html @@ -1,6 +1,7 @@
default font italic bold italic - typeqriter roman bold - italic bold still bold italic back to - bold back to italic + typeqriter roman + bold italic + bold still bold italic back to bold back to + italic
diff --git a/regress/usr.bin/mandoc/tbl/mod/Makefile b/regress/usr.bin/mandoc/tbl/mod/Makefile index a8b6c9d4449..7bbf30e5841 100644 --- a/regress/usr.bin/mandoc/tbl/mod/Makefile +++ b/regress/usr.bin/mandoc/tbl/mod/Makefile @@ -1,15 +1,16 @@ -# $OpenBSD: Makefile,v 1.5 2017/06/27 19:51:28 schwarze Exp $ +# $OpenBSD: Makefile,v 1.6 2021/08/10 12:36:42 schwarze Exp $ -REGRESS_TARGETS = badfont expand expand-toowide font misalign spacing width -LINT_TARGETS = badfont font +REGRESS_TARGETS = badfont expand expand-toowide font font-eol +REGRESS_TARGETS += misalign spacing width +LINT_TARGETS = badfont font font-eol -# groff-1.22.3 defects: +# groff-1.22.4 defects: # - The "f" font modifier swallows a following newline character. # - When space is insufficient (on either side) for properly aligning # a number, GNU tbl(1) moves the number too much to the right, # overflowing the column, even if space would be sufficient without # left padding. -SKIP_GROFF = badfont misalign +SKIP_GROFF = font-eol misalign .include diff --git a/regress/usr.bin/mandoc/tbl/mod/badfont.in b/regress/usr.bin/mandoc/tbl/mod/badfont.in index 2a4f0d0a8e7..12303149da2 100644 --- a/regress/usr.bin/mandoc/tbl/mod/badfont.in +++ b/regress/usr.bin/mandoc/tbl/mod/badfont.in @@ -1,15 +1,17 @@ -.\" $OpenBSD: badfont.in,v 1.2 2017/07/04 14:53:27 schwarze Exp $ -.TH TBL-MOD-BADFONT 1 "February 10, 2015" +.\" $OpenBSD: badfont.in,v 1.3 2021/08/10 12:36:42 schwarze Exp $ +.TH TBL-MOD-BADFONT 1 "August 9, 2021" .SH NAME tbl-mod-badfont \- invalid font modifiers in table layouts .SH DESCRIPTION normal text .TS box tab(:); -lfB lf +lfI lfX +lfB lfIB lfI lf. lfB lfI. -bold:none -italic:none +italic:one char +bold:two chars +italic:dot bold:italic .TE diff --git a/regress/usr.bin/mandoc/tbl/mod/badfont.out_ascii b/regress/usr.bin/mandoc/tbl/mod/badfont.out_ascii index 436833303a5..4cd3bd3f2ae 100644 --- a/regress/usr.bin/mandoc/tbl/mod/badfont.out_ascii +++ b/regress/usr.bin/mandoc/tbl/mod/badfont.out_ascii @@ -6,9 +6,10 @@ NNAAMMEE DDEESSCCRRIIPPTTIIOONN normal text - +----------------+ - |bboolldd none | - |_i_t_a_l_i_c none | - |bboolldd _i_t_a_l_i_c | - +----------------+ -OpenBSD February 10, 2015 TBL-MOD-BADFONT(1) + +-------------------+ + |_i_t_a_l_i_c one char | + |bboolldd two chars | + |_i_t_a_l_i_c dot | + |bboolldd _i_t_a_l_i_c | + +-------------------+ +OpenBSD August 9, 2021 TBL-MOD-BADFONT(1) diff --git a/regress/usr.bin/mandoc/tbl/mod/badfont.out_lint b/regress/usr.bin/mandoc/tbl/mod/badfont.out_lint index c19bae82420..7884ec88a08 100644 --- a/regress/usr.bin/mandoc/tbl/mod/badfont.out_lint +++ b/regress/usr.bin/mandoc/tbl/mod/badfont.out_lint @@ -1,2 +1,3 @@ -mandoc: badfont.in:9:7: WARNING: unknown font, skipping request: TS f -mandoc: badfont.in:10:7: WARNING: unknown font, skipping request: TS f. +mandoc: badfont.in:9:7: WARNING: unknown font, skipping request: TS fX +mandoc: badfont.in:10:7: WARNING: unknown font, skipping request: TS fIB +mandoc: badfont.in:11:7: WARNING: unknown font, skipping request: TS f. diff --git a/regress/usr.bin/mandoc/tbl/mod/font-eol.in b/regress/usr.bin/mandoc/tbl/mod/font-eol.in new file mode 100644 index 00000000000..fadf66ec905 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/mod/font-eol.in @@ -0,0 +1,13 @@ +.\" $OpenBSD: font-eol.in,v 1.1 2021/08/10 12:36:42 schwarze Exp $ +.TH TBL-MOD-FONT-EOL 1 "August 9, 2021" +.SH NAME +tbl-mod-font-eol \- font modifier at eol in table layout +.SH DESCRIPTION +normal text +.TS +box tab(:); +lfB lf +lfB lfI. +bold:none +bold:italic +.TE diff --git a/regress/usr.bin/mandoc/tbl/mod/font-eol.out_ascii b/regress/usr.bin/mandoc/tbl/mod/font-eol.out_ascii new file mode 100644 index 00000000000..c87d5aba56e --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/mod/font-eol.out_ascii @@ -0,0 +1,13 @@ +TBL-MOD-FONT-EOL(1) General Commands Manual TBL-MOD-FONT-EOL(1) + +NNAAMMEE + tbl-mod-font-eol - font modifier at eol in table layout + +DDEESSCCRRIIPPTTIIOONN + normal text + + +--------------+ + |bboolldd none | + |bboolldd _i_t_a_l_i_c | + +--------------+ +OpenBSD August 9, 2021 TBL-MOD-FONT-EOL(1) diff --git a/regress/usr.bin/mandoc/tbl/mod/font-eol.out_lint b/regress/usr.bin/mandoc/tbl/mod/font-eol.out_lint new file mode 100644 index 00000000000..c7f83f3475a --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/mod/font-eol.out_lint @@ -0,0 +1 @@ +mandoc: font-eol.in:9:7: WARNING: unknown font, skipping request: TS f diff --git a/regress/usr.bin/mandoc/tbl/mod/font.out_lint b/regress/usr.bin/mandoc/tbl/mod/font.out_lint index 06046a4380e..7ddd6280e96 100644 --- a/regress/usr.bin/mandoc/tbl/mod/font.out_lint +++ b/regress/usr.bin/mandoc/tbl/mod/font.out_lint @@ -1,4 +1,3 @@ -mandoc: font.in:9:6: WARNING: unknown font, skipping request: TS fCW|ci mandoc: font.in:19:2: WARNING: tab in filled text mandoc: font.in:19:4: WARNING: tab in filled text mandoc: font.in:19:6: WARNING: tab in filled text diff --git a/share/man/man7/tbl.7 b/share/man/man7/tbl.7 index 85d39f739d8..d086be78941 100644 --- a/share/man/man7/tbl.7 +++ b/share/man/man7/tbl.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tbl.7,v 1.23 2021/03/08 03:54:48 jsg Exp $ +.\" $OpenBSD: tbl.7,v 1.24 2021/08/10 12:36:42 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2014,2015,2017,2018,2019 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: March 8 2021 $ +.Dd $Mdocdate: August 10 2021 $ .Dt TBL 7 .Os .Sh NAME @@ -178,10 +178,11 @@ of any other column also having the .Cm e modifier. .It Cm f -The next character selects the font to use for this cell. +The next one or two characters select the font to use for this cell. +One-character font names must be followed by a blank or period. See the .Xr roff 7 -manual for supported one-character font names. +manual for supported font names. .It Cm i Use an italic font for the contents of this cell. .It Cm m diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c index 3b85019005e..799d06508a4 100644 --- a/usr.bin/mandoc/html.c +++ b/usr.bin/mandoc/html.c @@ -1,7 +1,7 @@ -/* $OpenBSD: html.c,v 1.144 2021/05/22 05:49:32 anton Exp $ */ +/* $OpenBSD: html.c,v 1.145 2021/08/10 12:36:42 schwarze Exp $ */ /* - * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons + * Copyright (c) 2011-2015, 2017-2021 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 @@ -238,8 +238,10 @@ html_setfont(struct html *h, enum mandoc_esc font) case ESCAPE_FONTITALIC: case ESCAPE_FONTBOLD: case ESCAPE_FONTBI: - case ESCAPE_FONTCW: case ESCAPE_FONTROMAN: + case ESCAPE_FONTCR: + case ESCAPE_FONTCB: + case ESCAPE_FONTCI: break; case ESCAPE_FONT: font = ESCAPE_FONTROMAN; @@ -270,9 +272,17 @@ print_metaf(struct html *h) h->metaf = print_otag(h, TAG_B, ""); print_otag(h, TAG_I, ""); break; - case ESCAPE_FONTCW: + case ESCAPE_FONTCR: h->metaf = print_otag(h, TAG_SPAN, "c", "Li"); break; + case ESCAPE_FONTCB: + h->metaf = print_otag(h, TAG_SPAN, "c", "Li"); + print_otag(h, TAG_B, ""); + break; + case ESCAPE_FONTCI: + h->metaf = print_otag(h, TAG_SPAN, "c", "Li"); + print_otag(h, TAG_I, ""); + break; default: break; } @@ -501,8 +511,10 @@ print_encode(struct html *h, const char *p, const char *pend, int norecurse) case ESCAPE_FONTBOLD: case ESCAPE_FONTITALIC: case ESCAPE_FONTBI: - case ESCAPE_FONTCW: case ESCAPE_FONTROMAN: + case ESCAPE_FONTCR: + case ESCAPE_FONTCB: + case ESCAPE_FONTCI: if (0 == norecurse) { h->flags |= HTML_NOSPACE; if (html_setfont(h, esc)) diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index fef89095243..32cb55a301f 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_validate.c,v 1.125 2020/10/30 13:24:26 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.126 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2010, 2012-2020 Ingo Schwarze * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons @@ -237,7 +237,9 @@ check_tag(struct roff_node *n, struct roff_node *nt) case ESCAPE_FONTITALIC: case ESCAPE_FONTBI: case ESCAPE_FONTROMAN: - case ESCAPE_FONTCW: + case ESCAPE_FONTCR: + case ESCAPE_FONTCB: + case ESCAPE_FONTCI: case ESCAPE_FONTPREV: case ESCAPE_IGNORE: break; diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index 265393d8a18..918ee255fe1 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mandoc.c,v 1.86 2020/10/24 22:52:34 schwarze Exp $ */ +/* $OpenBSD: mandoc.c,v 1.87 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons - * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze + * Copyright (c) 2011-2015, 2017-2021 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 @@ -72,12 +72,12 @@ mandoc_font(const char *cp, int sz) case 'C': switch (cp[1]) { case 'B': - return ESCAPE_FONTBOLD; + return ESCAPE_FONTCB; case 'I': - return ESCAPE_FONTITALIC; + return ESCAPE_FONTCI; case 'R': case 'W': - return ESCAPE_FONTCW; + return ESCAPE_FONTCR; default: return ESCAPE_ERROR; } diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 1aef8c2d69d..98cf7867485 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.214 2021/07/04 15:38:08 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.215 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2012-2021 Ingo Schwarze * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons @@ -291,7 +291,9 @@ enum mandoc_esc { ESCAPE_FONTITALIC, /* italic font mode */ ESCAPE_FONTBI, /* bold italic font mode */ ESCAPE_FONTROMAN, /* roman font mode */ - ESCAPE_FONTCW, /* constant width font mode */ + ESCAPE_FONTCR, /* constant width font mode */ + ESCAPE_FONTCB, /* constant width bold font mode */ + ESCAPE_FONTCI, /* constant width italic font mode */ ESCAPE_FONTPREV, /* previous font mode */ ESCAPE_NUMBERED, /* a numbered glyph */ ESCAPE_UNICODE, /* a unicode codepoint */ diff --git a/usr.bin/mandoc/mdoc_markdown.c b/usr.bin/mandoc/mdoc_markdown.c index e0572cb89b2..005a38315cb 100644 --- a/usr.bin/mandoc/mdoc_markdown.c +++ b/usr.bin/mandoc/mdoc_markdown.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_markdown.c,v 1.35 2020/04/03 11:34:19 schwarze Exp $ */ +/* $OpenBSD: mdoc_markdown.c,v 1.36 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2017, 2018, 2020 Ingo Schwarze * @@ -601,16 +601,18 @@ md_word(const char *s) md_rawword("markdown"); continue; case ESCAPE_FONTBOLD: + case ESCAPE_FONTCB: nextfont = "**"; break; case ESCAPE_FONTITALIC: + case ESCAPE_FONTCI: nextfont = "*"; break; case ESCAPE_FONTBI: nextfont = "***"; break; case ESCAPE_FONT: - case ESCAPE_FONTCW: + case ESCAPE_FONTCR: case ESCAPE_FONTROMAN: nextfont = ""; break; diff --git a/usr.bin/mandoc/out.c b/usr.bin/mandoc/out.c index 7cc5702b0d4..b82200d1e6f 100644 --- a/usr.bin/mandoc/out.c +++ b/usr.bin/mandoc/out.c @@ -1,4 +1,4 @@ -/* $OpenBSD: out.c,v 1.51 2019/12/31 22:49:17 schwarze Exp $ */ +/* $OpenBSD: out.c,v 1.52 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011,2014,2015,2017,2018 Ingo Schwarze @@ -20,11 +20,13 @@ #include #include #include +#include #include #include #include #include "mandoc_aux.h" +#include "mandoc.h" #include "tbl.h" #include "out.h" diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 8518d1901b1..f318444b7fa 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.249 2021/06/27 17:57:13 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.250 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2010-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons @@ -3665,7 +3665,9 @@ roff_char(ROFF_ARGS) case ESCAPE_FONTITALIC: case ESCAPE_FONTBOLD: case ESCAPE_FONTBI: - case ESCAPE_FONTCW: + case ESCAPE_FONTCR: + case ESCAPE_FONTCB: + case ESCAPE_FONTCI: case ESCAPE_FONTPREV: font++; break; diff --git a/usr.bin/mandoc/roff_term.c b/usr.bin/mandoc/roff_term.c index 069206a8768..a9eca43a1ce 100644 --- a/usr.bin/mandoc/roff_term.c +++ b/usr.bin/mandoc/roff_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff_term.c,v 1.21 2020/09/03 20:33:20 schwarze Exp $ */ +/* $OpenBSD: roff_term.c,v 1.22 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2010,2014,2015,2017-2020 Ingo Schwarze * @@ -110,9 +110,11 @@ roff_term_pre_ft(ROFF_TERM_ARGS) cp = n->child->string; switch (mandoc_font(cp, (int)strlen(cp))) { case ESCAPE_FONTBOLD: + case ESCAPE_FONTCB: term_fontrepl(p, TERMFONT_BOLD); break; case ESCAPE_FONTITALIC: + case ESCAPE_FONTCI: term_fontrepl(p, TERMFONT_UNDER); break; case ESCAPE_FONTBI: @@ -122,7 +124,7 @@ roff_term_pre_ft(ROFF_TERM_ARGS) term_fontlast(p); break; case ESCAPE_FONTROMAN: - case ESCAPE_FONTCW: + case ESCAPE_FONTCR: term_fontrepl(p, TERMFONT_NONE); break; default: diff --git a/usr.bin/mandoc/tbl.h b/usr.bin/mandoc/tbl.h index 2e77ac108be..9880d40d81a 100644 --- a/usr.bin/mandoc/tbl.h +++ b/usr.bin/mandoc/tbl.h @@ -1,7 +1,7 @@ -/* $OpenBSD: tbl.h,v 1.5 2018/12/12 21:54:30 schwarze Exp $ */ +/* $OpenBSD: tbl.h,v 1.6 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze + * Copyright (c) 2014,2015,2017,2018,2021 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 @@ -57,14 +57,13 @@ struct tbl_cell { int vert; /* Width of subsequent vertical line. */ int col; /* Column number, starting from 0. */ int flags; -#define TBL_CELL_BOLD (1 << 0) /* b, B, fB */ -#define TBL_CELL_ITALIC (1 << 1) /* i, I, fI */ #define TBL_CELL_TALIGN (1 << 2) /* t, T */ #define TBL_CELL_UP (1 << 3) /* u, U */ #define TBL_CELL_BALIGN (1 << 4) /* d, D */ #define TBL_CELL_WIGN (1 << 5) /* z, Z */ #define TBL_CELL_EQUAL (1 << 6) /* e, E */ #define TBL_CELL_WMAX (1 << 7) /* x, X */ + enum mandoc_esc font; enum tbl_cellt pos; }; diff --git a/usr.bin/mandoc/tbl_data.c b/usr.bin/mandoc/tbl_data.c index 93039de8aa8..2cfea257102 100644 --- a/usr.bin/mandoc/tbl_data.c +++ b/usr.bin/mandoc/tbl_data.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_data.c,v 1.42 2021/05/18 13:22:37 schwarze Exp $ */ +/* $OpenBSD: tbl_data.c,v 1.43 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011,2015,2017-2019,2021 Ingo Schwarze @@ -76,6 +76,7 @@ getdata(struct tbl_node *tbl, struct tbl_span *dp, if (dp->layout->last->col + 1 < dp->opts->cols) { cp = mandoc_calloc(1, sizeof(*cp)); cp->pos = TBL_CELL_LEFT; + cp->font = ESCAPE_FONTROMAN; cp->spacing = SIZE_MAX; dp->layout->last->next = cp; cp->col = dp->layout->last->col + 1; diff --git a/usr.bin/mandoc/tbl_html.c b/usr.bin/mandoc/tbl_html.c index 4dda78a49c9..d92a09182e2 100644 --- a/usr.bin/mandoc/tbl_html.c +++ b/usr.bin/mandoc/tbl_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_html.c,v 1.30 2021/05/16 23:16:22 schwarze Exp $ */ +/* $OpenBSD: tbl_html.c,v 1.31 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2014,2015,2017,2018,2021 Ingo Schwarze @@ -241,10 +241,7 @@ print_tbl(struct html *h, const struct tbl_span *sp) "border-right-style", rborder); if (dp->string != NULL) { save_font = h->metac; - if (dp->layout->flags & TBL_CELL_BOLD) - html_setfont(h, ESCAPE_FONTBOLD); - else if (dp->layout->flags & TBL_CELL_ITALIC) - html_setfont(h, ESCAPE_FONTITALIC); + html_setfont(h, dp->layout->font); if (dp->layout->pos == TBL_CELL_LONG) print_text(h, "\\[u2003]"); /* em space */ print_text(h, dp->string); diff --git a/usr.bin/mandoc/tbl_layout.c b/usr.bin/mandoc/tbl_layout.c index d7ecf3b2eb9..020a3b843ba 100644 --- a/usr.bin/mandoc/tbl_layout.c +++ b/usr.bin/mandoc/tbl_layout.c @@ -1,7 +1,8 @@ -/* $OpenBSD: tbl_layout.c,v 1.36 2020/09/01 18:24:10 schwarze Exp $ */ +/* $OpenBSD: tbl_layout.c,v 1.37 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2012, 2014, 2015, 2017 Ingo Schwarze + * Copyright (c) 2012, 2014, 2015, 2017, 2020, 2021 + * 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 @@ -65,6 +66,8 @@ mods(struct tbl_node *tbl, struct tbl_cell *cp, char *endptr; unsigned long spacing; size_t sz; + int isz; + enum mandoc_esc fontesc; mod: while (p[*pos] == ' ' || p[*pos] == '\t') @@ -103,7 +106,7 @@ mod: switch (tolower((unsigned char)p[(*pos)++])) { case 'b': - cp->flags |= TBL_CELL_BOLD; + cp->font = ESCAPE_FONTBOLD; goto mod; case 'd': cp->flags |= TBL_CELL_BALIGN; @@ -114,7 +117,7 @@ mod: case 'f': break; case 'i': - cp->flags |= TBL_CELL_ITALIC; + cp->font = ESCAPE_FONTITALIC; goto mod; case 'm': mandoc_msg(MANDOCERR_TBLLAYOUT_MOD, ln, *pos, "m"); @@ -168,40 +171,34 @@ mod: goto mod; } + while (p[*pos] == ' ' || p[*pos] == '\t') + (*pos)++; + /* Ignore parenthised font names for now. */ if (p[*pos] == '(') goto mod; - /* Support only one-character font-names for now. */ - - if (p[*pos] == '\0' || (p[*pos + 1] != ' ' && p[*pos + 1] != '.')) { + isz = 0; + if (p[*pos] != '\0') + isz++; + if (strchr(" \t.", p[*pos + isz]) == NULL) + isz++; + + fontesc = mandoc_font(p + *pos, isz); + + switch (fontesc) { + case ESCAPE_FONTPREV: + case ESCAPE_ERROR: mandoc_msg(MANDOCERR_FT_BAD, ln, *pos, "TS %s", p + *pos - 1); - if (p[*pos] != '\0') - (*pos)++; - if (p[*pos] != '\0') - (*pos)++; - goto mod; - } - - switch (p[(*pos)++]) { - case '3': - case 'B': - cp->flags |= TBL_CELL_BOLD; - goto mod; - case '2': - case 'I': - cp->flags |= TBL_CELL_ITALIC; - goto mod; - case '1': - case 'R': - goto mod; + break; default: - mandoc_msg(MANDOCERR_FT_BAD, - ln, *pos - 1, "TS f%c", p[*pos - 1]); - goto mod; + cp->font = fontesc; + break; } + *pos += isz; + goto mod; } static void @@ -360,6 +357,7 @@ cell_alloc(struct tbl_node *tbl, struct tbl_row *rp, enum tbl_cellt pos) p = mandoc_calloc(1, sizeof(*p)); p->spacing = SIZE_MAX; + p->font = ESCAPE_FONTROMAN; p->pos = pos; if ((pp = rp->last) != NULL) { diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c index 8f2d67c29d3..33504262e45 100644 --- a/usr.bin/mandoc/tbl_term.c +++ b/usr.bin/mandoc/tbl_term.c @@ -1,7 +1,7 @@ -/* $OpenBSD: tbl_term.c,v 1.62 2020/10/25 18:21:07 schwarze Exp $ */ +/* $OpenBSD: tbl_term.c,v 1.63 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons - * Copyright (c) 2011-2020 Ingo Schwarze + * Copyright (c) 2011-2021 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 @@ -921,10 +921,24 @@ tbl_word(struct termp *tp, const struct tbl_dat *dp) int prev_font; prev_font = tp->fonti; - if (dp->layout->flags & TBL_CELL_BOLD) - term_fontpush(tp, TERMFONT_BOLD); - else if (dp->layout->flags & TBL_CELL_ITALIC) - term_fontpush(tp, TERMFONT_UNDER); + switch (dp->layout->font) { + case ESCAPE_FONTBI: + term_fontpush(tp, TERMFONT_BI); + break; + case ESCAPE_FONTBOLD: + case ESCAPE_FONTCB: + term_fontpush(tp, TERMFONT_BOLD); + break; + case ESCAPE_FONTITALIC: + case ESCAPE_FONTCI: + term_fontpush(tp, TERMFONT_UNDER); + break; + case ESCAPE_FONTROMAN: + case ESCAPE_FONTCR: + break; + default: + abort(); + } term_word(tp, dp->string); diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index a3a6c89b340..219c6db7509 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.142 2020/09/02 16:36:48 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.143 2021/08/10 12:36:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2020 Ingo Schwarze @@ -587,16 +587,18 @@ term_word(struct termp *p, const char *word) uc = *seq; break; case ESCAPE_FONTBOLD: + case ESCAPE_FONTCB: term_fontrepl(p, TERMFONT_BOLD); continue; case ESCAPE_FONTITALIC: + case ESCAPE_FONTCI: term_fontrepl(p, TERMFONT_UNDER); continue; case ESCAPE_FONTBI: term_fontrepl(p, TERMFONT_BI); continue; case ESCAPE_FONT: - case ESCAPE_FONTCW: + case ESCAPE_FONTCR: case ESCAPE_FONTROMAN: term_fontrepl(p, TERMFONT_NONE); continue; diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c index 0125ebd42da..8da9c7a38e8 100644 --- a/usr.bin/mandoc/tree.c +++ b/usr.bin/mandoc/tree.c @@ -1,7 +1,7 @@ -/* $OpenBSD: tree.c,v 1.56 2020/04/08 11:54:14 schwarze Exp $ */ +/* $OpenBSD: tree.c,v 1.57 2021/08/10 12:36:42 schwarze Exp $ */ /* - * Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons + * Copyright (c) 2013-2015, 2017-2021 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 @@ -469,10 +469,28 @@ print_span(const struct tbl_span *sp, int indent) else { printf("%d", cp->col); print_cellt(dp->layout->pos); - if (cp->flags & TBL_CELL_BOLD) + switch (cp->font) { + case ESCAPE_FONTBOLD: putchar('b'); - if (cp->flags & TBL_CELL_ITALIC) + break; + case ESCAPE_FONTITALIC: putchar('i'); + break; + case ESCAPE_FONTBI: + fputs("bi", stdout); + break; + case ESCAPE_FONTCR: + putchar('c'); + break; + case ESCAPE_FONTCB: + fputs("cb", stdout); + break; + case ESCAPE_FONTCI: + fputs("ci", stdout); + break; + default: + abort(); + } if (cp->flags & TBL_CELL_TALIGN) putchar('t'); if (cp->flags & TBL_CELL_UP) -- 2.20.1