sw/qa/core/layout/data/floattable-wrapped-by-table-nested.docx |binary
 sw/qa/core/layout/tabfrm.cxx                                   |   15 
++++++++++
 sw/source/core/layout/tabfrm.cxx                               |   10 ++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

New commits:
commit 1958db722f80df2d2a8425a2efe1b529d484f0fc
Author:     Miklos Vajna <[email protected]>
AuthorDate: Tue Feb 20 08:06:08 2024 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Mar 5 14:36:11 2024 +0100

    tdf#159285 sw floattable: fix loop with inner table wrapped by inner table
    
    Regression from 868140fcc1311259b9d5f666637b33d226511a53 (tdf#60558 sw
    floattable: allow wrap of table on the right of a floattable,
    2023-12-05), the bugdoc layout looped on load.
    
    Somehow the big while() loop in SwTabFrame::MakeAll() never finishes: it
    always tries again but can't reach a state where all of frame area
    position, frame area size and frame print area is valid.
    
    Fix the problem by going back to the old behavior (floating table is
    wrapped by text frames, not by table frames) for the nested table case:
    that keeps the old tdf#60558 use-case working and fixes the new
    tdf#159285 use-case.
    
    At some point it would be useful to support the combination of nested
    floating tables and the "floating table wrapped by table" combination,
    but that will be a new layout feature.
    
    Conflicts:
            sw/source/core/layout/tabfrm.cxx
    
    Change-Id: Ia3fdbd08de87e13ddef086ae1339e79a8833674d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163630
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 2da4acdbf8c5a8ba3ef51e5f5dc3439716e71a91)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163612
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit 287d13d643bb98416baaf52179c1b32e70f2d269)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164073
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sw/qa/core/layout/data/floattable-wrapped-by-table-nested.docx 
b/sw/qa/core/layout/data/floattable-wrapped-by-table-nested.docx
new file mode 100644
index 000000000000..d6950a6c8e04
Binary files /dev/null and 
b/sw/qa/core/layout/data/floattable-wrapped-by-table-nested.docx differ
diff --git a/sw/qa/core/layout/tabfrm.cxx b/sw/qa/core/layout/tabfrm.cxx
index 2acd8106d20e..149e31ed100b 100644
--- a/sw/qa/core/layout/tabfrm.cxx
+++ b/sw/qa/core/layout/tabfrm.cxx
@@ -17,6 +17,7 @@
 #include <anchoredobject.hxx>
 #include <flyfrm.hxx>
 #include <flyfrms.hxx>
+#include <frameformats.hxx>
 
 namespace
 {
@@ -218,6 +219,20 @@ CPPUNIT_TEST_FIXTURE(Test, testInlineTableThenSplitFly)
     // large positive one.
     CPPUNIT_ASSERT_LESS(static_cast<SwTwips>(0), nInlineLeft);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testSplitFlyWrappedByTableNested)
+{
+    // Given a document with 3 tables, one inline toplevel and two inner ones 
(one inline, one
+    // floating):
+    // When laying out that document:
+    // Without the accompanying fix in place, this test would have failed here 
with a layout loop.
+    createSwDoc("floattable-wrapped-by-table-nested.docx");
+
+    // Than make sure we have 3 tables, but only one of them is floating:
+    SwDoc* pDoc = getSwDoc();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), 
pDoc->GetTableFrameFormats()->GetFormatCount());
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), 
pDoc->GetSpzFrameFormats()->GetFormatCount());
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index c6d836cf7642..430ec05721d7 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -3210,7 +3210,15 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
                         }
                     }
                     bool bFlyHoriOrientLeft = text::HoriOrientation::LEFT == 
rHori.GetHoriOrient();
-                    if (bSplitFly && !bFlyHoriOrientLeft)
+
+                    bool bToplevelSplitFly = false;
+                    if (bSplitFly)
+                    {
+                        // Floating table wrapped by table: avoid this in the 
nested case.
+                        bToplevelSplitFly = !pFly->GetAnchorFrame()->IsInTab();
+                    }
+
+                    if (bToplevelSplitFly && !bFlyHoriOrientLeft)
                     {
                         // Only shift to the right if we don't have enough 
space on the left.
                         SwTwips nTabWidth = getFramePrintArea().Width();

Reply via email to