gbranden pushed a commit to branch master
in repository groff.

commit ddba6a8295426a72c4559194ceccd911b151969e
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Apr 10 03:59:49 2025 -0500

    [troff]: Use scaling units in `break` warnings.
    
    * src/roff/troff/env.cpp (environment::possibly_break_line): Improve
      "break" warning diagnostic messages when adjustment is frustrated.  In
      troff mode, use the scaling unit configured by the `warnscale`
      request.  In nroff mode, use ens (which, since they are defined in a
      typeface-proportional manner, are not an acceptable scaling unit for
      `warnscale`).
    
    * doc/groff.texi.in (Warnings):
    * src/roff/troff/troff.1.man (Warnings): Document it.
    
    * NEWS: Update item regarding output warnings in nroff mode.
---
 ChangeLog                  | 14 ++++++++++++++
 NEWS                       |  7 ++++---
 doc/groff.texi.in          | 14 ++++++++++++++
 src/roff/troff/env.cpp     | 22 ++++++++++++++++++----
 src/roff/troff/troff.1.man | 15 +++++++++++++++
 5 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 22bf08fc3..e274d8080 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-04-10  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/env.cpp (environment::possibly_break_line):
+       Improve "break" warning diagnostic messages when adjustment is
+       frustrated.  In troff mode, use the scaling unit configured by
+       the `warnscale` request.  In nroff mode, use ens (which, since
+       they are defined in a typeface-proportional manner, are not an
+       acceptable scaling unit for `warnscale`).
+
+       * doc/groff.texi.in (Warnings):
+       * src/roff/troff/troff.1.man (Warnings): Document it.
+
+       * NEWS: Update item regarding output warnings in nroff mode.
+
 2025-04-08  G. Branden Robinson <[email protected]>
 
        [troff]: Refactor break/adjustment warning production.
diff --git a/NEWS b/NEWS
index 86cf3881d..d3db3630e 100644
--- a/NEWS
+++ b/NEWS
@@ -146,9 +146,10 @@ troff
 
 *  In nroff mode (in other words, when producing output for devices that
    claim to be terminals), the formatter now reports warning diagnostics
-   regarding certain output problems using units of lines instead of
-   inches (or the unit configured with the `warnscale` request) to
-   describe the vertical drawing position where the problem occurred.
+   regarding certain output problems using units of lines (vertically)
+   and character cells [ens] (horizontally) instead of inches (or the
+   unit configured with the `warnscale` request) to describe the
+   vertical drawing position where the problem occurred.
 
 *  The device-independent page description language produced by GNU
    troff now reports unbreakable spaces (those produced with the `\~`
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 0570e6fcd..b4e0007db 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -18118,6 +18118,20 @@ or
 adjusted such that its length was exactly equal to,
 the output line length
 @samp{\n[.l]}.
+GNU
+@command{troff} @c GNU
+reports the amount of overset or underset in the scaling unit configured
+by the
+@code{warnscale}
+request in
+@code{troff}
+mode,
+and in ens (@samp{n};
+character cells)
+in
+@code{nroff}
+mode.
+@xref{@code{troff} and @code{nroff} Modes}.
 This category is enabled by default.
 
 @item delim
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 8340b0ade..d29ad939a 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2220,6 +2220,10 @@ static bool distribute_space(node *nd, int nspaces,
   return true;
 }
 
+// from input.cpp
+extern double warn_scale;
+extern char warn_scaling_unit;
+
 void environment::possibly_break_line(bool must_break_here,
                                      bool must_adjust)
 {
@@ -2249,16 +2253,26 @@ void environment::possibly_break_line(bool 
must_break_here,
     hunits space_deficit = target_text_length - bp->width;
     // An overset line always gets a warning.
     if (space_deficit < H0)
-      output_warning(WARN_BREAK, "cannot %1 line; overset by %2 units",
+      output_warning(WARN_BREAK, "cannot %1 line; overset by %2%3",
                     (ADJUST_BOTH == adjust_mode) ? "adjust" : "break",
-                    abs(space_deficit.to_units()));
+                    in_nroff_mode
+                    ? static_cast<int>(ceil(abs(space_deficit
+                                                .to_units()
+                                       / hresolution)))
+                    : abs(space_deficit.to_units() / warn_scale),
+                    in_nroff_mode ? 'n' : warn_scaling_unit);
     // An underset line warns only if it requires adjustment but no
     // adjustable spaces exist on the line.
     else if ((ADJUST_BOTH == adjust_mode)
             && (space_deficit > H0)
             && (0 == bp->nspaces))
-      output_warning(WARN_BREAK, "cannot adjust line; underset by %1"
-                    " units", space_deficit.to_units());
+      output_warning(WARN_BREAK, "cannot adjust line; underset by %1%2",
+                    in_nroff_mode
+                    ? static_cast<int>(ceil(abs(space_deficit
+                                                .to_units()
+                                       / hresolution)))
+                    : abs(space_deficit.to_units() / warn_scale),
+                    in_nroff_mode ? 'n' : warn_scaling_unit);
     // The extra space is the amount of space to distribute among the
     // adjustable space nodes in an output line; this process occurs
     // only if adjustment is enabled.  We may however want to synthesize
diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man
index 3fcb850a2..378044244 100644
--- a/src/roff/troff/troff.1.man
+++ b/src/roff/troff/troff.1.man
@@ -587,6 +587,21 @@ adjusted such that its length was exactly equal to,
 the output line length
 .RB \[lq] \[rs]n[.l] \[rq].
 .
+GNU
+.I troff \" GNU
+reports the amount of overset or underset in the scaling unit configured
+by the
+.B \%warnscale
+request in
+.B troff \" mode
+mode,
+and in ens
+.RB (\[oq] n \[cq];
+character cells)
+in
+.B nroff \" mode
+mode.
+.
 This category is enabled by default.
 .
 .

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to