[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
- [lmi-commits] [lmi] master updated (caaecd8 -> 12d84c9), Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 37e9b0b 01/15: Update to wxWidgets v3.1.1-319-g9daf5bec98 snapshot, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 6465704 04/15: Restore the use of wxDCClipper in PDF table generation code, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master a8d5e26 08/15: Look for image files referenced in templates under data directory, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 005b3eb 06/15: Replace pdf_writer_wx::get_page_height() with get_total_height(), Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 28e3c42 11/15: Remove workarounds for wx 3.1.1 warnings not relevant any more, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master b6b6827 03/15: Do call EndPage() in PDF generation code,
Greg Chicares <=
- [lmi-commits] [lmi] master a86d90a 02/15: Use more recent wxPdfDocument fixing the text origin bug, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 554eb23 13/15: Forbid page breaks inside paragraphs in the illustrations, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 271db22 14/15: Fix over eager assert in pdf_writer_wx::output_html(), Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 12d84c9 15/15: Fix regression in font sizes used for the group quotes PDF, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 2bd38fa 12/15: Use standard <img> tag instead of <scaled_image> in templates, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 4cfcfe4 07/15: Refactor: remove render_page_template() helper function, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master e821acd 05/15: Require specifying font sizes when using pdf_writer_wx, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master c56a67f 09/15: Implement and use simple HTML output pagination, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master f03ff64 10/15: Merge first two notes pages of regular individual illustrations, Greg Chicares, 2018/07/27