Kaydet (Commit) e83d7993 authored tarafından Miklos Vajna's avatar Miklos Vajna

EPUB export, fixed layout: disable DTD string in SVG header

epubcheck complains:

ERROR(HTM-003): test.epub/OEBPS/images/image0001.svg(5675,37): External entities are not allowed in EPUB v3 documents. External entity declaration found: %svg-extensibility.mod.

and similar ones. Just not writing the DTD header is enough to address
the error.

Change-Id: I5307e932a0f07585297cce734aceae77e43cc7a6
Reviewed-on: https://gerrit.libreoffice.org/45648Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 3ed8466b
......@@ -31,6 +31,7 @@
#define SVG_EXPORTFILTER_CONFIGPATH "Office.Common/Filter/SVG/Export/"
#define SVG_PROP_TINYPROFILE "TinyMode"
#define SVG_PROP_DTDSTRING "DTDString"
#define SVG_PROP_EMBEDFONTS "EmbedFonts"
#define SVG_PROP_NATIVEDECORATION "UseNativeTextDecoration"
#define SVG_PROP_OPACITY "Opacity"
......
......@@ -317,6 +317,9 @@ SVGExport::SVGExport(
// TinyProfile
mbIsUseTinyProfile = aFilterDataHashMap.getUnpackedValueOrDefault(SVG_PROP_TINYPROFILE, false);
// DTD string
mbIsUseDTDString = aFilterDataHashMap.getUnpackedValueOrDefault(SVG_PROP_DTDSTRING, true);
// Font Embedding
comphelper::SequenceAsHashMap::const_iterator iter = aFilterDataHashMap.find(SVG_PROP_EMBEDFONTS);
if(iter==aFilterDataHashMap.end())
......@@ -2307,7 +2310,7 @@ void SVGExport::writeMtf( const GDIMetaFile& rMtf )
rtl::OUString aAttr;
Reference< XExtendedDocumentHandler> xExtDocHandler( GetDocHandler(), UNO_QUERY );
if( xExtDocHandler.is() )
if( xExtDocHandler.is() && IsUseDTDString() )
xExtDocHandler->unknown( SVG_DTD_STRING );
aAttr = OUString::number( aSize.Width() );
......
......@@ -71,6 +71,7 @@ static const OUString sPlaceholderTag( "<[:isPlaceholder:]>" );
class SVGExport : public SvXMLExport
{
bool mbIsUseTinyProfile;
bool mbIsUseDTDString;
bool mbIsEmbedFonts;
bool mbIsUseOpacity;
bool mbIsUseNativeTextDecoration;
......@@ -85,6 +86,7 @@ public:
virtual ~SVGExport() override;
bool IsUseTinyProfile() const { return mbIsUseTinyProfile; };
bool IsUseDTDString() const { return mbIsUseDTDString; };
bool IsEmbedFonts() const { return mbIsEmbedFonts; };
bool IsUseOpacity() const { return mbIsUseOpacity; };
bool IsUseNativeTextDecoration() const { return mbIsUseNativeTextDecoration; };
......
......@@ -96,6 +96,7 @@ public:
void testPopup();
void testPopupAPI();
void testPageSize();
void testSVG();
CPPUNIT_TEST_SUITE(EPUBExportTest);
CPPUNIT_TEST(testOutlineLevel);
......@@ -139,6 +140,7 @@ public:
CPPUNIT_TEST(testPopup);
CPPUNIT_TEST(testPopupAPI);
CPPUNIT_TEST(testPageSize);
CPPUNIT_TEST(testSVG);
CPPUNIT_TEST_SUITE_END();
};
......@@ -813,6 +815,29 @@ void EPUBExportTest::testPageSize()
assertXPath(mpXmlDoc, "/xhtml:html/xhtml:head/xhtml:meta[@name='viewport']", "content", "width=816, height=1056");
}
void EPUBExportTest::testSVG()
{
uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence(
{
{"EPUBLayoutMethod", uno::makeAny(static_cast<sal_Int32>(libepubgen::EPUB_LAYOUT_METHOD_FIXED))}
}));
createDoc("hello.fodt", aFilterData);
CPPUNIT_ASSERT(mxZipFile->hasByName("OEBPS/images/image0001.svg"));
uno::Reference<io::XInputStream> xInputStream(mxZipFile->getByName("OEBPS/images/image0001.svg"), uno::UNO_QUERY);
std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
SvMemoryStream aMemoryStream;
aMemoryStream.WriteStream(*pStream);
OString aExpected("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<svg");
CPPUNIT_ASSERT(aMemoryStream.GetSize() > static_cast<sal_uInt64>(aExpected.getLength()));
// This failed, there was a '<!DOCTYPE' line between the xml and the svg
// one, causing a validation error.
OString aActual(static_cast<const char *>(aMemoryStream.GetBuffer()), aExpected.getLength());
CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
}
CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
}
......
......@@ -17,6 +17,7 @@
#include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/xml/sax/Parser.hpp>
#include <com/sun/star/xml/sax/Writer.hpp>
#include <comphelper/propertyvalue.hxx>
#include <rtl/uri.hxx>
#include <tools/stream.hxx>
#include <tools/urlobj.hxx>
......@@ -283,7 +284,10 @@ void XMLOfficeDocContext::HandleFixedLayoutPage(const uno::Sequence<sal_Int8> &r
if (!xSaxWriter.is())
return;
uno::Sequence<uno::Any> aArguments;
uno::Sequence<uno::Any> aArguments =
{
uno::makeAny(uno::Sequence<beans::PropertyValue>({comphelper::makePropertyValue("DTDString", false)}))
};
uno::Reference<svg::XSVGWriter> xSVGWriter(xCtx->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.svg.SVGWriter", aArguments, xCtx), uno::UNO_QUERY);
if (!xSVGWriter.is())
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment