groff-commit
[Top][All Lists]
Advanced

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

[groff] 40/45: [tbl]: Fix Savannah #61854.


From: G. Branden Robinson
Subject: [groff] 40/45: [tbl]: Fix Savannah #61854.
Date: Thu, 20 Jan 2022 10:17:57 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit aae070bcc5e3825ed72b901588cc1ea5b26db0a6
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Jan 20 16:20:11 2022 +1100

    [tbl]: Fix Savannah #61854.
    
    * src/preproc/tbl/table.cpp (compute_expand_width): To properly warn if
      a table is too wide to fit between the indentation and the right
      margin, we need to compute its column widths including those eligible
      for expansion via the 'x' column modifier; we cannot use the same
      expression that we do to determine how the amount of space we have to
      distribute among the expanded columns.  Iterate through columns again
      (the function was already doing so twice), once to potentially produce
      the warning, and then as before to distribute any available width.  In
      other words, warnings were only being emitted for too-wide tables
      where one or more columns used the 'x' modifier.
    
    Fixes <https://savannah.gnu.org/bugs/?61854>.
---
 ChangeLog                 | 18 ++++++++++++++++++
 src/preproc/tbl/table.cpp | 14 ++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 575179e2..36d73203 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2022-01-20  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [tbl]: Fix Savannah #61854.
+
+       * src/preproc/tbl/table.cpp (compute_expand_width): To properly
+       warn if a table is too wide to fit between the indentation and
+       the right margin, we need to compute its column widths including
+       those eligible for expansion via the 'x' column modifier; we
+       cannot use the same expression that we do to determine how the
+       amount of space we have to distribute among the expanded
+       columns.  Iterate through columns again (the function was
+       already doing so twice), once to potentially produce the
+       warning, and then as before to distribute any available width.
+       In other words, warnings were only being emitted for too-wide
+       tables where one or more columns used the 'x' modifier.
+
+       Fixes <https://savannah.gnu.org/bugs/?61854>.
+
 2022-01-19  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [ms]: Don't add leaders that don't lead anywhere.
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index 435ac6bf..c1b66c2f 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -2160,10 +2160,11 @@ void table::compute_expand_width()
 {
   int i;
   int colcount = count_expand_columns();
+  // First, compute the unexpanded table width, measuring every column
+  // (including those eligible for expansion) and warn if it's too wide.
   prints(".nr " EXPAND_REG " \\n[.l]-\\n[.i]");
   for (i = 0; i < ncolumns; i++)
-    if (!expand[i])
-      printfs("-\\n[%1]", span_width_reg(i, i));
+    printfs("-\\n[%1]", span_width_reg(i, i));
   if (total_separation)
     printfs("-%1n", as_string(total_separation));
   prints("\n");
@@ -2187,6 +2188,15 @@ void table::compute_expand_width()
     prints(".nr " EXPAND_REG " 0\n");
   }
   prints(".\\}\n");
+  // Now, iterate through the columns again, spreading any excess line
+  // width among the expanded columns.
+  prints(".nr " EXPAND_REG " \\n[.l]-\\n[.i]");
+  for (i = 0; i < ncolumns; i++)
+    if (!expand[i])
+      printfs("-\\n[%1]", span_width_reg(i, i));
+  if (total_separation)
+    printfs("-%1n", as_string(total_separation));
+  prints("\n");
   if (colcount > 1)
     printfs(".nr " EXPAND_REG " \\n[" EXPAND_REG "]/%1\n",
            as_string(colcount));



reply via email to

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