From f8e1a62f944e5358fe498008b4ff8701f1e190a0 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 23 Aug 2023 08:34:01 +0200 Subject: 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. Change-Id: If71c44962f604f23fdcfccfe80b0d97787fd99d4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155961 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/CppunitTest_sw_core_layout.mk | 1 + sw/qa/core/layout/ftnfrm.cxx | 66 ++++++++++++++++++++++++++++++++++++++++ sw/source/core/layout/ftnfrm.cxx | 11 ++++++- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 sw/qa/core/layout/ftnfrm.cxx diff --git a/sw/CppunitTest_sw_core_layout.mk b/sw/CppunitTest_sw_core_layout.mk index 9431b6b83526..e965ae6f71aa 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 \ sw/qa/core/layout/tabfrm \ diff --git a/sw/qa/core/layout/ftnfrm.cxx b/sw/qa/core/layout/ftnfrm.cxx new file mode 100644 index 000000000000..4c874202da3f --- /dev/null +++ b/sw/qa/core/layout/ftnfrm.cxx @@ -0,0 +1,66 @@ +/* -*- 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 + +#include +#include +#include +#include +#include +#include +#include +#include + +/// 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(); + sw::FrameFormats& rFlys = *pDoc->GetSpzFrameFormats(); + sw::SpzFrameFormat* 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(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 00c5db65a27d..b2edab893023 100644 --- a/sw/source/core/layout/ftnfrm.cxx +++ b/sw/source/core/layout/ftnfrm.cxx @@ -41,6 +41,7 @@ #include #include #include +#include #define ENDNOTE 0x80000000 @@ -888,7 +889,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() ) -- cgit