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 1fb6de02709a5f420f21ebd683915da50ce0d198 Author: László Németh <nem...@numbertext.org> AuthorDate: Tue Oct 15 22:50:15 2024 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Oct 16 11:29:32 2024 +0200 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. 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> 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 7f62a3a9d6b8..2699f4d31d48 100644 --- a/sw/qa/extras/layout/layout3.cxx +++ b/sw/qa/extras/layout/layout3.cxx @@ -485,6 +485,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, testTdf132599_always) { uno::Reference<linguistic2::XHyphenator> xHyphenator = LinguMgr::GetHyphenator(); diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx index be004457b407..286b4f3a1718 100644 --- a/sw/source/core/text/itradj.cxx +++ b/sw/source/core/text/itradj.cxx @@ -482,7 +482,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 )