>From 7c50d694f25220c3115a806cb2c423a2d3f0b7b4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 7 Nov 2015 16:21:23 +0100 Subject: [PATCH] Don't output unnecessary empty footnotes lines in group quotes PDF If the corresponding footnote is empty, don't output the empty line separating it from the previous contents neither as this results in an ugly gap. Also, in the special case of the group quote prospectus, don't output the "" tags around it neither if it is empty -- while invisible in the output, this is still unnecessary and the same mechanism used for avoiding the empty lines can be used here as well. --- group_quote_pdf_gen_wx.cpp | 117 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 10 deletions(-) diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp index 2f43491..0f995fb 100644 --- a/group_quote_pdf_gen_wx.cpp +++ b/group_quote_pdf_gen_wx.cpp @@ -94,6 +94,69 @@ wxString escape_for_html_elem(std::string const& s) return z; } +/// Namespace for helpers used for HTML generation. + +namespace html +{ + +/// Namespace for the support HTML tags. +/// +/// Tags are only used as template arguments, so they don't need to be defined, +/// just declared -- and tag_info below specialized for them. + +namespace tag +{ + +struct b; +struct br; + +} // tag namespace + +template +struct tag_info; + +template<> +struct tag_info +{ + static char const* get_name() { return "b"; } + static bool has_end() { return true; } +}; + +template<> +struct tag_info +{ + static char const* get_name() { return "br"; } + static bool has_end() { return false; } +}; + +} // html namespace + +/// Wrap the given text in an HTML tag if it is not empty, otherwise just +/// return an empty string. +/// +/// For the tags without matching closing tags, such as e.g. "
", wrapping +/// the text means just prepending the tag to it. This is still done only if +/// the text is not empty. + +template +wxString wrap_if_not_empty(wxString const& html) +{ + wxString result; + if(!html.empty()) + { + result + << '<' << html::tag_info::get_name() << '>' + << html; + if(html::tag_info::has_end()) + { + result + << "::get_name() << '>'; + } + } + + return result; +} + /// Generate HTML representation of a field name and value in an HTML table and /// append it to the specified string, defining the HTML. /// @@ -561,17 +624,51 @@ void assert_nonblank(std::string const& value, std::string const& name) jdn_t eff_date = jdn_t(static_cast(invar.EffDateJdn)); effective_date_ = ConvertDateToWx(eff_date).FormatDate().ToStdString(); // Deliberately begin the footer with
tags, to separate it - // from the logo right above it. - // SOMEDAY !! Suppress
tags preceding blank strings. + // from the logo right above it, but don't use these tags if the footer is + // empty. footer_ = - "

" + escape_for_html_elem(invar.GroupQuoteIsNotAnOffer ) - + "

" + escape_for_html_elem(invar.GroupQuoteRidersFooter ) - + "

" + escape_for_html_elem(invar.GroupQuotePolicyFormId ) - + "

" + escape_for_html_elem(invar.GroupQuoteStateVariations) - + "

" + escape_for_html_elem(invar.MarketingNameFootnote ) - + "

" + escape_for_html_elem(invar.GroupQuoteProspectus ) + "" - + "

" + escape_for_html_elem(invar.GroupQuoteUnderwriter ) - + "

" + escape_for_html_elem(invar.GroupQuoteBrokerDealer ) + wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.GroupQuoteIsNotAnOffer) + ) + ) + + wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.GroupQuoteRidersFooter) + ) + ) + + wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.GroupQuotePolicyFormId) + ) + ) + + wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.GroupQuoteStateVariations) + ) + ) + + wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.MarketingNameFootnote) + ) + ) + + wrap_if_not_empty + (wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.GroupQuoteProspectus) + ) + ) + ) + + wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.GroupQuoteUnderwriter) + ) + ) + + wrap_if_not_empty + (wrap_if_not_empty + (escape_for_html_elem(invar.GroupQuoteBrokerDealer) + ) + ) ; assert_nonblank(company_ , "Sponsor"); -- 2.5.1