diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-02-19 21:47:04 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-02-21 21:32:56 +0100 |
commit | e48b4275ceee82bd0eb128b2947302b9022e9c89 (patch) | |
tree | c40d1d0d100c67c7fc8076e34b9d8e0769638d37 /xmloff | |
parent | 6fc75b669438728ba6a4e55d53a79fa0cf006529 (diff) |
report the saved mimetype when saving graphic + mime from stream
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 <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmlexp.cxx | 22 | ||||
-rw-r--r-- | xmloff/source/style/ImageStyle.cxx | 3 |
2 files changed, 14 insertions, 11 deletions
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 <RDFaExportHelper.hxx> #include <comphelper/xmltools.hxx> +#include <comphelper/graphicmimetype.hxx> 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<graphic::XGraphic> const & rxGraphic, OUString const & rRequestedName) +OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType, OUString const & rRequestedName) { OUString sURL; @@ -1900,9 +1901,7 @@ OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference<graphic::XGraphic> 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<io::XInputStream> SvXMLExport::GetEmbeddedXGraphicStream(uno::Reference<graphic::XGraphic> const & rxGraphic) +bool SvXMLExport::GetGraphicMimeTypeFromStream(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType) { - uno::Reference<io::XInputStream> xInputStream; - - if ((getExportFlags() & SvXMLExportFlags::EMBEDDED) && mxGraphicResolver.is()) + if (mxGraphicResolver.is()) { uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(mxGraphicResolver, uno::UNO_QUERY); if (xGraphicStorageHandler.is()) { - xInputStream = xGraphicStorageHandler->createInputStream(rxGraphic); + Reference<XInputStream> xInputStream(xGraphicStorageHandler->createInputStream(rxGraphic)); + if (xInputStream.is()) + { + rOutMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageStream(xInputStream); + return true; + } } } - return xInputStream; + return false; } bool SvXMLExport::AddEmbeddedXGraphicAsBase64(uno::Reference<graphic::XGraphic> 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<awt::XBitmap>>(); uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY); - const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic); + OUString aMimeType; + const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic, aMimeType); // uri if (!aStr.isEmpty()) |