[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 2478fbc 010/156: Start implementing PDF illus
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 2478fbc 010/156: Start implementing PDF illustrations directly |
Date: |
Tue, 30 Jan 2018 17:21:51 -0500 (EST) |
branch: master
commit 2478fbcb0d9b7bba236d61067d151d22692a6cd5
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Start implementing PDF illustrations directly
This commit just adds a skeleton of the new ledger_pdf_generator_wx.cpp
file with just the incomplete cover page implementation in it for now.
---
Makefile.am | 1 +
ledger_pdf_generator_wx.cpp | 318 ++++++++++++++++++++++++++++++++++++++++++++
main_wx.cpp | 1 +
main_wx_test.cpp | 1 +
objects.make | 1 +
5 files changed, 322 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 9164a0c..288754b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -172,6 +172,7 @@ libskeleton_la_SOURCES = \
illustration_document.cpp \
illustration_view.cpp \
input_sequence_entry.cpp \
+ ledger_pdf_generator_wx.cpp \
main_common.cpp \
mec_document.cpp \
mec_view.cpp \
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
new file mode 100644
index 0000000..dba5e2c
--- /dev/null
+++ b/ledger_pdf_generator_wx.cpp
@@ -0,0 +1,318 @@
+// Generate PDF files with ledger data using wxPdfDocument library.
+//
+// Copyright (C) 2017 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// http://savannah.nongnu.org/projects/lmi
+// email: <address@hidden>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#include "pchfile_wx.hpp"
+
+#include "ledger_pdf_generator.hpp"
+
+#include "authenticity.hpp"
+#include "calendar_date.hpp"
+#include "force_linking.hpp"
+#include "global_settings.hpp"
+#include "html.hpp"
+#include "ledger.hpp"
+#include "ledger_invariant.hpp"
+#include "pdf_writer_wx.hpp"
+#include "value_cast.hpp"
+#include "version.hpp"
+
+#include <wx/pdfdc.h>
+
+LMI_FORCE_LINKING_IN_SITU(ledger_pdf_generator_wx)
+
+using namespace html;
+
+namespace
+{
+
+// This is just a container for the illustration-global data.
+class pdf_illustration
+{
+ public:
+ pdf_illustration(Ledger const& ledger
+ ,fs::path const& output
+ )
+ :writer_(output.string(), wxPORTRAIT)
+ ,dc_(writer_.dc())
+ ,ledger_(ledger)
+ ,properties_(properties::init(ledger))
+ {
+ }
+
+ // Add a new page using its render() method.
+ template<typename T>
+ void add()
+ {
+ if(page_number_++)
+ {
+ dc_.StartPage();
+ }
+
+ T page;
+ page.render(ledger_, writer_, dc_, properties_);
+ }
+
+ // Global illustration properties.
+ class properties
+ {
+ public:
+ // Fields can be accessed directly by pages.
+ text lmi_version_;
+ text date_prepared_;
+
+ static properties init(Ledger const& ledger)
+ {
+ std::string lmi_version(LMI_VERSION);
+ calendar_date prep_date;
+
+ // Skip authentication for non-interactive regression testing.
+ if(!global_settings::instance().regression_testing())
+ {
+ authenticate_system();
+ }
+ else
+ {
+ // For regression tests,
+ // - use an invariant string as version
+ // - use EffDate as date prepared
+ // in order to avoid gratuitous failures.
+ lmi_version = "Regression testing";
+ prep_date.julian_day_number
+ (static_cast<int>(ledger.GetLedgerInvariant().EffDateJdn)
+ );
+ }
+
+ properties p;
+ p.lmi_version_ = text::from(lmi_version);
+ p.date_prepared_ =
+ text::from(month_name(prep_date.month()))
+ + text::nbsp()
+ + text::from(value_cast<std::string>(prep_date.day()))
+ + text::from(", ")
+ + text::from(value_cast<std::string>(prep_date.year()))
+ ;
+ return p;
+ }
+
+ private:
+ // Ctor is private, use init() to create objects of this type.
+ properties() = default;
+ };
+
+ private:
+ // Writer object used for the page metrics and higher level functions.
+ pdf_writer_wx writer_;
+
+ // The DC associated with the writer, it could be accessed via it, but as
+ // it's needed often, provide a shorter alias for it.
+ wxDC& dc_;
+
+ // Source of the data.
+ Ledger const& ledger_;
+
+ // Properties initialized only once and used by pages via public accessor.
+ properties const properties_;
+
+ // Number of last added page.
+ int page_number_{0};
+};
+
+class page
+{
+ public:
+ page() = default;
+
+ // Pages are not value-like objects, so prohibit copying them.
+ page(page const&) = delete;
+ page& operator=(page const&) = delete;
+
+ // Pages are never used polymorphically currently, but still give them a
+ // virtual dtor, if only to avoid gcc warnings about not having it.
+ virtual ~page() = default;
+
+ // Render this page contents.
+ virtual void render
+ (Ledger const& ledger
+ ,pdf_writer_wx& writer
+ ,wxDC& dc
+ ,pdf_illustration::properties const& props
+ ) = 0;
+};
+
+class cover_page : public page
+{
+ public:
+ void render
+ (Ledger const& ledger
+ ,pdf_writer_wx& writer
+ ,wxDC& dc
+ ,pdf_illustration::properties const& props
+ ) override
+ {
+ dc.SetPen(wxPen(*wxBLUE, 2));
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+ dc.DrawRectangle
+ (writer.get_horz_margin()
+ ,writer.get_vert_margin()
+ ,writer.get_page_width()
+ ,writer.get_page_height()
+ );
+
+ auto const& invar = ledger.GetLedgerInvariant();
+
+ // We use empty table cells to insert spaces into the table below.
+ auto const space = tag::tr(tag::td(text::nbsp()));
+
+ auto const cover_html =
+ tag::table[attr::width("100%")]
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+4")]
+ (tag::b(text::from(invar.PolicyMktgName))
+ )
+ )
+ )
+ )
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+4")]
+ (tag::b
+ (text::from
+ (invar.IsInforce
+ ? "In Force Life Insurance
Illustration"
+ : "Life Insurance Illustration"
+ )
+ )
+ )
+ )
+ )
+ )
+ (space)
+ (space)
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+2")]
+ (tag::b
+ (text::from("Prepared for:")
+ )
+ )
+ )
+ )
+ )
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+2")]
+ (text::from
+ (ledger.is_composite()
+ ? invar.CorpName
+ : invar.Insured1
+ )
+ )
+ )
+ )
+ )
+ (space)
+ (space)
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+2")]
+ (tag::b
+ (text::from("Presented by:")
+ )
+ )
+ )
+ )
+ )
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+2")]
+ (text::from(invar.ProducerName)
+ )
+ )
+ )
+ )
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+2")]
+ (text::from(invar.ProducerStreet)
+ )
+ )
+ )
+ )
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+2")]
+ (text::from(invar.ProducerCity)
+ )
+ )
+ )
+ )
+ (space)
+ (tag::tr
+ (tag::td[attr::align("center")]
+ (tag::font[attr::size("+2")]
+ (props.date_prepared_
+ )
+ )
+ )
+ )
+ ;
+
+ writer.output_html
+ (writer.get_horz_margin()
+ ,4*writer.get_vert_margin()
+ ,writer.get_page_width()
+ ,cover_html
+ );
+ }
+};
+
+class ledger_pdf_generator_wx : public ledger_pdf_generator
+{
+ public:
+ static std::shared_ptr<ledger_pdf_generator> do_create()
+ {
+ return std::make_shared<ledger_pdf_generator_wx>();
+ }
+
+ ledger_pdf_generator_wx() = default;
+ ledger_pdf_generator_wx(ledger_pdf_generator_wx const&) = delete;
+ ledger_pdf_generator_wx& operator=(ledger_pdf_generator_wx const&) =
delete;
+
+ void write(Ledger const& ledger, fs::path const& output) override;
+
+ private:
+};
+
+void ledger_pdf_generator_wx::write
+ (Ledger const& ledger
+ ,fs::path const& output
+ )
+{
+ pdf_illustration pdf_ill(ledger, output);
+ pdf_ill.add<cover_page>();
+}
+
+volatile bool ensure_setup = ledger_pdf_generator::set_creator
+ (ledger_pdf_generator_wx::do_create
+ );
+
+} // Unnamed namespace.
diff --git a/main_wx.cpp b/main_wx.cpp
index 751f723..ded96ba 100644
--- a/main_wx.cpp
+++ b/main_wx.cpp
@@ -46,6 +46,7 @@
LMI_FORCE_LINKING_EX_SITU(alert_wx)
LMI_FORCE_LINKING_EX_SITU(file_command_wx)
LMI_FORCE_LINKING_EX_SITU(group_quote_pdf_generator_wx)
+LMI_FORCE_LINKING_EX_SITU(ledger_pdf_generator_wx)
LMI_FORCE_LINKING_EX_SITU(progress_meter_wx)
LMI_FORCE_LINKING_EX_SITU(system_command_wx)
diff --git a/main_wx_test.cpp b/main_wx_test.cpp
index f96aef8..9e16845 100644
--- a/main_wx_test.cpp
+++ b/main_wx_test.cpp
@@ -56,6 +56,7 @@
LMI_FORCE_LINKING_EX_SITU(file_command_wx)
LMI_FORCE_LINKING_EX_SITU(group_quote_pdf_generator_wx)
+LMI_FORCE_LINKING_EX_SITU(ledger_pdf_generator_wx)
LMI_FORCE_LINKING_EX_SITU(progress_meter_wx)
LMI_FORCE_LINKING_EX_SITU(system_command_wx)
diff --git a/objects.make b/objects.make
index 37dbef0..c7eda34 100644
--- a/objects.make
+++ b/objects.make
@@ -323,6 +323,7 @@ skeleton_objects := \
illustration_document.o \
illustration_view.o \
input_sequence_entry.o \
+ ledger_pdf_generator_wx.o \
main_common.o \
mec_document.o \
mec_view.o \
- [lmi-commits] [lmi] master cc7fc05 143/156: Change template file extension from .mustache to .mst, (continued)
- [lmi-commits] [lmi] master cc7fc05 143/156: Change template file extension from .mustache to .mst, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 08984bb 148/156: Recognize Mustache files in the coding rules test, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master de5a5c7 151/156: Fix interpolate_string_test build, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master bb5693e 136/156: Harmonize spacing in header in reg_d_group illustrations too, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0c85a7a 154/156: Avoid using directive for the "html" namespace, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 463e8ca 138/156: Fix bug with page numbers in subsequent illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 830e1fd 130/156: Manually break column titles into lines, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 43859a6 053/156: Add support for "measure only" output mode to wx_table_generator, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 772f4a4 139/156: Refactor: use get_fixed_page_contents_template_name(), Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 81ccdc8 129/156: Remove the never used elements of the columns title map, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 2478fbc 010/156: Start implementing PDF illustrations directly,
Greg Chicares <=
- [lmi-commits] [lmi] master 9d24cd9 024/156: Compilation fix for C++11 but not C++14 compilers, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1229745 020/156: Make add_body_paragraph() even more convenient to use, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 14aca9e 142/156: Replace underscores in title map with explicit line breaks, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 5241f0f 045/156: Fix some typos in wx_table_generator::add_column() comment, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 47bddbf 155/156: Merge branch 'vz-no-xslfo' into gwc-no-xslfo, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master a1342a9 106/156: Fix supplemental NASD illustration page for split premiums, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master ec0b298 110/156: Add NASD illustration second explanatory notes page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 80423d2 134/156: Improve appearance of lower header part in NASD illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 408ba18 156/156: Merge branch 'gwc-no-xslfo' [387], Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master de5d0b8 060/156: Inline output_and_check_for_page_break() function, Greg Chicares, 2018/01/30