groff-commit
[Top][All Lists]
Advanced

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

[groff] 08/08: [tbl]: Fix Savannah #63449.


From: G. Branden Robinson
Subject: [groff] 08/08: [tbl]: Fix Savannah #63449.
Date: Thu, 1 Dec 2022 03:22:25 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 0e93ab410294677e3e4ea105b04f2a18b5c7f9dc
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Dec 1 00:53:11 2022 -0600

    [tbl]: Fix Savannah #63449.
    
    * src/preproc/tbl/table.h (class table): Add new enumeration constants
      for use with `flags` member variable: `HAS_TOP_VLINE` and
      `HAS_TOP_HLINE`, which track properties of the table.  Unlike others,
      these have no correspondence to table region options.
    
    * src/preproc/tbl/main.cpp (process_format): Add new local Boolean to
      track whether we're interpreting a format for the first row.  Use this
      to "or" on the `HAS_TOP_VLINE` or `HAS_TOP_HLINE` flags if "|" or [_-]
      are encountered in the first row's format, as appropriate.
    
      (process_data): "Or" on `HAS_TOP_HLINE` if a single or double
      horizontal line is used as the first row's data.
    
    * src/preproc/tbl/table.cpp (do_top): On nroff mode devices, add one 1v
      of space above the table if we're going to be drawing an unintersected
      vertical rule above the table's top.
    
    Fixes <https://savannah.gnu.org/bugs/?63449>.
---
 ChangeLog                 | 22 ++++++++++++++++++++++
 src/preproc/tbl/main.cpp  |  8 ++++++++
 src/preproc/tbl/table.cpp |  7 +++++++
 src/preproc/tbl/table.h   | 21 ++++++++++++---------
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index aa12b2318..9ba56b4fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2022-11-30  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [tbl]: Fix Savannah #63449.
+
+       * src/preproc/tbl/table.h (class table): Add new enumeration
+       constants for use with `flags` member variable: `HAS_TOP_VLINE`
+       and `HAS_TOP_HLINE`, which track properties of the table.
+       Unlike others, these have no correspondence to table region
+       options.
+       * src/preproc/tbl/main.cpp (process_format): Add new local
+       Boolean to track whether we're interpreting a format for the
+       first row.  Use this to "or" on the `HAS_TOP_VLINE` or
+       `HAS_TOP_HLINE` flags if "|" or [_-] are encountered in the
+       first row's format, as appropriate.
+       (process_data): "Or" on `HAS_TOP_HLINE` if a single or double
+       horizontal line is used as the first row's data.
+       * src/preproc/tbl/table.cpp (do_top): On nroff mode devices, add
+       one 1v of space above the table if we're going to be drawing an
+       unintersected vertical rule above the table's top.
+
+       Fixes <https://savannah.gnu.org/bugs/?63449>.
+
 2022-11-30  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [tbl]: Regression-test Savannah #63449.
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index 03cfb8f91..77a636888 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -773,6 +773,7 @@ format *process_format(table_input &in, options *opt,
 {
   input_entry_format *list = 0;
   bool have_expand = false;
+  bool is_first_row = true;
   int c = in.get();
   for (;;) {
     int vline_count = 0;
@@ -825,6 +826,8 @@ format *process_format(table_input &in, options *opt,
       case '-':                        // tbl also accepts this
        got_format = true;
        t = FORMAT_HLINE;
+       if (is_first_row)
+         opt->flags |= table::HAS_TOP_HLINE;
        break;
       case '=':
        got_format = true;
@@ -1099,6 +1102,8 @@ format *process_format(table_input &in, options *opt,
        list->zero_width = 1;
        break;
       case '|':
+       if (is_first_row)
+         opt->flags |= table::HAS_TOP_VLINE;
        c = in.get();
        list->vline++;
        break;
@@ -1119,6 +1124,7 @@ format *process_format(table_input &in, options *opt,
       error("more than 2 vertical bars between column descriptors");
     }
     if (c == '\n' || c == ',') {
+      is_first_row = false;
       c = in.get();
       list->is_last_column = true;
     }
@@ -1287,6 +1293,8 @@ table *process_data(table_input &in, format *f, options 
*opt)
          type = SINGLE_HLINE;
        else
          type = DOUBLE_HLINE;
+       if (0 == current_row)
+         tbl->flags |= table::HAS_TOP_HLINE;
       }
       else {
        in.unget(d);
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index 0ca74e31b..523d0054c 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -2959,6 +2959,13 @@ void table::do_top()
   }
   else if (flags & (ALLBOX | BOX))
     print_single_hline(0);
+  // On terminal devices, a vertical rule on the first row of the table
+  // will stick out 1v above it if it the table is unboxed or lacks a
+  // horizontal rule on the first row.  This is necessary for grotty's
+  // rule intersection detection.  We also make room for it so that the
+  // vertical rule is not drawn above the top of the page.
+  else if ((flags & HAS_TOP_VLINE) && !(flags & HAS_TOP_HLINE))
+    prints(".if n .sp\n");
   //printfs(".mk %1\n", row_top_reg(0));
 }
 
diff --git a/src/preproc/tbl/table.h b/src/preproc/tbl/table.h
index c703fb1cd..283c51863 100644
--- a/src/preproc/tbl/table.h
+++ b/src/preproc/tbl/table.h
@@ -132,15 +132,18 @@ class table {
 public:
   unsigned flags;
   enum {
-    CENTER       = 0x00000001,
-    EXPAND       = 0x00000002,
-    BOX          = 0x00000004,
-    ALLBOX       = 0x00000008,
-    DOUBLEBOX    = 0x00000010,
-    NOKEEP       = 0x00000020,
-    NOSPACES     = 0x00000040,
-    NOWARN       = 0x00000080,
-    EXPERIMENTAL = 0x80000000  // undocumented; use as a hook for experiments
+    CENTER        = 0x00000001,
+    EXPAND        = 0x00000002,
+    BOX           = 0x00000004,
+    ALLBOX        = 0x00000008,
+    DOUBLEBOX     = 0x00000010,
+    NOKEEP        = 0x00000020,
+    NOSPACES      = 0x00000040,
+    NOWARN        = 0x00000080,
+    // The next two properties help manage nroff mode output.
+    HAS_TOP_VLINE = 0x00000100,
+    HAS_TOP_HLINE = 0x00000200,
+    EXPERIMENTAL  = 0x80000000 // undocumented
     };
   char *expand;
   table(int nc, unsigned flags, int linesize, char decimal_point_char);



reply via email to

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