summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2014-06-13 14:47:05 +0200
committerMichael Stahl <mstahl@redhat.com>2014-06-13 15:29:55 +0200
commit83de5fe9c3161b9bfe655306253fc760fc64e8f3 (patch)
tree81029c5e9739dfdc0e6c6f219a082a051107c418
parente2cf3ef783a824b0a5733040db91e6ca3eb247b2 (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 (cherry picked from commit ba9b63d8101197d3fd8612193b1ca188271dfc1a)
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx3
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx29
-rw-r--r--writerfilter/source/rtftok/rtfsdrimport.cxx5
-rw-r--r--writerfilter/source/rtftok/rtfsdrimport.hxx2
4 files changed, 27 insertions, 12 deletions
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index e4254e74c1af..8c8f0381a3ef 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -578,14 +578,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 16b09eaec7b6..aafc9726bed5 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -775,16 +775,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);