[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - filter/source sw/qa xmloff/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Thu Jul 27 11:54:08 UTC 2017


 filter/source/xslt/odf2xhtml/export/common/body.xsl |   52 +++++++++++---------
 filter/source/xslt/odf2xhtml/export/xhtml/body.xsl  |    3 -
 sw/qa/extras/odfexport/data/image-mimetype.odt      |binary
 sw/qa/extras/odfexport/odfexport.cxx                |   11 ++++
 xmloff/source/text/txtparae.cxx                     |   26 ++++++++++
 5 files changed, 69 insertions(+), 23 deletions(-)

New commits:
commit 01b92d73b6efd638e025d4b0520c996d5e417937
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Mon Jul 24 15:46:06 2017 +0200

    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 at redhat.com>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Reviewed-on: https://gerrit.libreoffice.org/40478
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/filter/source/xslt/odf2xhtml/export/common/body.xsl b/filter/source/xslt/odf2xhtml/export/common/body.xsl
index 3196facc8092..05b78a5ed43e 100644
--- a/filter/source/xslt/odf2xhtml/export/common/body.xsl
+++ b/filter/source/xslt/odf2xhtml/export/common/body.xsl
@@ -1,21 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- -->
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ -->
 <!--
 	For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
 -->
@@ -317,6 +317,7 @@
 
 	<xsl:template name="create-href">
 		<xsl:param name="href"/>
+		<xsl:param name="mimetype"/>
 
 		<xsl:choose>
 			<!-- internal OOo URL used in content tables -->
@@ -332,7 +333,14 @@
 				<xsl:value-of select="concat('a_', translate(normalize-space($title), '.,;: %()[]/\+', '_____________'))"/>
 			</xsl:when>
 			<xsl:when test="self::draw:image[office:binary-data]">
-				<xsl:text>data:image/*;base64,</xsl:text><xsl:value-of select="office:binary-data"/>
+                <xsl:choose>
+                    <xsl:when test="$mimetype">
+                        <xsl:text>data:</xsl:text><xsl:value-of select="$mimetype"/><xsl:text>;base64,</xsl:text><xsl:value-of select="office:binary-data"/>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:text>data:image/*;base64,</xsl:text><xsl:value-of select="office:binary-data"/>
+                    </xsl:otherwise>
+                </xsl:choose>
 			</xsl:when>
 			<xsl:otherwise>
 				<xsl:choose>
@@ -361,10 +369,10 @@
 								<xsl:value-of select="concat($href, $optionalURLSuffix)"/>
 							</xsl:when>
 							 <!-- for relative URLs -->
-							 <xsl:when test="starts-with($href, '#')">
-							   <!-- intra document ref -->
-							   <xsl:value-of select="$href"/>
-							 </xsl:when>
+							 <xsl:when test="starts-with($href, '#')">
+							   <!-- intra document ref -->
+							   <xsl:value-of select="$href"/>
+							 </xsl:when>
 							<xsl:otherwise>
 								<xsl:value-of select="concat($sourceBaseURL, $href, $optionalURLSuffix)"/>
 							</xsl:otherwise>
diff --git a/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl b/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl
index 823d048254c5..d638f6294ad9 100644
--- a/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl
+++ b/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl
@@ -19,7 +19,7 @@
 <!--
 	For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
 -->
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:s
 tyle="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xt="http://www.jclark.com/xt" xmlns:common="http://exslt.org/common" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xforms xlink xsd xsi xt common xalan" xmlns="http://www.w3.org/1999/xhtml">
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:s
 tyle="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xt="http://www.jclark.com/xt" xmlns:common="http://exslt.org/common" xmlns:xalan="http://xml.apache.org/xalan" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xforms xlink xsd xsi xt common xalan" xmlns="http://www.w3.org/1999/xhtml">
 
 
 	<!--+++++ INCLUDED XSL MODULES +++++-->
@@ -1561,6 +1561,7 @@
 			<xsl:attribute name="src">
 				<xsl:call-template name="create-href">
 					<xsl:with-param name="href" select="@xlink:href"/>
+					<xsl:with-param name="mimetype" select="@loext:mime-type"/>
 				</xsl:call-template>
 			</xsl:attribute>
 
diff --git a/sw/qa/extras/odfexport/data/image-mimetype.odt b/sw/qa/extras/odfexport/data/image-mimetype.odt
new file mode 100644
index 000000000000..4c4924a1b254
Binary files /dev/null and b/sw/qa/extras/odfexport/data/image-mimetype.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 13b9a368fb02..012cbf1893ed 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -1578,6 +1578,17 @@ DECLARE_ODFEXPORT_TEST(testTableStyles5, "table_styles_5.odt")
     }
 }
 
+DECLARE_ODFEXPORT_TEST(testImageMimetype, "image-mimetype.odt")
+{
+    // Test that the loext:mimetype attribute is written for exported images, tdf#109202
+    if (xmlDocPtr pXmlDoc = parseExport("content.xml"))
+    {
+        // Original image (svg)
+        assertXPath(pXmlDoc, "/office:document-content/office:body/office:text/text:p/draw:frame/draw:image[@loext:mime-type='image/svg+xml']");
+    }
+}
+
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 903a35f517ce..c9b5acd0897c 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;
@@ -127,6 +131,7 @@ using namespace ::com::sun::star::util;
 using namespace ::com::sun::star::drawing;
 using namespace ::com::sun::star::document;
 using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::graphic;
 using namespace ::xmloff;
 using namespace ::xmloff::token;
 
@@ -3029,6 +3034,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 )
@@ -3090,6 +3111,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 );


More information about the Libreoffice-commits mailing list