summaryrefslogtreecommitdiff
path: root/xmloff/source/draw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-04-26 17:52:27 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-04-27 09:42:30 +0200
commitfee240db94d110d5c34d05c3b6c1792fece7a716 (patch)
treecfeb95c8f6b69976e9fe8fbf8f985261b37bce06 /xmloff/source/draw
parentf9de9af221f0824afda7660694c15fcf24836a48 (diff)
tdf#107392 ODF import: fix z-order sorting of SVG imagescp-5.3-8-win
The problem was that in case the document has shapes where the order does not match the z-index order, so sorting is needed, then sorting failed to take the multi-image feature into account. E.g. SVG images have a PNG fallback, but at the end of the shape import the PNG fallback is removed, which means the "actual" (not the "wished") z-index of the shapes after the SVG image has to be adjusted. Without this happening SvxDrawPage::getByIndex() (or in case of Writer, SwTextBoxHelper::getByIndex()) will throw when the importer calls getByIndex(3) but we only have 3 shapes. This results in not honoring the z-index request of the remaining shapes. Regression from commit 44cfc7cb6533d827fd2d6e586d92c61d7d7f7a70 (re-base on ALv2 code. Includes (at least) relevant parts of:, 2012-10-09), from the Svg: Reintegrated Svg replacement from /branches/alg/svgreplavement http://svn.apache.org/viewvc?view=revision&revision=1220836 part. Reviewed-on: https://gerrit.libreoffice.org/36998 Tested-by: Jenkins <ci@libreoffice.org> Conflicts: sw/qa/extras/odfimport/odfimport.cxx Change-Id: Ibe880e5c6c74b728b4a760498720ee31f052b726
Diffstat (limited to 'xmloff/source/draw')
-rw-r--r--xmloff/source/draw/shapeimport.cxx40
-rw-r--r--xmloff/source/draw/ximpshap.cxx2
-rw-r--r--xmloff/source/draw/ximpshap.hxx2
3 files changed, 39 insertions, 5 deletions
diff --git a/xmloff/source/draw/shapeimport.cxx b/xmloff/source/draw/shapeimport.cxx
index 121ab34fd6bf..a3da37016a1f 100644
--- a/xmloff/source/draw/shapeimport.cxx
+++ b/xmloff/source/draw/shapeimport.cxx
@@ -699,6 +699,8 @@ struct ZOrderHint
{
sal_Int32 nIs;
sal_Int32 nShould;
+ /// The hint is for this shape.
+ uno::Reference<drawing::XShape> xShape;
bool operator<(const ZOrderHint& rComp) const { return nShould < rComp.nShould; }
};
@@ -833,22 +835,23 @@ void XMLShapeImportHelper::popGroupAndSort()
{
mpImpl->mpSortContext->popGroupAndSort();
}
- catch( uno::Exception& )
+ catch( const uno::Exception& rException )
{
- OSL_FAIL("exception while sorting shapes, sorting failed!");
+ SAL_WARN("xmloff", "exception while sorting shapes, sorting failed: " << rException.Message);
}
// put parent on top and drop current context, we are done
mpImpl->mpSortContext = mpImpl->mpSortContext->mpParentContext;
}
-void XMLShapeImportHelper::shapeWithZIndexAdded( css::uno::Reference< css::drawing::XShape >&, sal_Int32 nZIndex )
+void XMLShapeImportHelper::shapeWithZIndexAdded( css::uno::Reference< css::drawing::XShape >& xShape, sal_Int32 nZIndex )
{
if( mpImpl->mpSortContext)
{
ZOrderHint aNewHint;
aNewHint.nIs = mpImpl->mpSortContext->mnCurrentZ++;
aNewHint.nShould = nZIndex;
+ aNewHint.xShape = xShape;
if( nZIndex == -1 )
{
@@ -863,6 +866,37 @@ void XMLShapeImportHelper::shapeWithZIndexAdded( css::uno::Reference< css::drawi
}
}
+void XMLShapeImportHelper::shapeRemoved(const uno::Reference<drawing::XShape>& xShape)
+{
+ auto it = std::find_if(mpImpl->mpSortContext->maZOrderList.begin(), mpImpl->mpSortContext->maZOrderList.end(), [&xShape](const ZOrderHint& rHint)
+ {
+ return rHint.xShape == xShape;
+ });
+ if (it == mpImpl->mpSortContext->maZOrderList.end())
+ // Part of the unsorted list, nothing to do.
+ return;
+
+ sal_Int32 nZIndex = it->nIs;
+
+ for (it = mpImpl->mpSortContext->maZOrderList.begin(); it != mpImpl->mpSortContext->maZOrderList.end();)
+ {
+ if (it->nIs == nZIndex)
+ {
+ // This is xShape: remove it and adjust the max of indexes
+ // accordingly.
+ it = mpImpl->mpSortContext->maZOrderList.erase(it);
+ mpImpl->mpSortContext->mnCurrentZ--;
+ continue;
+ }
+ else if (it->nIs > nZIndex)
+ // On top of xShape: adjust actual index to reflect removal.
+ it->nIs--;
+
+ // On top of or below xShape.
+ ++it;
+ }
+}
+
void XMLShapeImportHelper::addShapeConnection( css::uno::Reference< css::drawing::XShape >& rConnectorShape,
bool bStart,
const OUString& rDestShapeId,
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 0f9b6aaeb068..562a4e71db7c 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -3414,7 +3414,7 @@ SdXMLFrameShapeContext::~SdXMLFrameShapeContext()
{
}
-void SdXMLFrameShapeContext::removeGraphicFromImportContext(const SvXMLImportContext& rContext) const
+void SdXMLFrameShapeContext::removeGraphicFromImportContext(const SvXMLImportContext& rContext)
{
const SdXMLGraphicObjectShapeContext* pSdXMLGraphicObjectShapeContext = dynamic_cast< const SdXMLGraphicObjectShapeContext* >(&rContext);
diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx
index fe35475eb5e4..de83ecc5bccb 100644
--- a/xmloff/source/draw/ximpshap.hxx
+++ b/xmloff/source/draw/ximpshap.hxx
@@ -546,7 +546,7 @@ private:
protected:
/// helper to get the created xShape instance, needs to be overridden
virtual OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const override;
- virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) const override;
+ virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) override;
public: