tdf#77760 sw floattable: add support for footnotes, DOC import
This is similar to commit 178421a6c719dac9c16f220b76292fec16a53f60
(tdf#77760 sw floattable: add support for footnotes, DOCX import,
2023-08-24), the problematic part was to reject everything that is not
in the body text, relax that to allow insertion into split flys.
Do an early check to see if we'll insert into the fly/header/footer
section, because otherwise it would be pointless to call
SwNode::GetFlyFormat(), which can be expensive in case we don't have a
layout yet.
The DOC export, the RTF import and the RTF export was working already,
so filters are mostly covered with this.
Change-Id: I59c69fac0692c6656c054e32503ec0cbc2fd11e0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156083
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/filter/ww8/data/floattable-footnote.doc b/sw/qa/filter/ww8/data/floattable-footnote.doc
new file mode 100644
index 0000000..c99bc13
--- /dev/null
+++ b/sw/qa/filter/ww8/data/floattable-footnote.doc
Binary files differ
diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index db1dbcd1..14cde17 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -28,6 +28,7 @@
#include <IDocumentSettingAccess.hxx>
#include <sortedobjs.hxx>
#include <fmtwrapinfluenceonobjpos.hxx>
#include <ftnidx.hxx>
namespace
{
@@ -470,6 +471,23 @@ CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverDOCImport)
// "can overlap".
CPPUNIT_ASSERT(!pFly->GetAttrSet().GetWrapInfluenceOnObjPos().GetAllowOverlap());
}
CPPUNIT_TEST_FIXTURE(Test, testFloattableFootnote)
{
// Given a document with a floating table and a footnote inside:
// When importing that document:
createSwDoc("floattable-footnote.doc");
// Then make sure we both have a fly frame and a footnote:
SwDoc* pDoc = getSwDoc();
sw::FrameFormats<sw::SpzFrameFormat*>& rFlys = *pDoc->GetSpzFrameFormats();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFlys.size());
SwFootnoteIdxs& rFootnotes = pDoc->GetFootnoteIdxs();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1
// - Actual : 0
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFootnotes.size());
}
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index a461b46..6c18f5a 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -58,6 +58,7 @@
#include <fmtanchr.hxx>
#include <fmtrowsplt.hxx>
#include <fmtfollowtextflow.hxx>
#include <formatflysplit.hxx>
#include <numrule.hxx>
#include "sprmids.hxx"
#include <wwstyles.hxx>
@@ -167,14 +168,38 @@ sal_uInt32 wwSectionManager::GetWWPageTopMargin() const
return !maSegments.empty() ? maSegments.back().maSep.dyaTop : 0;
}
namespace
{
bool IsInSplitFly(SwPaM& rPaM)
{
SwNode& rNode = rPaM.GetPoint()->GetNode();
SwNodeOffset nNodeIndex = rNode.GetIndex();
SwNodes& rNodes = rNode.GetNodes();
if (nNodeIndex >= rNodes.GetEndOfAutotext().GetIndex()
|| nNodeIndex < rNodes.GetEndOfInserts().GetIndex())
{
return false;
}
SwFrameFormat* pFlyFormat = rNode.StartOfSectionNode()->GetFlyFormat();
if (!pFlyFormat)
{
return false;
}
return pFlyFormat->GetFlySplit().GetValue();
}
}
sal_uInt16 SwWW8ImplReader::End_Footnote()
{
/*
Ignoring Footnote outside of the normal Text. People will put footnotes
into field results and field commands.
*/
if (m_bIgnoreText ||
m_pPaM->GetPoint()->GetNode() < m_rDoc.GetNodes().GetEndOfExtras())
bool bSplitFly = IsInSplitFly(*m_pPaM);
if (m_bIgnoreText
|| (m_pPaM->GetPoint()->GetNode() < m_rDoc.GetNodes().GetEndOfExtras() && !bSplitFly))
{
return 0;
}
@@ -303,8 +328,9 @@ tools::Long SwWW8ImplReader::Read_Footnote(WW8PLCFManResult* pRes)
Ignoring Footnote outside of the normal Text. People will put footnotes
into field results and field commands.
*/
if (m_bIgnoreText ||
m_pPaM->GetPoint()->GetNode() < m_rDoc.GetNodes().GetEndOfExtras())
bool bSplitFly = IsInSplitFly(*m_pPaM);
if (m_bIgnoreText
|| (m_pPaM->GetPoint()->GetNode() < m_rDoc.GetNodes().GetEndOfExtras() && !bSplitFly))
{
return 0;
}