lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] odd/zero_columns 965d664 1/2: Investigate a reported


From: Greg Chicares
Subject: [lmi-commits] [lmi] odd/zero_columns 965d664 1/2: Investigate a reported defect
Date: Sun, 5 May 2019 15:56:39 -0400 (EDT)

branch: odd/zero_columns
commit 965d664ea9e24ef624208d040c4f5d276407bcaa
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Investigate a reported defect
    
    See:
      https://lists.nongnu.org/archive/html/lmi/2019-05/msg00004.html
---
 pdf_writer_wx.cpp      |  9 +++++++++
 report_table.cpp       | 25 ++++++++++++++++++++++++-
 wx_table_generator.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/pdf_writer_wx.cpp b/pdf_writer_wx.cpp
index 423a93e..c438325 100644
--- a/pdf_writer_wx.cpp
+++ b/pdf_writer_wx.cpp
@@ -335,6 +335,15 @@ int pdf_writer_wx::output_html
             // When rendering, all the text should have fit on this page,
             // otherwise this is not the right overload to use -- call
             // paginate_html() and the generic overload above instead.
+            if((get_total_height() - y) < height)
+                warning()
+                    << "assertion would fail: 'height <= get_total_height() - 
y'\n"
+                    << get_total_height() << " get_total_height()\n"
+                    << y << " y\n"
+                    << (get_total_height() - y) << " (get_total_height() - 
y)\n"
+                    << height << " height\n"
+                    << LMI_FLUSH
+                    ;
             LMI_ASSERT(height <= get_total_height() - y);
             break;
         case oe_only_measure:
diff --git a/report_table.cpp b/report_table.cpp
index 29e30ef..e5e7f63 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -129,17 +129,33 @@ std::vector<int> set_column_widths
 
     if(0 == n_columns_to_show)
         {
-        alarum() << "Not enough room for even the first column." << LMI_FLUSH;
+        warning()
+            << "BIG TROUBLE\n"
+            << max_table_width << " max_table_width\n"
+            << desired_margin << " desired_margin\n"
+            << minimum_margin << " minimum_margin\n"
+            << cardinality << " cardinality\n"
+// Indexing [0] would crash:
+//          << all_columns[0].col_width() << " all_columns[0].col_width()\n"
+            << data_width << " data_width\n"
+            << LMI_FLUSH
+            ;
+        warning() << "Not enough room for even the first column." << LMI_FLUSH;
+//      alarum() << "Not enough room for even the first column." << LMI_FLUSH;
+// Add a unit test for zero columns!
         }
 
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
     // These two are boolean, but vector<bool> isn't a Container.
     std::vector<int> bool_inelastic(n_columns_to_show, false);
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
     std::vector<int> bool_elastic  (n_columns_to_show, false);
     for(int j = 0; j < n_columns_to_show; ++j)
         {
         if(all_columns[j].is_elastic()) {bool_elastic  [j] = true;}
         else                            {bool_inelastic[j] = true;}
         }
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
 
     int const residue = max_table_width - data_width;
     LMI_ASSERT(0 <= residue);
@@ -147,22 +163,28 @@ std::vector<int> set_column_widths
     // Apportion any residue among inelastic columns, up to the number
     // of such columns times the desired_margin argument.
     int const n_inelastic = std::accumulate(bool_inelastic.begin(), 
bool_inelastic.end(), 0);
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
     int const residue_inelastic = std::min(residue, n_inelastic * 
desired_margin);
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
     LMI_ASSERT(0 <= residue_inelastic);
     std::vector<int> const delta_inelastic = apportion(bool_inelastic, 
residue_inelastic);
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
     // That part of the residue should always be fully consumed.
     LMI_ASSERT(residue_inelastic ==  std::accumulate(delta_inelastic.begin(), 
delta_inelastic.end(), 0));
 
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
     // Apportion all remaining residue, if any, among elastic columns.
     int const residue_elastic = residue - residue_inelastic;
     LMI_ASSERT(0 <= residue_elastic);
     std::vector<int> const delta_elastic   = apportion(bool_elastic, 
residue_elastic);
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
 
     std::vector<int> w(cardinality);
     for(int j = 0; j < n_columns_to_show; ++j)
         {
         w[j] = all_columns[j].col_width() + delta_inelastic[j] + 
delta_elastic[j];
         }
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
 
     if(cardinality != n_columns_to_show)
         {
@@ -173,6 +195,7 @@ std::vector<int> set_column_widths
             ;
         }
 
+if(0 == cardinality) warning() << __LINE__ << ' ' << __FILE__ << LMI_FLUSH;
     return w;
 }
 
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index af9f41f..182ce45 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -118,7 +118,31 @@ wx_table_generator::wx_table_generator
         ,2 * one_em_
         ,one_puncsp
         );
+if(0 == lmi::ssize(all_columns_))
+    {
+    warning()
+    << vc.size() << " vc.size()\n"
+    << indices.size() << " indices.size()\n"
+    << LMI_FLUSH
+    ;
+    for(auto const& i : vc)
+        {
+        warning()
+            << "vc element: "
+            << '\n' << i.header
+            << '\n' << i.widest_text
+            << '\n' << i.alignment
+            << '\n' << i.elasticity
+            << LMI_FLUSH
+            ;
+        }
+    for(auto const& i : indices)
+        {
+        warning() << "indices element: " << i << LMI_FLUSH;
+        }
+    }
 
+if(0 == lmi::ssize(all_columns_)) warning() << __LINE__ << ' ' << __FILE__ << 
LMI_FLUSH;
     std::vector<table_column_info> resized_columns;
     for(int j = 0; j < lmi::ssize(all_columns()); ++j)
         {
@@ -202,6 +226,8 @@ void wx_table_generator::output_headers
             ,headers_by_line.begin() + (1 + i) * number_of_columns
             );
         x = left_margin_;
+if(0 == lmi::ssize(all_columns_)) warning() << __LINE__ << " RETURNING" << 
LMI_FLUSH;
+if(0 == lmi::ssize(all_columns_)) {pos_y = anticipated_pos_y; return;}
         do_output_single_row(x, pos_y, nth_line);
         }
 
@@ -284,6 +310,7 @@ void wx_table_generator::output_highlighted_cell
     dc_.DrawRectangle(cell_rect(column, y));
     }
 
+if(0 == lmi::ssize(all_columns_)) warning() << __LINE__ << ' ' << __FILE__ << 
LMI_FLUSH;
     dc_.DrawLabel(value, text_rect(column, y), wxALIGN_CENTER_HORIZONTAL);
 
     do_output_vert_separator(cell_pos_x(column), y, y + row_height_);
@@ -302,6 +329,7 @@ void wx_table_generator::output_row
 {
     LMI_ASSERT(values.size() == all_columns().size());
     int x = left_margin_;
+if(0 == lmi::ssize(all_columns_)) warning() << __LINE__ << ' ' << __FILE__ << 
LMI_FLUSH;
     do_output_single_row(x, pos_y, values);
 
     if(draw_separators_)
@@ -346,6 +374,14 @@ void wx_table_generator::output_horz_separator
             return;
         }
 
+    if(!(begin_column < end_column))
+        {
+        warning() << "assertion would have failed" << LMI_FLUSH; return;
+        }
+    if(!(end_column <= lmi::ssize(all_columns())))
+        {
+        warning() << "assertion would have failed" << LMI_FLUSH; return;
+        }
     LMI_ASSERT(begin_column < end_column);
     LMI_ASSERT(end_column <= lmi::ssize(all_columns()));
 
@@ -379,6 +415,7 @@ int wx_table_generator::separator_line_height() const
 wxRect wx_table_generator::external_text_rect(int a_column, int y) const
 {
     int column = indices_[a_column];
+if(0 == lmi::ssize(all_columns_)) warning() << __LINE__ << ' ' << __FILE__ << 
LMI_FLUSH;
     return text_rect(column, y);
 }
 
@@ -389,6 +426,7 @@ wxRect wx_table_generator::external_text_rect(int a_column, 
int y) const
 
 wxRect wx_table_generator::text_rect(int column, int y) const
 {
+    if(!(column < lmi::ssize(all_columns()))) return wxRect{};
     LMI_ASSERT(column < lmi::ssize(all_columns()));
     wxRect z = cell_rect(column, y).Deflate(dc().GetCharWidth(), 0);
     z.Offset(0, (row_height_ - char_height_)/2);
@@ -457,6 +495,8 @@ void wx_table_generator::do_output_single_row
 {
     int const y_top = pos_y;
 
+if(0 == lmi::ssize(all_columns_)) warning() << __LINE__ << ' ' << __FILE__ << 
LMI_FLUSH;
+
     int const y_text = text_rect(0, pos_y).y;
     pos_y += row_height_;
 



reply via email to

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