lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 4a6c578 5/5: Prevent page breaks inside parag


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 4a6c578 5/5: Prevent page breaks inside paragraphs in a more robust way
Date: Fri, 31 Aug 2018 19:59:48 -0400 (EDT)

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

    Prevent page breaks inside paragraphs in a more robust way
    
    Just marking the current container as unbreakable in <P> HTML tag
    handler worked as long as the paragraph contained only text and inline,
    span-like tags such as <B> or <I> -- which was indeed the case in the
    current HTML templates, ensuring that pagination worked correctly.
    
    However a paragraph could still be broken if it contained any
    non-span-like element, such as <OL> or <UL> or even a simple <BR>.
    Prevent this from happening by keeping all such elements inside a nested
    wxHtmlContainerCell, which is not closed until the end of the paragraph,
    and thus ensuring that the parent container, corresponding to the
    paragraph itself, remains unbreakable in any case.
---
 ledger_pdf_generator_wx.cpp | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index efde307..e885830 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -1529,20 +1529,43 @@ TAG_HANDLER_END(numeric_summary_table)
 TAG_HANDLER_BEGIN(unbreakable_paragraph, "P")
     TAG_HANDLER_PROC(tag)
     {
-        m_WParser->CloseContainer();
-        auto const container = m_WParser->OpenContainer();
+        // Note: this code mimics what TAG_HANDLER_PROC()s for "div" and "p"
+        // tags in wxHTML itself do by copying their code because there is
+        // unfortunately no way to delegate to them currently.
+
+        // As usual, reuse the current container if it's empty.
+        auto container = m_WParser->GetContainer();
+        if (container->GetFirstChild())
+            {
+            // It isn't, we need to open a new one.
+            m_WParser->CloseContainer();
+            container = m_WParser->OpenContainer();
+            }
 
         // This is the reason for this handler existence: mark the container
         // used for the paragraph contents as being unbreakable.
         container->SetCanLiveOnPagebreak(false);
 
+        // Use a nested container so that nested tags that close and reopen a
+        // container again close this one, but still remain inside the outer
+        // "unbreakable" container.
+        container = m_WParser->OpenContainer();
+
         // This code reproduces what the standard "P" handler does.
         // Unfortunately there is no way to just delegate to it from here.
         container->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
         container->SetAlign(tag);
 
-        // Don't stop parsing, continue with the tag contents.
-        return false;
+        ParseInner(tag);
+
+        // Close both the inner and the outer containers and reopen the
+        // new current one.
+        m_WParser->CloseContainer();
+        m_WParser->CloseContainer();
+        m_WParser->OpenContainer();
+
+        // Return true to indicate that we've parsed the entire tag contents.
+        return true;
     }
 TAG_HANDLER_END(unbreakable_paragraph)
 



reply via email to

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