diff --git a/docs/changes.txt b/docs/changes.txt index 4b9ec418eb..a156283e77 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -106,6 +106,7 @@ All (GUI): - Add wxHtmlEasyPrinting::SetPromptMode() (pavel-t). - Fix possible infinite loop in wxHtmlWindow layout (trivia21). - Add "hint" property support to XRC for wxComboBox and wxSearchCtrl. +- Add support for style="page-break-inside:avoid" to
+ +
+
+
@@ -102,6 +109,7 @@ combined base/GUI library for GUI applications only.
+
+
diff --git a/src/html/m_layout.cpp b/src/html/m_layout.cpp index 95b0afbab2..5556c34396 100644 --- a/src/html/m_layout.cpp +++ b/src/html/m_layout.cpp @@ -187,6 +187,35 @@ TAG_HANDLER_BEGIN(DIV, "DIV") m_WParser->OpenContainer(); return false; } + else if(style.IsSameAs(wxT("PAGE-BREAK-INSIDE:AVOID"), false)) + { + // As usual, reuse the current container if it's empty. + wxHtmlContainerCell *c = m_WParser->GetContainer(); + if (c->GetFirstChild() != NULL) + { + // If not, open a new one. + m_WParser->CloseContainer(); + c = m_WParser->OpenContainer(); + } + + // Force this container to live entirely on the same page. + c->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. + m_WParser->OpenContainer(); + + 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; + } else { // Treat other STYLE parameters here when they're supported. diff --git a/tests/html/htmprint.cpp b/tests/html/htmprint.cpp index 34560d9cb8..64ce4b144e 100644 --- a/tests/html/htmprint.cpp +++ b/tests/html/htmprint.cpp @@ -59,6 +59,17 @@ TEST_CASE("wxHtmlPrintout::Pagination", "[html][print]") // the DPI-dependent factor, but it doesn't seem to be worth doing it). pr.SetMargins(0, 0, 0, 0, 0); + // Use font size in pixels to make it DPI-independent: if we just used a + // normal (say 12pt) font, it would have different height in pixels on 96 + // and 200 DPI systems, meaning that the text at the end of this test would + // take different number of (fixed to 1000px height) pages. + // + // We could also make the page height proportional to the DPI, but this + // would be more complicated as we also wouldn't be able to use hardcoded + // height attribute values in the HTML snippets below then. + const wxFont fontFixedPixelSize(wxFontInfo(wxSize(10, 16))); + pr.SetStandardFonts(fontFixedPixelSize.GetPointSize(), "Helvetica"); + wxBitmap bmp(1000, 1000); wxMemoryDC dc(bmp); pr.SetUp(dc); @@ -107,6 +118,75 @@ TEST_CASE("wxHtmlPrintout::Pagination", "[html][print]") "