summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-02-18 19:18:47 +0100
committerMichael Stahl <michael.stahl@cib.de>2020-02-19 16:48:28 +0100
commit509a02aa96f6d7620cb0bf06c20b3bfa0641be92 (patch)
treefacaac50f8f787613756e1339501a421f98e6700
parent4d5c0eaf3e0d3d3bcd9e691fffee19b75f3d6631 (diff)
tdf#125682 sw: don't insert empty page before first page with even number
This mostly reverts commit 14bb680949b47332d2921cc68f75340b31ad5c32 and replaces it by a hopefully better approach: if the first page in the document has an even number, it will become a right page, and "toggle" the document so that even pages are right pages and odd pages are left pages. This is closer to what Word does; the tests adapted in the above commit were actually regressions. Add a new function IsRightPageByNumber() to determine how the page number offsets should be interpreted. Also make it explicit that even/odd and right/left page are no longer synonymous by renaming various "Odd" variables. Historically documents that start with even page number didn't work well anyway; before the above commit you'd get a left page followed by a left page followed by a right page, which is clearly nonsense if the page style differs between left and right pages - so hopefully we can do without a compat setting for those. There is still one situation where an empty page is inserted before the first page: if the page style is "Left Page"; this appears to be impossible in Word so we'll have issues exporting that to Word formats anyway. Testing: Writer pre-commit; LO 5.4/OOo 3.3: 1.odd -> right, 2.even -> left 1.even -> left, 2.odd -> right + inserts a blank page on the right after reload: 1.even -> left, 2.odd -> left, no empty page Writer w/ commit; LO 6.0+: 1.odd -> right, 2.even -> left 1.even -> left, 2.odd -> right + blank page as first page (right) after reload: 1.even -> left, 2.odd -> right + blank page as first page (right) Word: 1.odd -> right, 2.even -> left 1.even -> right but left style, 2.odd -> left but right style [technically uses terminology even/odd instead of left/right, but if mirrored, the "inner margin" is always the same and leads to interpretation of left/right] Writer and Word appear to agree on inserting empty pages on SwFormatPageDesc items/Word section breaks: both even-ness of an explicit page number and "Left Page" only page style or explicit even/odd section break may insert empty page. A useful improvement would be to detect in Word import filters that the first page is even numbered and then invert the mapping of all of the page styles, i.e. odd header/footer->left instead of right, and if mirrorMargins, pgMar left -> inner instead of outer. Change-Id: Ibed0dbf888c120a3a7d11892f40d07ffb5bc0b68 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88978 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/qa/extras/odfimport/odfimport.cxx9
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport10.cxx8
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport4.cxx3
-rw-r--r--sw/qa/extras/ww8export/ww8export.cxx7
-rw-r--r--sw/source/core/inc/frmtool.hxx8
-rw-r--r--sw/source/core/layout/flowfrm.cxx18
-rw-r--r--sw/source/core/layout/frmtool.cxx25
-rw-r--r--sw/source/core/layout/laycache.cxx10
-rw-r--r--sw/source/core/layout/newfrm.cxx10
-rw-r--r--sw/source/core/layout/pagechg.cxx28
-rw-r--r--sw/source/core/layout/trvlfrm.cxx38
11 files changed, 86 insertions, 78 deletions
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index 56df38c6d686..973cc4a0d311 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -894,14 +894,11 @@ DECLARE_ODFIMPORT_TEST(testTdf94882, "tdf94882.odt")
DECLARE_ODFIMPORT_TEST(testBlankBeforeFirstPage, "tdf94882.odt")
{
- // This document starts on page 50, which is even, so it should have a
+ // This document starts on page 50, which is even, but it should not have a
// blank page inserted before it to make it a left page
- CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 2 pages output",
- OUString("2"), parseDump("count(/root/page)")
- );
- CPPUNIT_ASSERT_EQUAL_MESSAGE("The first page should be blank",
- OUString("0"), parseDump("count(/root/page[1]/body)")
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 1 pages output",
+ OUString("1"), parseDump("count(/root/page)")
);
}
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 6d11c3c12590..363584c78ea0 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -173,13 +173,13 @@ DECLARE_OOXMLEXPORT_TEST(testWpgNested, "wpg-nested.docx")
// This failed, the right edge of the shape was outside the page
// boundaries.
xmlDocPtr pXmlDoc = parseLayoutDump();
- sal_Int32 nPageLeft = getXPath(pXmlDoc, "/root/page[2]/infos/bounds", "left").toInt32();
- sal_Int32 nPageWidth = getXPath(pXmlDoc, "/root/page[2]/infos/bounds", "width").toInt32();
+ sal_Int32 nPageLeft = getXPath(pXmlDoc, "/root/page[1]/infos/bounds", "left").toInt32();
+ sal_Int32 nPageWidth = getXPath(pXmlDoc, "/root/page[1]/infos/bounds", "width").toInt32();
sal_Int32 nShapeLeft
- = getXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/SwAnchoredDrawObject/bounds", "left")
+ = getXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/SwAnchoredDrawObject/bounds", "left")
.toInt32();
sal_Int32 nShapeWidth
- = getXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/SwAnchoredDrawObject/bounds", "width")
+ = getXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/SwAnchoredDrawObject/bounds", "width")
.toInt32();
// Make sure the shape is within the page bounds.
CPPUNIT_ASSERT_GREATEREQUAL(nShapeLeft + nShapeWidth, nPageLeft + nPageWidth);
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 998d7cd5b2d8..aa4c902d6765 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -212,7 +212,8 @@ DECLARE_OOXMLEXPORT_TEST(testRelSizeRound, "rel-size-round.docx")
DECLARE_OOXMLEXPORT_TEST(testTestTitlePage, "testTitlePage.docx")
{
- CPPUNIT_ASSERT_EQUAL(OUString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), parseDump("/root/page[last()]/footer/txt/text()"));
+ // this has 2 pages in Word
+ CPPUNIT_ASSERT_EQUAL(OUString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), parseDump("/root/page[2]/footer/txt/text()"));
}
DECLARE_OOXMLEXPORT_TEST(testTableRowDataDisplayedTwice,"table-row-data-displayed-twice.docx")
diff --git a/sw/qa/extras/ww8export/ww8export.cxx b/sw/qa/extras/ww8export/ww8export.cxx
index ad43b3d26714..5b2499d231a4 100644
--- a/sw/qa/extras/ww8export/ww8export.cxx
+++ b/sw/qa/extras/ww8export/ww8export.cxx
@@ -592,11 +592,8 @@ DECLARE_WW8EXPORT_TEST(testBnc787942, "bnc787942.doc")
{
// The frame ended up on the second page instead of first.
- // Ensure that the anchor is on the same page as the text "Zelva Mana"
- // (Note that this can actually be the second physical page, since the
- // page number is set to 0 which is even so LO will insert a blank page
- // before it to make it a left page)
- parseDump("/root/page[body/txt/text()='Zelva Mana']/body/txt[4]/anchored");
+ // this is on page 1 in Word
+ parseDump("/root/page[1]/body/txt[4]/anchored");
}
DECLARE_WW8EXPORT_TEST(testLayoutHanging, "fdo68967.doc")
diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx
index a32a5a0b9c62..c8447d8dd0f1 100644
--- a/sw/source/core/inc/frmtool.hxx
+++ b/sw/source/core/inc/frmtool.hxx
@@ -150,8 +150,14 @@ extern bool bSetCompletePaintOnInvalidate;
SwTwips CalcRowRstHeight( SwLayoutFrame *pRow );
long CalcHeightWithFlys( const SwFrame *pFrame );
+namespace sw {
+
+bool IsRightPageByNumber(SwRootFrame const& rLayout, sal_uInt16 nPageNum);
+
+} // namespace sw
+
SwPageFrame *InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper,
- bool bOdd, bool bFirst, bool bInsertEmpty, bool bFootnote,
+ bool isRightPage, bool bFirst, bool bInsertEmpty, bool bFootnote,
SwFrame *pSibling );
// connect Flys with page
diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx
index 8f4d804f1b00..a10239af226f 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -848,7 +848,7 @@ bool SwFrame::WrongPageDesc( SwPageFrame* pNew )
//My Pagedesc doesn't count if I'm a follow!
const SwPageDesc *pDesc = nullptr;
- int nTmp = 0;
+ o3tl::optional<sal_uInt16> oTmp;
SwFlowFrame *pFlow = SwFlowFrame::CastFlowFrame( this );
if ( !pFlow || !pFlow->IsFollow() )
{
@@ -857,18 +857,18 @@ bool SwFrame::WrongPageDesc( SwPageFrame* pNew )
if( pDesc )
{
if( !pDesc->GetRightFormat() )
- nTmp = 2;
+ oTmp = 2;
else if( !pDesc->GetLeftFormat() )
- nTmp = 1;
+ oTmp = 1;
else if( rFormatDesc.GetNumOffset() )
- nTmp = *rFormatDesc.GetNumOffset();
+ oTmp = rFormatDesc.GetNumOffset();
}
}
// Does the Content bring a Pagedesc or do we need the
// virtual page number of the new layout leaf?
// PageDesc isn't allowed with Follows
- const bool bOdd = nTmp ? (nTmp % 2) !=0 : pNew->OnRightPage();
+ const bool isRightPage = oTmp ? sw::IsRightPageByNumber(*mpRoot, *oTmp) : pNew->OnRightPage();
if ( !pDesc )
pDesc = pNew->FindPageDesc();
@@ -886,14 +886,14 @@ bool SwFrame::WrongPageDesc( SwPageFrame* pNew )
SAL_INFO( "sw.pageframe", "WrongPageDesc p: " << pNew << " phys: " << pNew->GetPhyPageNum() );
SAL_INFO( "sw.pageframe", "WrongPageDesc " << pNew->GetPageDesc() << " " << pDesc );
- SAL_INFO( "sw.pageframe", "WrongPageDesc odd: " << bOdd
+ SAL_INFO( "sw.pageframe", "WrongPageDesc right: " << isRightPage
<< " first: " << bFirst << " " << pNew->GetFormat() << " == "
- << (bOdd ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)) << " "
- << (bOdd ? pDesc->GetLeftFormat(bFirst) : pDesc->GetRightFormat(bFirst)) );
+ << (isRightPage ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)) << " "
+ << (isRightPage ? pDesc->GetLeftFormat(bFirst) : pDesc->GetRightFormat(bFirst)) );
return (pNew->GetPageDesc() != pDesc) // own desc ?
|| (pNew->GetFormat() !=
- (bOdd ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)))
+ (isRightPage ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)))
|| (pNewDesc && pNewDesc == pDesc);
}
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index 975bf3f9ead4..4807cfcdb185 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -2883,10 +2883,27 @@ void RestoreContent( SwFrame *pSav, SwLayoutFrame *pParent, SwFrame *pSibling )
pParent->Grow( nGrowVal );
}
+namespace sw {
+
+bool IsRightPageByNumber(SwRootFrame const& rLayout, sal_uInt16 const nPageNum)
+{
+ assert(rLayout.GetLower());
+ // unfortunately can only get SwPageDesc, not SwFormatPageDesc here...
+ auto const nFirstVirtPageNum(rLayout.GetLower()->GetVirtPageNum());
+ bool const isFirstPageOfLayoutOdd(nFirstVirtPageNum % 2 == 1);
+ return ((nPageNum % 2) == 1) == isFirstPageOfLayoutOdd;
+}
+
+} // namespace sw
+
SwPageFrame * InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper,
- bool bOdd, bool bFirst, bool bInsertEmpty, bool bFootnote,
+ bool const isRightPage, bool const bFirst, bool bInsertEmpty,
+ bool const bFootnote,
SwFrame *pSibling )
{
+ assert(pUpper);
+ assert(pUpper->IsRootFrame());
+ assert(!pSibling || static_cast<SwLayoutFrame const*>(pUpper)->Lower() != pSibling); // currently no insert before 1st page
SwPageFrame *pRet;
SwDoc *pDoc = static_cast<SwLayoutFrame*>(pUpper)->GetFormat()->GetDoc();
if (bFirst)
@@ -2895,7 +2912,7 @@ SwPageFrame * InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper,
{
// We need to fallback to left or right page format, decide it now.
// FIXME: is this still needed?
- if (bOdd)
+ if (isRightPage)
{
rDesc.GetFirstMaster().SetFormatAttr( rDesc.GetMaster().GetHeader() );
rDesc.GetFirstMaster().SetFormatAttr( rDesc.GetMaster().GetFooter() );
@@ -2910,11 +2927,11 @@ SwPageFrame * InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper,
}
}
}
- SwFrameFormat *pFormat(bOdd ? rDesc.GetRightFormat(bFirst) : rDesc.GetLeftFormat(bFirst));
+ SwFrameFormat *pFormat(isRightPage ? rDesc.GetRightFormat(bFirst) : rDesc.GetLeftFormat(bFirst));
// If there is no FrameFormat for this page, add an empty page
if ( !pFormat )
{
- pFormat = bOdd ? rDesc.GetLeftFormat() : rDesc.GetRightFormat();
+ pFormat = isRightPage ? rDesc.GetLeftFormat() : rDesc.GetRightFormat();
OSL_ENSURE( pFormat, "Descriptor without any format?!" );
bInsertEmpty = !bInsertEmpty;
}
diff --git a/sw/source/core/layout/laycache.cxx b/sw/source/core/layout/laycache.cxx
index eb824827e4ac..a5da72128614 100644
--- a/sw/source/core/layout/laycache.cxx
+++ b/sw/source/core/layout/laycache.cxx
@@ -668,17 +668,19 @@ bool SwLayHelper::CheckInsertPage()
if ( oPgNum )
static_cast<SwRootFrame*>(mrpPage->GetUpper())->SetVirtPageNum(true);
}
- bool bNextPageOdd = !mrpPage->OnRightPage();
+ bool bNextPageRight = !mrpPage->OnRightPage();
bool bInsertEmpty = false;
- if( oPgNum && bNextPageOdd != ( ( *oPgNum % 2 ) != 0 ) )
+ assert(mrpPage->GetUpper()->GetLower());
+ if (oPgNum && bNextPageRight != IsRightPageByNumber(
+ *static_cast<SwRootFrame*>(mrpPage->GetUpper()), *oPgNum))
{
- bNextPageOdd = !bNextPageOdd;
+ bNextPageRight = !bNextPageRight;
bInsertEmpty = true;
}
// If the page style is changing, we'll have a first page.
bool bNextPageFirst = pDesc != mrpPage->GetPageDesc();
::InsertNewPage( const_cast<SwPageDesc&>(*pDesc), mrpPage->GetUpper(),
- bNextPageOdd, bNextPageFirst, bInsertEmpty, false, mrpPage->GetNext() );
+ bNextPageRight, bNextPageFirst, bInsertEmpty, false, mrpPage->GetNext());
if ( bEnd )
{
OSL_ENSURE( mrpPage->GetNext(), "No new page?" );
diff --git a/sw/source/core/layout/newfrm.cxx b/sw/source/core/layout/newfrm.cxx
index 90d4fbde380a..a712007f8c49 100644
--- a/sw/source/core/layout/newfrm.cxx
+++ b/sw/source/core/layout/newfrm.cxx
@@ -487,15 +487,9 @@ void SwRootFrame::Init( SwFrameFormat* pFormat )
if ( !pDesc )
pDesc = &pDoc->GetPageDesc( 0 );
- const bool bOdd = !oPgNum || 0 != ( *oPgNum % 2 );
- const bool bFirst = true;
- // Even page numbers are supposed to be printed as left pages. So if a
- // page number has been explicitly set for this first page, then we must
- // insert a blank page before it to make it a left page.
- const bool bInsertEmpty = !bOdd;
-
// Create a page and put it in the layout
- SwPageFrame *pPage = ::InsertNewPage( *pDesc, this, bOdd, bFirst, bInsertEmpty, false, nullptr );
+ // The first page is always a right-page and always a first-page
+ SwPageFrame *pPage = ::InsertNewPage(*pDesc, this, true, true, false, false, nullptr);
// Find the first page in the Bodytext section.
SwLayoutFrame *pLay = pPage->FindBodyCont();
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index cd97be4205a0..588b650fb920 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -991,7 +991,7 @@ void SwPageFrame::PrepareRegisterChg()
}
//FIXME: provide missing documentation
-/** Check all pages (starting from the given one) if they use the right frame format.
+/** Check all pages (starting from the given one) if they use the appropriate frame format.
*
* If "wrong" pages are found, try to fix this as simple as possible.
*
@@ -1291,8 +1291,8 @@ SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote )
SwPageDesc *pDesc = nullptr;
// insert right (odd) or left (even) page?
- bool bNextOdd = !pPrevPage->OnRightPage();
- bool bWishedOdd = bNextOdd;
+ bool bNextRightPage = !pPrevPage->OnRightPage();
+ bool bWishedRightPage = bNextRightPage;
// Which PageDesc is relevant?
// For ContentFrame take the one from format if provided,
@@ -1304,7 +1304,7 @@ SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote )
if ( rDesc.GetNumOffset() )
{
::o3tl::optional<sal_uInt16> oNumOffset = rDesc.GetNumOffset();
- bWishedOdd = oNumOffset && (*oNumOffset % 2) != 0;
+ bWishedRightPage = sw::IsRightPageByNumber(*pRoot, *oNumOffset);
// use the opportunity to set the flag at root
pRoot->SetVirtPageNum( true );
}
@@ -1313,20 +1313,20 @@ SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote )
pDesc = pPrevPage->GetPageDesc()->GetFollow();
assert(pDesc && "Missing PageDesc");
- if( !(bWishedOdd ? pDesc->GetRightFormat() : pDesc->GetLeftFormat()) )
- bWishedOdd = !bWishedOdd;
+ if( !(bWishedRightPage ? pDesc->GetRightFormat() : pDesc->GetLeftFormat()) )
+ bWishedRightPage = !bWishedRightPage;
bool const bWishedFirst = pDesc != pPrevPage->GetPageDesc();
SwDoc *pDoc = pPrevPage->GetFormat()->GetDoc();
bool bCheckPages = false;
// If there is no FrameFormat for this page, create an empty page.
- if( bWishedOdd != bNextOdd )
+ if (bWishedRightPage != bNextRightPage)
{
if( doInsertPage( pRoot, &pSibling, pDoc->GetEmptyPageFormat(),
pPrevPage->GetPageDesc(), bFootnote, nullptr ) )
bCheckPages = true;
}
- SwFrameFormat *const pFormat( bWishedOdd
+ SwFrameFormat *const pFormat( bWishedRightPage
? pDesc->GetRightFormat(bWishedFirst)
: pDesc->GetLeftFormat(bWishedFirst) );
assert(pFormat);
@@ -1560,17 +1560,17 @@ void SwRootFrame::AssertFlyPages()
// and let the ::Notify mechanism newly evaluate
// m_bEmptyPage (see SwPageFrame::UpdateAttr_). Code is taken and
// adapted from ::InsertPage (used below), this needs previous page
- bool bWishedOdd(!pPrevPage->OnRightPage());
+ bool bWishedRightPage(!pPrevPage->OnRightPage());
SwPageDesc* pDesc(pPrevPage->GetPageDesc()->GetFollow());
assert(pDesc && "Missing PageDesc");
- if(!(bWishedOdd ? pDesc->GetRightFormat() : pDesc->GetLeftFormat()))
+ if (!(bWishedRightPage ? pDesc->GetRightFormat() : pDesc->GetLeftFormat()))
{
- bWishedOdd = !bWishedOdd;
+ bWishedRightPage = !bWishedRightPage;
}
bool const bWishedFirst(pDesc != pPrevPage->GetPageDesc());
- SwFrameFormat* pFormat(bWishedOdd ? pDesc->GetRightFormat(bWishedFirst) : pDesc->GetLeftFormat(bWishedFirst));
+ SwFrameFormat* pFormat(bWishedRightPage ? pDesc->GetRightFormat(bWishedFirst) : pDesc->GetLeftFormat(bWishedFirst));
// set SwFrameFormat, this will trigger SwPageFrame::UpdateAttr_ and re-evaluate
// m_bEmptyPage, too
@@ -1614,9 +1614,9 @@ void SwRootFrame::AssertFlyPages()
if ( pPage )
{
SwPageDesc *pTmpDesc = pPage->FindPageDesc();
- bool bOdd = pPage->OnRightPage();
+ bool isRightPage = pPage->OnRightPage();
if ( pPage->GetFormat() !=
- (bOdd ? pTmpDesc->GetRightFormat() : pTmpDesc->GetLeftFormat()) )
+ (isRightPage ? pTmpDesc->GetRightFormat() : pTmpDesc->GetLeftFormat()) )
RemoveFootnotes( pPage, false, true );
}
}
diff --git a/sw/source/core/layout/trvlfrm.cxx b/sw/source/core/layout/trvlfrm.cxx
index 3834898f5ea9..6e2c7fba14c9 100644
--- a/sw/source/core/layout/trvlfrm.cxx
+++ b/sw/source/core/layout/trvlfrm.cxx
@@ -1695,16 +1695,18 @@ sal_uInt16 SwFrame::GetPhyPageNum() const
return pPage ? pPage->GetPhyPageNum() : 0;
}
-/** Decides if the page want to be a rightpage or not.
+/** Decides if the page want to be a right page or not.
*
* If the first content of the page has a page descriptor, we take the follow
* of the page descriptor of the last not empty page. If this descriptor allows
- * only right(left) pages and the page isn't an empty page then it want to be
+ * only right(left) pages and the page isn't an empty page then it wants to be
* such right(left) page. If the descriptor allows right and left pages, we
* look for a number offset in the first content. If there is one, odd number
- * results right pages, even number results left pages.
+ * results right pages (or left pages if document starts with even number),
+ * even number results left pages (or right pages if document starts with even
+ * number).
* If there is no number offset, we take the physical page number instead,
- * but a previous empty page don't count.
+ * but a previous empty page doesn't count.
*/
bool SwFrame::WannaRightPage() const
{
@@ -1741,23 +1743,23 @@ bool SwFrame::WannaRightPage() const
}
}
OSL_ENSURE( pDesc, "No pagedescriptor" );
- bool bOdd;
+ bool isRightPage;
if( oPgNum )
- bOdd = (*oPgNum % 2) != 0;
+ isRightPage = sw::IsRightPageByNumber(*mpRoot, *oPgNum);
else
{
- bOdd = pPage->OnRightPage();
+ isRightPage = pPage->OnRightPage();
if( pPage->GetPrev() && static_cast<const SwPageFrame*>(pPage->GetPrev())->IsEmptyPage() )
- bOdd = !bOdd;
+ isRightPage = !isRightPage;
}
if( !pPage->IsEmptyPage() )
{
if( !pDesc->GetRightFormat() )
- bOdd = false;
+ isRightPage = false;
else if( !pDesc->GetLeftFormat() )
- bOdd = true;
+ isRightPage = true;
}
- return bOdd;
+ return isRightPage;
}
bool SwFrame::OnFirstPage() const
@@ -1770,17 +1772,9 @@ bool SwFrame::OnFirstPage() const
const SwPageFrame* pPrevFrame = dynamic_cast<const SwPageFrame*>(pPage->GetPrev());
if (pPrevFrame)
{
- if (pPrevFrame->IsEmptyPage() && pPrevFrame->GetPhyPageNum()==1)
- {
- // This was the first page of the document, but its page number
- // was set to an even number, so a blank page was automatically
- // inserted before it to make this be a "left" page.
- // We still use the first page format of the page style here.
- bRet = true;
- } else {
- const SwPageDesc* pDesc = pPage->GetPageDesc();
- bRet = pPrevFrame->GetPageDesc() != pDesc;
- }
+ // first page of layout may be empty page, but only if it starts with "Left Page" style
+ const SwPageDesc* pDesc = pPage->GetPageDesc();
+ bRet = pPrevFrame->GetPageDesc() != pDesc;
}
else
bRet = true;