groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 09/10: [man]: Abbreviate the inside footer if necessary.


From: G. Branden Robinson
Subject: [groff] 09/10: [man]: Abbreviate the inside footer if necessary.
Date: Tue, 26 Oct 2021 07:36:03 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 8578254c09b9fd66cad59353caae479240037cbf
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Oct 26 16:15:32 2021 +1100

    [man]: Abbreviate the inside footer if necessary.
    
    * tmac/an.tmac (an-prepare-inner-footer): Prevent the inside footer from
      overrunning the center footer.
    
      (BT): Use new string `an-ifoot` instead of `an-extra2` in page
      footers.
    
    Fixes <https://savannah.gnu.org/bugs/?61386>.
---
 ChangeLog               | 11 +++++++++
 tmac/an.tmac            | 66 ++++++++++++++++++++++++++++++++++++++++++++++---
 tmac/groff_man.7.man.in |  7 ++++++
 3 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b7b84bd..f3e785b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2021-10-26  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       [man]: Abbreviate the inside footer if necessary.
+
+       * tmac/an.tmac (an-prepare-inner-footer): Prevent the inside
+       footer from overrunning the center footer.
+       (BT): Use new string `an-ifoot` instead of `an-extra2` in page
+       footers.
+
+       Fixes <https://savannah.gnu.org/bugs/?61386>.
+
+2021-10-26  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        Add regression test for Savannah #61386.
 
        * tmac/tests/an_inner-footer-abbreviation-works.sh: Do it.
diff --git a/tmac/an.tmac b/tmac/an.tmac
index af04be8..287983b 100644
--- a/tmac/an.tmac
+++ b/tmac/an.tmac
@@ -326,11 +326,11 @@
 .\" Write the page footer; can be redefined by man.local.
 .de1 BT
 .  ie \\n[D] \{\
-.    if o .tl '\\*[an-extra2]'\\*[an-extra1]'\\*[an-outer-footer-text]'
-.    if e .tl '\\*[an-outer-footer-text]'\\*[an-extra1]'\\*[an-extra2]'
+.    if o .tl '\\*[an-ifoot]'\\*[an-extra1]'\\*[an-outer-footer-text]'
+.    if e .tl '\\*[an-outer-footer-text]'\\*[an-extra1]'\\*[an-ifoot]'
 .  \}
 .  el \
-.    tl '\\*[an-extra2]'\\*[an-extra1]'\\*[an-outer-footer-text]'
+.    tl '\\*[an-ifoot]'\\*[an-extra1]'\\*[an-outer-footer-text]'
 ..
 .
 .\" Abbreviate the page title if it's too long for the header.  Leaves
@@ -380,6 +380,65 @@
 .  rm an-ellipsis
 ..
 .
+.\" Abbreviate the `an-extra2` string (set by .TH) if it's too long for
+.\" the footer.  By default, `an-extra2` is placed as the inner footer.
+.\" We call it `an-ifoot` here and leave it defined for .BT use.
+.\"
+.\" The method here differs from an-prepare-header, because the
+.\" (default) header is symmetrical, with `an-pageref` on both sides,
+.\" whereas the (default) footer is not.  Our approach is to chop
+.\" `an-extra1` (the default center footer) in half and ensure that the
+.\" formatted `an-ifoot` plus that is less than half the title length.
+.de an-prepare-inner-footer
+.  ds an-half-cfoot \\*[an-extra1]\"
+.  length an-half-cfoot-length \\*[an-half-cfoot]
+.  nr an-half-cfoot-length (\\n[an-half-cfoot-length] / 2u)
+.  substring an-half-cfoot 0 \\n[an-half-cfoot-length]
+.  rr an-half-cfoot-length
+.  ds an-ifoot \\*[an-extra2]\"
+.  nr an-half-title-width (\\n[.lt] / 2u)
+.  nr an-half-footer-width \\w'\\*[an-ifoot]\\*[an-half-cfoot]'
+.  \" If abbreviation is not necessary, skip the remaining work.
+.  if (\\n[an-half-footer-width] <= \\n[an-half-title-width]) .return
+.  ds an-ellipsis \|.\|.\|.\|\"
+.  \" Now divide the inner footer in half.
+.  length an-ifoot-length \\*[an-ifoot]
+.  nr an-mark1 (\\n[an-ifoot-length] / 2)
+.  nr an-mark2 (\\n[an-ifoot-length] / 2 + 1)
+.  rr an-ifoot-length
+.  ds an-ifoot-half1 \\*[an-ifoot]\"
+.  ds an-ifoot-half2 \\*[an-ifoot]\"
+.  substring an-ifoot-half1 0 \\n[an-mark1]
+.  substring an-ifoot-half2 \\n[an-mark2] -1
+.  \" Reduce the two halves until, when rejoined with each other, the
+.  \" ellipsis, and half of the center footer, they fit the half-title.
+.  nr an-half-footer-width \\w'\\*[an-ifoot-half1]\\*[an-ellipsis]\
+\\*[an-ifoot-half2]\\*[an-half-cfoot]'
+.  while (\\n[an-half-footer-width] > \\n[an-half-title-width]) \{\
+.    length an-half1-length \\*[an-ifoot-half1]
+.    length an-half2-length \\*[an-ifoot-half2]
+.    \" Give up if we'd have to trim ifoot's first or last characters.
+.    if ((\\n[an-half1-length] = 1) : (\\n[an-half2-length] = 1)) \
+.      break
+.    \" Trim a character from half1's end and half2's beginning.
+.    substring an-ifoot-half1 0 (\\n[an-half1-length] - 2)
+.    substring an-ifoot-half2 2 (\\n[an-half2-length] - 1)
+.    nr an-half-footer-width \\w'\\*[an-ifoot-half1]\\*[an-ellipsis]\
+\\*[an-ifoot-half2]\\*[an-half-cfoot]'
+.  \}
+.  ds an-ifoot \\*[an-ifoot-half1]\\*[an-ellipsis]\\*[an-ifoot-half2]\"
+.  rr an-half1-length
+.  rr an-half2-length
+.  rm an-ifoot-half1
+.  rm an-ifoot-half2
+.  rr an-mark1
+.  rr an-mark2
+.  rr an-half-footer-width
+.  rr an-half-title-width
+.  rm an-ellipsis
+.  rm an-half-cfoot
+..
+.
 .\" Prepare the header for a page of the document.
 .de1 an-header
 .  if \\n[an-suppress-header-and-footer] .return
@@ -424,6 +483,7 @@
 .      \}
 .    \}
 .  \}
+.  an-prepare-inner-footer
 .  if \\n[cR] .pl +1v
 .  BT
 .  rm an-outer-footer-text
diff --git a/tmac/groff_man.7.man.in b/tmac/groff_man.7.man.in
index 2ea676a..9a01a1d 100644
--- a/tmac/groff_man.7.man.in
+++ b/tmac/groff_man.7.man.in
@@ -408,6 +408,13 @@ there is no need to specify
 .IR header-middle ;
 the macro package will supply text for it.
 .
+.I title
+and
+.I footer-inside
+may each be abbreviated with an ellipsis if they overrun the space
+available in the header and footer,
+respectively.
+.
 For HTML output,
 headers and footers are completely suppressed.
 .



reply via email to

[Prev in Thread] Current Thread [Next in Thread]