[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Feb 5 10:48:37 UTC 2016


 sw/qa/extras/uiwriter/uiwriter.cxx |   30 ++++++++++++++++++++++++++++--
 sw/source/core/inc/pagefrm.hxx     |    5 +++--
 sw/source/core/layout/calcmove.cxx |   13 ++++++++-----
 sw/source/core/layout/pagechg.cxx  |    6 ++++--
 sw/source/core/layout/wsfrm.cxx    |   18 ++++++++++++++++--
 sw/source/core/text/widorp.cxx     |    3 ++-
 6 files changed, 61 insertions(+), 14 deletions(-)

New commits:
commit f14577899781a040fa7d505f8a7554b6266aeb0c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jan 8 14:56:26 2016 +0100

    tdf#96961 sw Hide Whitespace: still show whitespace on the last page
    
    Mainly to match Word's hide whitespace behavior.
    
    (cherry picked from commits cd51e0153a25f3950be54dd7fd58a0de6e148ae2,
    49b67cdc36b599f865d4a6de214d901861f27196 and
    363aa5dbb2c223b6cc3a109bd654f39772e310fa)
    
    Conflicts:
    	sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: Ica09bca5004adbfa14d1c9aca04079129f8a1a68
    Reviewed-on: https://gerrit.libreoffice.org/22122
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index bff3a4b..3e49ee9 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -176,6 +176,7 @@ public:
     void testTdf96943();
     void testTdf96479();
     void testTdf96536();
+    void testTdf96961();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -260,6 +261,7 @@ public:
     CPPUNIT_TEST(testTdf96943);
     CPPUNIT_TEST(testTdf96479);
     CPPUNIT_TEST(testTdf96536);
+    CPPUNIT_TEST(testTdf96961);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3031,7 +3033,11 @@ void SwUiWriterTest::testTdf96536()
     aViewOptions.SetHideWhitespaceMode(true);
     pWrtShell->ApplyViewOptions(aViewOptions);
 
-    // Insert a new paragraph at the end of the document, and then delete it.
+    // Insert a page break and go back to the first page.
+    pWrtShell->InsertPageBreak();
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+
+    // Insert a new paragraph at the end of the page, and then delete it.
     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>());
@@ -3043,7 +3049,27 @@ void SwUiWriterTest::testTdf96536()
     // This was 552, page did not shrink after deleting the second paragraph.
     // Expected 276, which is 12pt font size + default line spacing (15%), but
     // tolerate some difference to that.
-    CPPUNIT_ASSERT(parseDump("/root/infos/bounds", "height").toInt32() <= 276);
+    CPPUNIT_ASSERT(parseDump("/root/page[1]/infos/bounds", "height").toInt32() <= 276);
+}
+
+void SwUiWriterTest::testTdf96961()
+{
+    // Insert a page break.
+    SwDoc* pDoc = createDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->InsertPageBreak();
+
+    // Enable hide whitespace mode.
+    SwViewOption aViewOptions(*pWrtShell->GetViewOptions());
+    aViewOptions.SetHideWhitespaceMode(true);
+    pWrtShell->ApplyViewOptions(aViewOptions);
+
+    calcLayout();
+
+    // Assert that the height of the last page is larger than the height of other pages.
+    sal_Int32 nOther = parseDump("/root/page[1]/infos/bounds", "height").toInt32();
+    sal_Int32 nLast = parseDump("/root/page[2]/infos/bounds", "height").toInt32();
+    CPPUNIT_ASSERT(nLast > nOther);
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 2df4c1d..3fae2a3 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -335,8 +335,9 @@ public:
 
     static SwTwips GetSidebarBorderWidth( const SwViewShell* );
 
-    /// Adjust a bottom-of-page-frame - bottom-of-text-frame difference in case whitespace is hidden.
-    void HandleWhitespaceHiddenDiff(SwTwips& nDiff);
+    /// Is bottom-of-page-frame - bottom-of-text-frame difference valid in case whitespace is hidden?
+    /// If false is returned, then the caller should handle negative difference as (at least) zero difference instead.
+    bool CheckPageHeightValidForHideWhitespace(SwTwips nDiff);
 };
 
 inline SwContentFrame *SwPageFrame::FindFirstBodyContent()
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index 84daf90..9eba5eb 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -740,7 +740,8 @@ void SwPageFrame::MakeAll(vcl::RenderContext* pRenderContext)
                 }
                 assert(pAttrs);
 
-                SwViewShell *pSh = getRootFrame()->GetCurrShell();
+                SwRootFrame* pRootFrame = getRootFrame();
+                SwViewShell* pSh = pRootFrame->GetCurrShell();
                 if (pSh && pSh->GetViewOptions()->getBrowseMode())
                 {
                     // In BrowseView, we use fixed settings
@@ -787,7 +788,7 @@ void SwPageFrame::MakeAll(vcl::RenderContext* pRenderContext)
                     mbValidSize = mbValidPrtArea = true;
                     continue;
                 }
-                else if (pSh && pSh->GetViewOptions()->IsWhitespaceHidden())
+                else if (pSh && pSh->GetViewOptions()->IsWhitespaceHidden() && pRootFrame->GetLastPage() != this)
                 {
                     long height = 0;
                     SwLayoutFrame *pBody = FindBodyCont();
@@ -1524,10 +1525,12 @@ void SwContentFrame::MakeAll(vcl::RenderContext* /*pRenderContext*/)
 
         // Hide whitespace may require not to insert a new page.
         SwPageFrame* pPageFrame = FindPageFrame();
-        long nOldBottomDist = nBottomDist;
-        pPageFrame->HandleWhitespaceHiddenDiff(nBottomDist);
-        if (nOldBottomDist != nBottomDist)
+        const bool bHeightValid = pPageFrame->CheckPageHeightValidForHideWhitespace(nBottomDist);
+        if (!bHeightValid)
+        {
             pPageFrame->InvalidateSize();
+            nBottomDist = 0;
+        }
 
         if( nBottomDist >= 0 )
         {
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index 967ee2f..42ae8ac 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -2287,7 +2287,7 @@ bool SwPageFrame::IsOverHeaderFooterArea( const Point& rPt, FrameControlType &rC
     return false;
 }
 
-void SwPageFrame::HandleWhitespaceHiddenDiff(SwTwips& nDiff)
+bool SwPageFrame::CheckPageHeightValidForHideWhitespace(SwTwips nDiff)
 {
     SwViewShell* pShell = getRootFrame()->GetCurrShell();
     if (pShell && pShell->GetViewOptions()->IsWhitespaceHidden())
@@ -2309,10 +2309,12 @@ void SwPageFrame::HandleWhitespaceHiddenDiff(SwTwips& nDiff)
             {
                 // It does: don't move it and invalidate our page frame so
                 // that it gets a larger height.
-                nDiff = 0;
+                return false;
             }
         }
     }
+
+    return true;
 }
 
 SwTextGridItem const* GetGridItem(SwPageFrame const*const pPage)
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index 0f60476..032177a 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -2947,11 +2947,25 @@ void SwLayoutFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBord
     if ( mbValidPrtArea && mbValidSize )
         return;
 
+    bool bHideWhitespace = false;
+    if (IsPageFrame())
+    {
+        SwViewShell* pShell = getRootFrame()->GetCurrShell();
+        if (pShell && pShell->GetViewOptions()->IsWhitespaceHidden())
+        {
+            // This is needed so that no space is reserved for the margin on
+            // the last page of the document. Other pages would have no margin
+            // set even without this, as their frame height is the content
+            // height already.
+            bHideWhitespace = true;
+        }
+    }
+
     const sal_uInt16 nLeft = (sal_uInt16)pAttrs->CalcLeft(this);
-    const sal_uInt16 nUpper = pAttrs->CalcTop();
+    const sal_uInt16 nUpper = bHideWhitespace ? 0 : pAttrs->CalcTop();
 
     const sal_uInt16 nRight = (sal_uInt16)pAttrs->CalcRight(this);
-    const sal_uInt16 nLower = pAttrs->CalcBottom();
+    const sal_uInt16 nLower = bHideWhitespace ? 0 : pAttrs->CalcBottom();
 
     const bool bVert = IsVertical() && !IsPageFrame();
     SwRectFn fnRect = bVert ? ( IsVertLR() ? fnRectVertL2R : fnRectVert ) : fnRectHori;
diff --git a/sw/source/core/text/widorp.cxx b/sw/source/core/text/widorp.cxx
index c75a958..7c22b12 100644
--- a/sw/source/core/text/widorp.cxx
+++ b/sw/source/core/text/widorp.cxx
@@ -131,7 +131,8 @@ bool SwTextFrameBreak::IsInside( SwTextMargin &rLine ) const
 
         // Hide whitespace may require not to insert a new page.
         SwPageFrame* pPageFrame = m_pFrame->FindPageFrame();
-        pPageFrame->HandleWhitespaceHiddenDiff(nDiff);
+        if (!pPageFrame->CheckPageHeightValidForHideWhitespace(nDiff))
+            nDiff = 0;
 
         // If everything is inside the existing frame the result is true;
         bFit = nDiff >= 0;


More information about the Libreoffice-commits mailing list