lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 74872e0 1/3: Fix off by one errors in PDF pag


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 74872e0 1/3: Fix off by one errors in PDF pagination code
Date: Sun, 4 Feb 2018 08:51:58 -0500 (EST)

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

    Fix off by one errors in PDF pagination code
    
    First, compute the number of extra pages correctly by rounding up the
    division of the total number of years by the number of years per page
    properly: the old code gave the wrong result when the former was exactly
    divisible by the latter.
    
    Second, fix adding a new page unnecessarily in render() when the current
    group ends exactly at the end of the current page by checking if we
    reached the last year before checking whether we need a new page,
    instead of doing it in the wrong order.
---
 ledger_pdf_generator_wx.cpp | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index eef6f79..48d3b15 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -1614,7 +1614,7 @@ class page_with_tabular_report
                 ,e_output_normal
                 );
 
-            for(; year < year_max; ++year)
+            for(;;)
                 {
                 for(std::size_t col = 0; col < columns.size(); ++col)
                     {
@@ -1631,7 +1631,14 @@ class page_with_tabular_report
 
                 table.output_row(&pos_y, values.data());
 
-                if((year + 1) % rows_per_group == 0)
+                ++year;
+                if(year == year_max)
+                    {
+                    // We will also leave the outer loop.
+                    break;
+                    }
+
+                if(year % rows_per_group == 0)
                     {
                     // We need a group break.
                     pos_y += row_height;
@@ -1755,8 +1762,8 @@ class page_with_tabular_report
         // not the number of groups.
         int const years_per_page = groups_per_page * rows_per_group;
 
-        // Finally determine how many pages we need to show all the years.
-        return ledger.GetMaxLength() / years_per_page;
+        // Finally determine how many extra pages we need to show all the 
years.
+        return (ledger.GetMaxLength() + years_per_page - 1) / years_per_page - 
1;
     }
 };
 



reply via email to

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