diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-12-16 09:49:18 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-12-23 16:19:49 +0000 |
commit | d4c6c90c3491cf37181b13c1b867ac67bb098f80 (patch) | |
tree | 2884a6b8eebf083c1c8927eeb3bd0c56ff5b3d1a | |
parent | 2b8d5a2d5182ee90568173e702f531a2b9279ef9 (diff) |
tdf#96515 sw Hide Whitespace: avoid creating unneeded page frames
(cherry picked from commit 2c23d4ee1e1370b20560e47db7efaeaac1d94b26)
Change-Id: I9b273543ccf2eaa87116c6e1475860e9e872c445
Reviewed-on: https://gerrit.libreoffice.org/20740
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 21 | ||||
-rw-r--r-- | sw/source/core/layout/calcmove.cxx | 29 |
2 files changed, 49 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index c69f3306a048..097b295b7a0a 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -172,6 +172,7 @@ public: void testTdf87922(); void testTdf77014(); void testTdf92648(); + void testTdf96515(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -252,6 +253,7 @@ public: CPPUNIT_TEST(testTdf87922); CPPUNIT_TEST(testTdf77014); CPPUNIT_TEST(testTdf92648); + CPPUNIT_TEST(testTdf96515); CPPUNIT_TEST_SUITE_END(); private: @@ -2883,6 +2885,25 @@ void SwUiWriterTest::testTdf92648() } } +void SwUiWriterTest::testTdf96515() +{ + // Enable hide whitespace mode. + SwDoc* pDoc = createDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwViewOption aViewOptions(*pWrtShell->GetViewOptions()); + aViewOptions.SetHideWhitespaceMode(true); + pWrtShell->ApplyViewOptions(aViewOptions); + + // Insert a new paragraph at the end of the document. + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XParagraphAppend> xParagraphAppend(xTextDocument->getText(), uno::UNO_QUERY); + xParagraphAppend->finishParagraph(uno::Sequence<beans::PropertyValue>()); + calcLayout(); + + // This was 2, a new page was created for the new paragraph. + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index cac6574158d9..922041702f1e 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -1520,7 +1520,34 @@ void SwContentFrame::MakeAll(vcl::RenderContext* /*pRenderContext*/) // Bottom(). This might happen with undersized TextFrames on the lower edge of a // multi-column section const long nPrtBottom = (GetUpper()->*fnRect->fnGetPrtBottom)(); - const long nBottomDist = (Frame().*fnRect->fnBottomDist)( nPrtBottom ); + long nBottomDist = (Frame().*fnRect->fnBottomDist)(nPrtBottom); + + if (getRootFrame()->GetCurrShell()->GetViewOptions()->IsWhitespaceHidden()) + { + // When whitespace is hidden, the page frame has two heights: the + // nominal (defined by the frame format), and the actual (which is + // at most the nominal height, but can be smaller in case there is + // no content for the whole page). + // The layout size is the actual one, but we want to move the + // content frame to a new page only in case it doesn't fit the + // nominal size. + if (nBottomDist < 0) + { + // Content frame doesn't fit the actual size, check if it fits the nominal one. + SwPageFrame* pPageFrame = FindPageFrame(); + const SwFrameFormat* pPageFormat = static_cast<const SwFrameFormat*>(pPageFrame->GetRegisteredIn()); + const Size& rPageSize = pPageFormat->GetFrameSize().GetSize(); + long nWhitespace = rPageSize.getHeight() - pPageFrame->Frame().Height(); + if (nWhitespace > -nBottomDist) + { + // It does: don't move it and invalidate our page frame so + // that it gets a larger height. + nBottomDist = 0; + pPageFrame->InvalidateSize(); + } + } + } + if( nBottomDist >= 0 ) { if ( bKeep && bMoveable ) |