diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-07-13 08:14:42 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-07-13 11:14:28 +0200 |
commit | 52d265c0d2f2638c386475e58c3ee489ccd3f06c (patch) | |
tree | d9104487499e2e516d02ad37b7156700051c0953 | |
parent | 6532f77926154340c27131de452666788ca42e6c (diff) |
sw floattable: fix lost floating table right before a hidden para from DOCX
The bugdoc has a floating table, but that was not visible in Writer.
What happens is that the table's anchor was hidden, so Writer was hiding
the anchored table as well, but Word still shows the table in this case.
Fix the problem similar to what commit
79ddca4def81198e3eee42eca8aca42fef964c80 (sw floattable: fix lost
floating table right before a table from DOC, 2023-07-05) did for the
DOC import: if the paragraph has an anchored floating table and is
hidden, then show the paragraph.
An alternative would be to change how NS_ooxml::LN_EG_RPrBase_vanish is
handled in DomainMapper::sprmWithProps(), but that would be too early:
by the time we get the SPRM, there is no floating table yet. Another
alternative would be to make sure floating tables are part of the
"anchored object" list in DomainMapper_Impl::finishParagraph() (that's
how shapes don't have this problem), but the anchor paragraph is
finished before creating the floating table, so that would be again too
early.
Change-Id: I7df7e318b15e78ceb51474440923a80bfdc6054b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154376
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx | 19 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/data/floattable-hidden-anchor.docx | bin | 0 -> 21698 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 18 |
3 files changed, 37 insertions, 0 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx index 1f044bc2f309..8c11e3db22c7 100644 --- a/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx @@ -114,6 +114,25 @@ CPPUNIT_TEST_FIXTURE(Test, testFloatingTablesOuterNonsplitInner) // i.e. the inner floating table was not floating. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), xFrames->getCount()); } + +CPPUNIT_TEST_FIXTURE(Test, testDOCXFloatingTableHiddenAnchor) +{ + // Given a document with a floating table, anchored in a paragraph that is hidden: + loadFromURL(u"floattable-hidden-anchor.docx"); + + // When checking the visibility of the the anchor paragraph: + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xText(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); + uno::Reference<beans::XPropertySet> xAnchor(xParagraphs->nextElement(), uno::UNO_QUERY); + + // Then make sure the anchor (and thus the table) is visible: + bool bCharHidden{}; + CPPUNIT_ASSERT(xAnchor->getPropertyValue("CharHidden") >>= bCharHidden); + // Without the accompanying fix in place, this test would have failed, the paragraph + table was + // hidden. + CPPUNIT_ASSERT(!bCharHidden); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/qa/cppunittests/dmapper/data/floattable-hidden-anchor.docx b/writerfilter/qa/cppunittests/dmapper/data/floattable-hidden-anchor.docx Binary files differnew file mode 100644 index 000000000000..08816aacc47e --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/data/floattable-hidden-anchor.docx diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 370a89c0442f..5b0971eee20f 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -1643,6 +1643,24 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTab } } + if (xContent.is()) + { + // By the time the frame is created, the anchor's paragraph marker character + // properties are already imported. Check if we need to disable "vanish", that + // would lead to a hidden floating table in Writer, but it does not in Word. + uno::Reference<beans::XPropertySet> xParagraph(xContent->getAnchor(), + uno::UNO_QUERY); + if (xParagraph.is()) + { + bool bCharHidden{}; + xParagraph->getPropertyValue("CharHidden") >>= bCharHidden; + if (bCharHidden) + { + xParagraph->setPropertyValue("CharHidden", uno::Any(false)); + } + } + } + AfterConvertToTextFrame(m_rDMapper_Impl, aFramedRedlines, redPos, redLen, redCell, redTable); } |