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 /xmloff/source | |
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 'xmloff/source')
-rw-r--r-- | xmloff/source/core/xmlexp.cxx | 18 | ||||
-rw-r--r-- | xmloff/source/draw/shapeexport.cxx | 11 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 22 |
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 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 ) ); |