embeddedobj/source/inc/oleembobj.hxx | 10 +++++++++- embeddedobj/source/msole/olemisc.cxx | 14 ++++++++++++++ embeddedobj/source/msole/olepersist.cxx | 3 ++- sw/qa/extras/htmlexport/htmlexport.cxx | 7 ++++++- sw/source/filter/html/htmlplug.cxx | 19 +++++++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-)
New commits: commit ff67eb92954823ee0bc850917a9ead8a1aa03854 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Nov 14 17:17:46 2018 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Nov 15 09:45:39 2018 +0100 sw: fix modification of ole obj native data during HTML import It is expected that if you load an OLE2 storage (from reqif-xhtml) and you save it as ODT, the OLE2 data is not modified. This was almost the case, but we insisted on removing the OLE2 preview from the storage. Add a new flag to OleEmbeddedObject, so import filters can opt in for not modifying the OLE2 data. [ The nice situation is that we already had a test file which had a preview stream in the OLE2 storage, so we can easily assert there that the size doesn't change. ] Reviewed-on: https://gerrit.libreoffice.org/63381 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins (cherry picked from commit 72e6269b88a32a672e00d2c25f0d0400038d1360) Conflicts: sw/source/filter/html/htmlplug.cxx Change-Id: I9b8b29f015dd4f2513e51a1066767218580cb5d8 diff --git a/embeddedobj/source/inc/oleembobj.hxx b/embeddedobj/source/inc/oleembobj.hxx index 1ef712927a8d..776ee7329e44 100644 --- a/embeddedobj/source/inc/oleembobj.hxx +++ b/embeddedobj/source/inc/oleembobj.hxx @@ -37,6 +37,7 @@ #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/util/XCloseListener.hpp> #include <com/sun/star/io/XActiveDataStreamer.hpp> +#include <com/sun/star/lang/XInitialization.hpp> #include <cppuhelper/implbase.hxx> #include <rtl/ref.hxx> @@ -116,7 +117,8 @@ class OleEmbeddedObject : public ::cppu::WeakImplHelper , css::embed::XLinkageSupport , css::embed::XInplaceObject , css::container::XChild - , css::io::XActiveDataStreamer > + , css::io::XActiveDataStreamer + , css::lang::XInitialization > { friend class OleComponent; @@ -204,6 +206,9 @@ class OleEmbeddedObject : public ::cppu::WeakImplHelper css::uno::Reference< css::uno::XInterface > m_xParent; + /// If it is allowed to modify entires in the stream of the OLE storage. + bool m_bStreamReadOnly = false; + protected: /// @throws css::uno::Exception css::uno::Reference< css::io::XStream > TryToGetAcceptableFormat_Impl( @@ -440,6 +445,9 @@ public: // XActiveDataStreamer void SAL_CALL setStream(const css::uno::Reference<css::io::XStream>& xStream) override; css::uno::Reference<css::io::XStream> SAL_CALL getStream() override; + + // XInitialization + void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override; }; #endif diff --git a/embeddedobj/source/msole/olemisc.cxx b/embeddedobj/source/msole/olemisc.cxx index 586b615001b4..715594a89117 100644 --- a/embeddedobj/source/msole/olemisc.cxx +++ b/embeddedobj/source/msole/olemisc.cxx @@ -29,6 +29,7 @@ #include <com/sun/star/lang/DisposedException.hpp> #include <cppuhelper/interfacecontainer.h> +#include <comphelper/sequenceashashmap.hxx> #include <oleembobj.hxx> #include <olepersist.hxx> @@ -680,4 +681,17 @@ css::uno::Reference<css::io::XStream> OleEmbeddedObject::getStream() return m_xObjectStream; } +void OleEmbeddedObject::initialize(const uno::Sequence<uno::Any>& rArguments) +{ + if (!rArguments.hasElements()) + return; + + comphelper::SequenceAsHashMap aValues(rArguments[0]); + for (const auto& rValue : aValues) + { + if (rValue.first == "StreamReadOnly") + rValue.second >>= m_bStreamReadOnly; + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/embeddedobj/source/msole/olepersist.cxx b/embeddedobj/source/msole/olepersist.cxx index 9b1b86359741..5077f0a9f37d 100644 --- a/embeddedobj/source/msole/olepersist.cxx +++ b/embeddedobj/source/msole/olepersist.cxx @@ -1210,7 +1210,8 @@ void OleEmbeddedObject::StoreToLocation_Impl( if ( !xCachedVisualRepresentation.is() ) xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( xTargetStream ); - RemoveVisualCache_Impl( xTargetStream ); + if (!m_bStreamReadOnly) + RemoveVisualCache_Impl(xTargetStream); } } diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 884cbbd02d2e..3d046d028fa6 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -569,7 +569,12 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOle2, "reqif-ole2.xhtml") uno::Reference<io::XSeekable> xStream(xEmbeddedObject->getStream(), uno::UNO_QUERY); // This was 80913, the RTF hexdump -> OLE1 binary -> OLE2 conversion was // missing. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(38912), xStream->getLength()); + // Also, this was 38912 when we re-generated the OLE2 preview, which is + // wrong, the OLE2 data is 38375 bytes in the ole2.ole (referenced by + // reqif-ole2.xhtml). To see that this is the correct value, convert the + // hexdump in ole2.ole to binary, remove the ole1 header and check the byte + // size. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(38375), xStream->getLength()); // Finally the export also failed as it tried to open the stream from the // document storage, but the embedded object already opened it, so an // exception of type com.sun.star.io.IOException was thrown. diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 3565bf58952f..ad08834ac59a 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -64,6 +64,7 @@ #include <com/sun/star/io/XActiveDataStreamer.hpp> #include <com/sun/star/io/IOException.hpp> #include <com/sun/star/embed/XEmbedPersist2.hpp> +#include <com/sun/star/lang/XInitialization.hpp> #include <comphelper/embeddedobjectcontainer.hxx> #include <comphelper/classids.hxx> @@ -75,6 +76,7 @@ #include <filter/msfilter/msoleexp.hxx> #include <comphelper/fileurl.hxx> #include <osl/file.hxx> +#include <comphelper/propertyvalue.hxx> using namespace com::sun::star; @@ -635,10 +637,27 @@ bool SwHTMLParser::InsertEmbed() SetSpace( aSpace, aItemSet, aPropInfo, aFrameSet ); // und in das Dok einfuegen + uno::Reference<lang::XInitialization> xObjInitialization(xObj, uno::UNO_QUERY); + if (xObjInitialization.is()) + { + // Request that the native data of the embedded object is not modified + // during parsing. + uno::Sequence<beans::PropertyValue> aValues{ comphelper::makePropertyValue("StreamReadOnly", + true) }; + uno::Sequence<uno::Any> aArguments{ uno::makeAny(aValues) }; + xObjInitialization->initialize(aArguments); + } SwFrameFormat* pFlyFormat = m_xDoc->getIDocumentContentOperations().InsertEmbObject(*m_pPam, ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT), &aFrameSet); + if (xObjInitialization.is()) + { + uno::Sequence<beans::PropertyValue> aValues{ comphelper::makePropertyValue("StreamReadOnly", + false) }; + uno::Sequence<uno::Any> aArguments{ uno::makeAny(aValues) }; + xObjInitialization->initialize(aArguments); + } // Namen am FrameFormat setzen if( !aName.isEmpty() ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits