sw/qa/extras/layout/data/tdf164499.docx |binary
 sw/qa/extras/layout/layout3.cxx         |   28 +++++++++++++++++++++++-----
 sw/source/core/text/portxt.cxx          |    2 ++
 3 files changed, 25 insertions(+), 5 deletions(-)

New commits:
commit 55830c147b0f2cebfa4bc4f8c271ae455e6446b5
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue Feb 11 01:22:42 2025 +0100
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Thu Feb 13 05:51:47 2025 +0100

    tdf#164499 sw smart justify: disable in tabulated lines to fix ToC
    
    Calculated extra text content without shrinking resulted overhanging
    text lines, e.g page numbers over the margin in ToC. Fix it
    by skipping space shrinking completely in tabulated lines,
    restoring also interoperability.
    
    Regression since commit 53de98b29548ded88e0a44c80256fc5e340d551e
    "tdf#158333 sw smart justify: fix multiple text portions".
    
    Change-Id: I390a254b8a47c6563d2c01a2f818f5ac6122e2ac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181397
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit ed7fbfce0b434f7d2a5542483d2838af51958e34)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181450
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/qa/extras/layout/data/tdf164499.docx 
b/sw/qa/extras/layout/data/tdf164499.docx
new file mode 100644
index 000000000000..d970bb29affa
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf164499.docx differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index af6dac583f29..5460eae5199a 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -479,12 +479,10 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf161810)
             auto pTextArrayAction = static_cast<MetaTextArrayAction*>(pAction);
             auto pDXArray = pTextArrayAction->GetDXArray();
 
-            // There should be 73 chars on the first line
-            CPPUNIT_ASSERT_EQUAL(size_t(73), pDXArray.size());
+            // There should be 70 chars on the first line
+            // (tdf#164499 no space shrinking in lines with tabulation)
+            CPPUNIT_ASSERT_EQUAL(size_t(70), pDXArray.size());
 
-            // Assert we are using the expected position for the last char
-            // This was 9369, now 9165, according to the fixed space shrinking
-            CPPUNIT_ASSERT_LESS(sal_Int32(9300), sal_Int32(pDXArray[72]));
             break;
         }
     }
@@ -535,6 +533,26 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf163149)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf164499)
+{
+    createSwDoc("tdf164499.docx");
+
+    // Ensure that all text portions are calculated before testing.
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    CPPUNIT_ASSERT(pViewShell);
+    pViewShell->Reformat();
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+    // no shrinking in tabulated text lines
+
+    // This was 1 (no line break in heading 2.5.5)
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/section/txt[18]/SwParaPortion/SwLineLayout", 2);
+    // line break in heading 2.5.5: the second line contains only the page 
number
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/section/txt[18]/SwParaPortion/SwLineLayout[2]",
+                "portion", u"*1");
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf132599_always)
 {
     uno::Reference<linguistic2::XHyphenator> xHyphenator = 
LinguMgr::GetHyphenator();
diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx
index 8fd5f1c07623..d72bc719a730 100644
--- a/sw/source/core/text/portxt.cxx
+++ b/sw/source/core/text/portxt.cxx
@@ -333,6 +333,8 @@ bool SwTextPortion::Format_( SwTextFormatInfo &rInf )
          pGuess->BreakPos() != TextFrameIndex(COMPLETE_STRING) &&
          rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(
                     DocumentSettingId::JUSTIFY_LINES_WITH_SHRINKING) &&
+         // tdf#164499 no shrinking in tabulated line
+         ( !rInf.GetLast() || !rInf.GetLast()->InTabGrp() ) &&
          // tdf#158436 avoid shrinking at underflow, e.g. no-break space after 
a
          // very short word resulted endless loop
          !rInf.IsUnderflow() )

Reply via email to