sw/qa/filter/ww8/data/floattable-hidden-anchor.doc |binary sw/qa/filter/ww8/ww8.cxx | 16 ++++++++++++++++ sw/source/filter/ww8/ww8par6.cxx | 16 ++++++++++++++++ 3 files changed, 32 insertions(+)
New commits: commit b3f13fbe2958100e7034de8ba6a8207eaa48e8db Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jul 5 08:33:06 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Jul 10 17:02:02 2023 +0200 sw floattable: fix lost floating table right before a table from DOC The bugdoc has a floating table, anchored in a paragraph that is hidden via character formatting. The bugdoc also has a normal table. This leads to 1 table in Writer, but 2 tables in Word. We already have code that tries to make sure floating tables have a suitable anchor, see the code in WW8TabDesc::CreateSwTable(), but that checks for the case when the next node after a floating table would be table (and not text), instead of the hidden character property. Fix the problem by not creating the hidden char attribute in the first place in SwWW8ImplReader::SetToggleAttr() in case the pool item would be inserted at the paragraph start and we just inserted a floating table, which makes the 2nd table visible in Writer as well. This is for DOC, interesting when Word converts this document to DOCX, then the hidden attribute is removed, so there this is not really needed. Change-Id: I3a7411e6fcc318740bcbd4b0cde9f34134f384a1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154017 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154243 diff --git a/sw/qa/filter/ww8/data/floattable-hidden-anchor.doc b/sw/qa/filter/ww8/data/floattable-hidden-anchor.doc new file mode 100644 index 000000000000..3e8feb876964 Binary files /dev/null and b/sw/qa/filter/ww8/data/floattable-hidden-anchor.doc differ diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index 253317c0deac..20c1b993caa8 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -342,6 +342,22 @@ CPPUNIT_TEST_FIXTURE(Test, testDOCfDontBreakWrappedTables) // set. CPPUNIT_ASSERT(bDontBreakWrappedTables); } + +CPPUNIT_TEST_FIXTURE(Test, testDOCFloatingTableHiddenAnchor) +{ + // Given a document with a normal table and a floating table with a hidden anchor: + createSwDoc("floattable-hidden-anchor.doc"); + + // When laying out that document: + xmlDocUniquePtr pLayout = parseLayoutDump(); + + // Then make sure that both tables are visible: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 1 + // i.e. the floating table was lost. + assertXPath(pLayout, "//tab", 2); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index 4758c4646286..ca3a2ed1f101 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -3370,6 +3370,22 @@ void SwWW8ImplReader::SetToggleAttr(sal_uInt8 nAttrId, bool bOn) : SvxCaseMap::NotMapped, RES_CHRATR_CASEMAP ) ); break; case 7: + if (m_pPaM->GetPoint()->GetContentIndex() == 0 && m_xFormatOfJustInsertedApo) + { + // We just inserted a frame and we're at the next paragraph start. + SwFrameFormat* pFormat = m_xFormatOfJustInsertedApo->GetFormat(); + if (pFormat) + { + SwNode* pAnchorNode = pFormat->GetAnchor().GetAnchorNode(); + if (pAnchorNode && *pAnchorNode == m_pPaM->GetPoint()->GetNode()) + { + // The anchor paragraph would be hidden, leading to hiding the frame as + // well, prevent that. + break; + } + } + } + NewAttr(SvxCharHiddenItem(bOn, RES_CHRATR_HIDDEN)); break; case 8: