sw/qa/extras/layout/data/tdf163149.docx |binary sw/qa/extras/layout/layout3.cxx | 46 ++++++++++++++++++++++++++++++++ sw/source/core/text/itradj.cxx | 5 ++- 3 files changed, 50 insertions(+), 1 deletion(-)
New commits: commit e5d25fb0aec8578dbf846af77d99fe7eb53ed906 Author: László Németh <nem...@numbertext.org> AuthorDate: Tue Oct 15 22:50:15 2024 +0200 Commit: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> CommitDate: Mon Oct 28 14:03:28 2024 +0100 tdf#163149 sw smart justify: fix line shrinking at image wrapping Limited line width at image wrap could result negative nSpaceAdd value, i.e. paragraph line with extra letter spacing instead of line shrinking. Conflicts: sw/qa/extras/layout/layout3.cxx Regression from commit 17eaebee279772b6062ae3448012133897fc71bb "tdf#119908 sw smart justify: fix justification by shrinking". Change-Id: I76cc3004d246ff7af441ca9a92eaa8fc7b09f01b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174985 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 1fb6de02709a5f420f21ebd683915da50ce0d198) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174954 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175649 Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> diff --git a/sw/qa/extras/layout/data/tdf163149.docx b/sw/qa/extras/layout/data/tdf163149.docx new file mode 100644 index 000000000000..efe0c65451a7 Binary files /dev/null and b/sw/qa/extras/layout/data/tdf163149.docx differ diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx index ce517942ee03..2ffb320a816e 100644 --- a/sw/qa/extras/layout/layout3.cxx +++ b/sw/qa/extras/layout/layout3.cxx @@ -492,6 +492,52 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf161810) } } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf163149) +{ + createSwDoc("tdf163149.docx"); + // Ensure that all text portions are calculated before testing. + SwDoc* pDoc = getSwDoc(); + SwDocShell* pShell = pDoc->GetDocShell(); + + // Dump the rendering of the first page as an XML file. + std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile(); + MetafileXmlDump dumper; + + xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + + // Find the text array action for the second non-empty (shrunk) line + bool bFirst = true; + for (size_t nAction = 0; nAction < xMetaFile->GetActionSize(); nAction++) + { + auto pAction = xMetaFile->GetAction(nAction); + if (pAction->GetType() == MetaActionType::TEXTARRAY) + { + auto pTextArrayAction = static_cast<MetaTextArrayAction*>(pAction); + auto pDXArray = pTextArrayAction->GetDXArray(); + + // skip empty paragraphs + if (pDXArray.size() <= 1) + continue; + + // skip first non-empty line + if (bFirst) + { + bFirst = false; + continue; + } + + // There should be 46 chars on the second line + CPPUNIT_ASSERT_EQUAL(size_t(46), pDXArray.size()); + + // Assert we are using the expected position for the last char + // This was 4673, now 4163, according to the fixed space shrinking + CPPUNIT_ASSERT_LESS(sal_Int32(4200), pDXArray[45]); + break; + } + } +} + CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf106234) { createSwDoc("tdf106234.fodt"); diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx index 4e2650d2f494..1257d7427ffe 100644 --- a/sw/source/core/text/itradj.cxx +++ b/sw/source/core/text/itradj.cxx @@ -403,7 +403,10 @@ void SwTextAdjuster::CalcNewBlock( SwLineLayout *pCurrent, tools::Long nSpaceSub = ( nBreakWidth > pCurrent->Width() ) ? (nBreakWidth - pCurrent->Width()) * SPACING_PRECISION_FACTOR / sal_Int32(nGluePortion) + LONG_MAX/2 - : 0; + : ( nSpaceAdd < 0 ) + // shrink, if portions exceed the line width available before an image + ? -nSpaceAdd + LONG_MAX/2 + : 0; // i60594 if( rSI.CountKashida() && !bSkipKashida )