lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 554eb23 13/15: Forbid page breaks inside para


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 554eb23 13/15: Forbid page breaks inside paragraphs in the illustrations
Date: Fri, 27 Jul 2018 17:23:17 -0400 (EDT)

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

    Forbid page breaks inside paragraphs in the illustrations
    
    Define a custom handler for the standard HTML <p> tag and make all the
    paragraphs "unbreakable", i.e. forbid page breaks inside them.
    
    This results in better output quality, e.g. for the explanatory notes
    pages where page breaks could occur in the middle of a paragraph before,
    but not any longer.
---
 ledger_pdf_generator_wx.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index b599a04..3b237a9 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -1509,9 +1509,31 @@ TAG_HANDLER_BEGIN(numeric_summary_table, 
"NUMERIC_SUMMARY_TABLE")
     }
 TAG_HANDLER_END(numeric_summary_table)
 
+// Custom handler for <p> tags preventing the page breaks inside them.
+TAG_HANDLER_BEGIN(unbreakable_paragraph, "P")
+    TAG_HANDLER_PROC(tag)
+    {
+        m_WParser->CloseContainer();
+        auto const 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);
+
+        // 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;
+    }
+TAG_HANDLER_END(unbreakable_paragraph)
+
 TAGS_MODULE_BEGIN(lmi_illustration)
     TAGS_MODULE_ADD(scaled_image)
     TAGS_MODULE_ADD(numeric_summary_table)
+    TAGS_MODULE_ADD(unbreakable_paragraph)
 TAGS_MODULE_END(lmi_illustration)
 
 // Numeric summary page is used on its own, as a regular page, but also as the



reply via email to

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