tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: tech@mandoc.bsd.lv
Cc: 992002@bugs.debian.org
Subject: [PATCH][Debian#992002] tbl: allow two-character fonts and format fonts in -Thtml
Date: Sun, 8 Aug 2021 15:24:53 +0200	[thread overview]
Message-ID: <20210808132452.bekkztprjqoup3pa@tarta.nabijaczleweli.xyz> (raw)
In-Reply-To: <CANnVG6k_czNfH5qNt9N3oOFF+v2i0eNfF92GO5vVK1sad9TRTw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6342 bytes --]

Hi!

tbl's -Thtml ignores font requests; additionally, the tbl f-request
parser only allows single-character fonts. Cf. the Debian bug
(http://bugs.debian.org/992002) for additional context.

Please consider the following patch.
наб

---
With this patch, the following document:
-- >8 --
.Dd
.Dt V 1
.Os
.
\fBtext\fItext\f(BItext\f(CRtext\f(CBtext\f(CItext\fR
.Pp
.TS
lfB lfI lfBI lb li lbi lfCR lfCB lfCI .
text	text	text	text	text	text	text	text	text
.TE
-- >8 --

Renders to a teletype with the expected fonts:
  b, ul, bul;  b, ul, bul;  normal, b, ul

-Thtml -Ofragment yields, as expected:
-- >8 --
<table class="head">
  <tr>
    <td class="head-ltitle">V(1)</td>
    <td class="head-vol">General Commands Manual</td>
    <td class="head-rtitle">V(1)</td>
  </tr>
</table>
<div class="manual-text"><b>text</b><i>text</i><b><i>text</i></b><span class="Li">text</span><b>text</b><i>text</i>
<p class="Pp"></p>
<table class="tbl">
  <tr>
    <td><b>text</b></td>
    <td><i>text</i></td>
    <td><b><i>text</i></b></td>
    <td><b>text</b></td>
    <td><i>text</i></td>
    <td><b><i>text</i></b></td>
    <td><span class="Li">text</span></td>
    <td><b>text</b></td>
    <td><i>text</i></td>
  </tr>
</table>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">August 8, 2021</td>
    <td class="foot-os">Debian</td>
  </tr>
</table>
-- >8 --

--- mdocml-1.14.5.orig/tbl.7
+++ mdocml-1.14.5/tbl.7
@@ -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 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
--- mdocml-1.14.5.orig/tbl.h
+++ mdocml-1.14.5/tbl.h
@@ -59,12 +59,13 @@ struct	tbl_cell {
 	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 */
+#define	TBL_CELL_FONTCW	 (1 << 2)   /* fC[RBI] */
+#define	TBL_CELL_TALIGN	 (1 << 3)   /* t, T */
+#define	TBL_CELL_UP	 (1 << 4)   /* u, U */
+#define	TBL_CELL_BALIGN	 (1 << 5)   /* d, D */
+#define	TBL_CELL_WIGN	 (1 << 6)   /* z, Z */
+#define	TBL_CELL_EQUAL	 (1 << 7)   /* e, E */
+#define	TBL_CELL_WMAX	 (1 << 8)   /* x, X */
 	enum tbl_cellt	  pos;
 };
 
--- mdocml-1.14.5.orig/tbl_html.c
+++ mdocml-1.14.5/tbl_html.c
@@ -25,6 +25,7 @@
 #include <string.h>
 
 #include "mandoc.h"
+#include "mandoc_aux.h"
 #include "tbl.h"
 #include "out.h"
 #include "html.h"
@@ -218,6 +219,7 @@ print_tbl(struct html *h, const struct t
 		else
 			valign = NULL;
 
+		int flags = cp->flags;
 		for (i = dp->hspans; i > 0; i--)
 			cp = cp->next;
 		switch (cp->vert) {
@@ -239,8 +241,36 @@ print_tbl(struct html *h, const struct t
 		    "vertical-align", valign,
 		    "text-align", halign,
 		    "border-right-style", rborder);
-		if (dp->string != NULL)
-			print_text(h, dp->string);
+		if (dp->string != NULL) {
+			const char *font = NULL;
+			switch (flags & (TBL_CELL_BOLD | TBL_CELL_ITALIC | TBL_CELL_FONTCW)) {
+				case TBL_CELL_BOLD:
+					font = "\\fB";
+					break;
+				case TBL_CELL_ITALIC:
+					font = "\\fI";
+					break;
+				case TBL_CELL_BOLD | TBL_CELL_ITALIC:
+					font = "\\f(BI";
+					break;
+				case TBL_CELL_FONTCW:
+					font = "\\f(CR";
+					break;
+				case TBL_CELL_FONTCW | TBL_CELL_BOLD:
+					font = "\\f(CB";
+					break;
+				case TBL_CELL_FONTCW | TBL_CELL_ITALIC:
+					font = "\\f(CI";
+					break;
+			}
+			if (font) {
+				char *str;
+				mandoc_asprintf(&str, "%s%s\\fP", font, dp->string);
+				print_text(h, str);
+				free(str);
+			} else
+				print_text(h, dp->string);
+		}
 	}
 
 	print_tagq(h, tt);
--- mdocml-1.14.5.orig/tbl_layout.c
+++ mdocml-1.14.5/tbl_layout.c
@@ -170,9 +170,7 @@ mod:
 	if (p[*pos] == '(')
 		goto mod;
 
-	/* Support only one-character font-names for now. */
-
-	if (p[*pos] == '\0' || (p[*pos + 1] != ' ' && p[*pos + 1] != '.')) {
+	if (p[*pos] == '\0' || (!isalnum(p[*pos + 1]) && p[*pos + 1] != ' ' && p[*pos + 1] != '.')) {
 		mandoc_msg(MANDOCERR_FT_BAD,
 		    ln, *pos, "TS %s", p + *pos - 1);
 		if (p[*pos] != '\0')
@@ -182,23 +180,27 @@ mod:
 		goto mod;
 	}
 
-	switch (p[(*pos)++]) {
-	case '3':
-	case 'B':
+	char fn[3] = {'\0'}, *fp = fn;
+	fn[0] = p[(*pos)++];
+	fn[1] = p[*pos] == ' ' || p[*pos] == '.' ? '\0' : p[(*pos)++];
+
+refont:
+	if (!strcmp(fp, "3") || !strcmp(fp, "B"))
 		cp->flags |= TBL_CELL_BOLD;
-		goto mod;
-	case '2':
-	case 'I':
+	else if (!strcmp(fp, "2") || !strcmp(fp, "I"))
 		cp->flags |= TBL_CELL_ITALIC;
-		goto mod;
-	case '1':
-	case 'R':
-		goto mod;
-	default:
+	else if (!strcmp(fp, "1") || !strcmp(fp, "R"))
+		;
+	else if (!strcmp(fp, "BI"))
+		cp->flags |= TBL_CELL_BOLD | TBL_CELL_ITALIC;
+	else if (fp[0] == 'C' && fp[1]) {
+		cp->flags |= TBL_CELL_FONTCW;
+		++fp;
+		goto refont;
+	} else
 		mandoc_msg(MANDOCERR_FT_BAD,
-		    ln, *pos - 1, "TS f%c", p[*pos - 1]);
-		goto mod;
-	}
+		    ln, *pos - strlen(fn), "TS f%s", fn);
+	goto mod;
 }
 
 static void
--- mdocml-1.14.5.orig/tbl_term.c
+++ mdocml-1.14.5/tbl_term.c
@@ -922,10 +922,17 @@ tbl_word(struct termp *tp, const struct
 	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->flags & (TBL_CELL_BOLD | TBL_CELL_ITALIC)) {
+		case TBL_CELL_BOLD | TBL_CELL_ITALIC:
+			term_fontpush(tp, TERMFONT_BI);
+			break;
+		case TBL_CELL_BOLD:
+			term_fontpush(tp, TERMFONT_BOLD);
+			break;
+		case TBL_CELL_ITALIC:
+			term_fontpush(tp, TERMFONT_UNDER);
+			break;
+	}
 
 	term_word(tp, dp->string);
 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

       reply	other threads:[~2021-08-08 17:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210808111135.zisbfzlqqdsq35om@tarta.nabijaczleweli.xyz>
     [not found] ` <handler.992002.B.162842110127724.ack@bugs.debian.org>
     [not found]   ` <20210808124919.hevbw4gv6pis72pq@tarta.nabijaczleweli.xyz>
     [not found]     ` <CANnVG6k_czNfH5qNt9N3oOFF+v2i0eNfF92GO5vVK1sad9TRTw@mail.gmail.com>
2021-08-08 13:24       ` наб [this message]
2021-08-09  8:58         ` Ingo Schwarze
2021-08-09 23:08           ` наб
2021-08-10 13:43             ` Ingo Schwarze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210808132452.bekkztprjqoup3pa@tarta.nabijaczleweli.xyz \
    --to=nabijaczleweli@nabijaczleweli.xyz \
    --cc=992002@bugs.debian.org \
    --cc=tech@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).