[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;
- [lmi-commits] [lmi] master a8d5e26 08/15: Look for image files referenced in templates under data directory, (continued)
- [lmi-commits] [lmi] master a8d5e26 08/15: Look for image files referenced in templates under data directory, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 005b3eb 06/15: Replace pdf_writer_wx::get_page_height() with get_total_height(), Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 28e3c42 11/15: Remove workarounds for wx 3.1.1 warnings not relevant any more, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master b6b6827 03/15: Do call EndPage() in PDF generation code, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master a86d90a 02/15: Use more recent wxPdfDocument fixing the text origin bug, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 554eb23 13/15: Forbid page breaks inside paragraphs in the illustrations, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 271db22 14/15: Fix over eager assert in pdf_writer_wx::output_html(), Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 12d84c9 15/15: Fix regression in font sizes used for the group quotes PDF, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 2bd38fa 12/15: Use standard <img> tag instead of <scaled_image> in templates, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master 4cfcfe4 07/15: Refactor: remove render_page_template() helper function, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master e821acd 05/15: Require specifying font sizes when using pdf_writer_wx,
Greg Chicares <=
- [lmi-commits] [lmi] master c56a67f 09/15: Implement and use simple HTML output pagination, Greg Chicares, 2018/07/27
- [lmi-commits] [lmi] master f03ff64 10/15: Merge first two notes pages of regular individual illustrations, Greg Chicares, 2018/07/27