diff options
-rw-r--r-- | sw/qa/extras/odfimport/odfimport.cxx | 9 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 8 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport4.cxx | 3 | ||||
-rw-r--r-- | sw/qa/extras/ww8export/ww8export.cxx | 7 | ||||
-rw-r--r-- | sw/source/core/inc/frmtool.hxx | 8 | ||||
-rw-r--r-- | sw/source/core/layout/flowfrm.cxx | 18 | ||||
-rw-r--r-- | sw/source/core/layout/frmtool.cxx | 25 | ||||
-rw-r--r-- | sw/source/core/layout/laycache.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/layout/newfrm.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/layout/pagechg.cxx | 28 | ||||
-rw-r--r-- | sw/source/core/layout/trvlfrm.cxx | 38 |
11 files changed, 86 insertions, 78 deletions
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx index 08495526e572..eb65f0d63540 100644 --- a/sw/qa/extras/odfimport/odfimport.cxx +++ b/sw/qa/extras/odfimport/odfimport.cxx @@ -895,14 +895,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 f689b129b994..835947da9dfb 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -175,13 +175,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 a09479e44ea0..29d4d54534f8 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx @@ -230,7 +230,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 61506b8f3702..71d514e29ed5 100644 --- a/sw/qa/extras/ww8export/ww8export.cxx +++ b/sw/qa/extras/ww8export/ww8export.cxx @@ -594,11 +594,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 f35bf168ec4f..1b8997cd6c2b 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; + boost::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().get(); + 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 132e3345c0ca..0cad5caca44a 100644 --- a/sw/source/core/layout/frmtool.cxx +++ b/sw/source/core/layout/frmtool.cxx @@ -2884,10 +2884,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) @@ -2896,7 +2913,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() ); @@ -2911,11 +2928,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 f78f0a4e9a47..ff1ad6a53eb7 100644 --- a/sw/source/core/layout/laycache.cxx +++ b/sw/source/core/layout/laycache.cxx @@ -670,17 +670,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.get() % 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 e4ae9a45c53e..1d1f4597fcf2 100644 --- a/sw/source/core/layout/newfrm.cxx +++ b/sw/source/core/layout/newfrm.cxx @@ -489,15 +489,9 @@ void SwRootFrame::Init( SwFrameFormat* pFormat ) if ( !pDesc ) pDesc = &pDoc->GetPageDesc( 0 ); - const bool bOdd = !oPgNum || 0 != ( oPgNum.get() % 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 a2b70fb68e81..a684b1602a1a 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() ) { ::boost::optional<sal_uInt16> oNumOffset = rDesc.GetNumOffset(); - bWishedOdd = oNumOffset && (oNumOffset.get() % 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 850196487a22..8cb591d05026 100644 --- a/sw/source/core/layout/trvlfrm.cxx +++ b/sw/source/core/layout/trvlfrm.cxx @@ -1692,16 +1692,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 { @@ -1738,23 +1740,23 @@ bool SwFrame::WannaRightPage() const } } OSL_ENSURE( pDesc, "No pagedescriptor" ); - bool bOdd; + bool isRightPage; if( oPgNum ) - bOdd = (oPgNum.get() % 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 @@ -1767,17 +1769,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; |