24 #include <libdjvu/miniexp.h>
33 if (miniexp_numberp (sexp)) {
34 *number = miniexp_to_int (sexp);
43 if (miniexp_stringp (sexp)) {
44 *str = miniexp_to_str (sexp);
55 *number = g_ascii_strtoull(str, &end_ptr, 10);
56 if (*end_ptr ==
'\0') {
69 if (g_str_has_prefix (link_name,
"#")) {
70 if (g_str_has_suffix (link_name,
".djvu")) {
74 if (g_hash_table_lookup_extended (djvu_document->
file_ids, link_name + 1, NULL, &page)) {
75 return GPOINTER_TO_INT (page);
77 }
else if (base_page > 0 && g_str_has_prefix (link_name + 1,
"+")) {
79 return base_page + page_num;
81 }
else if (base_page > 0 && g_str_has_prefix (link_name + 1,
"-")) {
83 return base_page - page_num;
101 if (g_str_has_prefix (link_name,
"#")) {
102 if (g_str_has_suffix (link_name,
".djvu") ||
103 (base_page > 0 && g_str_has_prefix (link_name + 1,
"+")) ||
104 (base_page > 0 && g_str_has_prefix (link_name + 1,
"-"))) {
128 g_object_unref (ev_dest);
129 }
else if (strstr(link_name,
"://") != NULL) {
140 static const gchar *encodings_to_try[2];
141 static gint n_encodings_to_try = 0;
142 gchar *utf8_text = NULL;
145 if (n_encodings_to_try == 0) {
146 const gchar *charset;
147 gboolean charset_is_utf8;
149 charset_is_utf8 = g_get_charset (&charset);
150 if (!charset_is_utf8) {
151 encodings_to_try[n_encodings_to_try++] = charset;
154 if (g_ascii_strcasecmp (charset,
"ISO-8859-1") != 0) {
155 encodings_to_try[n_encodings_to_try++] =
"ISO-8859-1";
159 for (i = 0; i < n_encodings_to_try; i++) {
160 utf8_text = g_convert (text, -1,
"UTF-8",
188 const char *title, *link_dest;
193 GtkTreeIter tree_iter;
195 if (miniexp_car (iter) == miniexp_symbol (
"bookmarks")) {
197 iter = miniexp_cdr (iter);
198 }
else if ( miniexp_length (iter) >= 2 ) {
199 gchar *utf8_title = NULL;
206 if (!g_utf8_validate (title, -1, NULL)) {
208 title_markup = g_markup_escape_text (utf8_title, -1);
210 title_markup = g_markup_escape_text (title, -1);
216 ev_link =
ev_link_new (utf8_title ? utf8_title : title, ev_action);
217 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
218 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
223 g_object_unref (ev_action);
224 g_object_unref (ev_link);
226 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
227 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
233 g_free (title_markup);
235 iter = miniexp_cddr (iter);
241 for (; iter != miniexp_nil; iter = miniexp_cdr (iter)) {
242 build_tree (djvu_document, model, parent, miniexp_car (iter));
247 g_warning (
"DjvuLibre error: Unknown entry in bookmarks");
260 if ((miniexp_car (iter) == miniexp_symbol (
"rect") || miniexp_car (iter) == miniexp_symbol (
"oval"))
261 && miniexp_length (iter) == 5) {
263 int minx, miny, width, height;
265 iter = miniexp_cdr (iter);
267 iter = miniexp_cdr (iter);
269 iter = miniexp_cdr (iter);
271 iter = miniexp_cdr (iter);
274 ev_link_mapping->
area.
x1 = minx;
275 ev_link_mapping->
area.
x2 = (minx + width);
276 ev_link_mapping->
area.
y1 = (page_info->height - (miny + height));
277 ev_link_mapping->
area.
y2 = (page_info->height - miny);
278 }
else if (miniexp_car (iter) == miniexp_symbol (
"poly")
279 && miniexp_length (iter) >= 5 && miniexp_length (iter) % 2 == 1) {
282 int minx = G_MAXINT, miny = G_MAXINT;
283 int maxx = G_MININT, maxy = G_MININT;
285 iter = miniexp_cdr(iter);
286 while (iter != miniexp_nil) {
290 iter = miniexp_cdr (iter);
292 iter = miniexp_cdr (iter);
294 minx = MIN (minx, x);
295 miny = MIN (miny, y);
296 maxx = MAX (maxx, x);
297 maxy = MAX (maxy, y);
300 ev_link_mapping->
area.
x1 = minx;
301 ev_link_mapping->
area.
x2 = maxx;
302 ev_link_mapping->
area.
y1 = (page_info->height - maxy);
303 ev_link_mapping->
area.
y2 = (page_info->height - miny);
312 g_warning(
"DjvuLibre error: Unknown hyperlink area %s", miniexp_to_name(miniexp_car(sexp)));
319 ddjvu_pageinfo_t *page_info,
325 const char *url, *url_target, *comment;
331 if (miniexp_car (iter) != miniexp_symbol (
"maparea"))
goto unknown_mapping;
333 iter = miniexp_cdr(iter);
335 if (miniexp_caar(iter) == miniexp_symbol(
"url")) {
337 if (!
string_from_miniexp (miniexp_caddr (miniexp_car (iter)), &url_target))
goto unknown_mapping;
343 iter = miniexp_cdr (iter);
346 iter = miniexp_cdr (iter);
349 iter = miniexp_cdr (iter);
353 if (!ev_action)
goto unknown_mapping;
356 g_object_unref (ev_action);
358 return ev_link_mapping;
361 if (ev_link_mapping) g_free(ev_link_mapping);
362 g_warning(
"DjvuLibre error: Unknown hyperlink %s", miniexp_to_name(miniexp_car(sexp)));
373 while ((outline = ddjvu_document_get_outline (djvu_document->
d_document)) == miniexp_dummy)
377 ddjvu_miniexp_release (djvu_document->
d_document, outline);
390 GList *retval = NULL;
391 miniexp_t page_annotations = miniexp_nil;
392 miniexp_t *hyperlinks = NULL, *iter = NULL;
394 ddjvu_pageinfo_t page_info;
396 while ((page_annotations = ddjvu_document_get_pageanno (djvu_document->
d_document, page)) == miniexp_dummy)
399 while (ddjvu_document_get_pageinfo (djvu_document->
d_document, page, &page_info) < DDJVU_JOB_OK)
402 if (page_annotations) {
403 hyperlinks = ddjvu_anno_get_hyperlinks (page_annotations);
405 for (iter = hyperlinks; *iter; ++iter) {
407 if (ev_link_mapping) {
408 ev_link_mapping->
area.
x1 *= scale_factor;
409 ev_link_mapping->
area.
x2 *= scale_factor;
410 ev_link_mapping->
area.
y1 *= scale_factor;
411 ev_link_mapping->
area.
y2 *= scale_factor;
412 retval = g_list_prepend (retval, ev_link_mapping);
417 ddjvu_miniexp_release (djvu_document->
d_document, page_annotations);
425 const gchar *link_name)
433 g_warning (
"DjvuLibre error: unknown link destination %s", link_name);
441 const gchar *link_name)
449 g_warning (
"DjvuLibre error: unknown link destination %s", link_name);
459 GtkTreeModel *model = NULL;
460 miniexp_t outline = miniexp_nil;
462 while ((outline = ddjvu_document_get_outline (djvu_document->
d_document)) == miniexp_dummy)
471 build_tree (djvu_document, model, NULL, outline);
473 ddjvu_miniexp_release (djvu_document->
d_document, outline);