writerperfect/qa/unit/EPUBExportTest.cxx | 19 ++++++++++++++++ writerperfect/source/writer/exp/xmlimp.cxx | 34 ++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-)
New commits: commit 612821223c574fe0956d348730d40623943821f3 Author: Miklos Vajna <[email protected]> Date: Wed Nov 29 11:45:12 2017 +0100 EPUB export: allow setting a custom cover image explicitly If not set, fall back to the existing auto-find. Change-Id: I5df7a535e4132a18a803c10fa0e06352d9b6b533 diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index e038a7ef6135..72c9a27dc495 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -61,6 +61,7 @@ public: void testSpanAutostyle(); void testParaAutostyleCharProps(); void testMeta(); + void testCoverImage(); void testParaNamedstyle(); void testCharNamedstyle(); void testNamedStyleInheritance(); @@ -93,6 +94,7 @@ public: CPPUNIT_TEST(testSpanAutostyle); CPPUNIT_TEST(testParaAutostyleCharProps); CPPUNIT_TEST(testMeta); + CPPUNIT_TEST(testCoverImage); CPPUNIT_TEST(testParaNamedstyle); CPPUNIT_TEST(testCharNamedstyle); CPPUNIT_TEST(testNamedStyleInheritance); @@ -333,6 +335,23 @@ void EPUBExportTest::testMeta() CPPUNIT_ASSERT(mxZipFile->hasByName("OEBPS/images/image0001.png")); } +void EPUBExportTest::testCoverImage() +{ + OUString aCoverURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "meta.cover-image.png"; + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + {"EPUBCoverImage", uno::makeAny(aCoverURL)} + })); + createDoc("hello.fodt", aFilterData); + mpXmlDoc = parseExport("OEBPS/content.opf"); + + // Make sure that the explicitly set cover image is used. + // This failed, as the image was not part of the package. + assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/image0001.png']", "properties", "cover-image"); + assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/image0001.png']", "media-type", "image/png"); + CPPUNIT_ASSERT(mxZipFile->hasByName("OEBPS/images/image0001.png")); +} + void EPUBExportTest::testParaNamedstyle() { createDoc("para-namedstyle.fodt", {}); diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx index 3d7f99cc399e..bc3b9c7693e4 100644 --- a/writerperfect/source/writer/exp/xmlimp.cxx +++ b/writerperfect/source/writer/exp/xmlimp.cxx @@ -46,10 +46,38 @@ OUString GetMimeType(const OUString &rExtension) } /// Picks up a cover image from the base directory. -OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType) +OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, const uno::Sequence<beans::PropertyValue> &rDescriptor) { OUString aRet; + // See if filter data contains a cover image explicitly. + 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 == "EPUBCoverImage") + { + aFilterData[i].Value >>= aRet; + break; + } + } + + if (!aRet.isEmpty()) + { + INetURLObject aRetURL(aRet); + rMimeType = GetMimeType(aRetURL.GetExtension()); + return aRet; + } + + // Not set explicitly, try to pick it up from the base directory. if (rDocumentBaseURL.isEmpty()) return aRet; @@ -142,11 +170,11 @@ rtl::Reference<XMLImportContext> XMLOfficeDocContext::CreateChildContext(const O return nullptr; } -XMLImport::XMLImport(librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const uno::Sequence<beans::PropertyValue> &/*rDescriptor*/) +XMLImport::XMLImport(librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const uno::Sequence<beans::PropertyValue> &rDescriptor) : mrGenerator(rGenerator) { OUString aMimeType; - OUString aCoverImage = FindCoverImage(rURL, aMimeType); + OUString aCoverImage = FindCoverImage(rURL, aMimeType, rDescriptor); if (!aCoverImage.isEmpty()) { librevenge::RVNGBinaryData aBinaryData; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
