diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-02-16 09:16:43 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-02-16 09:16:43 +0100 |
commit | 6083a8f188e2cd3fe6849e2112a6b06fbf8e1ad3 (patch) | |
tree | fe15c1470e806b7eb4ef132221c47474b19dd35c | |
parent | ec935c9b83ff2872c039522398c49e070149eea1 (diff) |
Related: tdf#59699 DOCX import: fix linked graphics with relative URLs
Because the writerfilter::ooxml::OOXMLFastContextHandlerShape
constructor only sent the input stream (and not the full media
descriptor) to oox::shape::ShapeContextHandler, it's startFastElement()
tried to reconstruct a media descriptor from just the input stream. As a
result, the base URL of the document got lost at the time the
oox::drawingml::BlipContext constructor tried to call getAbsoluteUrl(),
to convert the relative URL to an absolute one.
Fix the problem by sending not only the input stream, but the full media
descriptor to the shape importer. As a bonus that makes code simpler,
too.
Change-Id: I1f06c04d0745aa7e2e06d4848cf454790d5073ca
-rw-r--r-- | offapi/com/sun/star/xml/sax/XFastShapeContextHandler.idl | 2 | ||||
-rw-r--r-- | oox/source/shape/ShapeContextHandler.cxx | 33 | ||||
-rw-r--r-- | oox/source/shape/ShapeContextHandler.hxx | 13 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/libreoffice.png | bin | 0 -> 767 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf59699.docx | bin | 0 -> 13232 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 8 | ||||
-rw-r--r-- | writerfilter/inc/ooxml/OOXMLDocument.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/filter/WriterFilter.cxx | 3 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 19 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.hxx | 6 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 2 |
11 files changed, 47 insertions, 41 deletions
diff --git a/offapi/com/sun/star/xml/sax/XFastShapeContextHandler.idl b/offapi/com/sun/star/xml/sax/XFastShapeContextHandler.idl index a15ae8d3b58a..301971a2141d 100644 --- a/offapi/com/sun/star/xml/sax/XFastShapeContextHandler.idl +++ b/offapi/com/sun/star/xml/sax/XFastShapeContextHandler.idl @@ -40,11 +40,11 @@ interface XFastShapeContextHandler: com::sun::star::xml::sax::XFastContextHandle [attribute, readonly] com::sun::star::drawing::XShape Shape; [attribute] com::sun::star::drawing::XDrawPage DrawPage; [attribute] com::sun::star::frame::XModel Model; - [attribute] com::sun::star::io::XInputStream InputStream; [attribute] string RelationFragmentPath; [attribute] long StartToken; [attribute] com::sun::star::awt::Point Position; [attribute] com::sun::star::document::XDocumentProperties DocumentProperties; + [attribute] sequence< com::sun::star::beans::PropertyValue > MediaDescriptor; }; diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx index ae14d4474efe..6e256ac21274 100644 --- a/oox/source/shape/ShapeContextHandler.cxx +++ b/oox/source/shape/ShapeContextHandler.cxx @@ -272,13 +272,7 @@ void SAL_CALL ShapeContextHandler::startFastElement const uno::Reference< xml::sax::XFastAttributeList > & Attribs) throw (uno::RuntimeException, xml::sax::SAXException, std::exception) { - static const OUString sInputStream - ("InputStream"); - - uno::Sequence<beans::PropertyValue> aSeq(1); - aSeq[0].Name = sInputStream; - aSeq[0].Value <<= mxInputStream; - mxFilterBase->filter(aSeq); + mxFilterBase->filter(maMediaDescriptor); mpThemePtr.reset(new Theme()); @@ -573,19 +567,6 @@ void SAL_CALL ShapeContextHandler::setModel mxFilterBase->setTargetDocument(xComp); } -uno::Reference< io::XInputStream > SAL_CALL -ShapeContextHandler::getInputStream() throw (uno::RuntimeException, std::exception) -{ - return mxInputStream; -} - -void SAL_CALL ShapeContextHandler::setInputStream -(const uno::Reference< io::XInputStream > & the_value) - throw (uno::RuntimeException, std::exception) -{ - mxInputStream = the_value; -} - OUString SAL_CALL ShapeContextHandler::getRelationFragmentPath() throw (uno::RuntimeException, std::exception) { @@ -631,6 +612,18 @@ uno::Reference<document::XDocumentProperties> SAL_CALL ShapeContextHandler::getD return mxDocumentProperties; } +uno::Sequence<beans::PropertyValue> SAL_CALL ShapeContextHandler::getMediaDescriptor() + throw (uno::RuntimeException, std::exception) +{ + return maMediaDescriptor; +} + +void SAL_CALL ShapeContextHandler::setMediaDescriptor(const uno::Sequence<beans::PropertyValue>& rMediaDescriptor) + throw (uno::RuntimeException, std::exception) +{ + maMediaDescriptor = rMediaDescriptor; +} + OUString ShapeContextHandler::getImplementationName() throw (css::uno::RuntimeException, std::exception) { diff --git a/oox/source/shape/ShapeContextHandler.hxx b/oox/source/shape/ShapeContextHandler.hxx index c336129b51e5..353b7c538777 100644 --- a/oox/source/shape/ShapeContextHandler.hxx +++ b/oox/source/shape/ShapeContextHandler.hxx @@ -120,13 +120,6 @@ public: (const css::uno::Reference< css::frame::XModel > & the_value) throw (css::uno::RuntimeException, std::exception) override; - virtual css::uno::Reference< css::io::XInputStream > SAL_CALL - getInputStream() throw (css::uno::RuntimeException, std::exception) override; - - virtual void SAL_CALL setInputStream - (const css::uno::Reference< css::io::XInputStream > & the_value) - throw (css::uno::RuntimeException, std::exception) override; - virtual OUString SAL_CALL getRelationFragmentPath() throw (css::uno::RuntimeException, std::exception) override; virtual void SAL_CALL setRelationFragmentPath @@ -143,6 +136,10 @@ public: throw (css::uno::RuntimeException, std::exception) override; virtual css::uno::Reference<css::document::XDocumentProperties> SAL_CALL getDocumentProperties() throw (css::uno::RuntimeException, std::exception) override; + virtual css::uno::Sequence<css::beans::PropertyValue> SAL_CALL getMediaDescriptor() + throw (css::uno::RuntimeException, std::exception) override; + virtual void SAL_CALL setMediaDescriptor(const css::uno::Sequence<css::beans::PropertyValue>& rMediaDescriptor) + throw (css::uno::RuntimeException, std::exception) override; private: ShapeContextHandler(ShapeContextHandler &) = delete; @@ -165,11 +162,11 @@ private: css::uno::Reference<XFastContextHandler> mxWpgContext; css::uno::Reference<XFastContextHandler> mxChartShapeContext; css::uno::Reference<css::document::XDocumentProperties> mxDocumentProperties; + css::uno::Sequence<css::beans::PropertyValue> maMediaDescriptor; ::rtl::Reference< core::XmlFilterBase > mxFilterBase; drawingml::ThemePtr mpThemePtr; css::uno::Reference<css::drawing::XDrawPage> mxDrawPage; - css::uno::Reference<css::io::XInputStream> mxInputStream; OUString msRelationFragmentPath; css::uno::Reference<XFastContextHandler> getGraphicShapeContext(::sal_Int32 Element); diff --git a/sw/qa/extras/ooxmlimport/data/libreoffice.png b/sw/qa/extras/ooxmlimport/data/libreoffice.png Binary files differnew file mode 100644 index 000000000000..437f613c178c --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/libreoffice.png diff --git a/sw/qa/extras/ooxmlimport/data/tdf59699.docx b/sw/qa/extras/ooxmlimport/data/tdf59699.docx Binary files differnew file mode 100644 index 000000000000..158ac338f88a --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/tdf59699.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 57507ea2c98e..5ede1d50f416 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -782,6 +782,14 @@ DECLARE_OOXMLIMPORT_TEST(testN777345, "n777345.docx") #endif } +DECLARE_OOXMLIMPORT_TEST(testTdf59699, "tdf59699.docx") +{ + uno::Reference<beans::XPropertySet> xImage(getShape(1), uno::UNO_QUERY); + auto xGraphic = getProperty<uno::Reference<graphic::XGraphic> >(xImage, "Graphic"); + // This was false: the referenced graphic data wasn't imported. + CPPUNIT_ASSERT(xGraphic.is()); +} + DECLARE_OOXMLIMPORT_TEST(testN777337, "n777337.docx") { /* diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx index 5ef9247011fa..9b2528ef8564 100644 --- a/writerfilter/inc/ooxml/OOXMLDocument.hxx +++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx @@ -254,7 +254,7 @@ public: static OOXMLDocument * createDocument(OOXMLStream::Pointer_t pStream, const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator, - bool bSkipImage, OUString const& rBaseURL); + bool bSkipImage, const css::uno::Sequence<css::beans::PropertyValue>& rDescriptor); }; diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx index 432ef51e633c..f3c370c85369 100644 --- a/writerfilter/source/filter/WriterFilter.cxx +++ b/writerfilter/source/filter/WriterFilter.cxx @@ -153,7 +153,6 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& aDesc utl::MediaDescriptor aMediaDesc(aDescriptor); bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault("RepairPackage", false); bool bSkipImages = aMediaDesc.getUnpackedValueOrDefault("FilterOptions", OUString("")) == "SkipImages"; - OUString const baseURI = aMediaDesc.getUnpackedValueOrDefault("DocumentBaseURL", OUString("")); uno::Reference< io::XInputStream > xInputStream; try @@ -174,7 +173,7 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& aDesc //create the tokenizer and domain mapper writerfilter::ooxml::OOXMLStream::Pointer_t pDocStream = writerfilter::ooxml::OOXMLDocumentFactory::createStream(m_xContext, xInputStream, bRepairStorage); uno::Reference<task::XStatusIndicator> xStatusIndicator = aMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), uno::Reference<task::XStatusIndicator>()); - writerfilter::ooxml::OOXMLDocument::Pointer_t pDocument(writerfilter::ooxml::OOXMLDocumentFactory::createDocument(pDocStream, xStatusIndicator, bSkipImages, baseURI)); + writerfilter::ooxml::OOXMLDocument::Pointer_t pDocument(writerfilter::ooxml::OOXMLDocumentFactory::createDocument(pDocStream, xStatusIndicator, bSkipImages, aDescriptor)); uno::Reference<frame::XModel> xModel(m_xDstDoc, uno::UNO_QUERY_THROW); pDocument->setModel(xModel); diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index 210384a89681..c3f99d216352 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -38,6 +38,7 @@ #include <vcl/settings.hxx> #include <svx/dialogs.hrc> #include <comphelper/sequence.hxx> +#include <unotools/mediadescriptor.hxx> #include <iostream> @@ -49,7 +50,7 @@ namespace writerfilter { namespace ooxml { -OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator, bool bSkipImages, OUString const& rBaseURL) +OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator, bool bSkipImages, const uno::Sequence<beans::PropertyValue>& rDescriptor) : mpStream(pStream) , mxStatusIndicator(xStatusIndicator) , mnXNoteId(0) @@ -61,7 +62,8 @@ OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const uno:: , mnProgressLastPos(0) , mnProgressCurrentPos(0) , mnProgressEndPos(0) - , m_rBaseURL(rBaseURL) + , m_rBaseURL(utl::MediaDescriptor(rDescriptor).getUnpackedValueOrDefault("DocumentBaseURL", OUString())) + , maMediaDescriptor(rDescriptor) { } @@ -266,7 +268,7 @@ OOXMLDocumentImpl::getSubStream(const OUString & rId) OOXMLDocumentImpl * pTemp; // Do not pass status indicator to sub-streams: they are typically marginal in size, so we just track the main document for now. - writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages, m_rBaseURL)); + writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages, maMediaDescriptor)); pTemp->setModel(mxModel); pTemp->setDrawPage(mxDrawPage); pTemp->setIsSubstream( true ); @@ -280,7 +282,7 @@ OOXMLDocumentImpl::getXNoteStream(OOXMLStream::StreamType_t nType, const Id & rT OOXMLStream::Pointer_t pStream = (OOXMLDocumentFactory::createStream(mpStream, nType)); // See above, no status indicator for the note stream, either. - OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages, m_rBaseURL); + OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages, maMediaDescriptor); pDocument->setXNoteId(nId); pDocument->setXNoteType(rType); pDocument->setModel(getModel()); @@ -886,6 +888,11 @@ uno::Reference<io::XInputStream> OOXMLDocumentImpl::getStorageStream() return mpStream->getStorageStream(); } +const uno::Sequence<beans::PropertyValue>& OOXMLDocumentImpl::getMediaDescriptor() +{ + return maMediaDescriptor; +} + void OOXMLDocumentImpl::setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext ) { mxShapeContext = xContext; @@ -930,9 +937,9 @@ OOXMLDocument * OOXMLDocumentFactory::createDocument (OOXMLStream::Pointer_t pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator, - bool mbSkipImages, OUString const& rBaseURL) + bool mbSkipImages, const uno::Sequence<beans::PropertyValue>& rDescriptor) { - return new OOXMLDocumentImpl(pStream, xStatusIndicator, mbSkipImages, rBaseURL); + return new OOXMLDocumentImpl(pStream, xStatusIndicator, mbSkipImages, rDescriptor); } }} diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx index 82a57deff7d4..6af6f8a1ac5c 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx @@ -64,7 +64,8 @@ class OOXMLDocumentImpl : public OOXMLDocument /// End position, i.e. the estimated number of paragraphs. sal_Int32 mnProgressEndPos; /// DocumentBaseURL - OUString const m_rBaseURL; + OUString m_rBaseURL; + css::uno::Sequence<css::beans::PropertyValue> maMediaDescriptor; protected: void resolveFastSubStream(Stream & rStream, @@ -92,7 +93,7 @@ protected: void resolveGlossaryStream(Stream & rStream); void resolveEmbeddingsStream(OOXMLStream::Pointer_t pStream); public: - OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator, bool bSkipImages, OUString const& rBaseURL); + OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator, bool bSkipImages, const css::uno::Sequence<css::beans::PropertyValue>& rDescriptor); virtual ~OOXMLDocumentImpl(); virtual void resolve(Stream & rStream) override; @@ -141,6 +142,7 @@ public: void incrementProgress(); bool IsSkipImages() { return mbSkipImages; }; OUString const& GetDocumentBaseURL() { return m_rBaseURL; }; + const css::uno::Sequence<css::beans::PropertyValue>& getMediaDescriptor(); }; }} #endif // OOXML_DOCUMENT_IMPL_HXX diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 3d2c3668050c..9721aef46e95 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1511,7 +1511,7 @@ OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape uno::Reference<document::XDocumentPropertiesSupplier> xDocSupplier(getDocument()->getModel(), uno::UNO_QUERY_THROW); mrShapeContext->setDocumentProperties(xDocSupplier->getDocumentProperties()); mrShapeContext->setDrawPage(getDocument()->getDrawPage()); - mrShapeContext->setInputStream(getDocument()->getStorageStream()); + mrShapeContext->setMediaDescriptor(getDocument()->getMediaDescriptor()); mrShapeContext->setRelationFragmentPath (mpParserState->getTarget()); |