tdf#119539: try to improve cover image info in epub for epub readers

Patch libepubgen so cover image has "cover" in its name and not "image"
+ add meta info

Adapt qa tests.

Change-Id: I0177113b113050252aac5bc2e1b5efc0a3ed2613
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207575
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
This commit is contained in:
Julien Nabet
2026-07-06 12:06:14 +02:00
parent 417ebad37a
commit 28711b69f5
3 changed files with 57 additions and 7 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
#
epubgen_patches :=
epubgen_patches += tdf-120491.patch
epubgen_patches += tdf-120491.patch tdf-119539.patch.1
$(eval $(call gb_UnpackedTarball_UnpackedTarball,libepubgen))
+50
View File
@@ -0,0 +1,50 @@
diff -ur libepubgen.org/src/lib/EPUBGenerator.cpp libepubgen/src/lib/EPUBGenerator.cpp
--- libepubgen.org/src/lib/EPUBGenerator.cpp 2026-07-02 18:46:39.616796632 +0200
+++ libepubgen/src/lib/EPUBGenerator.cpp 2026-07-02 18:50:55.733580395 +0200
@@ -336,6 +336,29 @@
sink.insertCharacters(language);
sink.closeElement("dc:language");
+ const librevenge::RVNGPropertyListVector *coverImages = m_metadata.child("librevenge:cover-images");
+ if (coverImages)
+ {
+ int nCurrentCover = 0;
+ for (size_t i = 0; i < coverImages->count(); ++i)
+ {
+ librevenge::RVNGPropertyList const &propertyList = (*coverImages)[i];
+ if (propertyList["office:binary-data"] && propertyList["librevenge:mime-type"])
+ {
+ ++nCurrentCover;
+
+ std::string strCurrentCover = std::to_string(nCurrentCover);
+ strCurrentCover.insert(0, 4 - strCurrentCover.length(), '0');
+ std::string content = "cover" + strCurrentCover;
+ RVNGPropertyList metaAttrs;
+ metaAttrs.insert("content", content.c_str());
+ metaAttrs.insert("name", "cover");
+ sink.openElement("meta", metaAttrs);
+ sink.closeElement("meta");
+ }
+ }
+ }
+
if (m_version >= 30)
{
RVNGString date;
diff -ur libepubgen.org/src/lib/EPUBImageManager.cpp libepubgen/src/lib/EPUBImageManager.cpp
--- libepubgen.org/src/lib/EPUBImageManager.cpp 2026-07-02 18:46:39.615945896 +0200
+++ libepubgen/src/lib/EPUBImageManager.cpp 2026-07-02 18:50:02.905292875 +0200
@@ -84,7 +84,12 @@
const string mime(mimetype.cstr());
std::ostringstream nameBuf;
- nameBuf << "image" << std::setw(4) << std::setfill('0') << m_number.next();
+ std::string prefix = "image";
+ if (properties == "cover-image")
+ {
+ prefix = "cover";
+ }
+ nameBuf << prefix << std::setw(4) << std::setfill('0') << m_number.next();
const string id = nameBuf.str();
nameBuf << "." << getExtension(mime);
+6 -6
View File
@@ -294,13 +294,13 @@ CPPUNIT_TEST_FIXTURE(EPUBExportTest, testMeta)
u"2017-09-27T09:51:19Z");
// Make sure that cover image next to the source document is picked up.
assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/image0001.png']",
assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/cover0001.png']",
"properties", u"cover-image");
assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/image0001.png']",
assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/cover0001.png']",
"media-type", u"image/png");
uno::Reference<packages::zip::XZipFileAccess2> xZipFile
= packages::zip::ZipFileAccess::createWithURL(m_xContext, maTempFile.GetURL());
CPPUNIT_ASSERT(xZipFile->hasByName(u"OEBPS/images/image0001.png"_ustr));
CPPUNIT_ASSERT(xZipFile->hasByName(u"OEBPS/images/cover0001.png"_ustr));
}
CPPUNIT_TEST_FIXTURE(EPUBExportTest, testMetaXMP)
@@ -358,13 +358,13 @@ CPPUNIT_TEST_FIXTURE(EPUBExportTest, testCoverImage)
// 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']",
assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/cover0001.png']",
"properties", u"cover-image");
assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/image0001.png']",
assertXPath(mpXmlDoc, "/opf:package/opf:manifest/opf:item[@href='images/cover0001.png']",
"media-type", u"image/png");
uno::Reference<packages::zip::XZipFileAccess2> xZipFile
= packages::zip::ZipFileAccess::createWithURL(m_xContext, maTempFile.GetURL());
CPPUNIT_ASSERT(xZipFile->hasByName(u"OEBPS/images/image0001.png"_ustr));
CPPUNIT_ASSERT(xZipFile->hasByName(u"OEBPS/images/cover0001.png"_ustr));
}
CPPUNIT_TEST_FIXTURE(EPUBExportTest, testParaNamedstyle)