diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-02-12 15:02:18 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-05-07 09:38:21 +0200 |
commit | 32750c8a1121177ea48d3e7b237a9ddc834fde38 (patch) | |
tree | 379d7933713c6cca037be3ac86e412504be219ed /writerfilter | |
parent | c44d85b32fdee8fedb40e30b61bcd7732600e4f5 (diff) |
DOCX import: fix ZOrder of inline vs anchored shapes
Shapes which are anchored but are not in the background should be always
on top of as-char anchored shapes in OOXML terms. Writer supports a
custom ZOrder even for as-char shapes, so make sure that they are
always behind anchored shapes.
To avoid unnecessary work, make sure that when there are multiple inline
shapes, we don't pointlessly reorder them (the old vs new style of the
sorting controls exactly this, what happens when two shapes have the
same ZOrder, and all inline shapes have a 0 ZOrder).
Adapt a few tests that used ZOrder indexes to access shapes, but the
intention was to just refer to a shape: fix the index and migrate to
shape names where possible.
(cherry picked from commit 99847d6b3005c5444ed5a46ca578c0e40149d77c)
Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
Change-Id: I670e4dc2acbd2a0c6d47fe964cb5e3f2300e6848
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx | 17 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx | bin | 0 -> 16684 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/GraphicImport.cxx | 11 |
3 files changed, 26 insertions, 2 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx index f20694b828cc..d5140f134cb3 100644 --- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx +++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx @@ -17,6 +17,7 @@ #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> #include <com/sun/star/text/RelOrientation.hpp> +#include <com/sun/star/container/XNamed.hpp> #include <comphelper/processfactory.hxx> @@ -107,6 +108,22 @@ CPPUNIT_TEST_FIXTURE(Test, testDrawShapeInlineEffect) // i.e. the layout result had less pages than expected (compared to Word). CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(273), nBottomMargin); } + +CPPUNIT_TEST_FIXTURE(Test, testInlineAnchoredZOrder) +{ + // Load a document which has two shapes: an inline one and an anchored one. The inline has no + // explicit ZOrder, the anchored one has, and it's set to a value so it's visible. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "inline-anchored-zorder.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference<container::XNamed> xOval(xDrawPage->getByIndex(1), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Oval 2 + // - Actual : + // i.e. the rectangle (with no name) was on top of the oval one, not the other way around. + CPPUNIT_ASSERT_EQUAL(OUString("Oval 2"), xOval->getName()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx b/writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx Binary files differnew file mode 100644 index 000000000000..93932c4703b7 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx index b69f4565fb13..df5f644e34ba 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -287,7 +287,12 @@ public: ,m_rPositionOffsets(rPositionOffsets) ,m_rAligns(rAligns) ,m_rPositivePercentages(rPositivePercentages) - {} + { + if (eGraphicImportType == GraphicImportType::IMPORT_AS_DETECTED_INLINE) + { + zOrder = 0; + } + } void setXSize(sal_Int32 _nXSize) { @@ -358,7 +363,8 @@ public: if (zOrder >= 0) { GraphicZOrderHelper* pZOrderHelper = rDomainMapper.graphicZOrderHelper(); - xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER), uno::makeAny(pZOrderHelper->findZOrder(zOrder))); + bool bOldStyle = eGraphicImportType == GraphicImportType::IMPORT_AS_DETECTED_INLINE; + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER), uno::makeAny(pZOrderHelper->findZOrder(zOrder, bOldStyle))); pZOrderHelper->addItem(xGraphicObjectProperties, zOrder); } } @@ -898,6 +904,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue) { uno::Reference< beans::XPropertySet > xShapeProps(m_xShape, uno::UNO_QUERY_THROW); m_pImpl->applyMargins(xShapeProps); + m_pImpl->applyZOrder(xShapeProps); comphelper::SequenceAsHashMap aInteropGrabBag(xShapeProps->getPropertyValue("InteropGrabBag")); aInteropGrabBag.update(m_pImpl->getInteropGrabBag()); xShapeProps->setPropertyValue("InteropGrabBag", uno::makeAny(aInteropGrabBag.getAsConstPropertyValueList())); |