lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master e821acd 05/15: Require specifying font sizes


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e821acd 05/15: Require specifying font sizes when using pdf_writer_wx
Date: Fri, 27 Jul 2018 17:23:16 -0400 (EDT)

branch: master
commit e821acd2e28bdc8083a597d9782a5fcae1e5dce7
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Require specifying font sizes when using pdf_writer_wx
    
    Make the previously optional "font sizes" argument mandatory.
    
    This seems to make more sense because the 2 users of this class use it
    with different font sizes sets and none of them is clearly better than
    the other, so specifying it in one case and not in the other was
    gratuitously asymmetric.
    
    It also simplicities pdf_writer_wx ctor code and avoids duplicating the
    font names in it.
---
 group_quote_pdf_gen_wx.cpp  |  6 +++++-
 ledger_pdf_generator_wx.cpp | 24 +++++++-----------------
 pdf_writer_wx.cpp           | 25 +++----------------------
 pdf_writer_wx.hpp           |  8 +++++---
 4 files changed, 20 insertions(+), 43 deletions(-)

diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index 37a737a..95372c9 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -663,7 +663,11 @@ void group_quote_pdf_generator_wx::add_ledger(Ledger 
const& ledger)
 
 void group_quote_pdf_generator_wx::save(std::string const& output_filename)
 {
-    pdf_writer_wx pdf_writer(output_filename, wxLANDSCAPE);
+    pdf_writer_wx pdf_writer
+        (output_filename
+        ,wxLANDSCAPE
+        ,{7, 8, 10, 12, 14, 17, 20} // Standard HTML font sizes.
+        );
 
     int pos_y = 0;
 
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 65b45fe..9c57b1b 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -727,7 +727,13 @@ class pdf_illustration : protected html_interpolator
     // Render all pages to the specified PDF file.
     void render_all(fs::path const& output)
     {
-        pdf_writer_wx writer(output.string(), wxPORTRAIT, &html_font_sizes);
+        // Use non-default font sizes that are used to make the new
+        // illustrations more similar to the previously existing ones.
+        pdf_writer_wx writer
+            (output.string()
+            ,wxPORTRAIT
+            ,{8, 9, 10, 12, 14, 18, 20}
+            );
 
         html_cell_for_pdf_output::pdf_context_setter
             set_pdf_context(ledger_, writer, *this);
@@ -908,10 +914,6 @@ class pdf_illustration : protected html_interpolator
             );
     }
 
-    // This array stores the non-default font sizes that are used to make it
-    // simpler to replicate the existing illustrations.
-    static std::array<int, 7> const html_font_sizes;
-
     // Source of the data.
     Ledger const& ledger_;
 
@@ -919,18 +921,6 @@ class pdf_illustration : protected html_interpolator
     std::vector<std::unique_ptr<page>> pages_;
 };
 
-std::array<int, 7> const pdf_illustration::html_font_sizes
-    {
-    { 8
-    , 9
-    ,10
-    ,12
-    ,14
-    ,18
-    ,20
-    }
-    };
-
 // Cover page used by several different illustration kinds.
 class cover_page : public page
 {
diff --git a/pdf_writer_wx.cpp b/pdf_writer_wx.cpp
index d4835b4..e515bea 100644
--- a/pdf_writer_wx.cpp
+++ b/pdf_writer_wx.cpp
@@ -60,7 +60,7 @@ wxPrintData make_print_data
 pdf_writer_wx::pdf_writer_wx
     (wxString const&    output_filename
     ,wxPrintOrientation orientation
-    ,std::array<int, 7> const* html_font_sizes
+    ,html_font_sizes const& font_sizes
     )
     :print_data_        {make_print_data(output_filename, orientation)}
     ,pdf_dc_            {print_data_}
@@ -86,33 +86,14 @@ pdf_writer_wx::pdf_writer_wx
     // Use a standard PDF Helvetica font (without embedding any custom fonts in
     // the generated file, the only other realistic choice is Times New Roman).
     pdf_dc_.SetFont
-        (wxFontInfo
-            (html_font_sizes
-                ? html_font_sizes->at(2)
-                : 8
-            )
+        (wxFontInfo(font_sizes.at(2))
             .Family(wxFONTFAMILY_SWISS)
             .FaceName("Helvetica")
         );
 
     // Create an HTML parser to allow easily adding HTML contents to the 
output.
     html_parser_.SetDC(&pdf_dc_);
-    if(html_font_sizes)
-        {
-        html_parser_.SetFonts
-            ("Helvetica"
-            ,"Courier"
-            ,html_font_sizes->data()
-            );
-        }
-    else
-        {
-        html_parser_.SetStandardFonts
-            (pdf_dc_.GetFont().GetPointSize()
-            ,"Helvetica"
-            ,"Courier"
-            );
-        }
+    html_parser_.SetFonts("Helvetica", "Courier", font_sizes.data());
 
     // Create the virtual file system object for loading images referenced from
     // HTML and interpret relative paths from the data directory.
diff --git a/pdf_writer_wx.hpp b/pdf_writer_wx.hpp
index a782718..3013024 100644
--- a/pdf_writer_wx.hpp
+++ b/pdf_writer_wx.hpp
@@ -41,12 +41,14 @@ namespace html { class text; }
 class pdf_writer_wx
 {
   public:
-    // Optional html_font_sizes array allows to override default font sizes for
-    // the standard HTML3 fonts (1..7).
+    using html_font_sizes = std::array<int, 7>;
+
+    // The font sizes array specifies the sizes, in points, of the standard
+    // HTML3 fonts (1..7).
     pdf_writer_wx
         (wxString const&           output_filename
         ,wxPrintOrientation        orientation
-        ,std::array<int, 7> const* html_font_sizes = nullptr
+        ,html_font_sizes const&    font_sizes
         );
 
     pdf_writer_wx(pdf_writer_wx const&) = delete;



reply via email to

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