[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 22/24: [mdoc]: Support `HF` string.
From: |
G. Branden Robinson |
Subject: |
[groff] 22/24: [mdoc]: Support `HF` string. |
Date: |
Tue, 27 Dec 2022 04:22:46 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 78922cf9f39f6ebcd3a80aaab9c3a2931b8b0ad4
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Dec 27 02:46:19 2022 -0600
[mdoc]: Support `HF` string.
* tmac/doc.tmac (initialization): Add logic supporting `HF` string just
as our man(7) implementation does. If the font name ends with `B` (as
the default does), set `doc-remap-I-style-in-headings` register and
extract font family, which can be empty (as is the default).
* tmac/mdoc/doc-common (Sh, Ss): If `doc-remap-I-style-in-headings`
register set, perform (and unwind) font remapping of italic to
bold-italic face.
* tmac/mdoc/doc-ditroff:
* tmac/mdoc/doc-nroff: Define `doc-Sh-font` in terms of `HF`.
* tmac/tests/doc_heading-font-remapping-works.sh: Test it.
* tmac/tmac.am (tmac_TESTS): Run test.
* tmac/groff_mdoc.7.man (Options): Document it.
* NEWS: Update item.
Fixes last part of <https://savannah.gnu.org/bugs/?63046>.
---
ChangeLog | 23 +++++++++++
NEWS | 3 +-
tmac/doc.tmac | 19 ++++++++-
tmac/groff_mdoc.7.man | 24 +++++++-----
tmac/mdoc/doc-common | 12 ++++++
tmac/mdoc/doc-ditroff | 2 +-
tmac/mdoc/doc-nroff | 2 +-
tmac/tests/doc_heading-font-remapping-works.sh | 53 ++++++++++++++++++++++++++
tmac/tmac.am | 1 +
9 files changed, 126 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1ed6de1fd..75b3b129b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2022-12-27 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [mdoc]: Support `HF` string.
+
+ * tmac/doc.tmac (initialization): Add logic supporting `HF`
+ string just as our man(7) implementation does. If the font name
+ ends with `B` (as the default does), set
+ `doc-remap-I-style-in-headings` register and extract font
+ family, which can be empty (as is the default).
+ * tmac/mdoc/doc-common (Sh, Ss): If
+ `doc-remap-I-style-in-headings` register set, perform (and
+ unwind) font remapping of italic to bold-italic face.
+ * tmac/mdoc/doc-ditroff:
+ * tmac/mdoc/doc-nroff: Define `doc-Sh-font` in terms of `HF`.
+
+ * tmac/tests/doc_heading-font-remapping-works.sh: Test it.
+ * tmac/tmac.am (tmac_TESTS): Run test.
+
+ * tmac/groff_mdoc.7.man (Options): Document it.
+ * NEWS: Update item.
+
+ Fixes last part of <https://savannah.gnu.org/bugs/?63046>.
+
2022-12-26 G. Branden Robinson <g.branden.robinson@gmail.com>
[tmac]: Revise "fallback" character definitions in several
diff --git a/NEWS b/NEWS
index 808223202..72a8674f5 100644
--- a/NEWS
+++ b/NEWS
@@ -321,7 +321,8 @@ o The groff_man(7) man page documenting the groff
implementation of the
reader who is not an expert in *roff systems or in writing man pages.
o The doc (mdoc) macro package now honors the `C`, `FT`, `HY`, `IN`,
- `P`, `SN`, and `X` registers as the an (man) package does.
+ `P`, `SN`, and `X` registers and `HF` string as the an (man) package
+ does.
o The doc (mdoc) macro package now renders man page (sub)section cross
references cited with the `Sx` macro by quoting them instead of
diff --git a/tmac/doc.tmac b/tmac/doc.tmac
index 587cef1ee..5bfa65e34 100644
--- a/tmac/doc.tmac
+++ b/tmac/doc.tmac
@@ -155,7 +155,24 @@
. \}
.\}
.
-.\" TODO: Implement HF string.
+.\" (sub)section heading font
+.if !d HF \
+. ds HF B\"
+.
+.\" If HF is a bold style, use bold italics for italics in headings.
+.ds doc-heading-style \*[HF]\"
+.substring doc-heading-style -1 -1
+.ds doc-heading-family \" empty
+.length doc-HF-length \*[HF]
+.if (\n[doc-HF-length] > 1) \{\
+. as doc-heading-family \*[HF]\"
+. substring doc-heading-family 0 -2
+.\}
+.if '\*[doc-heading-style]'B' \
+. if F \*[doc-heading-family]BI \
+. nr doc-remap-I-style-in-headings 1
+.rr doc-HF-length
+.rm doc-heading-style
.
.\" \n[HY] is recognized for groff_man(7) compatibility, particuarly via
.\" andoc.tmac and man(1); see \n[doc-hyphen-flags] in doc-common.
diff --git a/tmac/groff_mdoc.7.man b/tmac/groff_mdoc.7.man
index 2f525fe0c..cad71cb0f 100644
--- a/tmac/groff_mdoc.7.man
+++ b/tmac/groff_mdoc.7.man
@@ -5052,6 +5052,21 @@ The default is \-0.5i.
.
.
.Pp
+The
+.Ql HF
+string sets
+the font used for section and subsection headings;
+the default is
+.Ql B
+(bold style of the default family).
+.
+Any valid argument to
+.Xr groff 7 's
+.Ql ft
+request may be used.
+.
+.
+.Pp
Normally,
automatic hyphenation is enabled using a mode appropriate to the
.Xr groff
@@ -5135,15 +5150,6 @@ request in
.Xr groff @MAN7EXT@ ) .
.
.
-.Pp
-The
-.Ql HF
-string
-is reserved for potential future compatibility with
-.Xr groff_man @MAN7EXT@
-page rendering options.
-.
-.
.br
.ne 4v
.Sh Files
diff --git a/tmac/mdoc/doc-common b/tmac/mdoc/doc-common
index a00a96943..e059c491e 100644
--- a/tmac/mdoc/doc-common
+++ b/tmac/mdoc/doc-common
@@ -1382,6 +1382,9 @@
. el \
. nr doc-in-name-section 0
.
+. if \n[doc-remap-I-style-in-headings] \
+. ftr I \*[doc-heading-family]BI
+.
. ie \n[doc-arg-count] \{\
. \" we only allow 'Sh' within 'Sh'; it will change the font back to
. \" 'doc-Sh-font'
@@ -1485,6 +1488,9 @@
. doc-check-depth
. \}
.
+. if \n[doc-remap-I-style-in-headings] \
+. ftr I I
+.
. \" Don't let doc-print-recursive force caps on anything else.
. nr doc-do-capitalize 0
..
@@ -1505,6 +1511,9 @@
.
.eo
.de Ss
+. if \n[doc-remap-I-style-in-headings] \
+. ftr I \*[doc-heading-family]BI
+.
. ie \n[doc-arg-count] \{\
. \" we only allow 'Ss' within 'Ss'; it will change the font back to
. \" 'doc-Sh-font'
@@ -1562,6 +1571,9 @@
.
. doc-check-depth
. \}
+.
+. if \n[doc-remap-I-style-in-headings] \
+. ftr I I
..
.ec
.
diff --git a/tmac/mdoc/doc-ditroff b/tmac/mdoc/doc-ditroff
index a0347256c..96cb2f725 100644
--- a/tmac/mdoc/doc-ditroff
+++ b/tmac/mdoc/doc-ditroff
@@ -71,7 +71,7 @@
.ds doc-Nm-font \f[CB]
.ds doc-No-font \f[R]
.ds doc-Pa-font \f[I]
-.ds doc-Sh-font \f[B]
+.ds doc-Sh-font \f[\*[HF]]\"
.ds doc-Sy-font \f[B]
.ds doc-Tn-font \f[R]
.ds doc-Va-font \f[I]
diff --git a/tmac/mdoc/doc-nroff b/tmac/mdoc/doc-nroff
index a23c57b3d..5167af3ea 100644
--- a/tmac/mdoc/doc-nroff
+++ b/tmac/mdoc/doc-nroff
@@ -63,7 +63,7 @@
.ds doc-Nm-font \f[B]
.ds doc-No-font \f[R]
.ds doc-Pa-font \f[I]
-.ds doc-Sh-font \f[B]
+.ds doc-Sh-font \f[\*[HF]]\"
.ds doc-Sy-font \f[B]
.ds doc-Tn-font \f[R]
.ds doc-Va-font \f[I]
diff --git a/tmac/tests/doc_heading-font-remapping-works.sh
b/tmac/tests/doc_heading-font-remapping-works.sh
new file mode 100755
index 000000000..4fdd95acf
--- /dev/null
+++ b/tmac/tests/doc_heading-font-remapping-works.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+ echo ...FAILED >&2
+ fail=yes
+}
+
+# Ensure that italics in a section heading get remapped to bold italics
+# (if the heading font is bold).
+
+input='.Dd 2022-12-26
+.Dt foo 1
+.Os "groff test suite"
+.Sh Name
+.Nm foo
+.Nd frobnicate a bar
+.Sh Hacking Xr groff
+Have fun!'
+
+output=$(printf "%s\n" "$input" | "$groff" -mdoc -Tascii -Z)
+echo "$output"
+
+echo "$output" | sed -n '/tHacking/{n
+/x font 4 BI/{n
+/f4/{n
+/h/{n
+/tgroff/{n
+/n/{n
+/f1/p}}}}}}' | grep -Fqx f1
+
+# vim:set ai et sw=4 ts=4 tw=72:
diff --git a/tmac/tmac.am b/tmac/tmac.am
index 51b9de289..82cbb8bbe 100644
--- a/tmac/tmac.am
+++ b/tmac/tmac.am
@@ -201,6 +201,7 @@ tmac_TESTS = \
tmac/tests/doc_X-register-works.sh \
tmac/tests/doc_accept-mixed-case-section-headings.sh \
tmac/tests/doc_do-not-loop-infinitely-when-shortening-headers.sh \
+ tmac/tests/doc_heading-font-remapping-works.sh \
tmac/tests/doc_indents-correctly.sh \
tmac/tests/doc_output-footer-when-continuously-rendering.sh \
tmac/tests/doc_smoke-test.sh \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 22/24: [mdoc]: Support `HF` string.,
G. Branden Robinson <=