[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d1204c2 111/156: Factor out common parts of r
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d1204c2 111/156: Factor out common parts of render_or_measure_fixed_page_part() |
Date: |
Tue, 30 Jan 2018 17:22:23 -0500 (EST) |
branch: master
commit d1204c2c1874a9697f04217d6dee9817b27c0667
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Factor out common parts of render_or_measure_fixed_page_part()
Reduce code duplication by moving all code common to all pages with
tables into the base class implementation of this function itself and
adding get_fixed_page_contents() and render_or_measure_extra_headers()
virtual methods for the really page-specific parts.
---
ledger_pdf_generator_wx.cpp | 217 ++++++++++++++++++++------------------------
1 file changed, 98 insertions(+), 119 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 42d8bb0..a33a470 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -1542,17 +1542,70 @@ class page_with_tabular_report
}
protected:
- // Must be overridden to render (only if output_mode is e_output_normal)
- // the fixed page part and (in any case) return the vertical coordinate of
- // its bottom, where the tabular report starts.
- virtual int render_or_measure_fixed_page_part
+ // Must be overridden to return the contents of the fixed page part. This
+ // string will be interpolated and typically will be just "{{>template}}".
+ virtual std::string get_fixed_page_contents() const = 0;
+
+ // May be overridden to render (only if output_mode is e_output_normal)
+ // the extra headers just above the regular table headers.
+ //
+ // If this function does anything, it must show the first super-header at
+ // pos_y and update it to account for the added lines. The base class
+ // version does nothing.
+ virtual void render_or_measure_extra_headers
(illustration_table_generator& table
- ,pdf_writer_wx& writer
,html_interpolator const& interpolate_html
+ ,int* pos_y
,enum_output_mode output_mode
- ) const = 0;
+ ) const
+ {
+ stifle_warning_for_unused_value(table);
+ stifle_warning_for_unused_value(interpolate_html);
+ stifle_warning_for_unused_value(pos_y);
+ stifle_warning_for_unused_value(output_mode);
+ }
private:
+ // Render (only if output_mode is e_output_normal) the fixed page part and
+ // (in any case) return the vertical coordinate of its bottom, where the
+ // tabular report starts.
+ int render_or_measure_fixed_page_part
+ (illustration_table_generator& table
+ ,pdf_writer_wx& writer
+ ,html_interpolator const& interpolate_html
+ ,enum_output_mode output_mode
+ ) const
+ {
+ int pos_y = writer.get_vert_margin();
+
+ pos_y += writer.output_html
+ (writer.get_horz_margin()
+ ,pos_y
+ ,writer.get_page_width()
+ ,interpolate_html(get_fixed_page_contents())
+ ,output_mode
+ );
+
+ render_or_measure_extra_headers
+ (table
+ ,interpolate_html
+ ,&pos_y,
+ output_mode
+ );
+
+ table.output_header(&pos_y, output_mode);
+
+ pos_y += table.get_separator_line_height();
+ table.output_horz_separator
+ (0
+ ,table.columns_count()
+ ,pos_y
+ ,output_mode
+ );
+
+ return pos_y;
+ }
+
// Override the base class method as the table may overflow onto the next
// page(s).
int get_extra_pages_needed
@@ -1614,26 +1667,23 @@ class tabular_detail_page : public
page_with_tabular_report
,column_max
};
- int render_or_measure_fixed_page_part
+ std::string get_fixed_page_contents() const override
+ {
+ return "{{>tabular_details}}";
+ }
+
+ void render_or_measure_extra_headers
(illustration_table_generator& table
- ,pdf_writer_wx& writer
,html_interpolator const& interpolate_html
+ ,int* pos_y
,enum_output_mode output_mode
) const override
{
- int pos_y = writer.get_vert_margin();
-
- pos_y += writer.output_html
- (writer.get_horz_margin()
- ,pos_y
- ,writer.get_page_width()
- ,interpolate_html("{{>tabular_details}}")
- ,output_mode
- );
+ stifle_warning_for_unused_value(interpolate_html);
// Make a copy because we want the real pos_y to be modified only once,
// not twice, by both output_super_header() calls.
- auto pos_y_copy = pos_y;
+ auto pos_y_copy = *pos_y;
table.output_super_header
("Guaranteed Values"
,column_guar_account_value
@@ -1645,35 +1695,23 @@ class tabular_detail_page : public
page_with_tabular_report
("Non-Guaranteed Values"
,column_cur_account_value
,column_max
- ,&pos_y
+ ,pos_y
,output_mode
);
- pos_y += table.get_separator_line_height();
+ *pos_y += table.get_separator_line_height();
table.output_horz_separator
(column_guar_account_value
,column_dummy_separator
- ,pos_y
+ ,*pos_y
,output_mode
);
table.output_horz_separator
(column_cur_account_value
,column_max
- ,pos_y
- ,output_mode
- );
-
- table.output_header(&pos_y, output_mode);
-
- pos_y += table.get_separator_line_height();
- table.output_horz_separator
- (0
- ,column_max
- ,pos_y
+ ,*pos_y
,output_mode
);
-
- return pos_y;
}
illustration_table_columns const& get_table_columns() const override
@@ -1712,6 +1750,11 @@ class tabular_detail2_page : public
page_with_tabular_report
,column_max
};
+ std::string get_fixed_page_contents() const override
+ {
+ return "{{>tabular_details2}}";
+ }
+
illustration_table_columns const& get_table_columns() const override
{
static illustration_table_columns const columns =
@@ -1729,32 +1772,6 @@ class tabular_detail2_page : public
page_with_tabular_report
// One column should be hidden for composite ledgers.
return column != column_end_of_year_age || !ledger.is_composite();
}
-
- int render_or_measure_fixed_page_part
- (illustration_table_generator& table
- ,pdf_writer_wx& writer
- ,html_interpolator const& interpolate_html
- ,enum_output_mode output_mode
- ) const override
- {
- int pos_y = writer.get_vert_margin();
-
- pos_y += writer.output_html
- (writer.get_horz_margin()
- ,pos_y
- ,writer.get_page_width()
- ,interpolate_html("{{>tabular_details2}}")
- ,output_mode
- );
-
- table.output_header(&pos_y, output_mode);
-
- pos_y += table.get_separator_line_height();
- table.output_horz_separator(0, column_max, pos_y, output_mode);
-
- return pos_y;
- }
-
};
// Regular illustration.
@@ -1925,6 +1942,11 @@ class nasd_basic : public page_with_tabular_report
,column_max
};
+ std::string get_fixed_page_contents() const override
+ {
+ return "{{>nasd_basic}}";
+ }
+
illustration_table_columns const& get_table_columns() const override
{
static illustration_table_columns const columns =
@@ -1953,54 +1975,44 @@ class nasd_basic : public page_with_tabular_report
return column != column_end_of_year_age || !ledger.is_composite();
}
- int render_or_measure_fixed_page_part
+ void render_or_measure_extra_headers
(illustration_table_generator& table
- ,pdf_writer_wx& writer
,html_interpolator const& interpolate_html
+ ,int* pos_y
,enum_output_mode output_mode
) const override
{
- int pos_y = writer.get_vert_margin();
-
- pos_y += writer.output_html
- (writer.get_horz_margin()
- ,pos_y
- ,writer.get_page_width()
- ,interpolate_html("{{>nasd_basic}}")
- ,output_mode
- );
-
// Output the first super header row.
- auto pos_y_copy = pos_y;
+ auto pos_y_copy = *pos_y;
table.output_super_header
("Using guaranteed charges"
,column_guar0_cash_surr_value
,column_separator_guar_cur0
- ,&pos_y
+ ,pos_y
,output_mode
);
- pos_y = pos_y_copy;
+ *pos_y = pos_y_copy;
table.output_super_header
("Using current charges"
,column_cur0_cash_surr_value
,column_max
- ,&pos_y
+ ,pos_y
,output_mode
);
- pos_y += table.get_separator_line_height();
+ *pos_y += table.get_separator_line_height();
table.output_horz_separator
(column_guar0_cash_surr_value
,column_separator_guar_cur0
- ,pos_y
+ ,*pos_y
,output_mode
);
table.output_horz_separator
(column_cur0_cash_surr_value
,column_max
- ,pos_y
+ ,*pos_y
,output_mode
);
@@ -2029,7 +2041,7 @@ class nasd_basic : public page_with_tabular_report
std::size_t end_column = begin_column + 2;
LMI_ASSERT(end_column <= column_max);
- auto y = pos_y;
+ auto y = *pos_y;
std::string const suffix_short = [=]()
{
@@ -2102,19 +2114,11 @@ class nasd_basic : public page_with_tabular_report
,column_cur0_cash_surr_value
);
- pos_y = output_two_column_super_header
+ *pos_y = output_two_column_super_header
(base::current
,interest_rate::non_zero
,column_cur_cash_surr_value
);
-
- // Finally output the standard header.
- table.output_header(&pos_y, output_mode);
-
- pos_y += table.get_separator_line_height();
- table.output_horz_separator(0, column_max, pos_y, output_mode);
-
- return pos_y;
}
};
@@ -2140,6 +2144,11 @@ class nasd_supplemental : public page_with_tabular_report
,column_max
};
+ std::string get_fixed_page_contents() const override
+ {
+ return "{{>nasd_supplemental}}";
+ }
+
illustration_table_columns const& get_table_columns() const override
{
static illustration_table_columns const columns =
@@ -2203,36 +2212,6 @@ class nasd_supplemental : public page_with_tabular_report
return true;
}
-
- int render_or_measure_fixed_page_part
- (illustration_table_generator& table
- ,pdf_writer_wx& writer
- ,html_interpolator const& interpolate_html
- ,enum_output_mode output_mode
- ) const override
- {
- int pos_y = writer.get_vert_margin();
-
- pos_y += writer.output_html
- (writer.get_horz_margin()
- ,pos_y
- ,writer.get_page_width()
- ,interpolate_html("{{>nasd_supplemental}}")
- ,output_mode
- );
-
- table.output_header(&pos_y, output_mode);
-
- pos_y += table.get_separator_line_height();
- table.output_horz_separator
- (0
- ,table.columns_count()
- ,pos_y
- ,output_mode
- );
-
- return pos_y;
- }
};
// NASD illustration.
- [lmi-commits] [lmi] master 0f885a2 116/156: Define CorpNameAbbrev60 and Insured1Abbrev30 in common code, (continued)
- [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, 2018/01/30
- [lmi-commits] [lmi] master d1204c2 111/156: Factor out common parts of render_or_measure_fixed_page_part(),
Greg Chicares <=
- [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
- [lmi-commits] [lmi] master e00ab7d 080/156: Hide "attained age" column for composite illustrations, Greg Chicares, 2018/01/30