sw/CppunitTest_sw_core_layout.mk |    1 
 sw/qa/core/layout/ftnfrm.cxx     |   67 +++++++++++++++++++++++++++++++++++++++
 sw/source/core/layout/ftnfrm.cxx |   11 +++++-
 3 files changed, 78 insertions(+), 1 deletion(-)

New commits:
commit 6b8d92ebeba263cdba72e4ed95f520ad99c0e12c
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Aug 23 08:34:01 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Aug 24 14:08:18 2023 +0200

    tdf#77760 sw floattable: add support for footnotes, layout
    
    Once the footnote was inserted to the document model, the layout was
    also missing (footnote portion, footnote frame).
    
    One problem is that the footnote portion was empty instead of the
    footnote counter, because SwTextFormatter::NewFootnotePortion() returned
    early in the fly case.
    
    The other problem was the missing footnote frame, but once the footnote
    portion was created correctly, the matching footnote frame was also
    created.
    
    File filters (ODT, DOCX) still needs more work.
    
    (cherry picked from commit f8e1a62f944e5358fe498008b4ff8701f1e190a0)
    
    Change-Id: If71c44962f604f23fdcfccfe80b0d97787fd99d4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156025
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/CppunitTest_sw_core_layout.mk b/sw/CppunitTest_sw_core_layout.mk
index fd608516f6ba..a86bd78c2cd7 100644
--- a/sw/CppunitTest_sw_core_layout.mk
+++ b/sw/CppunitTest_sw_core_layout.mk
@@ -15,6 +15,7 @@ $(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sw_core_layout))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sw_core_layout, \
     sw/qa/core/layout/flycnt \
+    sw/qa/core/layout/ftnfrm \
     sw/qa/core/layout/layout \
     sw/qa/core/layout/paintfrm \
 ))
diff --git a/sw/qa/core/layout/ftnfrm.cxx b/sw/qa/core/layout/ftnfrm.cxx
new file mode 100644
index 000000000000..0b60ecc0c6cf
--- /dev/null
+++ b/sw/qa/core/layout/ftnfrm.cxx
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <IDocumentLayoutAccess.hxx>
+#include <docsh.hxx>
+#include <formatflysplit.hxx>
+#include <frmmgr.hxx>
+#include <pagefrm.hxx>
+#include <rootfrm.hxx>
+#include <view.hxx>
+#include <wrtsh.hxx>
+#include <frameformats.hxx>
+
+/// Covers sw/source/core/layout/ftnfrm.cxx fixes.
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase("/sw/qa/core/layout/data/")
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testFlySplitFootnoteLayout)
+{
+    // Given a document with a split fly (to host a table):
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+    SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
+    RndStdIds eAnchor = RndStdIds::FLY_AT_PARA;
+    pWrtShell->StartAllAction();
+    aMgr.InsertFlyFrame(eAnchor, aMgr.GetPos(), aMgr.GetSize());
+    pWrtShell->EndAllAction();
+    pWrtShell->StartAllAction();
+    SwFrameFormats& rFlys = *pDoc->GetSpzFrameFormats();
+    SwFrameFormat* pFly = rFlys[0];
+    SwAttrSet aSet(pFly->GetAttrSet());
+    aSet.Put(SwFormatFlySplit(true));
+    pDoc->SetAttr(aSet, *pFly);
+    pWrtShell->EndAllAction();
+    pWrtShell->UnSelectFrame();
+    pWrtShell->LeaveSelFrameMode();
+    pWrtShell->GetView().AttrChangedNotify(nullptr);
+    pWrtShell->MoveSection(GoCurrSection, fnSectionEnd);
+
+    // When inserting a footnote:
+    pWrtShell->InsertFootnote(OUString());
+
+    // Then make sure the footnote frame and its container is created:
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage);
+    // Without the accompanying fix in place, this test would have failed, the 
footnote frame was
+    // not created, the footnote reference was empty.
+    CPPUNIT_ASSERT(pPage->FindFootnoteCont());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/ftnfrm.cxx b/sw/source/core/layout/ftnfrm.cxx
index 6fb88185a6f2..8fdf21d01ef8 100644
--- a/sw/source/core/layout/ftnfrm.cxx
+++ b/sw/source/core/layout/ftnfrm.cxx
@@ -39,6 +39,7 @@
 #include <osl/diagnose.h>
 #include <sal/log.hxx>
 #include <IDocumentSettingAccess.hxx>
+#include <flyfrm.hxx>
 
 #define ENDNOTE 0x80000000
 
@@ -886,7 +887,15 @@ SwLayoutFrame *SwFrame::GetPrevFootnoteLeaf( MakePageType 
eMakeFootnote )
 
 bool SwFrame::IsFootnoteAllowed() const
 {
-    if ( !IsInDocBody() )
+    bool bSplitFly = false;
+    const SwFlyFrame* pFlyFrame = FindFlyFrame();
+    if (pFlyFrame)
+    {
+        // This is a fly. Check if it's a split fly, which is OK to host a 
footnote.
+        bSplitFly = pFlyFrame->IsFlySplitAllowed();
+    }
+
+    if (!IsInDocBody() && !bSplitFly)
         return false;
 
     if ( IsInTab() )

Reply via email to