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>
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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:style="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:style="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>
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1644,6 +1644,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();
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user