lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 42525e9 5/7: Behave reasonably in unexpected


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 42525e9 5/7: Behave reasonably in unexpected circumstances
Date: Thu, 11 Oct 2018 15:41:12 -0400 (EDT)

branch: master
commit 42525e928e53992867da698391487a536ecb6f24
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Behave reasonably in unexpected circumstances
    
    See:
      https://lists.nongnu.org/archive/html/lmi/2018-10/msg00020.html
---
 ledger_pdf_generator_wx.cpp | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 705aae9..4b035ec 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -454,17 +454,22 @@ static char const* const header_cell_id = 
"_lmi_page_header_id";
 TAG_HANDLER_BEGIN(page_header, "HEADER")
     TAG_HANDLER_PROC(tag)
     {
-        // Although the header typically occurs at the very beginning of the
+        // As usual, reuse the current container if empty. That's unlikely:
+        // although the header typically occurs at the very beginning of the
         // HTML template, it doesn't mean that the current container is empty,
         // quite on the contrary, it typically isn't because it contains the
         // cells setting the initial colors and font for the HTML body and we
         // must not make these cells part of the header cell as otherwise they
         // would be removed from the containing HTML document later and it
         // would use default font instead of the one set by pdf_writer_wx.
-        // So first, close the existing container and open a new one which we
-        // will mark as being the actual header cell.
-        m_WParser->CloseContainer();
-        auto const container = m_WParser->OpenContainer();
+        auto container = m_WParser->GetContainer();
+        if (container->GetFirstChild())
+            {
+            // It isn't, so we need to open a new one, which we will mark as
+            // being the actual header cell.
+            m_WParser->CloseContainer();
+            container = m_WParser->OpenContainer();
+            }
 
         // Set a unique ID for this container to allow finding it later.
         container->SetId(header_cell_id);



reply via email to

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