[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 6b3b5b2 054/156: Factor out illustration_tabl
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 6b3b5b2 054/156: Factor out illustration_table_generator from tabular_detail2_page |
Date: |
Tue, 30 Jan 2018 17:22:08 -0500 (EST) |
branch: master
commit 6b3b5b25e00ee640db6fb4896c7f6f60369e94fe
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Factor out illustration_table_generator from tabular_detail2_page
Extract a reusable table generator class from a particular page. This
class takes care of grouping table rows into groups and also
encapsulates the page break detection logic.
No real changes yet.
---
ledger_pdf_generator_wx.cpp | 105 ++++++++++++++++++++++++++++++++------------
1 file changed, 76 insertions(+), 29 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index c662e33..a8154c8 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -243,6 +243,71 @@ class html_interpolator
std::map<std::string, text> vars_;
};
+// A slightly specialized table generator for the tables used in the
+// illustrations.
+class illustration_table_generator : public wx_table_generator
+{
+ public:
+ static int const rows_per_group = 5;
+
+ illustration_table_generator
+ (pdf_writer_wx& writer
+ ,wxDC& dc
+ ,int page_bottom
+ )
+ :wx_table_generator
+ (dc
+ ,writer.get_horz_margin()
+ ,writer.get_page_width()
+ )
+ ,page_bottom_(page_bottom)
+ {
+ use_condensed_style();
+ align_right();
+ }
+
+ // This is a wrapper around the base class output_row() which also adds
+ // breaks between row groups for readability and returns true if we need to
+ // start a new page.
+ bool output_and_check_for_page_break
+ (int year
+ ,int* pos_y
+ ,std::string const* values
+ )
+ {
+ wx_table_generator::output_row(pos_y, values);
+
+ if((year + 1) % rows_per_group == 0)
+ {
+ // We need a group break.
+ *pos_y += row_height();
+
+ // And possibly a page break, which will be necessary if we don't
+ // have enough space for another full group because we don't want
+ // to have page breaks in the middle of a group.
+ if(*pos_y >= page_bottom_ - rows_per_group*row_height())
+ {
+ return true;
+ }
+ }
+
+ // No need for a page break yet.
+ return false;
+ }
+
+ // Return the amount of vertical space taken by separator lines in the
+ // table headers.
+ int get_separator_line_height() const
+ {
+ // This is completely arbitrary and chosen just because it seems to
+ // look well.
+ return row_height() / 2;
+ }
+
+ private:
+ int page_bottom_ = 0;
+};
+
class page
{
public:
@@ -1650,12 +1715,11 @@ class tabular_detail2_page : public numbered_page
{
numbered_page::render(ledger, writer, dc, interpolate_html);
- wx_table_generator table{create_table_generator(writer, dc)};
+ illustration_table_generator table{create_table_generator(writer, dc)};
std::vector<std::string> values(column_max);
// The table may need several pages, loop over them.
- int const row_height = table.row_height();
int const year_max = ledger.GetMaxLength();
for(int year = 0; year < year_max; ++year)
{
@@ -1676,22 +1740,12 @@ class tabular_detail2_page : public numbered_page
values[column_ill_crediting_rate] =
interpolate_html.evaluate("AnnGAIntRate_Current", year);
values[column_selected_face_amount] =
interpolate_html.evaluate("SpecAmt", year);
- table.output_row(&pos_y, values.data());
- // Insert a space after every 5th row for readability.
- if((year + 1) % rows_per_group == 0)
+ if(table.output_and_check_for_page_break(year, &pos_y,
values.data()))
{
- pos_y += row_height;
-
- // Start a new page if necessary, which will be the case
if we
- // don't have enough space for another full group because
we
- // don't want to have page breaks in the middle of a group.
- if(pos_y >= get_footer_top() - rows_per_group*row_height)
- {
- next_page(dc);
- numbered_page::render(ledger, writer, dc,
interpolate_html);
- break;
- }
+ next_page(dc);
+ numbered_page::render(ledger, writer, dc,
interpolate_html);
+ break;
}
}
}
@@ -1706,8 +1760,6 @@ class tabular_detail2_page : public numbered_page
,column_max
};
- static int const rows_per_group = 5;
-
// Helper of render() and get_extra_pages_needed(): either outputs the
// fixed part of the page or just measures the space needed by it,
// depending on the output_mode parameter. Returns the vertical position of
@@ -1736,26 +1788,19 @@ class tabular_detail2_page : public numbered_page
table.output_header(&pos_y, output_mode);
- pos_y += 5;
+ pos_y += table.get_separator_line_height();
return pos_y;
}
// Common part of render() and get_extra_pages_needed(): create the table
// generator to use.
- wx_table_generator create_table_generator
+ illustration_table_generator create_table_generator
(pdf_writer_wx& writer
,wxDC& dc
) const
{
- wx_table_generator table
- (dc
- ,writer.get_horz_margin()
- ,writer.get_page_width()
- );
-
- table.use_condensed_style();
- table.align_right();
+ illustration_table_generator table(writer, dc, get_footer_top());
std::vector<std::pair<std::string, std::string>> const
columns =
@@ -1782,7 +1827,7 @@ class tabular_detail2_page : public numbered_page
,html_interpolator const& interpolate_html
) const override
{
- wx_table_generator table{create_table_generator(writer, dc)};
+ illustration_table_generator table{create_table_generator(writer, dc)};
int const pos_y = render_or_measure_fixed_page_part
(table
@@ -1794,6 +1839,8 @@ class tabular_detail2_page : public numbered_page
int const rows_per_page = (get_footer_top() - pos_y) /
table.row_height();
+ int const rows_per_group =
illustration_table_generator::rows_per_group;
+
if(rows_per_page < rows_per_group)
{
// We can't afford to continue in this case as we can never output
- [lmi-commits] [lmi] master d2b2cae 038/156: Change column_headings page to use external template, (continued)
- [lmi-commits] [lmi] master d2b2cae 038/156: Change column_headings page to use external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 2bb1c91 041/156: Remove unnecessary outer html and body tags, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1afd45c 040/156: Avoid spurious coding style violation, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 9695e9e 112/156: Create InitAnnLoanDueRate vector in addition to the scalar, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 5f6dc89 131/156: Use string objects for illustration_table_column fields, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master fb01571 035/156: Pass what is being expanded to interpolation function, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master fc6d8b7 034/156: Implement the "Columns Headings" page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 46788b8 119/156: Start implementing individual private placement illustration kind, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1287474 114/156: Start private group placement illustration class implementation, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0f78daf 050/156: Compute the footer size in page_with_footer::pre_render(), Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6b3b5b2 054/156: Factor out illustration_table_generator from tabular_detail2_page,
Greg Chicares <=
- [lmi-commits] [lmi] master 23d26f8 055/156: Factor out reusable page_with_tabular_report class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master f484622 044/156: Only show numeric summary if not in force, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 67db94b 042/156: Implement more of numeric summary page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master dbaf3c4 048/156: Render PDF illustrations in two passes, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master de9567e 152/156: Fix misplaced commas in ledger PDF generator code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 783befa 006/156: Add separate class for representing HTML contents, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 8c5be11 128/156: Use proper types for get_two_column_header() parameters, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 257ff4b 065/156: Add numeric summary table to PDF illustrations, Greg Chicares, 2018/01/30
- [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