[Libreoffice-commits] core.git: 2 commits - sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Thu Jan 7 06:13:37 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 59ae2d11d5884ffdf77dec95d8cd2566943fd789
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.
Change-Id: I9b4b9a33d5d2da825c5da93e69790277eba8d0b3
diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 840c580..2df4c1d 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -334,6 +334,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 SwContentFrame *SwPageFrame::FindFirstBodyContent()
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index 21d479a..84daf90 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -1522,32 +1522,12 @@ void SwContentFrame::MakeAll(vcl::RenderContext* /*pRenderContext*/)
const long nPrtBottom = (GetUpper()->*fnRect->fnGetPrtBottom)();
long nBottomDist = (Frame().*fnRect->fnBottomDist)(nPrtBottom);
- SwViewShell* pShell = getRootFrame()->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.
- 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();
- }
- }
- }
+ // Hide whitespace may require not to insert a new page.
+ SwPageFrame* pPageFrame = FindPageFrame();
+ 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 34adb7a..967ee2f 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -2287,6 +2287,34 @@ bool SwPageFrame::IsOverHeaderFooterArea( const Point& rPt, FrameControlType &rC
return false;
}
+void SwPageFrame::HandleWhitespaceHiddenDiff(SwTwips& nDiff)
+{
+ SwViewShell* pShell = getRootFrame()->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->GetFrameSize().GetSize();
+ long nWhitespace = rPageSize.getHeight() - Frame().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(SwPageFrame const*const pPage)
{
if (pPage && pPage->HasGrid())
diff --git a/sw/source/core/text/widorp.cxx b/sw/source/core/text/widorp.cxx
index 322bdab..c75a958 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
@@ -132,19 +129,9 @@ bool SwTextFrameBreak::IsInside( SwTextMargin &rLine ) const
(*fnRect->fnYDiff)( (m_pFrame->GetUpper()->*fnRect->fnGetPrtBottom)(), m_nOrigin );
SwTwips nDiff = nHeight - nLineHeight;
- SwViewShell* pShell = m_pFrame->getRootFrame()->GetCurrShell();
- if (pShell && pShell->GetViewOptions()->IsWhitespaceHidden())
- {
- if (nDiff < 0)
- {
- SwPageFrame* pPageFrame = m_pFrame->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 > -nDiff)
- nDiff = 0;
- }
- }
+ // Hide whitespace may require not to insert a new page.
+ SwPageFrame* pPageFrame = m_pFrame->FindPageFrame();
+ pPageFrame->HandleWhitespaceHiddenDiff(nDiff);
// If everything is inside the existing frame the result is true;
bFit = nDiff >= 0;
commit 6d8da2b2deb4be2182ca1852cec7eb38a4c654eb
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
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 af882f1..b001d04 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -177,6 +177,7 @@ public:
void testTdf77014();
void testTdf92648();
void testTdf96515();
+ void testTdf96943();
void testTdf96536();
void testTdf96479();
@@ -262,6 +263,7 @@ public:
CPPUNIT_TEST(testTdf77014);
CPPUNIT_TEST(testTdf92648);
CPPUNIT_TEST(testTdf96515);
+ CPPUNIT_TEST(testTdf96943);
CPPUNIT_TEST(testTdf96536);
CPPUNIT_TEST(testTdf96479);
CPPUNIT_TEST_SUITE_END();
@@ -2945,6 +2947,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 11e8c7a..322bdab 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
@@ -126,8 +130,24 @@ bool SwTextFrameBreak::IsInside( SwTextMargin &rLine ) const
// The Frame has a height to fit on the page.
SwTwips nHeight =
(*fnRect->fnYDiff)( (m_pFrame->GetUpper()->*fnRect->fnGetPrtBottom)(), m_nOrigin );
+ SwTwips nDiff = nHeight - nLineHeight;
+
+ SwViewShell* pShell = m_pFrame->getRootFrame()->GetCurrShell();
+ if (pShell && pShell->GetViewOptions()->IsWhitespaceHidden())
+ {
+ if (nDiff < 0)
+ {
+ SwPageFrame* pPageFrame = m_pFrame->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 > -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