[evince] [djvu] Implement document_links_find_link_page()



commit 4f13859ce0aa0918a5c6a0a24686d97ffd7d2ee2
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Fri Sep 3 10:29:33 2010 +0200

    [djvu] Implement document_links_find_link_page()

 backend/djvu/djvu-document.c |    1 +
 backend/djvu/djvu-links.c    |   34 ++++++++++++++++++++++++++++------
 backend/djvu/djvu-links.h    |    2 ++
 3 files changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c
index 3349f40..89925e4 100644
--- a/backend/djvu/djvu-document.c
+++ b/backend/djvu/djvu-document.c
@@ -665,4 +665,5 @@ djvu_document_document_links_iface_init  (EvDocumentLinksInterface *iface)
 	iface->get_links_model = djvu_links_get_links_model;
 	iface->get_links = djvu_document_links_get_links;
 	iface->find_link_dest = djvu_links_find_link_dest;
+	iface->find_link_page = djvu_links_find_link_page;
 }
diff --git a/backend/djvu/djvu-links.c b/backend/djvu/djvu-links.c
index d13af0b..e4d2791 100644
--- a/backend/djvu/djvu-links.c
+++ b/backend/djvu/djvu-links.c
@@ -60,8 +60,8 @@ static gboolean number_from_string_10(const gchar *str, guint64 *number)
 	}
 }
 
-static EvLinkDest *
-get_djvu_link_dest (const DjvuDocument *djvu_document, const gchar *link_name, int base_page)
+static guint64
+get_djvu_link_page (const DjvuDocument *djvu_document, const gchar *link_name, int base_page)
 {
 	guint64 page_num = 0;
 
@@ -69,22 +69,28 @@ get_djvu_link_dest (const DjvuDocument *djvu_document, const gchar *link_name, i
 	if (g_str_has_prefix (link_name, "#")) {
 		if (base_page > 0 && g_str_has_prefix (link_name+1, "+")) {
 			if (number_from_string_10 (link_name + 2, &page_num)) {
-				return ev_link_dest_new_page (base_page + page_num);
+				return base_page + page_num;
 			}
 		} else if (base_page > 0 && g_str_has_prefix (link_name+1, "-")) {
 			if (number_from_string_10 (link_name + 2, &page_num)) {
-				return ev_link_dest_new_page (base_page - page_num);
+				return base_page - page_num;
 			}
 		} else {
 			if (number_from_string_10 (link_name + 1, &page_num)) {
-				return ev_link_dest_new_page (page_num - 1);
+				return page_num - 1;
 			}
 		}
 	} else {
 		/* FIXME: component file identifiers */
 	}
 
-	return NULL;
+	return page_num;
+}
+
+static EvLinkDest *
+get_djvu_link_dest (const DjvuDocument *djvu_document, const gchar *link_name, int base_page)
+{
+	return ev_link_dest_new_page (get_djvu_link_page (djvu_document, link_name, base_page));
 }
 
 static EvLinkAction *
@@ -409,6 +415,22 @@ djvu_links_find_link_dest (EvDocumentLinks  *document_links,
 	return ev_dest;
 }
 
+gint
+djvu_links_find_link_page (EvDocumentLinks  *document_links,
+			   const gchar      *link_name)
+{
+	DjvuDocument *djvu_document = DJVU_DOCUMENT (document_links);
+	gint page;
+
+	page = get_djvu_link_page (djvu_document, link_name, -1);
+
+	if (page == -1) {
+		g_warning ("DjvuLibre error: unknown link destination %s", link_name);
+	}
+
+	return page;
+}
+
 GtkTreeModel *
 djvu_links_get_links_model (EvDocumentLinks *document_links)
 {
diff --git a/backend/djvu/djvu-links.h b/backend/djvu/djvu-links.h
index 76d9072..6cacdd3 100644
--- a/backend/djvu/djvu-links.h
+++ b/backend/djvu/djvu-links.h
@@ -30,6 +30,8 @@ EvMappingList *djvu_links_get_links          (EvDocumentLinks *document_links,
 					      double           scale_factor);
 EvLinkDest    *djvu_links_find_link_dest     (EvDocumentLinks *document_links,
 					      const gchar     *link_name);
+gint           djvu_links_find_link_page     (EvDocumentLinks *document_links,
+					      const gchar     *link_name);
 gboolean       djvu_links_has_document_links (EvDocumentLinks *document_links);
 
 #endif /* __DJVU_LINK_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]