sw/qa/extras/layout/data/fld-in-tbl.docx |binary
 sw/qa/extras/layout/layout3.cxx          |   21 +++++++++++++++++++++
 sw/source/core/text/guess.cxx            |   14 ++++++++------
 3 files changed, 29 insertions(+), 6 deletions(-)

New commits:
commit 0f436a2fe6dfe8b2a7b159a94ed7a8706a1b4482
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Jan 19 11:07:58 2024 +0600
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Jan 19 17:05:40 2024 +0100

    tdf#159271: do not try to put fields' spaces to hole portions
    
    Change-Id: Ic1b3f9602089cc773f9c3adc0be09a3be08d690f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162269
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162293
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/layout/data/fld-in-tbl.docx 
b/sw/qa/extras/layout/data/fld-in-tbl.docx
new file mode 100644
index 000000000000..95d1b8adae38
Binary files /dev/null and b/sw/qa/extras/layout/data/fld-in-tbl.docx differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index e0b29b43fc54..7112f8daae1a 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -2232,6 +2232,27 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159050)
                 u"PortionType::Margin"_ustr);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159271)
+{
+    // Given a document with a field with several spaces in a field content
+    createSwDoc("fld-in-tbl.docx");
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    // Make sure there is only one page, one table with one row and two cells, 
and one paragraph
+    assertXPath(pXmlDoc, "/root/page"_ostr, 1);
+    assertXPath(pXmlDoc, "/root/page/body/tab"_ostr, 1);
+    assertXPath(pXmlDoc, "/root/page/body/tab/row"_ostr, 1);
+    assertXPath(pXmlDoc, "/root/page/body/tab/row/cell"_ostr, 2);
+    assertXPath(pXmlDoc, "/root/page/body/txt"_ostr, 1);
+    assertXPath(pXmlDoc, 
"/root/page/body/tab/row/cell[2]/txt/SwParaPortion"_ostr, 1);
+
+    // Without the fix, this would fail:
+    // - Expected: 1
+    // - Actual  : 16
+    // - In <>, XPath '/root/page/body/tab/row/cell[2]/txt//SwLineLayout' 
number of nodes is incorrect
+    assertXPath(pXmlDoc, 
"/root/page/body/tab/row/cell[2]/txt//SwLineLayout"_ostr, 1);
+    assertXPath(pXmlDoc, 
"/root/page/body/tab/row/cell[2]/txt//SwFieldPortion"_ostr, 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index 3c85a42f4f15..3346fe345acc 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -253,9 +253,10 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
         {
             // portion fits to line
             m_nCutPos = rInf.GetIdx() + nMaxLen;
-            bool bRet = maybeAdjustPositionsForBlockAdjust(m_nCutPos, 
m_nBreakPos, m_nBreakStart,
-                                                           m_nBreakWidth, 
m_nExtraBlankWidth,
-                                                           nMaxSizeDiff, rInf, 
rSI, nMaxComp);
+            bool bRet = rPor.InFieldGrp()
+                        || maybeAdjustPositionsForBlockAdjust(m_nCutPos, 
m_nBreakPos, m_nBreakStart,
+                                                              m_nBreakWidth, 
m_nExtraBlankWidth,
+                                                              nMaxSizeDiff, 
rInf, rSI, nMaxComp);
             if( nItalic &&
                 (m_nCutPos >= TextFrameIndex(rInf.GetText().getLength()) ||
                   // #i48035# Needed for CalcFitToContent
@@ -408,9 +409,10 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
         // there likely has been a pixel rounding error in GetTextBreak
         if ( m_nBreakWidth <= nLineWidth )
         {
-            bool bRet = maybeAdjustPositionsForBlockAdjust(m_nCutPos, 
m_nBreakPos, m_nBreakStart,
-                                                           m_nBreakWidth, 
m_nExtraBlankWidth,
-                                                           nMaxSizeDiff, rInf, 
rSI, nMaxComp);
+            bool bRet = rPor.InFieldGrp()
+                        || maybeAdjustPositionsForBlockAdjust(m_nCutPos, 
m_nBreakPos, m_nBreakStart,
+                                                              m_nBreakWidth, 
m_nExtraBlankWidth,
+                                                              nMaxSizeDiff, 
rInf, rSI, nMaxComp);
 
             if (nItalic && (m_nBreakPos + TextFrameIndex(1)) >= 
TextFrameIndex(rInf.GetText().getLength()))
                 m_nBreakWidth += nItalic;

Reply via email to