[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 38cab5e 096/156: Make footer template depend
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 38cab5e 096/156: Make footer template depend on illustration kind |
Date: |
Tue, 30 Jan 2018 17:22:20 -0500 (EST) |
branch: master
commit 38cab5ed8f68c28a30393ea2e99cb70c01e35085
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Make footer template depend on illustration kind
Also support lower and upper footer parts (not called "bottom" and "top"
to avoid confusion with the existing get_footer_top()), with the upper
part being above the footer separator line, as this is used by all the
non-regular illustrations.
---
ledger_pdf_generator_wx.cpp | 100 +++++++++++++++++++++++++++++++++++++-------
nasd_footer_lower.mustache | 19 +++++++++
nasd_footer_upper.mustache | 13 ++++++
3 files changed, 118 insertions(+), 14 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 0c4414a..2c7b55d 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -578,6 +578,8 @@ TAG_HANDLER_BEGIN(scaled_image, "SCALED_IMAGE")
}
TAG_HANDLER_END(scaled_image)
+class pdf_illustration;
+
class page
{
public:
@@ -590,6 +592,18 @@ class page
// Make base class dtor virtual.
virtual ~page() = default;
+ // Associate the illustration object using this page with it.
+ //
+ // This object is not passed as a ctor argument because it would be
+ // redundant, instead it is associated with the page when it's added to an
+ // illustration. This method is supposed to be called only once.
+ void illustration(pdf_illustration const& illustration)
+ {
+ LMI_ASSERT(!illustration_);
+
+ illustration_ = &illustration;
+ }
+
// Called before rendering any pages to prepare for doing this, e.g. by
// computing the number of pages needed.
//
@@ -632,6 +646,10 @@ class page
,interpolate_html("{{>" + template_name + "}}")
);
}
+
+ // The associated illustration, which will be non-null by the time our
+ // virtual methods such as pre_render() and render() are called.
+ pdf_illustration const* illustration_ = nullptr;
};
// This is just a container for the illustration-global data.
@@ -658,7 +676,9 @@ class pdf_illustration : protected html_interpolator
template<typename T, typename... Args>
void add(Args&&... args)
{
- pages_.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
+ auto page = std::make_unique<T>(std::forward<Args>(args)...);
+ page->illustration(*this);
+ pages_.emplace_back(std::move(page));
}
// Render all pages.
@@ -688,6 +708,13 @@ class pdf_illustration : protected html_interpolator
}
}
+ // Methods to be implemented by the derived classes to indicate which
+ // templates should be used for the upper (above the separating line) and
+ // the lower parts of the footer. The upper template name may be empty if
+ // it is not used at all.
+ virtual std::string get_upper_footer_template_name() const = 0;
+ virtual std::string get_lower_footer_template_name() const = 0;
+
protected:
// Helper for abbreviating a string to at most the given length (in bytes).
static std::string abbreviate_if_necessary(std::string s, size_t len)
@@ -856,22 +883,38 @@ class page_with_footer : public page
,html_interpolator const& interpolate_html
) override
{
- // Note that we implicitly assume here that get_footer_html() result
- // doesn't materially depend on the exact value of last_page_number_ as
+ auto const frame_horz_margin = writer.get_horz_margin();
+ auto const frame_width = writer.get_page_width();
+
+ // We implicitly assume here that get_footer_lower_html() result
+ // doesn't materially depend on the exact value of the page number as
// we don't know its definitive value here yet. In theory, this doesn't
// need to be true, e.g. we may later discover that 10 pages are needed
// instead of 9 and the extra digit might result in a line wrapping on
// a new line and this increasing the footer height, but in practice
// this doesn't risk happening and taking into account this possibility
// wouldn't be simple at all, so just ignore this possibility.
- auto const footer_height = writer.output_html
- (writer.get_horz_margin()
+ auto footer_height = writer.output_html
+ (frame_horz_margin
,0
- ,writer.get_page_width()
- ,get_footer_html(interpolate_html)
+ ,frame_width
+ ,get_footer_lower_html(interpolate_html)
,e_output_measure_only
);
+ auto const&
+ upper_template = illustration_->get_upper_footer_template_name();
+ if(!upper_template.empty())
+ {
+ footer_height += writer.output_html
+ (frame_horz_margin
+ ,0
+ ,frame_width
+ ,interpolate_html("{{>" + upper_template + "}}")
+ ,e_output_measure_only
+ );
+ }
+
footer_top_ = writer.get_page_bottom() - footer_height;
}
@@ -884,11 +927,25 @@ class page_with_footer : public page
auto const frame_horz_margin = writer.get_horz_margin();
auto const frame_width = writer.get_page_width();
+ auto y = footer_top_;
+
+ auto const&
+ upper_template = illustration_->get_upper_footer_template_name();
+ if(!upper_template.empty())
+ {
+ y += writer.output_html
+ (frame_horz_margin
+ ,footer_top_
+ ,frame_width
+ ,interpolate_html("{{>" + upper_template + "}}")
+ );
+ }
+
writer.output_html
(frame_horz_margin
- ,footer_top_
+ ,y
,frame_width
- ,get_footer_html(interpolate_html)
+ ,get_footer_lower_html(interpolate_html)
);
auto& dc = writer.dc();
@@ -896,9 +953,9 @@ class page_with_footer : public page
dc.SetPen(HIGHLIGHT_COL);
dc.DrawLine
(frame_horz_margin
- ,footer_top_
+ ,y
,frame_width + frame_horz_margin
- ,footer_top_
+ ,y
);
}
@@ -919,17 +976,19 @@ class page_with_footer : public page
virtual std::string get_page_number() const = 0;
// This method uses get_page_number() and returns the HTML wrapping it
- // and other fixed information appearing in the footer.
- text get_footer_html(html_interpolator const& interpolate_html) const
+ // and other fixed information appearing in the lower part of the footer.
+ text get_footer_lower_html(html_interpolator const& interpolate_html) const
{
auto const page_number_str = get_page_number();
+ auto const templ = illustration_->get_lower_footer_template_name();
+
// Use our own interpolation function to handle the special
// "page_number" variable that is replaced with the actual
// (possibly dynamic) page number.
return text::from_html
(interpolate_string
- ("{{>footer}}"
+ (("{{>" + templ + "}}").c_str()
,[page_number_str, interpolate_html]
(std::string const& s
,interpolate_lookup_kind kind
@@ -1836,6 +1895,9 @@ class pdf_illustration_regular : public pdf_illustration
add<numeric_summary_or_attachment_page<true>>();
}
}
+
+ std::string get_upper_footer_template_name() const override { return {}; }
+ std::string get_lower_footer_template_name() const override { return
"footer"; }
};
// NASD illustration.
@@ -1850,6 +1912,16 @@ class pdf_illustration_nasd : public pdf_illustration
{
add<cover_page>();
}
+
+ std::string get_upper_footer_template_name() const override
+ {
+ return "nasd_footer_upper";
+ }
+
+ std::string get_lower_footer_template_name() const override
+ {
+ return "nasd_footer_lower";
+ }
};
class ledger_pdf_generator_wx : public ledger_pdf_generator
diff --git a/nasd_footer_lower.mustache b/nasd_footer_lower.mustache
new file mode 100644
index 0000000..c22a594
--- /dev/null
+++ b/nasd_footer_lower.mustache
@@ -0,0 +1,19 @@
+<font size="-2">
+
+<table width="100%" cellspacing="0" cellpadding="0">
+ <tr>
+ <td colspan="3"> </td>
+ </tr>
+ <tr>
+ <td>{{InsCoName}}</td>
+ <td align="center">Date Prepared: {{date_prepared}}</td>
+ <td align="right">Policy Form: {{PolicyForm}}</td>
+ </tr>
+ <tr>
+ <td>{{InsCoAddr}}</td>
+ <td align="center">System Version: {{LmiVersion}}</td>
+ <td align="right">{{page_number}}</td>
+ </tr>
+</table>
+
+</font>
diff --git a/nasd_footer_upper.mustache b/nasd_footer_upper.mustache
new file mode 100644
index 0000000..df7ceae
--- /dev/null
+++ b/nasd_footer_upper.mustache
@@ -0,0 +1,13 @@
+<font size="-2">
+
+<p>
+* This illustration is based on the assumed Gross Rate shown.
+The Net Rate is provided for information purposes only.
+<br>
+** {{PremAllocationFootnote}}
+<br>
+See the Explanatory Notes for important {{ContractName}} information.
+This illustration is not complete without all pages.
+</p>
+
+</font>
- [lmi-commits] [lmi] master 89b4674 120/156: Add automatic support for multiline super-headers, (continued)
- [lmi-commits] [lmi] master 89b4674 120/156: Add automatic support for multiline super-headers, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0f885a2 116/156: Define CorpNameAbbrev60 and Insured1Abbrev30 in common code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 08559c3 121/156: Factor out base_suffix() and ir_suffix() functions, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 36c84ce 123/156: Add another individual private placement illustration page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0ecc8ec 036/156: Add support for partials to our ad hoc Mustache parser, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6f09722 107/156: Add missing words to the narrative summary continuation page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6510601 150/156: Rename a mute variable to avoid gcc -Wshadow warning, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 048ae05 093/156: Start NASD PDF illustration class implementation, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 5ea5c86 101/156: Simplify and correct current PDF DC font handling, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master ec490eb 153/156: Revise and extend some comments in PDF generation code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 38cab5e 096/156: Make footer template depend on illustration kind,
Greg Chicares <=
- [lmi-commits] [lmi] master d1204c2 111/156: Factor out common parts of render_or_measure_fixed_page_part(), Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master e388f6e 037/156: Add beginning of numeric summary page using an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 531699b 115/156: Factor out common page_with_basic_tabular_report class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master a85943b 124/156: Add the rest of individual private placement illustration pages, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master f0b9cea 113/156: Add "Assumption Detail" page to NASD illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 031070b 132/156: Implement supplemental report page for the regular illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 9fe1d07 125/156: Implement page-specific footer for "Tabular Details" pages, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4f3a02e 078/156: Add company logo to the cover page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 2d93248 118/156: Add the rest of group private placement illustration pages, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1272ce2 127/156: Don't include "Assumptions" page in composite NASD illustrations, Greg Chicares, 2018/01/30