sw/qa/filter/ww8/ww8.cxx | 45 +++++++++++++++++++++++++++++++ sw/source/filter/ww8/docxtableexport.cxx | 8 +++++ 2 files changed, 53 insertions(+)
New commits: commit 6dd6f84d93390e5a1cc89bf62583a53d4dc31635 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Aug 11 08:27:32 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Aug 14 11:17:29 2023 +0200 sw floattable: export <w:tblOverlap w:val=never> to DOCX Once split flys containing tables have "allow overlap" disabled, this is not saved to DOCX when we map them to floating tables. The working case is the allowOverlap attribute on shapes, added in commit f8c7a2284b88c149addc8a30abb0cad8a10dad77 (Related: tdf#124600 sw anchored object allow overlap: add DOCX filter, 2019-09-20). Fix the problem by extending DocxAttributeOutput::TableDefinition(), to write <w:tblOverlap> in case overlap is not allowed, after <w:tblpPr>. DOC and RTF filters are still missing. (cherry picked from commit 5af44a176d2a738dd7523713202aeee27c5578b6) Conflicts: sw/qa/filter/ww8/ww8.cxx Change-Id: I7d0bd4a15567014d3add8cbbcd92c62c5a33b7e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155652 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index 85ba05483e1e..ca9fb00b95ab 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -26,6 +26,7 @@ #include <pagefrm.hxx> #include <IDocumentSettingAccess.hxx> #include <sortedobjs.hxx> +#include <fmtwrapinfluenceonobjpos.hxx> namespace { @@ -385,6 +386,50 @@ CPPUNIT_TEST_FIXTURE(Test, testDOCVerticalFlyOffset) // Page 2 starts with an inline table: CPPUNIT_ASSERT(pTable2->IsTabFrame()); } + +CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverDOCXExport) +{ + // Given a document with a floating table, overlap is not allowed: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + pWrtShell->Insert2("before table"); + // Insert a table: + SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(aTableOptions, /*nRows=*/1, /*nCols=*/1); + pWrtShell->MoveTable(GotoPrevTable, fnTableStart); + // Select table: + pWrtShell->SelAll(); + // Wrap the table in a text frame: + SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr); + pWrtShell->StartAllAction(); + aMgr.InsertFlyFrame(RndStdIds::FLY_AT_PARA, aMgr.GetPos(), aMgr.GetSize()); + pWrtShell->EndAllAction(); + // Allow the text frame to split: + pWrtShell->StartAllAction(); + auto& rFlys = *pDoc->GetSpzFrameFormats(); + auto pFly = rFlys[0]; + SwAttrSet aSet(pFly->GetAttrSet()); + aSet.Put(SwFormatFlySplit(true)); + // Don't allow overlap: + SwFormatWrapInfluenceOnObjPos aInfluence; + aInfluence.SetAllowOverlap(false); + aSet.Put(aInfluence); + pDoc->SetAttr(aSet, *pFly); + pWrtShell->EndAllAction(); + + // When saving to DOCX: + save("Office Open XML Text"); + + // Then make sure that the overlap=never markup is written: + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//w:tblPr/w:tblOverlap' number of nodes is incorrect + // i.e. <w:tblOverlap> was not written. + assertXPath(pXmlDoc, "//w:tblPr/w:tblOverlap", "val", "never"); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/docxtableexport.cxx b/sw/source/filter/ww8/docxtableexport.cxx index 8f036cf407f2..9e68759dab73 100644 --- a/sw/source/filter/ww8/docxtableexport.cxx +++ b/sw/source/filter/ww8/docxtableexport.cxx @@ -37,6 +37,7 @@ #include <frmatr.hxx> #include <swmodule.hxx> #include <fmtrowsplt.hxx> +#include <fmtwrapinfluenceonobjpos.hxx> #include "docxexportfilter.hxx" #include "docxhelper.hxx" @@ -281,6 +282,13 @@ void DocxAttributeOutput::TableDefinition( bFloatingTableWritten = true; // The outer table was floating, make sure potential inner tables are not floating. m_rExport.SetFloatingTableFrame(nullptr); + + const SwFrameFormat& rFloatingTableFormat = pFloatingTableFrame->GetFrameFormat(); + if (!rFloatingTableFormat.GetWrapInfluenceOnObjPos().GetAllowOverlap()) + { + // Allowing overlap is the default, both in OOXML and in Writer. + m_pSerializer->singleElementNS(XML_w, XML_tblOverlap, FSNS(XML_w, XML_val), "never"); + } } // Extract properties from grab bag