summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-07-24 15:46:06 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-07-27 09:02:20 +0200
commit4469b29faeb8dbf7793a5d81d9c5ddebacf3015f (patch)
tree5d88d54b7c9af5504d7bf287b6f81a8aed083bf2 /xmloff
parent7f381be4d3261149a5b54048f9605fab0340c221 (diff)
tdf#109202 Add mimetype to image element
Browsers don't recognize base64 svg if the mimetype is missing. So we add the image mimetype to our flat odf export, which the xhtml export uses and transforms it into an xhtml document. Change-Id: I21aafdb97b4104e14e2d40abda73a526bb37041a Reviewed-on: https://gerrit.libreoffice.org/40371 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/text/txtparae.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index fc08ff2238d6..5ca9e5953892 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -31,6 +31,9 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XMultiPropertySet.hpp>
#include <com/sun/star/beans/XPropertyState.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/graphic/GraphicProvider.hpp>
+#include <com/sun/star/graphic/XGraphicProvider.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XTextSectionsSupplier.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
@@ -114,6 +117,7 @@
#include <vector>
#include <algorithm>
#include <iterator>
+#include <comphelper/processfactory.hxx>
using namespace ::std;
using namespace ::com::sun::star;
@@ -126,6 +130,7 @@ using namespace ::com::sun::star::style;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::graphic;
using namespace ::xmloff;
using namespace ::xmloff::token;
@@ -3012,6 +3017,22 @@ 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 > xGraphicPropertySet( xGraphic, UNO_QUERY_THROW );
+ if ( xGraphicPropertySet->getPropertyValue( "MimeType" ) >>= aSourceMimeType )
+ return aSourceMimeType;
+ return OUString("");
+}
+
void XMLTextParagraphExport::_exportTextGraphic(
const Reference < XPropertySet > & rPropSet,
const Reference < XPropertySetInfo > & rPropSetInfo )
@@ -3073,6 +3094,11 @@ void XMLTextParagraphExport::_exportTextGraphic(
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME,
sGrfFilter );
+ // Add mimetype to make it easier for readers to get the base64 image type right, tdf#109202
+ OUString aSourceMimeType = getMimeType(sOrigURL);
+ if ( !aSourceMimeType.isEmpty() )
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", aSourceMimeType);
+
{
SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW,
XML_IMAGE, false, true );