summaryrefslogtreecommitdiff
path: root/xmloff
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 /xmloff
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 'xmloff')
-rw-r--r--xmloff/source/core/xmlexp.cxx18
-rw-r--r--xmloff/source/draw/shapeexport.cxx11
-rw-r--r--xmloff/source/text/txtparae.cxx22
3 files changed, 30 insertions, 21 deletions
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 e6752066a89e..7f43937f0c7d 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 ) );