summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comphelper/source/misc/graphicmimetype.cxx54
-rw-r--r--include/comphelper/graphicmimetype.hxx8
-rw-r--r--include/xmloff/xmlexp.hxx2
-rw-r--r--xmloff/source/core/xmlexp.cxx18
-rw-r--r--xmloff/source/draw/shapeexport.cxx11
-rw-r--r--xmloff/source/text/txtparae.cxx22
6 files changed, 94 insertions, 21 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: */
diff --git a/include/comphelper/graphicmimetype.hxx b/include/comphelper/graphicmimetype.hxx
index 3f2b5308b2d6..970342f2e5f5 100644
--- a/include/comphelper/graphicmimetype.hxx
+++ b/include/comphelper/graphicmimetype.hxx
@@ -13,12 +13,20 @@
#include <comphelper/comphelperdllapi.h>
#include <rtl/ustring.hxx>
+#include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
namespace comphelper
{
class COMPHELPER_DLLPUBLIC GraphicMimeTypeHelper
{
public:
static OUString GetMimeTypeForExtension(const OString& rExt);
+ static OUString GetMimeTypeForXGraphic(css::uno::Reference<css::graphic::XGraphic> xGraphic);
+ static OUString GetMimeTypeForImageUrl(const OUString& rImageUrl);
+ static OUString
+ GetMimeTypeForImageStream(css::uno::Reference<css::io::XInputStream> xInputStream);
};
}
diff --git a/include/xmloff/xmlexp.hxx b/include/xmloff/xmlexp.hxx
index 474d718d5a41..4127e2a883fa 100644
--- a/include/xmloff/xmlexp.hxx
+++ b/include/xmloff/xmlexp.hxx
@@ -460,6 +460,8 @@ public:
OUString AddEmbeddedGraphicObject(
const OUString& rGraphicObjectURL );
+ css::uno::Reference<css::io::XInputStream> GetEmbeddedGraphicObjectStream(
+ const OUString& rGraphicObjectURL);
bool AddEmbeddedGraphicObjectAsBase64(
const OUString& rGraphicObjectURL );
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index f8970a58f2c2..329fe258b766 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -1885,6 +1885,24 @@ OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectUR
return sRet;
}
+Reference< XInputStream > SvXMLExport::GetEmbeddedGraphicObjectStream( const OUString& rGraphicObjectURL )
+{
+ if( (getExportFlags() & SvXMLExportFlags::EMBEDDED) &&
+ rGraphicObjectURL.startsWith( msGraphicObjectProtocol ) &&
+ mxGraphicResolver.is() )
+ {
+ Reference< XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
+
+ if( xStmResolver.is() )
+ {
+ Reference< XInputStream > xIn( xStmResolver->getInputStream( rGraphicObjectURL ) );
+ return xIn;
+ }
+ }
+
+ return nullptr;
+}
+
bool SvXMLExport::AddEmbeddedGraphicObjectAsBase64( const OUString& rGraphicObjectURL )
{
bool bRet = false;
diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx
index 3f7f1d54ec18..29d3c74a84af 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -82,6 +82,7 @@
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <comphelper/classids.hxx>
+#include <comphelper/graphicmimetype.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/storagehelper.hxx>
@@ -2352,6 +2353,16 @@ void XMLShapeExport::ImpExportGraphicObjectShape(
}
{
+ // We can't guess the mimetype from sImageURL because the image type might be changed
+ // while creating the stream (by SvXMLGraphicInputStream). So we first need to create
+ // the stream, get the mime type and then write the stream.
+ uno::Reference<io::XInputStream> xInputStream(
+ mrExport.GetEmbeddedGraphicObjectStream(sImageURL));
+ OUString aMimeType(
+ comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageStream(xInputStream));
+ if (!aMimeType.isEmpty())
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", aMimeType);
+
SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DRAW, XML_IMAGE, true, true);
if( !sImageURL.isEmpty() )
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 4ab345e599c3..eaaf3ff0f2aa 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -117,7 +117,6 @@
#include <vector>
#include <algorithm>
#include <iterator>
-#include <comphelper/processfactory.hxx>
#include <comphelper/graphicmimetype.hxx>
using namespace ::std;
@@ -3016,25 +3015,6 @@ void XMLTextParagraphExport::exportContour(
true, true );
}
-static OUString getMimeType(const OUString& sImageUrl)
-{
- // 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 <<= sImageUrl;
- Reference< XGraphic > xGraphic( xProvider->queryGraphic( aMediaProperties ) );
-
- 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("");
-}
-
void XMLTextParagraphExport::_exportTextGraphic(
const Reference < XPropertySet > & rPropSet,
const Reference < XPropertySetInfo > & rPropSetInfo )
@@ -3101,7 +3081,7 @@ void XMLTextParagraphExport::_exportTextGraphic(
OUString aSourceMimeType = GetExport().GetImageFilterName();
// otherwise determine mimetype from graphic
if ( aSourceMimeType.isEmpty() )
- aSourceMimeType = getMimeType(sOrigURL);
+ aSourceMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageUrl(sOrigURL);
else // !aSourceMimeType.isEmpty()
{
const OString aExt( OUStringToOString( aSourceMimeType, RTL_TEXTENCODING_ASCII_US ) );