sw/qa/filter/ww8/ww8.cxx | 45 +++++++++++++++++++++++++++++++ sw/source/filter/ww8/docxtableexport.cxx | 8 +++++ 2 files changed, 53 insertions(+)
New commits: commit 5af44a176d2a738dd7523713202aeee27c5578b6 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Aug 11 08:27:32 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Aug 11 11:09:30 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. Change-Id: I7d0bd4a15567014d3add8cbbcd92c62c5a33b7e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155573 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index 68bbc28fcfc3..2d12e980dbdb 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -27,6 +27,7 @@ #include <ftnfrm.hxx> #include <IDocumentSettingAccess.hxx> #include <sortedobjs.hxx> +#include <fmtwrapinfluenceonobjpos.hxx> namespace { @@ -410,6 +411,50 @@ CPPUNIT_TEST_FIXTURE(Test, testFloattableThenFloattable) // anchor. CPPUNIT_ASSERT_EQUAL(nFly1Anchor + 1, nFly2Anchor); } + +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 51fb3540c9df..b3e2d014222b 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