sw floattable, crashtesting: fix PDF export of fdo72790-1.docx, part 2

Converting the bugdoc to PDF crashed Writer layout since commit
ce3308a926f036b87515b8cd97d2b197063dc77a (tdf#61594 sw floattable:
import floating tables as split flys by default, 2023-04-12).

Part 1 already fixed a crash, but a layout loop remains. One problem
there is that we move too many rows to a next page. Analyzing what Word
does and how we behave, we handled the TABLE_ROW_KEEP flag even for
floating tables, but Word only does this when table wrapping is "none".

Fix the problem by following suit, which gives the correct 2.5 rows on
the first page of a reduced bugdoc.

The layout loop for the original document still needs more work, though.

Change-Id: Ief79d4b4e984a9e46ee133ae3e7e7cf81e13a836
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151009
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/core/layout/data/floattable-table-row-keep.docx b/sw/qa/core/layout/data/floattable-table-row-keep.docx
new file mode 100644
index 0000000..c7edcc0
--- /dev/null
+++ b/sw/qa/core/layout/data/floattable-table-row-keep.docx
Binary files differ
diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx
index b23edb7..bd3e98a 100644
--- a/sw/qa/core/layout/flycnt.cxx
+++ b/sw/qa/core/layout/flycnt.cxx
@@ -707,6 +707,36 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyInTextSection)
    // section frame, which is broken.
    createSwDoc("floattable-in-text-section.docx");
}

CPPUNIT_TEST_FIXTURE(Test, testSplitFlyTableRowKeep)
{
    // Given a document with a floating table, 2.5 rows on the first page:
    createSwDoc("floattable-table-row-keep.docx");

    // When laying out that document:
    calcLayout();

    // Then make sure that the expected amount of rows is on the first page:
    SwDoc* pDoc = getSwDoc();
    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
    auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower());
    CPPUNIT_ASSERT(pPage1);
    const SwSortedObjs& rPage1Objs = *pPage1->GetSortedObjs();
    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage1Objs.size());
    auto pPage1Fly = dynamic_cast<SwFlyAtContentFrame*>(rPage1Objs[0]);
    CPPUNIT_ASSERT(pPage1Fly);
    SwFrame* pTab1 = pPage1Fly->GetLower();
    SwFrame* pRow1 = pTab1->GetLower();
    CPPUNIT_ASSERT(pRow1);
    SwFrame* pRow2 = pRow1->GetNext();
    // Without the accompanying fix in place, this test would have failed, the table on the first
    // page only had 1 row, due to TableRowKeep kicking in for floating tables, which is incorrect.
    CPPUNIT_ASSERT(pRow2);
    SwFrame* pRow3 = pRow2->GetNext();
    CPPUNIT_ASSERT(pRow3);
    auto pCell3 = dynamic_cast<SwCellFrame*>(pRow3->GetLower());
    CPPUNIT_ASSERT(pCell3->GetFollowCell());
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index a8f34f3..6c8fa0e 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -1983,7 +1983,15 @@ void SwTabFrame::MakeAll(vcl::RenderContext* pRenderContext)

    // Indicates that two individual rows may keep together, based on the keep
    // attribute set at the first paragraph in the first cell.
    const bool bTableRowKeep = !bDontSplit && GetFormat()->GetDoc()->GetDocumentSettingManager().get(DocumentSettingId::TABLE_ROW_KEEP);
    bool bTableRowKeep = !bDontSplit && GetFormat()->GetDoc()->GetDocumentSettingManager().get(DocumentSettingId::TABLE_ROW_KEEP);
    if (SwFlyFrame* pFly = FindFlyFrame())
    {
        if (pFly->IsFlySplitAllowed())
        {
            // Ignore the above text node -> row inheritance for floating tables.
            bTableRowKeep = false;
        }
    }

    // The Magic Move: Used for the table row keep feature.
    // If only the last row of the table wants to keep (implicitly by setting