X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=backend%2Fdjvu%2Fdjvu-links.c;h=87057d49d4f7dcbadbe36b9e21a2c3baab1242cf;hb=4f6105d3df2cbf07bccd7de156693aab7e71bc31;hp=38fad0d198943de0fce5d5528831dd8fdf36077c;hpb=13a06349251874bd35d2f03c3fc93217cee749a2;p=evince.git diff --git a/backend/djvu/djvu-links.c b/backend/djvu/djvu-links.c index 38fad0d1..87057d49 100644 --- a/backend/djvu/djvu-links.c +++ b/backend/djvu/djvu-links.c @@ -18,15 +18,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#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) { @@ -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 * @@ -141,7 +173,16 @@ build_tree (const DjvuDocument *djvu_document, 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)) { + gchar *utf8_title; + + utf8_title = str_to_utf8 (title); + title_markup = g_markup_escape_text (utf8_title, -1); + g_free (utf8_title); + } 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")) { @@ -383,7 +424,8 @@ djvu_links_get_links_model (EvDocumentLinks *document_links) model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_OBJECT, - G_TYPE_BOOLEAN); + G_TYPE_BOOLEAN, + G_TYPE_STRING); build_tree (djvu_document, model, NULL, outline); ddjvu_miniexp_release (djvu_document->d_document, outline);