lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master c3055e7 5/6: Don't shrink PDF table columns t


From: Greg Chicares
Subject: [lmi-commits] [lmi] master c3055e7 5/6: Don't shrink PDF table columns too much
Date: Thu, 8 Mar 2018 21:04:49 -0500 (EST)

branch: master
commit c3055e7848f1a3000892cd7b91d5fa71273999e5
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Don't shrink PDF table columns too much
    
    The total width of the columns could be made less than the available
    width if it had initially been too big as the code adjusting the margins
    shrunk them too much, due to rounding errors inevitable when using
    integer division.
    
    Compensate for them by explicitly adding the "missing" pixels back.
---
 wx_table_generator.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index 846254c..604351e 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -207,10 +207,18 @@ void 
wx_table_generator::do_compute_column_widths_if_necessary()
         // reduce them by up to half if really needed.
         if(!num_expand)
             {
+            // We need to round up in division here to be sure that all columns
+            // fit into the available width.
             auto const overflow_per_column =
                 (overflow + num_columns - 1)/num_columns;
             if(overflow_per_column <= column_margin_)
                 {
+                // We are going to reduce the total width by more than
+                // necessary, in general, because of rounding up above, so
+                // compensate for it by giving 1 extra pixel until we run out
+                // of these "underflow" pixels.
+                auto underflow = overflow_per_column*num_columns - overflow;
+
                 for(auto& i : columns_)
                     {
                     if(i.is_hidden())
@@ -219,6 +227,12 @@ void 
wx_table_generator::do_compute_column_widths_if_necessary()
                         }
 
                     i.width_ -= overflow_per_column;
+
+                    if(underflow > 0)
+                        {
+                        i.width_++;
+                        underflow--;
+                        }
                     }
 
                 column_margin_ -= (overflow_per_column + 1)/2;



reply via email to

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