lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master f7eb882 2/5: Derive cover page from standard_


From: Greg Chicares
Subject: [lmi-commits] [lmi] master f7eb882 2/5: Derive cover page from standard_page, not from numbered_page
Date: Tue, 14 May 2019 16:19:06 -0400 (EDT)

branch: master
commit f7eb88287b6e4f865748c8448a78431c3bbe7501
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Derive cover page from standard_page, not from numbered_page
    
    Deriving a leaf class from a more-derived class is generally preferable
    because it allows more behavior to be inherited. In this case, it was no
    longer useful to override render() (because the decorative rectangle had
    been removed), and it is better not to override get_extra_pages_needed()
    (because blithely returning zero would silently become wrong if the
    cover page ever needed more than one physical page).
---
 pdf_command_wx.cpp | 89 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 54 insertions(+), 35 deletions(-)

diff --git a/pdf_command_wx.cpp b/pdf_command_wx.cpp
index 5f90385..5a8b6ce 100644
--- a/pdf_command_wx.cpp
+++ b/pdf_command_wx.cpp
@@ -1330,41 +1330,6 @@ class numbered_page : public page_with_marginals
     int               extra_pages_      {0};
 };
 
-/// Generic cover page for most ledger types.
-///
-/// See discussion here:
-///   https://lists.nongnu.org/archive/html/lmi/2019-04/msg00024.html
-
-class cover_page : public numbered_page
-{
-  public:
-    using numbered_page::numbered_page;
-
-    void render() override
-    {
-        // Call base-class implementation to render the footer.
-        numbered_page::render();
-        writer_.output_html
-            (writer_.get_horz_margin()
-            ,writer_.get_vert_margin()
-            ,writer_.get_page_width()
-            ,interpolator_.expand_template("cover")
-            );
-    }
-
-  private:
-    int get_extra_pages_needed() override
-    {
-        return 0;
-    }
-
-    // Only the lower part of the footer is wanted here.
-    std::string get_upper_footer_template_name() const override
-    {
-        return std::string {};
-    }
-};
-
 // Simplest possible page which is entirely defined by its external template
 // whose name must be specified when constructing it.
 class standard_page : public numbered_page
@@ -1489,6 +1454,60 @@ class standard_page : public numbered_page
     std::vector<int>                     page_break_positions_;
 };
 
+/// Generic cover page for most ledger types.
+///
+/// See discussion here:
+///   https://lists.nongnu.org/archive/html/lmi/2019-04/msg00024.html
+
+class cover_page : public standard_page
+{
+  public:
+    cover_page
+        (pdf_illustration  const& illustration
+        ,Ledger            const& ledger
+        ,pdf_writer_wx          & writer
+        ,html_interpolator const& interpolator
+        )
+        :standard_page
+            (illustration
+            ,ledger
+            ,writer
+            ,interpolator
+            ,"cover"
+            )
+    {
+    }
+
+#if 0
+// Now that this class derives from class standard_page, this virtual
+// member must no longer be overridden. If this override is not
+// commented out, then the cover page is entirely blank.
+//
+// Is this because standard_page::page_break_positions_ must be set
+// (by calling standard_page::get_extra_pages_needed() in any
+// override, or (as seems best in this case) by not overriding that
+// virtual member here)?
+//
+// But maybe that's not the reason: it seems remarkable that replacing
+// +        ,"ill_reg_numeric_summary"
+// -        ,"cover"
+// above in the ctor causes a non-blank first page to be printed, even
+// if this override is not commented out.
+//
+  private:
+    int get_extra_pages_needed() override
+    {
+        return 0;
+    }
+#endif // 0
+
+    // Only the lower part of the footer is wanted here.
+    std::string get_upper_footer_template_name() const override
+    {
+        return std::string {};
+    }
+};
+
 // Helper classes used to show the numeric summary table. The approach used
 // here is to define a custom HTML tag (<numeric_summary_table>) and use the
 // existing wx_table_generator to replace it with the actual table when



reply via email to

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