diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-03-08 20:03:35 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-03-15 10:15:57 +0100 |
commit | 9bc6160e0acbc78be998129ea55ed7e4529959fa (patch) | |
tree | d07f099dbf264a24c4d291997637fc49d5ebbf96 /xmloff | |
parent | bfa320ef2ac7ab9a84f86eee6dfa7f3ee67fa630 (diff) |
tdf#133487 sw ODF export: reorder flys' ZOrder/z-index...
... so background shapes have lower z-index than foreground shapes,
as is recommended by ODF 1.3.
Also let SdrObjList::sort() record Undo actions, because earlier Undo
actions could expect the previous sort order.
Change-Id: Idbecf0a2acd525d42efc0ac92677b1c7987cc6ad
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112180
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/draw/shapeexport.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx index c8bbcbfa3ca2..27f280d7ed9b 100644 --- a/xmloff/source/draw/shapeexport.cxx +++ b/xmloff/source/draw/shapeexport.cxx @@ -61,6 +61,7 @@ #include <com/sun/star/drawing/XGluePointsSupplier.hpp> #include <com/sun/star/drawing/QRCode.hpp> #include <com/sun/star/drawing/QRCodeErrorCorrection.hpp> +#include <com/sun/star/drawing/XShapes3.hpp> #include <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/embed/XTransactedObject.hpp> @@ -981,6 +982,52 @@ void XMLShapeExport::exportShapes( const uno::Reference < drawing::XShapes >& xS maCurrentShapesIter = aOldCurrentShapesIter; } +namespace xmloff { + +void FixZOrder(uno::Reference<drawing::XShapes> const& xShapes, + std::function<bool(uno::Reference<beans::XPropertySet> const&)> const& rIsInBackground) +{ + uno::Reference<drawing::XShapes3> const xShapes3(xShapes, uno::UNO_QUERY); + assert(xShapes3.is()); + if (!xShapes3.is()) + { + return; // only SvxDrawPage implements this + } + std::vector<sal_Int32> background; + std::vector<sal_Int32> foreground; + // shapes are sorted by ZOrder + sal_Int32 const nCount(xShapes->getCount()); + for (sal_Int32 i = 0; i < nCount; ++i) + { + uno::Reference<beans::XPropertySet> const xShape(xShapes->getByIndex(i), uno::UNO_QUERY); + if (rIsInBackground(xShape)) + { + background.emplace_back(i); + } + else + { + foreground.emplace_back(i); + } + } + if (background.empty() || foreground.empty()) + { + return; // nothing to do + } + uno::Sequence<sal_Int32> aNewOrder(nCount); + std::copy(background.begin(), background.end(), aNewOrder.begin()); + std::copy(foreground.begin(), foreground.end(), aNewOrder.begin() + background.size()); + try + { + xShapes3->sort(aNewOrder); + } + catch (uno::Exception const&) + { + SAL_WARN("xmloff", "FixZOrder: exception"); + } +} + +} // namespace xmloff + void XMLShapeExport::seekShapes( const uno::Reference< drawing::XShapes >& xShapes ) throw() { if( xShapes.is() ) |