X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=backend%2Fdjvu%2Fdjvu-links.c;h=d54c410bb79586090f930a63ba4d4f0abce542fe;hb=0b6b3dff626d31a368ef9a95f8ed73b404eec9bf;hp=1fc394ada488f6927f04f803aab3e47a6d68853d;hpb=4bb9bc83e2de5cd88fa2e3f81a7da6e7d81cbf99;p=evince.git diff --git a/backend/djvu/djvu-links.c b/backend/djvu/djvu-links.c index 1fc394ad..d54c410b 100644 --- a/backend/djvu/djvu-links.c +++ b/backend/djvu/djvu-links.c @@ -18,15 +18,15 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include +#include +#include +#include #include "djvu-document.h" #include "djvu-links.h" #include "djvu-document-private.h" #include "ev-document-links.h" -#include -#include -#include -#include static gboolean number_from_miniexp(miniexp_t sexp, int *number) { @@ -64,7 +64,6 @@ static EvLinkDest * get_djvu_link_dest (const DjvuDocument *djvu_document, const gchar *link_name, int base_page) { guint64 page_num = 0; - gchar *end_ptr; /* #pagenum, #+pageoffset, #-pageoffset */ if (g_str_has_prefix (link_name, "#")) { @@ -108,6 +107,39 @@ get_djvu_link_action (const DjvuDocument *djvu_document, const gchar *link_name, return ev_action; } +static gchar * +str_to_utf8 (const gchar *text) +{ + static const gchar *encodings_to_try[2]; + static gint n_encodings_to_try = 0; + gchar *utf8_text = NULL; + gint i; + + if (n_encodings_to_try == 0) { + const gchar *charset; + gboolean charset_is_utf8; + + charset_is_utf8 = g_get_charset (&charset); + if (!charset_is_utf8) { + encodings_to_try[n_encodings_to_try++] = charset; + } + + if (g_ascii_strcasecmp (charset, "ISO-8859-1") != 0) { + encodings_to_try[n_encodings_to_try++] = "ISO-8859-1"; + } + } + + for (i = 0; i < n_encodings_to_try; i++) { + utf8_text = g_convert (text, -1, "UTF-8", + encodings_to_try[i], + NULL, NULL, NULL); + if (utf8_text) + break; + } + + return utf8_text; +} + /** * Builds the index GtkTreeModel from DjVu s-expr * @@ -137,17 +169,26 @@ build_tree (const DjvuDocument *djvu_document, /* The (bookmarks) cons */ iter = miniexp_cdr (iter); } else if ( miniexp_length (iter) >= 2 ) { + gchar *utf8_title = NULL; + /* An entry */ if (!string_from_miniexp (miniexp_car (iter), &title)) goto unknown_entry; if (!string_from_miniexp (miniexp_cadr (iter), &link_dest)) goto unknown_entry; - title_markup = g_markup_escape_text (title, -1); + + if (!g_utf8_validate (title, -1, NULL)) { + utf8_title = str_to_utf8 (title); + title_markup = g_markup_escape_text (utf8_title, -1); + } else { + title_markup = g_markup_escape_text (title, -1); + } + ev_action = get_djvu_link_action (djvu_document, link_dest, -1); if (g_str_has_suffix (link_dest, ".djvu")) { /* FIXME: component file identifiers */ } else if (ev_action) { - ev_link = ev_link_new (title, ev_action); + ev_link = ev_link_new (utf8_title ? utf8_title : title, ev_action); gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent); gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter, EV_DOCUMENT_LINKS_COLUMN_MARKUP, title_markup, @@ -164,7 +205,7 @@ build_tree (const DjvuDocument *djvu_document, } g_free (title_markup); - + g_free (utf8_title); iter = miniexp_cddr (iter); parent = &tree_iter; } else { @@ -187,7 +228,6 @@ get_djvu_hyperlink_area (ddjvu_pageinfo_t *page_info, EvLinkMapping *ev_link_mapping) { miniexp_t iter; - ddjvu_pageinfo_t info; iter = sexp; @@ -304,7 +344,7 @@ djvu_links_has_document_links (EvDocumentLinks *document_links) miniexp_t outline; while ((outline = ddjvu_document_get_outline (djvu_document->d_document)) == miniexp_dummy) - djvu_handle_events (djvu_document, TRUE); + djvu_handle_events (djvu_document, TRUE, NULL); if (outline) { ddjvu_miniexp_release (djvu_document->d_document, outline); @@ -327,10 +367,10 @@ djvu_links_get_links (EvDocumentLinks *document_links, ddjvu_pageinfo_t page_info; while ((page_annotations = ddjvu_document_get_pageanno (djvu_document->d_document, page)) == miniexp_dummy) - djvu_handle_events (djvu_document, TRUE); + djvu_handle_events (djvu_document, TRUE, NULL); while (ddjvu_document_get_pageinfo (djvu_document->d_document, page, &page_info) < DDJVU_JOB_OK) - djvu_handle_events(djvu_document, TRUE); + djvu_handle_events(djvu_document, TRUE, NULL); if (page_annotations) { hyperlinks = ddjvu_anno_get_hyperlinks (page_annotations); @@ -360,7 +400,7 @@ djvu_links_find_link_dest (EvDocumentLinks *document_links, DjvuDocument *djvu_document = DJVU_DOCUMENT (document_links); EvLinkDest *ev_dest = NULL; - ev_dest = get_djvu_link_dest (DJVU_DOCUMENT (document_links), link_name, -1); + ev_dest = get_djvu_link_dest (djvu_document, link_name, -1); if (!ev_dest) { g_warning ("DjvuLibre error: unknown link destination %s", link_name); @@ -377,7 +417,7 @@ djvu_links_get_links_model (EvDocumentLinks *document_links) miniexp_t outline = miniexp_nil; while ((outline = ddjvu_document_get_outline (djvu_document->d_document)) == miniexp_dummy) - djvu_handle_events (djvu_document, TRUE); + djvu_handle_events (djvu_document, TRUE, NULL); if (outline) { model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,