lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 234cd39 012/156: Use custom font sizes to be


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 234cd39 012/156: Use custom font sizes to be closer to the existing illustrations
Date: Tue, 30 Jan 2018 17:21:51 -0500 (EST)

branch: master
commit 234cd39c8d4f3622b44b795d25ed9a6cfc97f9ce
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Use custom font sizes to be closer to the existing illustrations
    
    Allow specifying custom font sizes in pdf_writer_wx and use this to get
    closer to the existing output which uses specific font sizes.
---
 ledger_pdf_generator_wx.cpp | 37 +++++++++++++++++++++++++++----------
 pdf_writer_wx.cpp           | 30 ++++++++++++++++++++++++------
 pdf_writer_wx.hpp           |  8 ++++++--
 3 files changed, 57 insertions(+), 18 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 6863d11..432f9c9 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -50,7 +50,7 @@ class pdf_illustration
     pdf_illustration(Ledger const& ledger
                     ,fs::path const& output
                     )
-        :writer_(output.string(), wxPORTRAIT)
+        :writer_(output.string(), wxPORTRAIT, &html_font_sizes)
         ,dc_(writer_.dc())
         ,ledger_(ledger)
         ,properties_(properties::init(ledger))
@@ -118,6 +118,11 @@ class pdf_illustration
     };
 
   private:
+    // Use non-default font sizes to make it simpler to replicate the existing
+    // illustrations.
+    static std::array<int, 7> const html_font_sizes;
+
+
     // Writer object used for the page metrics and higher level functions.
     pdf_writer_wx writer_;
 
@@ -135,6 +140,16 @@ class pdf_illustration
     int page_number_{0};
 };
 
+std::array<int, 7> const pdf_illustration::html_font_sizes =
+    { 8
+    , 9
+    ,10
+    ,12
+    ,14
+    ,18
+    ,20
+    };
+
 class page
 {
   public:
@@ -292,15 +307,17 @@ class cover_page : public page
             );
 
         auto const footer_html = tag::p[attr::align("center")]
-            (text::from
-                (invar.InsCoShortName
-                +"Financial Group is a marketing name for "
-                +invar.InsCoName
-                +"("
-                +invar.InsCoShortName
-                +") and its affiliated company and sales representatives, "
-                +invar.InsCoAddr
-                +"."
+            (tag::font[attr::size("-1")]
+                (text::from
+                    (invar.InsCoShortName
+                    +"Financial Group is a marketing name for "
+                    +invar.InsCoName
+                    +"("
+                    +invar.InsCoShortName
+                    +") and its affiliated company and sales representatives, "
+                    +invar.InsCoAddr
+                    +"."
+                    )
                 )
             );
 
diff --git a/pdf_writer_wx.cpp b/pdf_writer_wx.cpp
index c3b20ee..6b4ab4d 100644
--- a/pdf_writer_wx.cpp
+++ b/pdf_writer_wx.cpp
@@ -53,6 +53,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
     )
     :print_data_        {make_print_data(output_filename, orientation)}
     ,pdf_dc_            {print_data_}
@@ -74,16 +75,33 @@ 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(8).Family(wxFONTFAMILY_SWISS).FaceName("Helvetica")
+        (wxFontInfo
+            (html_font_sizes
+                ? html_font_sizes->at(2)
+                : 8
+            )
+            .Family(wxFONTFAMILY_SWISS)
+            .FaceName("Helvetica")
         );
 
     // Create an HTML parser to allow easily adding HTML contents to the 
output.
     html_parser_.SetDC(&pdf_dc_);
-    html_parser_.SetStandardFonts
-        (pdf_dc_.GetFont().GetPointSize()
-        ,"Helvetica"
-        ,"Courier"
-        );
+    if(html_font_sizes)
+        {
+        html_parser_.SetFonts
+            ("Helvetica"
+            ,"Courier"
+            ,html_font_sizes->data()
+            );
+        }
+    else
+        {
+        html_parser_.SetStandardFonts
+            (pdf_dc_.GetFont().GetPointSize()
+            ,"Helvetica"
+            ,"Courier"
+            );
+        }
 }
 
 /// Output an image at the given scale into the PDF.
diff --git a/pdf_writer_wx.hpp b/pdf_writer_wx.hpp
index 20e1726..b375fcd 100644
--- a/pdf_writer_wx.hpp
+++ b/pdf_writer_wx.hpp
@@ -30,6 +30,7 @@
 
 #include <wx/pdfdc.h>
 
+#include <array>
 #include <memory>                       // std::unique_ptr
 
 namespace html { class text; }
@@ -42,9 +43,12 @@ enum enum_output_mode
 class pdf_writer_wx
 {
   public:
+    // Optional html_font_sizes array allows to override default font sizes for
+    // the standard HTML3 fonts (1..7).
     pdf_writer_wx
-        (wxString const&    output_filename
-        ,wxPrintOrientation orientation
+        (wxString const&           output_filename
+        ,wxPrintOrientation        orientation
+        ,std::array<int, 7> const* html_font_sizes = nullptr
         );
 
     pdf_writer_wx(pdf_writer_wx const&) = delete;



reply via email to

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