diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2017-11-29 21:12:32 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2017-11-30 17:42:42 +0100 |
commit | 32efde5cef2b8516a9decd0bf7091d7def1da971 (patch) | |
tree | d92e02b3834b08b8e02ef8ca7adfcd2ded509107 /comphelper | |
parent | b17c29d493a1fc588524d6da332254fbb959f0db (diff) |
tdf#113696 Add mimetype to image element
Otherwise browsers don't recognize base64 encoded svg files.
Change-Id: I54d0b87c52a1ca9da1d820751ae32159b88ed28f
Reviewed-on: https://gerrit.libreoffice.org/45528
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/graphicmimetype.cxx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/comphelper/source/misc/graphicmimetype.cxx b/comphelper/source/misc/graphicmimetype.cxx index f8eeb3e92de5..bf88312304b1 100644 --- a/comphelper/source/misc/graphicmimetype.cxx +++ b/comphelper/source/misc/graphicmimetype.cxx @@ -19,6 +19,22 @@ #include <comphelper/graphicmimetype.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/graphic/GraphicProvider.hpp> +#include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <comphelper/processfactory.hxx> + +using namespace css; +using namespace css::beans; +using namespace css::graphic; +using namespace css::io; +using namespace css::uno; + namespace comphelper { OUString GraphicMimeTypeHelper::GetMimeTypeForExtension(const OString& rExt) @@ -47,5 +63,43 @@ OUString GraphicMimeTypeHelper::GetMimeTypeForExtension(const OString& rExt) return aMimeType; } + +OUString GraphicMimeTypeHelper::GetMimeTypeForXGraphic(Reference<XGraphic> xGraphic) +{ + OUString aSourceMimeType; + Reference<XPropertySet> const xGraphicPropertySet(xGraphic, UNO_QUERY); + if (xGraphicPropertySet.is() && // it's null if it's an external link + (xGraphicPropertySet->getPropertyValue("MimeType") >>= aSourceMimeType)) + { + return aSourceMimeType; + } + return OUString(""); +} + +OUString GraphicMimeTypeHelper::GetMimeTypeForImageUrl(const OUString& rImageUrl) +{ + // Create the graphic to retrieve the mimetype from it + Reference<XGraphicProvider> xProvider + = css::graphic::GraphicProvider::create(comphelper::getProcessComponentContext()); + Sequence<PropertyValue> aMediaProperties(1); + aMediaProperties[0].Name = "URL"; + aMediaProperties[0].Value <<= rImageUrl; + Reference<XGraphic> xGraphic(xProvider->queryGraphic(aMediaProperties)); + + return GetMimeTypeForXGraphic(xGraphic); +} + +OUString GraphicMimeTypeHelper::GetMimeTypeForImageStream(Reference<XInputStream> xInputStream) +{ + // Create the graphic to retrieve the mimetype from it + Reference<XGraphicProvider> xProvider + = css::graphic::GraphicProvider::create(comphelper::getProcessComponentContext()); + Sequence<PropertyValue> aMediaProperties(1); + aMediaProperties[0].Name = "InputStream"; + aMediaProperties[0].Value <<= xInputStream; + Reference<XGraphic> xGraphic(xProvider->queryGraphic(aMediaProperties)); + + return GetMimeTypeForXGraphic(xGraphic); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |