summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-08-25 14:10:01 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-08-25 16:07:30 +0200
commit3a1d6a2bccd05e5859ab44593609d11c39fc518a (patch)
tree9aafa9c1c95ff3dc749aee3d4cbc37d477dd74f4 /writerperfect
parentbafe8a5ef091a83a90d639fd3f583422fa055d53 (diff)
EPUB export: allow setting a custom version
By parsing the FilterData key of the media descriptor, similar to how the PDF export does it. The default is still EPUB3, but this now exposes the ability of libepubgen to emit EPUB2 if wanted. Change-Id: I23834fa28db9b01ef4cce4a142331b1cc9ecb3c2 Reviewed-on: https://gerrit.libreoffice.org/41566 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/CppunitTest_writerperfect_epubexport.mk4
-rw-r--r--writerperfect/qa/unit/EPUBExportTest.cxx44
-rw-r--r--writerperfect/source/writer/EPUBExportFilter.cxx19
3 files changed, 59 insertions, 8 deletions
diff --git a/writerperfect/CppunitTest_writerperfect_epubexport.mk b/writerperfect/CppunitTest_writerperfect_epubexport.mk
index ea5285730b31..00a49a522805 100644
--- a/writerperfect/CppunitTest_writerperfect_epubexport.mk
+++ b/writerperfect/CppunitTest_writerperfect_epubexport.mk
@@ -27,6 +27,10 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_epubexport, \
$(gb_UWINAPI) \
))
+$(eval $(call gb_CppunitTest_use_externals,writerperfect_epubexport,\
+ libxml2 \
+))
+
$(eval $(call gb_CppunitTest_use_external,writerperfect_epubexport,boost_headers))
$(eval $(call gb_CppunitTest_use_sdk_api,writerperfect_epubexport))
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index ab1ca51c855b..859e98374cb5 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -12,11 +12,14 @@
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
#include <comphelper/processfactory.hxx>
+#include <comphelper/propertysequence.hxx>
#include <cppuhelper/implbase.hxx>
#include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
#include <unotest/macros_test.hxx>
#include <unotools/mediadescriptor.hxx>
#include <unotools/tempfile.hxx>
+#include <unotools/ucbstreamhelper.hxx>
using namespace ::com::sun::star;
@@ -26,22 +29,25 @@ namespace
char const DATA_DIRECTORY[] = "/writerperfect/qa/unit/data/writer/epubexport/";
/// Tests the EPUB export filter.
-class EPUBExportTest : public test::BootstrapFixture, public unotest::MacrosTest
+class EPUBExportTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
{
uno::Reference<uno::XComponentContext> mxComponentContext;
uno::Reference<lang::XComponent> mxComponent;
utl::TempFile maTempFile;
public:
- virtual void setUp() override;
- virtual void tearDown() override;
- void createDoc(const OUString &rFile);
+ void setUp() override;
+ void tearDown() override;
+ void registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx) override;
+ void createDoc(const OUString &rFile, const uno::Sequence<beans::PropertyValue> &rFilterData);
void testOutlineLevel();
void testMimetype();
+ void testEPUB2();
CPPUNIT_TEST_SUITE(EPUBExportTest);
CPPUNIT_TEST(testOutlineLevel);
CPPUNIT_TEST(testMimetype);
+ CPPUNIT_TEST(testEPUB2);
CPPUNIT_TEST_SUITE_END();
};
@@ -61,7 +67,12 @@ void EPUBExportTest::tearDown()
test::BootstrapFixture::tearDown();
}
-void EPUBExportTest::createDoc(const OUString &rFile)
+void EPUBExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
+{
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("opf"), BAD_CAST("http://www.idpf.org/2007/opf"));
+}
+
+void EPUBExportTest::createDoc(const OUString &rFile, const uno::Sequence<beans::PropertyValue> &rFilterData)
{
// Import the bugdoc and export as EPUB.
OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFile;
@@ -72,12 +83,13 @@ void EPUBExportTest::createDoc(const OUString &rFile)
maTempFile.EnableKillingFile();
utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor["FilterName"] <<= OUString("EPUB");
+ aMediaDescriptor["FilterData"] <<= rFilterData;
xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
}
void EPUBExportTest::testOutlineLevel()
{
- createDoc("outline-level.fodt");
+ createDoc("outline-level.fodt", {});
// Make sure that the output is split into two.
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, maTempFile.GetURL());
@@ -89,7 +101,7 @@ void EPUBExportTest::testOutlineLevel()
void EPUBExportTest::testMimetype()
{
- createDoc("hello.fodt");
+ createDoc("hello.fodt", {});
// Check that the mime type is written uncompressed at the expected location.
SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
@@ -103,6 +115,24 @@ void EPUBExportTest::testMimetype()
CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
}
+void EPUBExportTest::testEPUB2()
+{
+ uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence(
+ {
+ // Explicitly request EPUB2.
+ {"EPUBVersion", uno::makeAny(static_cast<sal_Int32>(20))}
+ }));
+ createDoc("hello.fodt", aFilterData);
+
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, maTempFile.GetURL());
+ uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("OEBPS/content.opf"), uno::UNO_QUERY);
+ std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
+ xmlDocPtr pXmlDoc = parseXmlStream(pStream.get());
+ // This was 3.0, EPUBVersion filter option was ignored and we always emitted EPUB3.
+ assertXPath(pXmlDoc, "/opf:package", "version", "2.0");
+ xmlFreeDoc(pXmlDoc);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
}
diff --git a/writerperfect/source/writer/EPUBExportFilter.cxx b/writerperfect/source/writer/EPUBExportFilter.cxx
index 465d8bc256ac..ac16cd570198 100644
--- a/writerperfect/source/writer/EPUBExportFilter.cxx
+++ b/writerperfect/source/writer/EPUBExportFilter.cxx
@@ -34,13 +34,30 @@ EPUBExportFilter::EPUBExportFilter(const uno::Reference<uno::XComponentContext>
sal_Bool EPUBExportFilter::filter(const uno::Sequence<beans::PropertyValue> &rDescriptor)
{
+ sal_Int32 nVersion = 30;
+ uno::Sequence<beans::PropertyValue> aFilterData;
+ for (sal_Int32 i = 0; i < rDescriptor.getLength(); ++i)
+ {
+ if (rDescriptor[i].Name == "FilterData")
+ {
+ rDescriptor[i].Value >>= aFilterData;
+ break;
+ }
+ }
+
+ for (sal_Int32 i = 0; i < aFilterData.getLength(); ++i)
+ {
+ if (aFilterData[i].Name == "EPUBVersion")
+ aFilterData[i].Value >>= nVersion;
+ }
+
// Build the export filter chain: the package has direct access to the ZIP
// file, the flat ODF filter has access to the doc model, everything else
// is in-between.
EPUBPackage aPackage(mxContext, rDescriptor);
libepubgen::EPUBTextGenerator aGenerator(&aPackage, libepubgen::EPUB_SPLIT_METHOD_HEADING
#if LIBEPUBGEN_VERSION_SUPPORT
- , /*version=*/30
+ , nVersion
#endif
);
uno::Reference<xml::sax::XDocumentHandler> xExportHandler(new exp::XMLImport(aGenerator));