sw/qa/filter/ww8/data/floattable-footnote.doc |binary sw/qa/filter/ww8/ww8.cxx | 18 +++++++++++++ sw/source/filter/ww8/ww8par2.cxx | 34 ++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 4 deletions(-)
New commits: commit 4443913ee7777990aeb309b4e2ef85c4fbdbe1f4 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Aug 25 08:31:08 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Aug 30 11:19:30 2023 +0200 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. (cherry picked from commit c7b59c9484ae6ff88cd8d7017aeb83b02e212c9c) Change-Id: I59c69fac0692c6656c054e32503ec0cbc2fd11e0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156278 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> 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 000000000000..c99bc13f43f2 Binary files /dev/null and b/sw/qa/filter/ww8/data/floattable-footnote.doc differ diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index a4e81c8e3a96..6914ea8677b6 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -27,6 +27,7 @@ #include <IDocumentSettingAccess.hxx> #include <sortedobjs.hxx> #include <fmtwrapinfluenceonobjpos.hxx> +#include <ftnidx.hxx> namespace { @@ -445,6 +446,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(); + SwFrameFormats& 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 d73b02dbb208..0f8ab1f8ebc6 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; } @@ -301,8 +326,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; }