lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 5ea5c86 101/156: Simplify and correct current


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 5ea5c86 101/156: Simplify and correct current PDF DC font handling
Date: Tue, 30 Jan 2018 17:22:21 -0500 (EST)

branch: master
commit 5ea5c86f17e73c6cdc5b63fb04d16a5eff88c8f5
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Simplify and correct current PDF DC font handling
    
    Only set the smaller font (and although the pen) used for tables once,
    when creating the table generator object and avoid changing in it
    pdf_writer_wx::output_html() to make it unnecessary to ever set it
    again.
    
    This ensures that the same font size is used for the table column widths
    determination and actually outputting the text of these columns, which
    required explicit use of wxDCFontChanger before.
    
    Also explicitly use 9pt font instead of using wxFont::Smaller() which
    resulted in too small font (8pt).
---
 ledger_pdf_generator_wx.cpp | 25 +++++++++++--------------
 pdf_writer_wx.cpp           |  4 ++++
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 0bd03e1..a80b111 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -335,8 +335,19 @@ class using_illustration_table
         ,pdf_writer_wx& writer
         ) const
     {
+        // Set the smaller font used for all tables before creating the table
+        // generator which uses the DC font for its measurements.
+        auto& dc = writer.dc();
+        auto font = dc.GetFont();
+        font.SetPointSize(9);
+        dc.SetFont(font);
+
         illustration_table_generator table(writer);
 
+        // But set the highlight colour for drawing separator lines after
+        // creating it to override its default pen.
+        dc.SetPen(HIGHLIGHT_COL);
+
         int column = 0;
         for(auto const& i : get_table_columns())
             {
@@ -1224,8 +1235,6 @@ class numeric_summary_table_cell
     {
         auto const& ledger = pdf_context_for_html_output.ledger();
         auto& writer = pdf_context_for_html_output.writer();
-        auto& dc = writer.dc();
-        wxDCFontChanger set_smaller_font(dc, dc.GetFont().Smaller());
 
         illustration_table_generator
             table{create_table_generator(ledger, writer)};
@@ -1600,13 +1609,6 @@ class tabular_detail_page : public 
page_with_tabular_report
             ,output_mode
             );
 
-        auto& dc = writer.dc();
-
-        // Decrease the font size for the table to match the main page
-        // body text size.
-        dc.SetFont(dc.GetFont().Smaller());
-        dc.SetPen(HIGHLIGHT_COL);
-
         // 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;
@@ -1723,11 +1725,6 @@ class tabular_detail2_page : public 
page_with_tabular_report
             ,output_mode
             );
 
-        // Decrease the font size for the table to match the main page
-        // body text size.
-        auto& dc = writer.dc();
-        dc.SetFont(dc.GetFont().Smaller());
-
         table.output_header(&pos_y, output_mode);
 
         pos_y += table.get_separator_line_height();
diff --git a/pdf_writer_wx.cpp b/pdf_writer_wx.cpp
index 9b9b193..5ae36c2 100644
--- a/pdf_writer_wx.cpp
+++ b/pdf_writer_wx.cpp
@@ -174,6 +174,10 @@ int pdf_writer_wx::output_html
     ,enum_output_mode output_mode
     )
 {
+    // We don't really want to change the font, but to preserve the current DC
+    // font which is changed by rendering the HTML contents.
+    wxDCFontChanger preserve_font(pdf_dc_, wxFont());
+
     auto const html_str = wxString::FromUTF8(html.as_html());
     std::unique_ptr<wxHtmlContainerCell> const cell
         (static_cast<wxHtmlContainerCell*>(html_parser_.Parse(html_str))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]