sw/qa/extras/layout/data/tdf163149.docx |binary sw/qa/extras/layout/layout3.cxx | 46 +++++++++++++++++++++++++++++ sw/qa/extras/odfexport/data/tdf163575.docx |binary sw/qa/extras/odfexport/odfexport2.cxx | 6 +++ sw/source/core/text/itradj.cxx | 5 ++- sw/source/core/text/pormulti.cxx | 2 + 6 files changed, 58 insertions(+), 1 deletion(-)
New commits: commit 4e5373903a992a145abc903ed3bab844a1944618 Author: László Németh <nem...@numbertext.org> AuthorDate: Tue Oct 22 16:59:24 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Oct 25 16:08:37 2024 +0200 tdf#163575 sw smart justify: fix size resolution for SwBidiPortion Negative space sizes (i.e. shrunk lines at image wrapping) stored over LONG_MAX/2, and these values had no resolution in SwBidiPortion, causing crash/assert in conversion of DOCX document containing e.g. Arabic text wrapping around images. Note: apply the resolution in SwDoubleLinePortion, too. Regression since commit 1fb6de02709a5f420f21ebd683915da50ce0d198 "tdf#163149 sw smart justify: fix line shrinking at image wrapping". Change-Id: I6e45592c4eed247871d35e1f02fd5a038baddf85 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175419 Reviewed-by: László Németh <nem...@numbertext.org> Tested-by: Jenkins (cherry picked from commit 270c96e12c4a14c4f9e130d15310843da3a6af68) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175433 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/qa/extras/odfexport/data/tdf163575.docx b/sw/qa/extras/odfexport/data/tdf163575.docx new file mode 100644 index 000000000000..8d6c8f17fe69 Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf163575.docx differ diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index a2acec11393f..71345908df4e 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -366,6 +366,12 @@ CPPUNIT_TEST_FIXTURE(Test, tdf99631) assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaHeight']"_ostr, "1355"); } +CPPUNIT_TEST_FIXTURE(Test, tdf163575) +{ + // crashes/assert at export time + loadAndReload("tdf163575.docx"); +} + CPPUNIT_TEST_FIXTURE(Test, tdf145871) { loadAndReload("tdf145871.odt"); diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx index 7771ab9b5e8f..fe26c73af69f 100644 --- a/sw/source/core/text/pormulti.cxx +++ b/sw/source/core/text/pormulti.cxx @@ -221,6 +221,7 @@ SwBidiPortion::SwBidiPortion(TextFrameIndex const nEnd, sal_uInt8 nLv) SwTwips SwBidiPortion::CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo& rInf ) const { + nSpaceAdd = nSpaceAdd > LONG_MAX/2 ? LONG_MAX/2 - nSpaceAdd : nSpaceAdd; return HasTabulator() ? 0 : sal_Int32(GetSpaceCnt(rInf)) * nSpaceAdd / SPACING_PRECISION_FACTOR; } @@ -507,6 +508,7 @@ void SwDoubleLinePortion::CalcBlanks( SwTextFormatInfo &rInf ) SwTwips SwDoubleLinePortion::CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo & ) const { + nSpaceAdd = nSpaceAdd > LONG_MAX/2 ? LONG_MAX/2 - nSpaceAdd : nSpaceAdd; return HasTabulator() ? 0 : sal_Int32(GetSpaceCnt()) * nSpaceAdd / SPACING_PRECISION_FACTOR; } commit aace792db965178a11941d7b791db18f087b0105 Author: László Németh <nem...@numbertext.org> AuthorDate: Tue Oct 15 22:50:15 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Oct 25 16:08:22 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. 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> 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 )