sw/qa/extras/ww8export/ww8export4.cxx | 50 +++++++++++++++++++++++ sw/qa/filter/ww8/data/floattable-tbl-overlap.doc |binary sw/qa/filter/ww8/ww8.cxx | 15 ++++++ sw/source/filter/ww8/wrtww8.cxx | 8 +++ sw/source/filter/ww8/ww8par6.cxx | 17 +++++++ sw/source/filter/ww8/ww8struc.hxx | 1 6 files changed, 91 insertions(+)
New commits: commit d44af60677740b151305799a4325d0f0699fce66 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Aug 14 08:25:41 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Aug 14 10:49:45 2023 +0200 sw floattable: handle AllowOverlap==false in the DOC filter Map sprmTFNoAllowOverlap to SwFormatWrapInfluenceOnObjPos::mbAllowOverlap on import, and do the opposite on export. Change-Id: Id61be49adb39862e30ffb2da9ff9aabae11f7d83 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155650 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/ww8export/ww8export4.cxx b/sw/qa/extras/ww8export/ww8export4.cxx index 459daa69ec81..0d101f818acf 100644 --- a/sw/qa/extras/ww8export/ww8export4.cxx +++ b/sw/qa/extras/ww8export/ww8export4.cxx @@ -27,6 +27,11 @@ #include <unotxdoc.hxx> #include <ndtxt.hxx> #include <editeng/lrspitem.hxx> +#include <wrtsh.hxx> +#include <itabenum.hxx> +#include <frmmgr.hxx> +#include <formatflysplit.hxx> +#include <fmtwrapinfluenceonobjpos.hxx> class Test : public SwModelTestBase { @@ -144,6 +149,51 @@ CPPUNIT_TEST_FIXTURE(Test, testDontBreakWrappedTables) CPPUNIT_ASSERT(bDontBreakWrappedTables); } +CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverDOCExport) +{ + // 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(); + sw::FrameFormats<sw::SpzFrameFormat*>* pFlys = pDoc->GetSpzFrameFormats(); + sw::SpzFrameFormat* pFly = (*pFlys)[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 DOC: + saveAndReload("MS Word 97"); + + // Then make sure that the overlap=never markup is written: + SwDoc* pDoc = getSwDoc(); + sw::FrameFormats<sw::SpzFrameFormat*>* pFlys = pDoc->GetSpzFrameFormats(); + sw::SpzFrameFormat* pFly = (*pFlys)[0]; + // Without the accompanying fix in place, this test would have failed, i.e. TFNoAllowOverlap was + // not written. + CPPUNIT_ASSERT(!pFly->GetAttrSet().GetWrapInfluenceOnObjPos().GetAllowOverlap()); +} + static bool IsFirstLine(const SwTextNode* pTextNode) { const SfxPoolItem* pItem = pTextNode->GetNoCondAttr(RES_MARGIN_FIRSTLINE, false); diff --git a/sw/qa/filter/ww8/data/floattable-tbl-overlap.doc b/sw/qa/filter/ww8/data/floattable-tbl-overlap.doc new file mode 100644 index 000000000000..921ffe1fa667 Binary files /dev/null and b/sw/qa/filter/ww8/data/floattable-tbl-overlap.doc differ diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index 2d12e980dbdb..db1dbcd1bf36 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -455,6 +455,21 @@ CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverDOCXExport) // i.e. <w:tblOverlap> was not written. assertXPath(pXmlDoc, "//w:tblPr/w:tblOverlap", "val", "never"); } + +CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverDOCImport) +{ + // Given a document with two floating tables, the second has sprmTFNoAllowOverlap=1 set: + // When importing that document: + createSwDoc("floattable-tbl-overlap.doc"); + + // Then make sure the second table is marked as "can't overlap": + SwDoc* pDoc = getSwDoc(); + sw::FrameFormats<sw::SpzFrameFormat*>& rFlys = *pDoc->GetSpzFrameFormats(); + sw::SpzFrameFormat* pFly = rFlys[1]; + // Without the accompanying fix in place, this test would have failed, the fly had the default + // "can overlap". + CPPUNIT_ASSERT(!pFly->GetAttrSet().GetWrapInfluenceOnObjPos().GetAllowOverlap()); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index c51b1c3f7777..fc2beabe9bef 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -117,6 +117,7 @@ #include <rdfhelper.hxx> #include <fmtclbl.hxx> #include <iodetect.hxx> +#include <fmtwrapinfluenceonobjpos.hxx> using namespace css; using namespace sw::util; @@ -2407,6 +2408,13 @@ void WW8AttributeOutput::TablePositioning(SwFrameFormat* pFlyFormat) sal_uInt16 nDxaFromTextRight = pFlyFormat->GetLRSpace().GetRight(); m_rWW8Export.InsUInt16(NS_sprm::TDxaFromTextRight::val); m_rWW8Export.InsUInt16(nDxaFromTextRight); + + if (!pFlyFormat->GetWrapInfluenceOnObjPos().GetAllowOverlap()) + { + // Allowing overlap is the default in both Writer and in WW8. + m_rWW8Export.InsUInt16(NS_sprm::TFNoAllowOverlap::val); + m_rWW8Export.m_pO->push_back(1); + } } void WW8AttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner ) diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index 2376692d4892..982e3ba5dc17 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -2536,6 +2536,15 @@ bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *p // Map a positioned table to a split fly. aFlySet.Put(SwFormatFlySplit(true)); + + if (pTabPos->nTFNoAllowOverlap) + { + // text::WrapInfluenceOnPosition::ONCE_SUCCESSIVE is not the default and is set in + // the WW8FlySet ctor already, keep that unchanged. + SwFormatWrapInfluenceOnObjPos aInfluence(aFlySet.Get(RES_WRAP_INFLUENCE_ON_OBJPOS)); + aInfluence.SetAllowOverlap(false); + aFlySet.Put(aInfluence); + } } m_xSFlyPara->SetFlyFormat(m_rDoc.MakeFlySection(WW8SwFlyPara::eAnchor, @@ -5404,6 +5413,14 @@ bool SwWW8ImplReader::ParseTabPos(WW8_TablePos *pTabPos, WW8PLCFx_Cp_FKP* pPap) aRes = pPap->HasSprm(NS_sprm::TDyaFromTextBottom::val); if (aRes.pSprm && aRes.nRemainingData >= 2) pTabPos->nLowerMargin = SVBT16ToUInt16(aRes.pSprm); + + aRes = pPap->HasSprm(NS_sprm::TFNoAllowOverlap::val); + if (aRes.pSprm) + { + // Remember the no-overlap request, to be consumed in SwWW8ImplReader::StartApo(). + pTabPos->nTFNoAllowOverlap = *aRes.pSprm; + } + bRet = true; } return bRet; diff --git a/sw/source/filter/ww8/ww8struc.hxx b/sw/source/filter/ww8/ww8struc.hxx index cdd1fed1da8f..2802c383056d 100644 --- a/sw/source/filter/ww8/ww8struc.hxx +++ b/sw/source/filter/ww8/ww8struc.hxx @@ -897,6 +897,7 @@ struct WW8_TablePos sal_Int16 nLowerMargin; sal_uInt8 nTPc; sal_uInt8 nPWr; + sal_uInt8 nTFNoAllowOverlap; }; struct WW8_FSPA