From e48b4275ceee82bd0eb128b2947302b9022e9c89 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 19 Feb 2018 21:47:04 +0900 Subject: report the saved mimetype when saving graphic + mime from stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When saving we need to determine which mime type to use for the graphic. Return this information back to the caller so the metadata can be written into the file if necessary. Also add function to determine the mime type from the XGraphic by converting it to a stream first (only then we can determine the format that will actually be used and written to the storage file. Change-Id: I796da715e47f29d77dea605a2769a2217ecd6ba5 Reviewed-on: https://gerrit.libreoffice.org/49992 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- xmloff/source/core/xmlexp.cxx | 22 ++++++++++++---------- xmloff/source/style/ImageStyle.cxx | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'xmloff') diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx index 4d3533ae4c09..7b3221f5bc3e 100644 --- a/xmloff/source/core/xmlexp.cxx +++ b/xmloff/source/core/xmlexp.cxx @@ -93,6 +93,7 @@ #include #include +#include using namespace ::osl; using namespace ::com::sun::star; @@ -1883,7 +1884,7 @@ OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectUR return sRet; } -OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference const & rxGraphic, OUString const & rRequestedName) +OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference const & rxGraphic, OUString & rOutMimeType, OUString const & rRequestedName) { OUString sURL; @@ -1900,9 +1901,7 @@ OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference cons if (mxGraphicResolver.is() && xGraphicStorageHandler.is()) { if (!(getExportFlags() & SvXMLExportFlags::EMBEDDED)) - { - sURL = xGraphicStorageHandler->saveGraphicByName(rxGraphic, rRequestedName); - } + sURL = xGraphicStorageHandler->saveGraphicByName(rxGraphic, rOutMimeType, rRequestedName); } } return sURL; @@ -1926,21 +1925,24 @@ Reference< XInputStream > SvXMLExport::GetEmbeddedGraphicObjectStream( const OUS return nullptr; } -uno::Reference SvXMLExport::GetEmbeddedXGraphicStream(uno::Reference const & rxGraphic) +bool SvXMLExport::GetGraphicMimeTypeFromStream(uno::Reference const & rxGraphic, OUString & rOutMimeType) { - uno::Reference xInputStream; - - if ((getExportFlags() & SvXMLExportFlags::EMBEDDED) && mxGraphicResolver.is()) + if (mxGraphicResolver.is()) { uno::Reference xGraphicStorageHandler(mxGraphicResolver, uno::UNO_QUERY); if (xGraphicStorageHandler.is()) { - xInputStream = xGraphicStorageHandler->createInputStream(rxGraphic); + Reference xInputStream(xGraphicStorageHandler->createInputStream(rxGraphic)); + if (xInputStream.is()) + { + rOutMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageStream(xInputStream); + return true; + } } } - return xInputStream; + return false; } bool SvXMLExport::AddEmbeddedXGraphicAsBase64(uno::Reference const & rxGraphic) diff --git a/xmloff/source/style/ImageStyle.cxx b/xmloff/source/style/ImageStyle.cxx index cd8b7fcb4659..5842b659dc11 100644 --- a/xmloff/source/style/ImageStyle.cxx +++ b/xmloff/source/style/ImageStyle.cxx @@ -62,7 +62,8 @@ void XMLImageStyle::exportXML(OUString const & rStrName, uno::Any const & rValue auto xBitmap = rValue.get>(); uno::Reference xGraphic(xBitmap, uno::UNO_QUERY); - const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic); + OUString aMimeType; + const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic, aMimeType); // uri if (!aStr.isEmpty()) -- cgit