[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 2 commits - sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Jan 7 07:08:21 PST 2016


 sw/qa/extras/uiwriter/data/tdf96943.odt |binary
 sw/qa/extras/uiwriter/uiwriter.cxx      |   19 +++++++++++++++++++
 sw/source/core/inc/pagefrm.hxx          |    3 +++
 sw/source/core/layout/calcmove.cxx      |   32 ++++++--------------------------
 sw/source/core/layout/pagechg.cxx       |   28 ++++++++++++++++++++++++++++
 sw/source/core/text/widorp.cxx          |    9 ++++++++-
 6 files changed, 64 insertions(+), 27 deletions(-)

New commits:
commit 7fdbc8839d620ec124102ce50cdf6e38d885f322
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jan 7 14:54:36 2016 +0100

    Related: tdf#96943 sw Hide Whitespace: add HandleWhitespaceHiddenDiff()
    
    To have the "we want the difference vs the nominal size, not the actual
    size" code at a single place.
    
    (cherry picked from commit 59ae2d11d5884ffdf77dec95d8cd2566943fd789)
    
    Conflicts:
    	sw/source/core/layout/calcmove.cxx
    	sw/source/core/layout/pagechg.cxx
    	sw/source/core/text/widorp.cxx
    
    Change-Id: I9b4b9a33d5d2da825c5da93e69790277eba8d0b3

diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 8afa92b..32eccc4 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -339,6 +339,9 @@ public:
     static const vcl::Font& GetEmptyPageFont();
 
     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);
 };
 
 inline SwContentFrm *SwPageFrm::FindFirstBodyContent()
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index 75024af..148a953 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -1521,32 +1521,12 @@ void SwContentFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/)
         const long nPrtBottom = (GetUpper()->*fnRect->fnGetPrtBottom)();
         long nBottomDist =  (Frm().*fnRect->fnBottomDist)( nPrtBottom );
 
-        SwViewShell* pShell = getRootFrm()->GetCurrShell();
-        if (pShell && pShell->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.
-                SwPageFrm* pPageFrame = FindPageFrm();
-                const SwFrameFormat* pPageFormat = static_cast<const SwFrameFormat*>(pPageFrame->GetRegisteredIn());
-                const Size& rPageSize = pPageFormat->GetFrmSize().GetSize();
-                long nWhitespace = rPageSize.getHeight() - pPageFrame->Frm().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();
-                }
-            }
-        }
+        // Hide whitespace may require not to insert a new page.
+        SwPageFrm* pPageFrame = FindPageFrm();
+        long nOldBottomDist = nBottomDist;
+        pPageFrame->HandleWhitespaceHiddenDiff(nBottomDist);
+        if (nOldBottomDist != nBottomDist)
+            pPageFrame->InvalidateSize();
 
         if( nBottomDist >= 0 )
         {
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index aa6c799..2c3ff42 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -2280,6 +2280,34 @@ bool SwPageFrm::IsOverHeaderFooterArea( const Point& rPt, FrameControlType &rCon
     return false;
 }
 
+void SwPageFrm::HandleWhitespaceHiddenDiff(SwTwips& nDiff)
+{
+    SwViewShell* pShell = getRootFrm()->GetCurrShell();
+    if (pShell && pShell->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 (nDiff < 0)
+        {
+            // Content frame doesn't fit the actual size, check if it fits the nominal one.
+            const SwFrameFormat* pPageFormat = static_cast<const SwFrameFormat*>(GetRegisteredIn());
+            const Size& rPageSize = pPageFormat->GetFrmSize().GetSize();
+            long nWhitespace = rPageSize.getHeight() - Frm().Height();
+            if (nWhitespace > -nDiff)
+            {
+                // It does: don't move it and invalidate our page frame so
+                // that it gets a larger height.
+                nDiff = 0;
+            }
+        }
+    }
+}
+
 SwTextGridItem const* GetGridItem(SwPageFrm const*const pPage)
 {
     if (pPage && pPage->HasGrid())
diff --git a/sw/source/core/text/widorp.cxx b/sw/source/core/text/widorp.cxx
index 08edff1..c08c07d 100644
--- a/sw/source/core/text/widorp.cxx
+++ b/sw/source/core/text/widorp.cxx
@@ -37,10 +37,7 @@
 #include "itrtxt.hxx"
 #include "sectfrm.hxx"
 #include "ftnfrm.hxx"
-#include "rootfrm.hxx"
-#include "viewopt.hxx"
 #include "pagefrm.hxx"
-#include "fmtfsize.hxx"
 
 #undef WIDOWTWIPS
 
@@ -134,19 +131,9 @@ bool SwTextFrmBreak::IsInside( SwTextMargin &rLine ) const
             (*fnRect->fnYDiff)( (pFrm->GetUpper()->*fnRect->fnGetPrtBottom)(), nOrigin );
         SwTwips nDiff = nHeight - nLineHeight;
 
-        SwViewShell* pShell = pFrm->getRootFrm()->GetCurrShell();
-        if (pShell && pShell->GetViewOptions()->IsWhitespaceHidden())
-        {
-            if (nDiff < 0)
-            {
-                SwPageFrm* pPageFrame = pFrm->FindPageFrm();
-                const SwFrameFormat* pPageFormat = static_cast<const SwFrameFormat*>(pPageFrame->GetRegisteredIn());
-                const Size& rPageSize = pPageFormat->GetFrmSize().GetSize();
-                long nWhitespace = rPageSize.getHeight() - pPageFrame->Frm().Height();
-                if (nWhitespace > -nDiff)
-                    nDiff = 0;
-            }
-        }
+        // Hide whitespace may require not to insert a new page.
+        SwPageFrm* pPageFrame = pFrm->FindPageFrm();
+        pPageFrame->HandleWhitespaceHiddenDiff(nDiff);
 
         // If everything is inside the existing frame the result is true;
         bFit = nDiff >= 0;
commit 03e9fe02ff6ffd81f9af773a8effb154838eaf83
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jan 7 12:30:23 2016 +0100

    tdf#96943 sw Hide Whitespace: don't create pages for widow / orphan ...
    
    ... paragraphs that would otherwise fit nominal size of the page frame
    
    (cherry picked from commit 6d8da2b2deb4be2182ca1852cec7eb38a4c654eb)
    
    Conflicts:
    	sw/source/core/text/widorp.cxx
    
    Change-Id: I90c3de9150b17c951e1ac4158babb7a71afee9ee

diff --git a/sw/qa/extras/uiwriter/data/tdf96943.odt b/sw/qa/extras/uiwriter/data/tdf96943.odt
new file mode 100644
index 0000000..1ee5b9f
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf96943.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index ca57c28..59ffbf2 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -106,6 +106,7 @@ public:
     void testTdf89954();
     void testTdf89720();
     void testTdf96515();
+    void testTdf96943();
     void testTdf96536();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
@@ -150,6 +151,7 @@ public:
     CPPUNIT_TEST(testTdf89954);
     CPPUNIT_TEST(testTdf89720);
     CPPUNIT_TEST(testTdf96515);
+    CPPUNIT_TEST(testTdf96943);
     CPPUNIT_TEST(testTdf96536);
 
     CPPUNIT_TEST_SUITE_END();
@@ -1174,6 +1176,23 @@ void SwUiWriterTest::testTdf96515()
     CPPUNIT_ASSERT_EQUAL(1, getPages());
 }
 
+void SwUiWriterTest::testTdf96943()
+{
+    // Enable hide whitespace mode.
+    SwDoc* pDoc = createDoc("tdf96943.odt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    SwViewOption aViewOptions(*pWrtShell->GetViewOptions());
+    aViewOptions.SetHideWhitespaceMode(true);
+    pWrtShell->ApplyViewOptions(aViewOptions);
+
+    // Insert a new character at the end of the document.
+    pWrtShell->SttEndDoc(/*bStt=*/false);
+    pWrtShell->Insert("d");
+
+    // This was 2, a new page was created for the new layout line.
+    CPPUNIT_ASSERT_EQUAL(1, getPages());
+}
+
 void SwUiWriterTest::testTdf96536()
 {
     // Enable hide whitespace mode.
diff --git a/sw/source/core/text/widorp.cxx b/sw/source/core/text/widorp.cxx
index f526c28..08edff1 100644
--- a/sw/source/core/text/widorp.cxx
+++ b/sw/source/core/text/widorp.cxx
@@ -37,6 +37,10 @@
 #include "itrtxt.hxx"
 #include "sectfrm.hxx"
 #include "ftnfrm.hxx"
+#include "rootfrm.hxx"
+#include "viewopt.hxx"
+#include "pagefrm.hxx"
+#include "fmtfsize.hxx"
 
 #undef WIDOWTWIPS
 
@@ -128,8 +132,24 @@ bool SwTextFrmBreak::IsInside( SwTextMargin &rLine ) const
         // The Frm has a height to fit on the page.
         SwTwips nHeight =
             (*fnRect->fnYDiff)( (pFrm->GetUpper()->*fnRect->fnGetPrtBottom)(), nOrigin );
+        SwTwips nDiff = nHeight - nLineHeight;
+
+        SwViewShell* pShell = pFrm->getRootFrm()->GetCurrShell();
+        if (pShell && pShell->GetViewOptions()->IsWhitespaceHidden())
+        {
+            if (nDiff < 0)
+            {
+                SwPageFrm* pPageFrame = pFrm->FindPageFrm();
+                const SwFrameFormat* pPageFormat = static_cast<const SwFrameFormat*>(pPageFrame->GetRegisteredIn());
+                const Size& rPageSize = pPageFormat->GetFrmSize().GetSize();
+                long nWhitespace = rPageSize.getHeight() - pPageFrame->Frm().Height();
+                if (nWhitespace > -nDiff)
+                    nDiff = 0;
+            }
+        }
+
         // If everything is inside the existing frame the result is true;
-        bFit = nHeight >= nLineHeight;
+        bFit = nDiff >= 0;
 
         // --> OD #i103292#
         if ( !bFit )


More information about the Libreoffice-commits mailing list