diff options
author | infirit <[email protected]> | 2014-12-09 12:44:15 +0100 |
---|---|---|
committer | infirit <[email protected]> | 2014-12-09 23:02:27 +0100 |
commit | 21b6463cd687edfbf40bbb6df1cca239d7a6b925 (patch) | |
tree | 1e4362ae5085e6a5d1a2092c41884f7617181e84 /backend | |
parent | 07ac65d00384adeec314e677a66a5bb2dcb90cd0 (diff) | |
download | atril-21b6463cd687edfbf40bbb6df1cca239d7a6b925.tar.bz2 atril-21b6463cd687edfbf40bbb6df1cca239d7a6b925.tar.xz |
[djvu] Implement document_links_find_link_page()
Taken from evince commit: 4f13859ce0aa0918a5c6a0a24686d97ffd7d2ee2
From: Carlos Garcia Campos <[email protected]>
Diffstat (limited to 'backend')
-rw-r--r-- | backend/djvu/djvu-document.c | 1 | ||||
-rw-r--r-- | backend/djvu/djvu-links.c | 34 | ||||
-rw-r--r-- | 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 bddcef51..3cdb7043 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -703,4 +703,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 c5e72870..5999ebcd 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 76d9072c..6cacdd36 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__ */ |