diff options
author | Michael Stahl <mstahl@redhat.com> | 2014-06-13 14:47:05 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2014-06-13 15:27:02 +0200 |
commit | ba9b63d8101197d3fd8612193b1ca188271dfc1a (patch) | |
tree | 4ac56f3d9bbe6f1d54c6982fad3e7ef207ae5907 | |
parent | b7857e5cfe9d5d007785ae93e5505620fc8ed475 (diff) |
fdo#76633: writerfilter: RTF import: do not leak the XShape of image
RTFSdrImport::resolve() is called for \picprop and creates an XShape
that is stored in RTFSdrImport::m_xShape and also
DomainMapper_Impl::m_aPendingShapes;
later RTFDocumentImpl::resolvePict() completely ignores that XShape
and creates a new one, which is also inserted in the document;
the first XShape is effectively leaked.
Try to avoid that by re-using the exising m_xShape in resolvePict().
Not sure if there are any problems with doing this, it's all a bit
confusing.
Change-Id: I98456242acb0766f547eb8f7d877f51d53323f3a
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 3 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 29 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfsdrimport.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfsdrimport.hxx | 2 |
4 files changed, 27 insertions, 12 deletions
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 50b2b27a67be..89366d03b347 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -577,14 +577,11 @@ DECLARE_RTFIMPORT_TEST(testFdo76633, "fdo76633.rtf") // check that there is only a graphic object, not an additional rectangle uno::Reference<lang::XServiceInfo> xShape(getShape(1), uno::UNO_QUERY); CPPUNIT_ASSERT(xShape.is()); -#if 0 - // disabled - fails currently CPPUNIT_ASSERT(xShape->supportsService("com.sun.star.text.TextGraphicObject")); try { uno::Reference<drawing::XShape> xShape2(getShape(2), uno::UNO_QUERY); CPPUNIT_FAIL("exception expected"); } catch (lang::IndexOutOfBoundsException const&) { /* expected */ } -#endif } DECLARE_RTFIMPORT_TEST(testFdo48033, "fdo48033.rtf") diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index d882378521be..5f6743277c31 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -771,16 +771,29 @@ int RTFDocumentImpl::resolvePict(bool bInline) // Wrap it in an XShape. uno::Reference<drawing::XShape> xShape; - if (m_xModelFactory.is()) - xShape.set(m_xModelFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY); - uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY); - uno::Reference<drawing::XDrawPageSupplier> xDrawSupplier(m_xDstDoc, uno::UNO_QUERY); - if (xDrawSupplier.is()) + xShape = m_pSdrImport->getCurrentShape();//Mapper().PopPendingShape(); + if (xShape.is()) { - uno::Reference< drawing::XShapes > xShapes(xDrawSupplier->getDrawPage(), uno::UNO_QUERY); - if (xShapes.is()) - xShapes->add(xShape); + uno::Reference<lang::XServiceInfo> xSI(xShape, uno::UNO_QUERY_THROW); + assert(xSI->supportsService("com.sun.star.drawing.GraphicObjectShape")); } + else + { + if (m_xModelFactory.is()) + xShape.set(m_xModelFactory->createInstance( + "com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPageSupplier> const xDrawSupplier( + m_xDstDoc, uno::UNO_QUERY); + if (xDrawSupplier.is()) + { + uno::Reference<drawing::XShapes> xShapes( + xDrawSupplier->getDrawPage(), uno::UNO_QUERY); + if (xShapes.is()) + xShapes->add(xShape); + } + } + + uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY); // check if the picture is in an OLE object and if the \objdata element is used // (see RTF_OBJECT in RTFDocumentImpl::dispatchDestination) diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx index 5d0424ad2619..a47731d9c7a0 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.cxx +++ b/writerfilter/source/rtftok/rtfsdrimport.cxx @@ -226,7 +226,10 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, uno::Reference<drawing::XShape> xShape; uno::Reference<beans::XPropertySet> xPropertySet; // Create this early, as custom shapes may have properties before the type arrives. - createShape("com.sun.star.drawing.CustomShape", xShape, xPropertySet); + if (PICT == shapeOrPict) + createShape("com.sun.star.drawing.GraphicObjectShape", xShape, xPropertySet); + else + createShape("com.sun.star.drawing.CustomShape", xShape, xPropertySet); uno::Any aAny; beans::PropertyValue aPropertyValue; awt::Rectangle aViewBox; diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx index 770aff4f1c59..0b6958993bb2 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.hxx +++ b/writerfilter/source/rtftok/rtfsdrimport.hxx @@ -43,6 +43,8 @@ public: void pushParent(css::uno::Reference<css::drawing::XShapes> xParent); /// Pop the current group shape from the parent stack. void popParent(); + css::uno::Reference<css::drawing::XShape> const& getCurrentShape() + { return m_xShape; } private: void createShape(const OUString& aService, css::uno::Reference<css::drawing::XShape>& xShape, css::uno::Reference<css::beans::XPropertySet>& xPropertySet); void applyProperty(css::uno::Reference<css::drawing::XShape> xShape, const OUString& aKey, const OUString& aValue); |