sw/qa/core/text/data/floattable-wrap-empty-para-legacy.docx |binary
 sw/qa/core/text/itrform2.cxx                                |   28 ++++++++++++
 sw/qa/core/text/text.cxx                                    |    4 -
 sw/source/core/inc/txtfly.hxx                               |    3 +
 sw/source/core/text/itrform2.cxx                            |   10 ++--
 sw/source/core/text/txtfly.cxx                              |    3 -
 6 files changed, 38 insertions(+), 10 deletions(-)

New commits:
commit 3756708f593557b9d39dae51d071b5d1459c95f4
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jul 17 09:00:33 2023 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jul 18 12:25:29 2023 +0200

    tdf#120262 sw floattable, legacy: fix text wrap around fly when no content 
fits
    
    The bugdoc is created from DOC (so tables are shifted to the left,
    slightly) and has 2 floating tables on 2 pages. Writer puts them to a
    single page, so they overlap, which is not wanted.
    
    The trouble is that there is some space (but not much) on the right of
    the floating table on page 1, and Writer wraps the empty anchor of the
    floating table on the right of the floating table, while Word puts it
    below the table, so no overlap happens.
    
    Fix the problem by extending the work from commit
    8f8b31abd02876c3601e343b8b3274754f8a61b6 (compatibility setting for MS
    Word wrapping text in less space (bnc#822908), 2013-08-06), and work
    with that limit in SwTextFormatter::CalcFlyWidth(). This way Writer
    keeps its behavior that PARALLEL wrap text mode requires no minimal text
    width for existing documents, but correctly ~300 twips minimal text
    width (Word formats).
    
    The bugdoc still has a footer vs floating table overlap, but at least no
    2 floating tables overlap now.
    
    (cherry picked from commit a4af5432753408c4eea8a8d56c2f48202160c5fe)
    
    Change-Id: Ib307ede08ead272fe16dca261db615fd8e9c547d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154576
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/core/text/data/floattable-wrap-empty-para-legacy.docx 
b/sw/qa/core/text/data/floattable-wrap-empty-para-legacy.docx
new file mode 100644
index 000000000000..c62a25a193a7
Binary files /dev/null and 
b/sw/qa/core/text/data/floattable-wrap-empty-para-legacy.docx differ
diff --git a/sw/qa/core/text/itrform2.cxx b/sw/qa/core/text/itrform2.cxx
index 066a8fb331a6..e190bed46f33 100644
--- a/sw/qa/core/text/itrform2.cxx
+++ b/sw/qa/core/text/itrform2.cxx
@@ -54,6 +54,34 @@ CPPUNIT_TEST_FIXTURE(Test, testFloattableWrapEmptyParagraph)
     const SwSortedObjs& rPageObjs2 = *pPage2->GetSortedObjs();
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs2.size());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testFloattableLegacyWrapEmptyParagraph)
+{
+    // Given a document with 2 pages, a floating table on both pages (from 
DOC, so the table is
+    // shifted towards the left page edge slightly):
+    createSwDoc("floattable-wrap-empty-para-legacy.docx");
+
+    // When calculating the layout:
+    calcLayout();
+
+    // Then make sure that each page has exactly 1 floating table:
+    SwDoc* pDoc = getSwDoc();
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage);
+    CPPUNIT_ASSERT(pPage->GetSortedObjs());
+    const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 2
+    // i.e. both tables were on page 1, leading to an overlap.
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs.size());
+    auto pPage2 = dynamic_cast<SwPageFrame*>(pPage->GetNext());
+    CPPUNIT_ASSERT(pPage2);
+    CPPUNIT_ASSERT(pPage2->GetSortedObjs());
+    const SwSortedObjs& rPageObjs2 = *pPage2->GetSortedObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs2.size());
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index f5b8c9253ea4..a3435238ddba 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -1011,10 +1011,10 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testParaUpperMarginFlyIntersect)
         nHeight += getXPath(pXmlDoc, xPath, "height").toInt32();
     }
     // Without the accompanying fix in place, this test would have failed with:
-    // - Expected: 521 (~500)
+    // - Expected: 542 (~500)
     // - Actual  : 857 (~1000)
     // I.e. both upper and lower margin was taken into account.
-    CPPUNIT_ASSERT_EQUAL(521, nHeight);
+    CPPUNIT_ASSERT_EQUAL(542, nHeight);
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/inc/txtfly.hxx b/sw/source/core/inc/txtfly.hxx
index 37d78e3c822f..3a3af9183e99 100644
--- a/sw/source/core/inc/txtfly.hxx
+++ b/sw/source/core/inc/txtfly.hxx
@@ -86,6 +86,9 @@ public:
                                        const bool bRight );
 };
 
+// MS Word wraps on sides with even less space (value guessed).
+#define TEXT_MIN_SMALL 300
+
 /**
    The purpose of this class is to be the universal interface between
    formatting/text output and the possibly overlapping free-flying frames.
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index de7beb4b29e7..bb0886b6981b 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -2783,12 +2783,12 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo 
&rInf )
 
     bool bFullLine =  aLine.Left()  == aInter.Left() &&
                             aLine.Right() == aInter.Right();
-    if (!bFullLine && bWordFlyWrap)
+    if (!bFullLine && bWordFlyWrap && !GetTextFrame()->IsInTab())
     {
-        // Word >= 2013 style: if there is minimal space remaining, then 
handle that similar to a
-        // full line and put the actual empty paragraph below the fly.
-        bFullLine = std::abs(aLine.Left() - aInter.Left()) < MINLAY
-                    && std::abs(aLine.Right() - aInter.Right()) < MINLAY;
+        // Word style: if there is minimal space remaining, then handle that 
similar to a full line
+        // and put the actual empty paragraph below the fly.
+        bFullLine = std::abs(aLine.Left() - aInter.Left()) < TEXT_MIN_SMALL
+                    && std::abs(aLine.Right() - aInter.Right()) < 
TEXT_MIN_SMALL;
     }
 
     // Although no text is left, we need to format another line,
diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx
index 64b8991875ab..4b1c0695af35 100644
--- a/sw/source/core/text/txtfly.cxx
+++ b/sw/source/core/text/txtfly.cxx
@@ -1383,9 +1383,6 @@ SwRect SwTextFly::AnchoredObjToRect( const 
SwAnchoredObject* pAnchoredObj,
 // Wrap only on sides with at least 2cm space for the text
 #define TEXT_MIN 1134
 
-// MS Word wraps on sides with even less space (value guessed).
-#define TEXT_MIN_SMALL 300
-
 // Wrap on both sides up to a frame width of 1.5cm
 #define FRAME_MAX 850
 

Reply via email to