sw/qa/extras/layout/data/tdf164905.docx |binary
 sw/qa/extras/layout/layout3.cxx         |   16 ++++++++++++++++
 sw/source/core/text/itradj.cxx          |   11 +++++++----
 3 files changed, 23 insertions(+), 4 deletions(-)

New commits:
commit e336b24a99cd2bfc70d27a26274dc43e21fc60b2
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon Mar 3 13:50:22 2025 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Mar 6 15:54:05 2025 +0100

    tdf#164905 tdf#164499 sw smart justify: fix overlapping text in ToC
    
    Unnecessary calculation with the width of the glue portions resulted
    bad ToC, i.e. text lines with tabulators got overlapping text.
    
    Regression from commit 857dd6000c877f2c6d8bb73806a8557fa0baea73
    "tdf#161810 sw smart justify: fix overhanging lines containing tabs".
    
    Revert only the calculation, but not the unit test, which is still
    correct, according to commit ed7fbfce0b434f7d2a5542483d2838af51958e34
    "tdf#164499 sw smart justify: disable in tabulated lines to fix ToC".
    
    Change-Id: I3fe6d0d56ea8593ddee23d3c4063024762b65bab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182433
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 434af9dea64f95e1d5f93a5563106b9124bb17af)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182437
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/layout/data/tdf164905.docx 
b/sw/qa/extras/layout/data/tdf164905.docx
new file mode 100644
index 000000000000..9dca805ae13d
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf164905.docx differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index 5460eae5199a..1b2f2c28271d 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -488,6 +488,22 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf161810)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf164905)
+{
+    createSwDoc("tdf164905.docx");
+    // Ensure that all text portions are calculated before testing.
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    CPPUNIT_ASSERT(pViewShell);
+    pViewShell->Reformat();
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    // This was 9 (resulting broken ToC layout)
+    assertXPath(pXmlDoc, "//SwGluePortion", 3);
+    // For example, it was an unnecessary glue portion here
+    assertXPath(pXmlDoc,
+                
"/root/page/body/section[2]/txt[1]/SwParaPortion/SwLineLayout/SwGluePortion", 
0);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf163149)
 {
     createSwDoc("tdf163149.docx");
diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx
index 002d43f296d9..a0836bb02170 100644
--- a/sw/source/core/text/itradj.cxx
+++ b/sw/source/core/text/itradj.cxx
@@ -61,9 +61,10 @@ void SwTextAdjuster::FormatBlock( )
         const SwLinePortion *pPos = m_pCurr->GetNextPortion();
         while( pPos && bSkip )
         {
-            if( // don't calculate with the terminating space,
+            if( !pPos->InGlueGrp() &&
+                // don't calculate with the terminating space,
                 // otherwise it would result justified line mistakenly
-                pPos->GetNextPortion() || !pPos->IsHolePortion() )
+                ( pPos->GetNextPortion() || !pPos->IsHolePortion() ) )
             {
                 nBreakWidth += pPos->Width();
             }
@@ -426,8 +427,6 @@ void SwTextAdjuster::CalcNewBlock( SwLineLayout *pCurrent,
 
     while( pPos )
     {
-        nBreakWidth += pPos->Width();
-
         if ( ( bDoNotJustifyLinesWithManualBreak || bDoNotJustifyTab ) &&
              pPos->IsBreakPortion() && !IsLastBlock() )
         {
@@ -552,6 +551,10 @@ void SwTextAdjuster::CalcNewBlock( SwLineLayout *pCurrent,
             else
                 ++nGluePortion;
         }
+        else
+        {
+            nBreakWidth += pPos->Width();
+        }
         GetInfo().SetIdx( GetInfo().GetIdx() + pPos->GetLen() );
         if ( pPos == pStopAt )
         {

Reply via email to