From ad628045f62b0656c58d2e195e33186c055c2196 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 8 Mar 2018 14:58:01 +0100 Subject: sw XHTML export: handle media type for OLE objects Both native data and replacement graphic. Change-Id: I2f89493e56e9d22a54aa3e4175d8b750c33d98f0 Reviewed-on: https://gerrit.libreoffice.org/50964 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/extras/htmlexport/htmlexport.cxx | 10 +++++----- sw/source/filter/html/htmlflywriter.cxx | 12 ++++++++++++ sw/source/filter/html/htmlplug.cxx | 9 ++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'sw') diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index e3c1f33321bb..2f9ff7dbbf07 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -379,10 +379,6 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml") // This was only 1247, size was not set explicitly. CPPUNIT_ASSERT_EQUAL(static_cast(aLogic.getWidth()), aSize.Width); - if (mbExported) - // The below is not yet working for export. - return; - // Check mime/media types. CPPUNIT_ASSERT_EQUAL(OUString("image/png"), getProperty(xGraphic, "MimeType")); @@ -391,9 +387,13 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml") auto aStreamName = getProperty(xObject, "StreamName"); uno::Reference xStream = xStorage->openStreamElement(aStreamName, embed::ElementModes::READ); - // This was empty. + // This was empty when either import or export handling was missing. CPPUNIT_ASSERT_EQUAL(OUString("text/rtf"), getProperty(xStream, "MediaType")); + if (mbExported) + // The below is not yet working for export. + return; + // Check alternate text (it was empty). CPPUNIT_ASSERT_EQUAL(OUString("OLE Object"), getProperty(xObject, "Title").trim()); } diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index de06ac48a199..ba9a62260543 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1385,6 +1385,18 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat, aHtml.attribute(aAttribute, sBuffer.makeStringAndClear().getStr()); } + if (nFrameOpts & HtmlFrmOpts::Replacement) + { + // Handle XHTML type attribute for OLE replacement images. + uno::Reference xGraphic(rGraphic.GetXGraphic(), uno::UNO_QUERY); + if (xGraphic.is()) + { + OUString aMimeType; + xGraphic->getPropertyValue("MimeType") >>= aMimeType; + aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_type, aMimeType.toUtf8()); + } + } + // Events if (SfxItemState::SET == rItemSet.GetItemState(RES_FRMMACRO, true, &pItem)) { diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 4d272872aa8f..7ad6b589e2b3 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -1424,12 +1424,19 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame comphelper::OStorageHelper::CopyInputToOutput(xInStream->getInputStream(), xOutStream->getOutputStream()); aFileName = URIHelper::simpleNormalizedMakeRelative(rWrt.GetBaseURL(), aFileName); + uno::Reference xOutStreamProps(xInStream, uno::UNO_QUERY); + OUString aFileType; + if (xOutStreamProps.is()) + xOutStreamProps->getPropertyValue("MediaType") >>= aFileType; // Refer to this data. if (rHTMLWrt.m_bLFPossible) rHTMLWrt.OutNewLine(); rWrt.Strm().WriteOString("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_object); - rWrt.Strm().WriteOString(" data=\"" + aFileName.toUtf8() + "\">"); + rWrt.Strm().WriteOString(" data=\"" + aFileName.toUtf8() + "\""); + if (!aFileType.isEmpty()) + rWrt.Strm().WriteOString(" type=\"" + aFileType.toUtf8() + "\""); + rWrt.Strm().WriteOString(">"); bObjectOpened = true; rHTMLWrt.m_bLFPossible = true; } -- cgit