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

EPUB export: allow setting a custom cover image explicitly

If not set, fall back to the existing auto-find.

Change-Id: I5df7a535e4132a18a803c10fa0e06352d9b6b533
üst 6c18082c
......@@ -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", {});
......
......@@ -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;
......
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