[gnome-epub-thumbnailer/wip/hadess/fix-cover-properties: 2/2] epub: Fix thumbnailing of books with ePub 3.2 "cover-image"
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-epub-thumbnailer/wip/hadess/fix-cover-properties: 2/2] epub: Fix thumbnailing of books with ePub 3.2 "cover-image"
- Date: Wed, 4 Aug 2021 10:05:54 +0000 (UTC)
commit a0c0d13b7b8869641f16aba7ceda57dffe9ac4f3
Author: Bastien Nocera <hadess hadess net>
Date: Wed Aug 4 12:03:58 2021 +0200
epub: Fix thumbnailing of books with ePub 3.2 "cover-image"
Look for the "cover-image" manifest item property as defined in the
EPUB 3.2 spec:
https://www.w3.org/publishing/epub3/epub-packages.html#bib-epub32
Closes: #2
gnome-epub-thumbnailer.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/gnome-epub-thumbnailer.c b/gnome-epub-thumbnailer.c
index 490f387..841d8c7 100644
--- a/gnome-epub-thumbnailer.c
+++ b/gnome-epub-thumbnailer.c
@@ -215,8 +215,6 @@ get_cover_path_from_root_file (const char *metafile,
char *root_path;
char *root_file;
gsize root_length;
- char *content_name;
- char *xpath;
char *cover_path, *full_cover_path;
cover_path = NULL;
@@ -242,15 +240,23 @@ get_cover_path_from_root_file (const char *metafile,
xpath_ctx = xmlXPathNewContext(doc);
xmlXPathRegisterNs (xpath_ctx, BAD_CAST ("ns"), BAD_CAST (OPF_NAMESPACE));
- content_name = get_prop_for_xpath (doc, xpath_ctx, "//ns:package/ns:metadata/ns:meta[@name='cover']",
"content");
- if (!content_name)
- goto bail;
- g_debug ("Found content_name '%s'", content_name);
+ /* Look for "cover-image" manifest item property
+ * https://www.w3.org/publishing/epub3/epub-packages.html#sec-item-property-values */
+ cover_path = get_prop_for_xpath (doc, xpath_ctx,
"//ns:package/ns:manifest/ns:item[@properties='cover-image']", "href");
+
+ if (!cover_path) {
+ g_autofree char *xpath = NULL;
+ g_autofree char *content_name = NULL;
+
+ content_name = get_prop_for_xpath (doc, xpath_ctx,
"//ns:package/ns:metadata/ns:meta[@name='cover']", "content");
+ if (!content_name)
+ goto bail;
+ g_debug ("Found content_name '%s'", content_name);
+
+ xpath = g_strdup_printf ("//ns:package/ns:manifest/ns:item[@id='%s']", content_name);
+ cover_path = get_prop_for_xpath (doc, xpath_ctx, xpath, "href");
+ }
- xpath = g_strdup_printf ("//ns:package/ns:manifest/ns:item[@id='%s']", content_name);
- g_free (content_name);
- cover_path = get_prop_for_xpath (doc, xpath_ctx, xpath, "href");
- g_free (xpath);
g_debug ("Found cover_path '%s'", cover_path);
full_cover_path = resolve_cover_path (cover_path, root_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]