lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master b6b6827 03/15: Do call EndPage() in PDF gener


From: Greg Chicares
Subject: [lmi-commits] [lmi] master b6b6827 03/15: Do call EndPage() in PDF generation code
Date: Fri, 27 Jul 2018 17:23:15 -0400 (EDT)

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

    Do call EndPage() in PDF generation code
    
    Although most things worked correctly even if EndPage() was never called
    (and only StartPage() was), the clipping region remaining from the last
    page, if any, was reused for the new page, breaking wxPdfDocument
    assumptions about the coordinate systems and resulting in printing the
    text upside down, due to the unexpected coordinates system orientation,
    among other things.
    
    Ensure that EndPage() is always called by adding a helper next_page()
    method which always calls it before calling StartPage(). Encapsulating
    these wxDC methods calls in pdf_writer_wx is also more consistent with
    what had been already done for StartDoc() and EndDoc().
---
 ledger_pdf_generator_wx.cpp |  6 +++---
 pdf_writer_wx.cpp           | 16 ++++++++++++++++
 pdf_writer_wx.hpp           |  2 ++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 4bc2e20..65b45fe 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -749,8 +749,8 @@ class pdf_illustration : protected html_interpolator
                 {
                 // Do start a new physical page before rendering all the
                 // subsequent pages (notice that a page is also free to call
-                // StartPage() from its render()).
-                writer.dc().StartPage();
+                // next_page() from its render()).
+                writer.next_page();
                 }
 
             i->render(ledger_, writer, *this);
@@ -1181,7 +1181,7 @@ class numbered_page : public page_with_footer
         // pages for this logical pages by overriding get_extra_pages_needed().
         LMI_ASSERT(0 < extra_pages_);
 
-        writer.dc().StartPage();
+        writer.next_page();
 
         ++this_page_number_;
         --extra_pages_;
diff --git a/pdf_writer_wx.cpp b/pdf_writer_wx.cpp
index db7c11f..d4835b4 100644
--- a/pdf_writer_wx.cpp
+++ b/pdf_writer_wx.cpp
@@ -124,6 +124,22 @@ pdf_writer_wx::pdf_writer_wx
     html_parser_.SetFS(html_vfs_.get());
 }
 
+/// Start a new page in the output PDF document.
+///
+/// This is equivalent to wxDC::EndPage() followed by wxDC::StartPage(), but
+/// preferable to using these 2 functions directly, both because it's simpler
+/// and because it's too easy to forget to call EndPage() otherwise, especially
+/// as almost everything still works correctly even when it's not called --
+/// except that the clipping region is not reset for the new page, which can
+/// result in hard to diagnose problems.
+
+void pdf_writer_wx::next_page()
+{
+    LMI_ASSERT(!save_has_been_called_);
+    pdf_dc_.EndPage();
+    pdf_dc_.StartPage();
+}
+
 wxDC& pdf_writer_wx::dc()
 {
     LMI_ASSERT(!save_has_been_called_);
diff --git a/pdf_writer_wx.hpp b/pdf_writer_wx.hpp
index 1bf0431..a782718 100644
--- a/pdf_writer_wx.hpp
+++ b/pdf_writer_wx.hpp
@@ -76,6 +76,8 @@ class pdf_writer_wx
         ,oenum_render_or_only_measure output_mode = oe_render
         );
 
+    void next_page();
+
     wxDC& dc();
 
     // Page metrics: the page width and height are the size of the page region



reply via email to

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