[libgepub] Fixed SVG image resource replacement
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgepub] Fixed SVG image resource replacement
- Date: Tue, 15 Aug 2017 17:06:59 +0000 (UTC)
commit 27f0d374e0c8f6fa972dbd111d4ce0c0f3096914
Author: Daniel GarcĂa Moreno <danigm wadobo com>
Date: Tue Aug 15 19:04:34 2017 +0200
Fixed SVG image resource replacement
https://bugzilla.gnome.org/show_bug.cgi?id=786277
libgepub/gepub-utils.c | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/libgepub/gepub-utils.c b/libgepub/gepub-utils.c
index 3b9b9d1..eda1524 100644
--- a/libgepub/gepub-utils.c
+++ b/libgepub/gepub-utils.c
@@ -31,25 +31,38 @@
* function also makes the resource absolute based on the epub root
*/
static void
-set_epub_uri (xmlNode *node, const gchar *path, const gchar *tagname, const gchar *attr)
+set_epub_uri (xmlNode *node,
+ const gchar *path,
+ const gchar *tagname,
+ const gchar *attr,
+ const gchar *ns)
{
xmlNode *cur_node = NULL;
xmlChar *text = NULL;
+ gchar *attrname = NULL;
+
SoupURI *baseURI;
gchar *basepath = g_strdup_printf ("epub:///%s/", path);
baseURI = soup_uri_new (basepath);
g_free (basepath);
+ if (ns) {
+ attrname = g_strdup_printf ("%s:%s", ns, attr);
+ } else {
+ attrname = g_strdup (attr);
+ }
+
for (cur_node = node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE ) {
text = xmlGetProp (cur_node, BAD_CAST (attr));
+
if (!strcmp ((const char *) cur_node->name, tagname) && text) {
SoupURI *uri = soup_uri_new_with_base (baseURI, (const char *) text);
gchar *value = soup_uri_to_string (uri, FALSE);
- xmlSetProp (cur_node, BAD_CAST (attr), BAD_CAST (value));
+ xmlSetProp (cur_node, BAD_CAST (attrname), BAD_CAST (value));
soup_uri_free (uri);
g_free (value);
@@ -61,9 +74,11 @@ set_epub_uri (xmlNode *node, const gchar *path, const gchar *tagname, const gcha
}
if (cur_node->children)
- set_epub_uri (cur_node->children, path, tagname, attr);
+ set_epub_uri (cur_node->children, path, tagname, attr, ns);
}
+ g_free (attrname);
+
soup_uri_free (baseURI);
}
@@ -252,13 +267,13 @@ gepub_utils_replace_resources (GBytes *content, const gchar *path)
root_element = xmlDocGetRootElement (doc);
// replacing css resources
- set_epub_uri (root_element, path, "link", "href");
+ set_epub_uri (root_element, path, "link", "href", NULL);
// replacing images resources
- set_epub_uri (root_element, path, "img", "src");
+ set_epub_uri (root_element, path, "img", "src", NULL);
// replacing svg images resources
- set_epub_uri (root_element, path, "image", "xlink:href");
+ set_epub_uri (root_element, path, "image", "href", "xlink");
// replacing crosslinks
- set_epub_uri (root_element, path, "a", "href");
+ set_epub_uri (root_element, path, "a", "href", NULL);
xmlDocDumpFormatMemory (doc, (xmlChar**)&buffer, (int*)&bufsize, 1);
xmlFreeDoc (doc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]