sw XHTML import: handle media type of OLE object data
For both the native data and the replacement image.
Change-Id: I590fa037f78fe1a4dca41ec4173670f554bb9c6c
Reviewed-on: https://gerrit.libreoffice.org/50876
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index 7cdf5f4..23017e4 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -14,6 +14,7 @@
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
#include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <tools/datetime.hxx>
#include <unotools/datetime.hxx>
#include <vcl/GraphicNativeTransform.hxx>
@@ -315,7 +316,8 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
uno::Reference<document::XEmbeddedObjectSupplier2> xObject(xObjects->getByIndex(0),
uno::UNO_QUERY);
// This failed, OLE object had no replacement image.
CPPUNIT_ASSERT(xObject->getReplacementGraphic().is());
uno::Reference<graphic::XGraphic> xGraphic = xObject->getReplacementGraphic();
CPPUNIT_ASSERT(xGraphic.is());
uno::Reference<drawing::XShape> xShape(xObject, uno::UNO_QUERY);
OutputDevice* pDevice = Application::GetDefaultDevice();
@@ -325,6 +327,17 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
awt::Size aSize = xShape->getSize();
// This was only 1247, size was not set explicitly.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aLogic.getWidth()), aSize.Width);
// Check mime/media types.
CPPUNIT_ASSERT_EQUAL(OUString("image/png"), getProperty<OUString>(xGraphic, "MimeType"));
uno::Reference<document::XStorageBasedDocument> xStorageProvider(mxComponent, uno::UNO_QUERY);
uno::Reference<embed::XStorage> xStorage = xStorageProvider->getDocumentStorage();
auto aStreamName = getProperty<OUString>(xObject, "StreamName");
uno::Reference<io::XStream> xStream
= xStorage->openStreamElement(aStreamName, embed::ElementModes::READ);
// This was empty.
CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty<OUString>(xStream, "MediaType"));
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index ca7219b..83d04d3 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -433,7 +433,7 @@ void SwHTMLParser::InsertEmbed()
if (GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURLObj) != ERRCODE_NONE)
return;
rObj.SetGraphic(aGraphic, OUString());
rObj.SetGraphic(aGraphic, aType);
// Set the size of the OLE frame to the size of the graphic.
OutputDevice* pDevice = Application::GetDefaultDevice();
@@ -496,6 +496,14 @@ void SwHTMLParser::InsertEmbed()
uno::Reference<io::XStream> xOutStream
= xStorage->openStreamElement(aObjName, embed::ElementModes::READWRITE);
comphelper::OStorageHelper::CopyInputToOutput(xInStream, xOutStream->getOutputStream());
if (!aType.isEmpty())
{
// Set media type of the native data.
uno::Reference<beans::XPropertySet> xOutStreamProps(xOutStream, uno::UNO_QUERY);
if (xOutStreamProps.is())
xOutStreamProps->setPropertyValue("MediaType", uno::makeAny(aType));
}
}
xObj = aCnt.GetEmbeddedObject(aObjName);
}