sw/qa/extras/layout/layout3.cxx | 48 +++++++++++++++++++++++++++++++++++----- sw/source/core/text/itrcrsr.cxx | 4 +-- sw/source/core/text/porlay.hxx | 7 ----- 3 files changed, 45 insertions(+), 14 deletions(-)
New commits: commit 20cbe88ce5610fd8ee302e5780a4c0821ddb3db4 Author: László Németh <nem...@numbertext.org> AuthorDate: Tue Nov 28 15:09:52 2023 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Nov 29 00:16:08 2023 +0100 tdf#119908 tdf#158419 sw smart justify: fix cursor position Text cursor didn't follow the new word positions yet, because of unsigned casting of the negative shrinking value. Revert the temporary change of GetLLSpaceAdd() added by commit 17eaebee279772b6062ae3448012133897fc71bb "tdf#119908 sw smart justify: fix justification by shrinking". Follow-up to commit 53de98b29548ded88e0a44c80256fc5e340d551e "tdf#158333 sw smart justify: fix multiple text portions". Change-Id: I82cb395fc5af800d8da67d27c16c5ed6837df695 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160050 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx index dc70bf41b6f8..843712e62221 100644 --- a/sw/qa/extras/layout/layout3.cxx +++ b/sw/qa/extras/layout/layout3.cxx @@ -237,6 +237,48 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158333) "consequat arcu ut diam tempor luctus. Cum sociis natoque penatibus et magnis "); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158419) +{ + createSwDoc("tdf130088.docx"); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pShell = pDoc->GetDocShell(); + + // Ensure that all text portions are calculated before testing. + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwViewShell* pViewShell + = pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell(); + CPPUNIT_ASSERT(pViewShell); + pViewShell->Reformat(); + + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + + // second paragraph. + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + SwWrtShell* pWrtShell = pShell->GetWrtShell(); + SwPosition aPosition(*pWrtShell->GetCursor()->Start()); + SwTwips nSecondParaLeft + = getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "left"_ostr).toInt32(); + SwTwips nSecondParaWidth + = getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "width"_ostr).toInt32(); + SwTwips nSecondParaTop + = getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "top"_ostr).toInt32(); + SwTwips nSecondParaHeight + = getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "height"_ostr).toInt32(); + Point aPoint; + + // click at the end of the second line of the second paragraph + // (a line shrunk by the new justification) + + aPoint.setX(nSecondParaLeft + nSecondParaWidth); + aPoint.setY(nSecondParaTop + (nSecondParaHeight / 6) * 1.5); + SwCursorMoveState aState(CursorMoveState::NONE); + pLayout->GetModelPositionForViewPoint(&aPosition, aPoint, &aState); + // Without the accompanying fix in place, this test would have failed: character position was 155, + // i.e. cursor was before the end of the paragraph. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(156), aPosition.GetContentIndex()); +} + CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf106234) { createSwDoc("tdf106234.fodt"); @@ -822,12 +864,6 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testAbi11870) createSwDoc("abi11870-2.odt"); } -CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testOfz64109) -{ - //just care it doesn't assert - createSwDoc("ofz64109-1.fodt"); -} - CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf118719) { // Insert a page break. diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx index 7a7024d97a09..1770361c19de 100644 --- a/sw/source/core/text/itrcrsr.cxx +++ b/sw/source/core/text/itrcrsr.cxx @@ -1371,7 +1371,7 @@ TextFrameIndex SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con if ( pPor->InSpaceGrp() && nSpaceAdd ) { const_cast<SwTextSizeInfo&>(GetInfo()).SetIdx( nCurrStart ); - nWidth = nWidth + sal_uInt16( pPor->CalcSpacing( nSpaceAdd, GetInfo() ) ); + nWidth = nWidth + sal_Int16( pPor->CalcSpacing( nSpaceAdd, GetInfo() ) ); } if( ( pPor->InFixMargGrp() && ! pPor->IsMarginPortion() ) || ( pPor->IsMultiPortion() && static_cast<SwMultiPortion*>(pPor)->HasTabulator() ) @@ -1415,7 +1415,7 @@ TextFrameIndex SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con if ( pPor->InSpaceGrp() && nSpaceAdd ) { const_cast<SwTextSizeInfo&>(GetInfo()).SetIdx( nCurrStart ); - nWidth = nWidth + sal_uInt16( pPor->CalcSpacing( nSpaceAdd, GetInfo() ) ); + nWidth = nWidth + sal_Int16( pPor->CalcSpacing( nSpaceAdd, GetInfo() ) ); } if( ( pPor->InFixMargGrp() && ! pPor->IsMarginPortion() ) || diff --git a/sw/source/core/text/porlay.hxx b/sw/source/core/text/porlay.hxx index e9e5f3d3f261..3b07b7016118 100644 --- a/sw/source/core/text/porlay.hxx +++ b/sw/source/core/text/porlay.hxx @@ -192,12 +192,7 @@ public: else (*m_pLLSpaceAdd)[ nIdx ] = nNew; } - tools::Long GetLLSpaceAdd( sal_uInt16 nIdx, bool bShrink = false ) - { - // get shrink data only if asked explicitly, otherwise zero it - return ( bShrink || (*m_pLLSpaceAdd)[ nIdx ] < LONG_MAX/2 ) - ? (*m_pLLSpaceAdd)[ nIdx ] : 0; - } + tools::Long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*m_pLLSpaceAdd)[ nIdx ]; } void RemoveFirstLLSpaceAdd() { m_pLLSpaceAdd->erase( m_pLLSpaceAdd->begin() ); } std::vector<tools::Long>* GetpLLSpaceAdd() const { return m_pLLSpaceAdd.get(); }