summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-11-29 21:12:32 +0100
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-12-04 09:19:18 +0100
commit5dc757b5d25894c08792036043b8714fa28a8b87 (patch)
tree3ba0563731826c94a773de5674980924e9e0ea9e /comphelper
parentf6ce8116b14892e26549c2dc2d59044a961c1dff (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> (cherry picked from commit 32efde5cef2b8516a9decd0bf7091d7def1da971) Reviewed-on: https://gerrit.libreoffice.org/45674
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/graphicmimetype.cxx54
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: */