[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b425030 082/156: Factor out html_cell_for_pdf
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b425030 082/156: Factor out html_cell_for_pdf_output from numeric_summary_table_cell |
Date: |
Tue, 30 Jan 2018 17:22:16 -0500 (EST) |
branch: master
commit b42503005d29eff809f814f30d6a1d532b6c8880
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Factor out html_cell_for_pdf_output from numeric_summary_table_cell
No real changes, just refactor the existing custom HTML cell class to
extract a common base class that can be used with other custom HTML cell
classes to be added in the future.
---
ledger_pdf_generator_wx.cpp | 220 ++++++++++++++++++++++++--------------------
1 file changed, 120 insertions(+), 100 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index f85792b..9610646 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -351,6 +351,121 @@ class using_illustration_table
}
};
+// Base class for our custom HTML cells providing a way to pass them
+// information about the PDF document being generated and the ledger used to
+// generate it.
+class html_cell_for_pdf_output : public wxHtmlCell
+{
+ public:
+ // Before using this class a pdf_context_setter object needs to be
+ // instantiated (and remain alive for as long as this class is used).
+ class pdf_context_setter
+ {
+ public:
+ // References passed to the ctor must have lifetime greater than that
+ // of this object itself.
+ explicit pdf_context_setter
+ (Ledger const& ledger
+ ,pdf_writer_wx& writer
+ ,html_interpolator const& interpolate_html
+ )
+ {
+ html_cell_for_pdf_output::pdf_context_for_html_output.set
+ (&ledger
+ ,&writer
+ ,&interpolate_html
+ );
+ }
+
+ ~pdf_context_setter()
+ {
+ html_cell_for_pdf_output::pdf_context_for_html_output.set
+ (nullptr
+ ,nullptr
+ ,nullptr
+ );
+ }
+ };
+
+ protected:
+ // This is ugly, but we have to use a global variable to make pdf_writer_wx
+ // and wxDC objects used by the main code accessible to this cell class,
+ // there is no way to pass them as parameters through wxHTML machinery.
+ //
+ // To at least make it a little bit safer to deal with this, the variable
+ // itself is private and a public pdf_context_setter class is provided to
+ // actually set it.
+ class pdf_context
+ {
+ public:
+ void set
+ (Ledger const* ledger
+ ,pdf_writer_wx* writer
+ ,html_interpolator const* interpolate_html
+ )
+ {
+ ledger_ = ledger;
+ writer_ = writer;
+ interpolate_html_ = interpolate_html;
+ }
+
+ Ledger const& ledger() const
+ {
+ LMI_ASSERT(ledger_);
+ return *ledger_;
+ }
+
+ pdf_writer_wx& writer() const
+ {
+ LMI_ASSERT(writer_);
+ return *writer_;
+ }
+
+ html_interpolator const& interpolate_html() const
+ {
+ LMI_ASSERT(interpolate_html_);
+ return *interpolate_html_;
+ }
+
+ private:
+ Ledger const* ledger_ = nullptr;
+ pdf_writer_wx* writer_ = nullptr;
+ html_interpolator const* interpolate_html_ = nullptr;
+ };
+
+ // Small helper to check that we're using the expected DC and, also, acting
+ // as a sink for the never used parameters of Draw().
+ void draw_check_precondition
+ (wxDC& dc
+ ,int view_y1
+ ,int view_y2,
+ wxHtmlRenderingInfo& info
+ )
+ {
+ // The DC passed to this function is supposed to be the same as the one
+ // associated with the writer we will use for rendering, but check that
+ // this is really so in order to avoid unexpectedly drawing the table
+ // on something else.
+ LMI_ASSERT(&dc == &pdf_context_for_html_output.writer().dc());
+
+ // There is no need to optimize drawing by restricting it to the
+ // currently shown positions, we always render the cell entirely.
+ stifle_warning_for_unused_value(view_y1);
+ stifle_warning_for_unused_value(view_y2);
+
+ // We don't care about rendering state as we don't support interactive
+ // selection anyhow.
+ stifle_warning_for_unused_value(info);
+ }
+
+ static pdf_context pdf_context_for_html_output;
+
+ friend pdf_context_setter;
+};
+
+html_cell_for_pdf_output::pdf_context
+html_cell_for_pdf_output::pdf_context_for_html_output;
+
class page
{
public:
@@ -432,6 +547,9 @@ class pdf_illustration : protected html_interpolator
// Render all pages.
void render_all()
{
+ html_cell_for_pdf_output::pdf_context_setter
+ set_pdf_context(ledger_, writer_, *this);
+
for(auto const& page : pages_)
{
page->pre_render(ledger_, writer_, *this);
@@ -826,40 +944,10 @@ class column_headings_page : public numbered_page
// An HTML cell showing the contents of the numeric summary table.
class numeric_summary_table_cell
- :public wxHtmlCell
+ :public html_cell_for_pdf_output
,private using_illustration_table
{
public:
- // Before using this class a pdf_context_setter object needs to be
- // instantiated (and remain alive for as long as this class is used).
- class pdf_context_setter
- {
- public:
- // References passed to the ctor must have lifetime greater than that
- // of this object itself.
- explicit pdf_context_setter
- (Ledger const& ledger
- ,pdf_writer_wx& writer
- ,html_interpolator const& interpolate_html
- )
- {
- numeric_summary_table_cell::pdf_context_for_html_output.set
- (&ledger
- ,&writer
- ,&interpolate_html
- );
- }
-
- ~pdf_context_setter()
- {
- numeric_summary_table_cell::pdf_context_for_html_output.set
- (nullptr
- ,nullptr
- ,nullptr
- );
- }
- };
-
numeric_summary_table_cell()
{
m_Height = render_or_measure(0, e_output_measure_only);
@@ -875,25 +963,12 @@ class numeric_summary_table_cell
wxHtmlRenderingInfo& info
) override
{
- // The DC passed to this function is supposed to be the same as the one
- // associated with the writer we will use for rendering, but check that
- // this is really so in order to avoid unexpectedly drawing the table
- // on something else.
- LMI_ASSERT(&dc == &pdf_context_for_html_output.writer().dc());
+ draw_check_precondition(dc, view_y1, view_y2, info);
// We ignore the horizontal coordinate which is always 0 for this cell
// anyhow.
stifle_warning_for_unused_value(x);
- // There is no need to optimize drawing by restricting it to the
- // currently shown positions, we always render the cell entirely.
- stifle_warning_for_unused_value(view_y1);
- stifle_warning_for_unused_value(view_y2);
-
- // We don't care about rendering state as we don't support interactive
- // selection anyhow.
- stifle_warning_for_unused_value(info);
-
render_or_measure(y + m_PosY, e_output_normal);
}
@@ -1089,60 +1164,8 @@ class numeric_summary_table_cell
return pos_y;
}
-
- // This is ugly, but we have to use a global variable to make pdf_writer_wx
- // and wxDC objects used by the main code accessible to this cell class,
- // there is no way to pass them as parameters through wxHTML machinery.
- //
- // To at least make it a little bit safer to deal with this, the variable
- // itself is private and a public pdf_context_setter class is provided to
- // actually set it.
- class pdf_context
- {
- public:
- void set
- (Ledger const* ledger
- ,pdf_writer_wx* writer
- ,html_interpolator const* interpolate_html
- )
- {
- ledger_ = ledger;
- writer_ = writer;
- interpolate_html_ = interpolate_html;
- }
-
- Ledger const& ledger() const
- {
- LMI_ASSERT(ledger_);
- return *ledger_;
- }
-
- pdf_writer_wx& writer() const
- {
- LMI_ASSERT(writer_);
- return *writer_;
- }
-
- html_interpolator const& interpolate_html() const
- {
- LMI_ASSERT(interpolate_html_);
- return *interpolate_html_;
- }
-
- private:
- Ledger const* ledger_ = nullptr;
- pdf_writer_wx* writer_ = nullptr;
- html_interpolator const* interpolate_html_ = nullptr;
- };
-
- static pdf_context pdf_context_for_html_output;
-
- friend pdf_context_setter;
};
-numeric_summary_table_cell::pdf_context
-numeric_summary_table_cell::pdf_context_for_html_output;
-
// Custom tag which is replaced by the numeric summary table.
TAG_HANDLER_BEGIN(numeric_summary_table, "NUMERIC_SUMMARY_TABLE")
TAG_HANDLER_PROC(tag)
@@ -1200,9 +1223,6 @@ class numeric_summary_or_attachment_page
,interpolate_html
);
- numeric_summary_table_cell::pdf_context_setter
- set_pdf_context(ledger, writer, interpolate_html);
-
this->render_page_template("numeric_summary", writer,
interpolate_html);
}
};
- [lmi-commits] [lmi] master ef38c9d 141/156: Revert the title map related changes, (continued)
- [lmi-commits] [lmi] master ef38c9d 141/156: Revert the title map related changes, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b1ab0fa 126/156: Leave a gap between upper footer part and main page contents, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 940198c 059/156: Add numeric summary attachment page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b341a2a 061/156: Factor out using_illustration_table helper class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1b46585 076/156: Use MarketingNameFootnote & StateMarketingImprimatur on cover page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 234cd39 012/156: Use custom font sizes to be closer to the existing illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 956fcca 071/156: Change the second narrative summary page to use a template too, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master dbe5955 015/156: Factor out html_interpolator from pdf_illustration, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 9665573 070/156: Change narrative summary page to use an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master a629602 083/156: Use custom <scaled_image> HTML tag for the embedded images, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b425030 082/156: Factor out html_cell_for_pdf_output from numeric_summary_table_cell,
Greg Chicares <=
- [lmi-commits] [lmi] master d99576a 069/156: Change cover page to use an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 416ab02 030/156: Add support for vector variables to PDF generating code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master d4dfaa9 075/156: Also use data directory for image files referenced from HTML, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4f98db5 081/156: Don't show "Age 70" row in numeric summary for composites, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master f8853b9 090/156: Add "contract numbers" fragment to the header, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 61430d2 092/156: Move some variable definitions to the base illustration class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 7ccd207 087/156: Rename "footer_contents" to more precise "page_number", Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 3a64b87 094/156: Correct misleading comment for page class dtor, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4e76bba 098/156: Add support for comments to the string interpolation function, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b5fe850 102/156: Add NASD basic illustration page, Greg Chicares, 2018/01/30