summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-01-24 12:53:25 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-01-24 15:10:24 +0100
commite993638d5ecd33783f2eebdccfa87a81e5a8a2c5 (patch)
treece809d491dba62d56610cc31ced972ebacca2daf /writerfilter
parentcf0b49af5464507a269b03900b29e3cba155ce2b (diff)
DOCX import: fix <wp:anchor layoutInCell="1"> with <wp:wrapNone>
If wrap is set to none ("in front of text"), then <wp:positionH relativeFrom="column"> ignores layoutInCell="1" in Word. But in case relativeFrom is something else (e.g. page) or wrap is not none, then the old behavior is OK. Adjust our import so that Writer's layout also allows this shape to leave the cell. Change-Id: I6ca7511d46d7a70df11a65dc67c182f4fff4ae69 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128862 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx22
-rw-r--r--writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docxbin0 -> 12900 bytes
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx7
3 files changed, 29 insertions, 0 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
index edd6e02ff8ea..2f9faefab55f 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -366,6 +366,28 @@ CPPUNIT_TEST_FIXTURE(Test, testTextboxTextlineTop)
sal_Int16 nExpectedOrient = text::VertOrientation::BOTTOM;
CPPUNIT_ASSERT_EQUAL(nExpectedOrient, nActualOrient);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testLayoutInCellWrapnoneColumn)
+{
+ // Given a file with a table, then a shape anchored inside the cell:
+ OUString aURL
+ = m_directories.getURLFromSrc(DATA_DIRECTORY) + "layout-in-cell-wrapnone-column.docx";
+
+ // When loading that document:
+ getComponent() = loadFromDesktop(aURL);
+
+ // Then make sure the shape can leave the cell:
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
+ uno::Reference<container::XNamed> xNamedShape(xShape, uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("Text Box 1"), xNamedShape->getName());
+ bool bFollowingTextFlow = true;
+ // Without the accompanying fix in place, this test would have failed, the shape was not allowed
+ // to leave the cell, leading to incorrect layout.
+ CPPUNIT_ASSERT(xShape->getPropertyValue("IsFollowingTextFlow") >>= bFollowingTextFlow);
+ CPPUNIT_ASSERT(!bFollowingTextFlow);
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docx b/writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docx
new file mode 100644
index 000000000000..d88761421154
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/data/layout-in-cell-wrapnone-column.docx
Binary files differ
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 704774ec504a..bb3b2077e4aa 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1228,6 +1228,13 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
// But they aren't Writer pictures, either (which are already handled above).
uno::Reference< beans::XPropertySet > xShapeProps(m_xShape, uno::UNO_QUERY_THROW);
+ if (m_pImpl->nWrap == text::WrapTextMode_THROUGH && m_pImpl->nHoriRelation == text::RelOrientation::FRAME)
+ {
+ // text::RelOrientation::FRAME is OOXML's "column", which behaves as if
+ // layout-in-cell would be always off.
+ m_pImpl->bLayoutInCell = false;
+ }
+
// Anchored: Word only supports at-char in that case.
text::TextContentAnchorType eAnchorType = text::TextContentAnchorType_AT_CHARACTER;