[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 683f549 2/7: Move code manipulating wxHtmlCel
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 683f549 2/7: Move code manipulating wxHtmlCells into pdf_writer_wx |
Date: |
Thu, 11 Oct 2018 15:41:12 -0400 (EDT) |
branch: master
commit 683f549654d469387993d7c3be022db4bebd0456
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Move code manipulating wxHtmlCells into pdf_writer_wx
No real changes, just prefer to keep all code using wxHtmlWinParser in
pdf_writer_wx, which already uses it anyhow.
This allows to make pdf_writer_wx::initialize_html_parser() private,
albeit at the price of adding a new make_html_from() function, but the
new public function provides a better level of abstraction than the old
one.
---
ledger_pdf_generator_wx.cpp | 16 +++-------------
pdf_writer_wx.cpp | 27 +++++++++++++++++++++++++++
pdf_writer_wx.hpp | 6 ++++--
3 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 6caf75e..49457ca 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -1414,24 +1414,14 @@ class standard_page : public numbered_page
// rendered as part of the page body.
page_body_cell_->Detach(cell);
- // Initializing wxHtmlWinParser changes the font of the DC, so
- // ensure that we preserve the original font.
- wxDCFontChanger preserve_font(writer.dc(), *wxNORMAL_FONT);
-
- // And attach it to another HTML document representing just
- // the header contents.
+ // And convert it to self-containing HTML document representing
+ // just the header contents.
//
// Note that we can't just use this cell on its own, we
// must let wxHtmlWinParser build the usual structure as
// wxHTML relies on having extra cells in its DOM, notably
// the wxHtmlFontCell setting the initial document font.
- wxHtmlWinParser html_parser;
- writer.initialize_html_parser(html_parser);
- html_parser.InitParser(wxString{});
- header_cell_.reset
-
(static_cast<wxHtmlContainerCell*>(html_parser.GetProduct())
- );
- header_cell_->InsertCell(cell);
+ header_cell_ = writer.make_html_from(cell);
break;
}
diff --git a/pdf_writer_wx.cpp b/pdf_writer_wx.cpp
index d393fb8..eacf946 100644
--- a/pdf_writer_wx.cpp
+++ b/pdf_writer_wx.cpp
@@ -350,6 +350,33 @@ std::unique_ptr<wxHtmlContainerCell>
pdf_writer_wx::parse_html(html::text&& html
);
}
+/// Construct a self-contained HTML document from the given cell.
+///
+/// The function takes ownership of its argument and attaches it to the new,
+/// empty, HTML document using the same parameters (i.e. fonts) as all the
+/// other HTML created by output_html().
+
+std::unique_ptr<wxHtmlContainerCell>
+pdf_writer_wx::make_html_from(wxHtmlCell* cell)
+{
+ // Initializing wxHtmlWinParser changes the font of the DC, so
+ // ensure that we preserve the original font.
+ wxDCFontChanger preserve_font(writer.dc(), *wxNORMAL_FONT);
+
+ wxHtmlWinParser html_parser;
+ initialize_html_parser(html_parser);
+ html_parser.InitParser(wxString{});
+
+ auto document_cell = std::make_unique<wxHtmlContainerCell>
+ (static_cast<wxHtmlContainerCell*>(html_parser.GetProduct())
+ );
+
+ // Give ownership of the cell to the new document.
+ document_cell->InsertCell(cell);
+
+ return document_cell;
+}
+
int pdf_writer_wx::get_horz_margin() const
{
return horz_margin;
diff --git a/pdf_writer_wx.hpp b/pdf_writer_wx.hpp
index d5ea584..7c75ded 100644
--- a/pdf_writer_wx.hpp
+++ b/pdf_writer_wx.hpp
@@ -108,10 +108,10 @@ class pdf_writer_wx
// Helper methods for working with HTML contents.
- void initialize_html_parser(wxHtmlWinParser& html_parser);
-
std::unique_ptr<wxHtmlContainerCell> parse_html(html::text&& html);
+ std::unique_ptr<wxHtmlContainerCell> make_html_from(wxHtmlCell* cell);
+
// Page metrics: the page width and height are the size of the page region
// reserved for the normal contents, excluding horizontal and vertical
// margins. Total width and height include the margins.
@@ -124,6 +124,8 @@ class pdf_writer_wx
int get_page_bottom() const;
private:
+ void initialize_html_parser(wxHtmlWinParser& html_parser);
+
wxPrintData print_data_;
wxPdfDC pdf_dc_;
- [lmi-commits] [lmi] master updated (9ec9f44 -> b9f72cb), Greg Chicares, 2018/10/11
- [lmi-commits] [lmi] master 42525e9 5/7: Behave reasonably in unexpected circumstances, Greg Chicares, 2018/10/11
- [lmi-commits] [lmi] master ebfdc8a 3/7: Replace wxDCFontChanger with dc_font_preserver, Greg Chicares, 2018/10/11
- [lmi-commits] [lmi] master 145965d 1/7: Fix initial font after detaching the header HTML cell, Greg Chicares, 2018/10/11
- [lmi-commits] [lmi] master 2f1464a 4/7: Improve concinnity, Greg Chicares, 2018/10/11
- [lmi-commits] [lmi] master 683f549 2/7: Move code manipulating wxHtmlCells into pdf_writer_wx,
Greg Chicares <=
- [lmi-commits] [lmi] master 1cfcae9 6/7: Improve concinnity, Greg Chicares, 2018/10/11
- [lmi-commits] [lmi] master b9f72cb 7/7: Improve const correctness, Greg Chicares, 2018/10/11