]> www.fi.muni.cz Git - evince.git/blob - backend/djvu/djvu-document.c
a9559c22d854583431154dd1f6156395972d55d1
[evince.git] / backend / djvu / djvu-document.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /*
3  * Copyright (C) 2005, Nickolay V. Shmyrev <nshmyrev@yandex.ru>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <config.h>
23 #include "djvu-document.h"
24 #include "djvu-text-page.h"
25 #include "djvu-links.h"
26 #include "djvu-document-private.h"
27 #include "ev-document-thumbnails.h"
28 #include "ev-file-exporter.h"
29 #include "ev-document-misc.h"
30 #include "ev-document-find.h"
31 #include "ev-document-links.h"
32 #include "ev-selection.h"
33 #include "ev-file-helpers.h"
34
35 #include <gdk-pixbuf/gdk-pixbuf-core.h>
36 #include <glib/gi18n.h>
37 #include <glib/gunicode.h>
38 #include <string.h>
39
40 #define SCALE_FACTOR 0.2
41
42 enum {
43         PROP_0,
44         PROP_TITLE
45 };
46
47 struct _DjvuDocumentClass
48 {
49         GObjectClass parent_class;
50 };
51
52 typedef struct _DjvuDocumentClass DjvuDocumentClass;
53
54 static void djvu_document_document_iface_init (EvDocumentIface *iface);
55 static void djvu_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
56 static void djvu_document_file_exporter_iface_init (EvFileExporterIface *iface);
57 static void djvu_document_find_iface_init (EvDocumentFindIface *iface);
58 static void djvu_document_document_links_iface_init  (EvDocumentLinksIface *iface);
59 static void djvu_selection_iface_init (EvSelectionIface *iface);
60
61 EV_BACKEND_REGISTER_WITH_CODE (DjvuDocument, djvu_document,
62     {
63       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, djvu_document_document_thumbnails_iface_init);
64       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, djvu_document_file_exporter_iface_init);
65       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, djvu_document_find_iface_init);
66       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS, djvu_document_document_links_iface_init);
67       EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION, djvu_selection_iface_init);
68      });
69
70
71 #define EV_DJVU_ERROR ev_djvu_error_quark ()
72
73 static GQuark
74 ev_djvu_error_quark (void)
75 {
76         static GQuark q = 0;
77         if (q == 0)
78                 q = g_quark_from_static_string ("ev-djvu-quark");
79         
80         return q;
81 }
82
83 static void
84 handle_message (const ddjvu_message_t *msg, GError **error)
85 {
86         switch (msg->m_any.tag) {
87                 case DDJVU_ERROR: {
88                         gchar *error_str;
89                         
90                         if (msg->m_error.filename) {
91                                 error_str = g_strdup_printf ("DjvuLibre error: %s:%d",
92                                                              msg->m_error.filename,
93                                                              msg->m_error.lineno);
94                         } else {
95                                 error_str = g_strdup_printf ("DjvuLibre error: %s",
96                                                              msg->m_error.message);
97                         }
98                         
99                         if (error) {
100                                 g_set_error_literal (error, EV_DJVU_ERROR, 0, error_str);
101                         } else {
102                                 g_warning ("%s", error_str);
103                         }
104                                 
105                         g_free (error_str);
106                         return;
107                         }                                                    
108                         break;
109                 default:
110                         break;
111         }
112 }
113
114 void
115 djvu_handle_events (DjvuDocument *djvu_document, int wait, GError **error)
116 {
117         ddjvu_context_t *ctx = djvu_document->d_context;
118         const ddjvu_message_t *msg;
119         
120         if (!ctx)
121                 return;
122
123         if (wait)
124                 ddjvu_message_wait (ctx);
125
126         while ((msg = ddjvu_message_peek (ctx))) {
127                 handle_message (msg, error);
128                 ddjvu_message_pop (ctx);
129                 if (error && *error)
130                         return;
131         }
132 }
133
134 static void
135 djvu_wait_for_message (DjvuDocument *djvu_document, ddjvu_message_tag_t message, GError **error)
136 {
137         ddjvu_context_t *ctx = djvu_document->d_context;
138         const ddjvu_message_t *msg;
139
140         ddjvu_message_wait (ctx);
141         while ((msg = ddjvu_message_peek (ctx)) && (msg->m_any.tag != message)) {
142                 handle_message (msg, error);
143                 ddjvu_message_pop (ctx);
144                 if (error && *error)
145                         return;
146         }
147         if (msg && msg->m_any.tag == message)
148                 ddjvu_message_pop (ctx);
149 }
150
151 static gboolean
152 djvu_document_load (EvDocument  *document,
153                     const char  *uri,
154                     GError     **error)
155 {
156         DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
157         ddjvu_document_t *doc;
158         gchar *filename;
159         gboolean missing_files = FALSE;
160         GError *djvu_error = NULL;
161
162         /* FIXME: We could actually load uris  */
163         filename = g_filename_from_uri (uri, NULL, error);
164         if (!filename)
165                 return FALSE;
166         
167         doc = ddjvu_document_create_by_filename (djvu_document->d_context, filename, TRUE);
168
169         if (!doc) {
170                 g_free (filename);
171                 return FALSE;
172         }
173
174         if (djvu_document->d_document)
175             ddjvu_document_release (djvu_document->d_document);
176
177         djvu_document->d_document = doc;
178
179         djvu_wait_for_message (djvu_document, DDJVU_DOCINFO, &djvu_error);
180         if (djvu_error) {
181                 g_set_error_literal (error,
182                                      EV_DOCUMENT_ERROR,
183                                      EV_DOCUMENT_ERROR_INVALID,
184                                      djvu_error->message);
185                 g_error_free (djvu_error);
186                 g_free (filename);
187                 ddjvu_document_release (djvu_document->d_document);
188                 djvu_document->d_document = NULL;
189
190                 return FALSE;
191         }
192
193         if (ddjvu_document_decoding_error (djvu_document->d_document))
194                 djvu_handle_events (djvu_document, TRUE, &djvu_error);
195
196         if (djvu_error) {
197                 g_set_error_literal (error,
198                                      EV_DOCUMENT_ERROR,
199                                      EV_DOCUMENT_ERROR_INVALID,
200                                      djvu_error->message);
201                 g_error_free (djvu_error);
202                 g_free (filename);
203                 ddjvu_document_release (djvu_document->d_document);
204                 djvu_document->d_document = NULL;
205                 
206                 return FALSE;
207         }
208         
209         g_free (djvu_document->uri);
210         djvu_document->uri = g_strdup (uri);
211
212         if (ddjvu_document_get_type (djvu_document->d_document) == DDJVU_DOCTYPE_INDIRECT) {
213                 gint n_files;
214                 gint i;
215                 gchar *base;
216
217                 base = g_path_get_dirname (filename);
218
219                 n_files = ddjvu_document_get_filenum (djvu_document->d_document);
220                 for (i = 0; i < n_files; i++) {
221                         struct ddjvu_fileinfo_s fileinfo;
222                         gchar *file;
223                         
224                         ddjvu_document_get_fileinfo (djvu_document->d_document,
225                                                      i, &fileinfo);
226
227                         if (fileinfo.type != 'P')
228                                 continue;
229
230                         file = g_build_filename (base, fileinfo.id, NULL);
231                         if (!g_file_test (file, G_FILE_TEST_EXISTS)) {
232                                 missing_files = TRUE;
233                                 g_free (file);
234                                 
235                                 break;
236                         }
237                         g_free (file);
238                 }
239                 g_free (base);
240         }
241         g_free (filename);
242
243         if (missing_files) {
244                 g_set_error (error,
245                              G_FILE_ERROR,
246                              G_FILE_ERROR_EXIST,
247                              _("The document is composed by several files. "
248                                "One or more of such files cannot be accessed."));
249
250                 return FALSE;
251         }
252
253         return TRUE;
254 }
255
256
257 static gboolean
258 djvu_document_save (EvDocument  *document,
259                     const char  *uri,
260                     GError     **error)
261 {
262         DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
263
264         return ev_xfer_uri_simple (djvu_document->uri, uri, error);
265 }
266
267 int
268 djvu_document_get_n_pages (EvDocument  *document)
269 {
270         DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
271         
272         g_return_val_if_fail (djvu_document->d_document, 0);
273         
274         return ddjvu_document_get_pagenum (djvu_document->d_document);
275 }
276
277 static void
278 document_get_page_size (DjvuDocument *djvu_document,
279                         gint          page,
280                         double       *width,
281                         double       *height)
282 {
283         ddjvu_pageinfo_t info;
284         ddjvu_status_t r;
285         
286         while ((r = ddjvu_document_get_pageinfo(djvu_document->d_document, page, &info)) < DDJVU_JOB_OK)
287                 djvu_handle_events(djvu_document, TRUE, NULL);
288         
289         if (r >= DDJVU_JOB_FAILED)
290                 djvu_handle_events(djvu_document, TRUE, NULL);
291
292         *width = info.width * SCALE_FACTOR; 
293         *height = info.height * SCALE_FACTOR;
294 }
295
296 static void
297 djvu_document_get_page_size (EvDocument   *document,
298                              EvPage       *page,
299                              double       *width,
300                              double       *height)
301 {
302         DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
303
304         g_return_if_fail (djvu_document->d_document);
305
306         document_get_page_size (djvu_document, page->index,
307                                 width, height);
308 }
309
310 static cairo_surface_t *
311 djvu_document_render (EvDocument      *document, 
312                       EvRenderContext *rc)
313 {
314         DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
315         cairo_surface_t *surface;
316         gchar *pixels;
317         gint   rowstride;
318         ddjvu_rect_t rrect;
319         ddjvu_rect_t prect;
320         ddjvu_page_t *d_page;
321         ddjvu_page_rotation_t rotation;
322         double page_width, page_height, tmp;
323         static const cairo_user_data_key_t key;
324
325         d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page->index);
326         
327         while (!ddjvu_page_decoding_done (d_page))
328                 djvu_handle_events(djvu_document, TRUE, NULL);
329
330         page_width = ddjvu_page_get_width (d_page) * rc->scale * SCALE_FACTOR + 0.5;
331         page_height = ddjvu_page_get_height (d_page) * rc->scale * SCALE_FACTOR + 0.5;
332         
333         switch (rc->rotation) {
334                 case 90:
335                         rotation = DDJVU_ROTATE_90;
336                         tmp = page_height;
337                         page_height = page_width;
338                         page_width = tmp;
339                         
340                         break;
341                 case 180:
342                         rotation = DDJVU_ROTATE_180;
343                         
344                         break;
345                 case 270:
346                         rotation = DDJVU_ROTATE_270;
347                         tmp = page_height;
348                         page_height = page_width;
349                         page_width = tmp;
350                         
351                         break;
352                 default:
353                         rotation = DDJVU_ROTATE_0;
354         }
355 #ifdef HAVE_CAIRO_FORMAT_STRIDE_FOR_WIDTH
356         rowstride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, page_width);
357 #else
358         rowstride = page_width * 4;
359 #endif
360         pixels = (gchar *) g_malloc (page_height * rowstride);
361         surface = cairo_image_surface_create_for_data ((guchar *)pixels,
362                                                        CAIRO_FORMAT_RGB24,
363                                                        page_width,
364                                                        page_height,
365                                                        rowstride);
366         cairo_surface_set_user_data (surface, &key,
367                                      pixels, (cairo_destroy_func_t)g_free);
368         prect.x = 0;
369         prect.y = 0;
370         prect.w = page_width;
371         prect.h = page_height;
372         rrect = prect;
373
374         ddjvu_page_set_rotation (d_page, rotation);
375         
376         ddjvu_page_render (d_page, DDJVU_RENDER_COLOR,
377                            &prect,
378                            &rrect,
379                            djvu_document->d_format,
380                            rowstride,
381                            pixels);
382
383         return surface;
384 }
385
386 static void
387 djvu_document_finalize (GObject *object)
388 {
389         DjvuDocument *djvu_document = DJVU_DOCUMENT (object);
390
391         if (djvu_document->d_document)
392             ddjvu_document_release (djvu_document->d_document);
393             
394         if (djvu_document->opts)
395             g_string_free (djvu_document->opts, TRUE);
396
397         if (djvu_document->ps_filename)
398             g_free (djvu_document->ps_filename);
399             
400         ddjvu_context_release (djvu_document->d_context);
401         ddjvu_format_release (djvu_document->d_format);
402         ddjvu_format_release (djvu_document->thumbs_format);
403         g_free (djvu_document->uri);
404         
405         G_OBJECT_CLASS (djvu_document_parent_class)->finalize (object);
406 }
407
408 static void
409 djvu_document_class_init (DjvuDocumentClass *klass)
410 {
411         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
412
413         gobject_class->finalize = djvu_document_finalize;
414 }
415
416 static EvDocumentInfo *
417 djvu_document_get_info (EvDocument *document)
418 {
419         EvDocumentInfo *info;
420
421         info = g_new0 (EvDocumentInfo, 1);
422
423         return info;
424 }
425
426 static void
427 djvu_document_document_iface_init (EvDocumentIface *iface)
428 {
429         iface->load = djvu_document_load;
430         iface->save = djvu_document_save;
431         iface->get_n_pages = djvu_document_get_n_pages;
432         iface->get_page_size = djvu_document_get_page_size;
433         iface->render = djvu_document_render;
434         iface->get_info = djvu_document_get_info;
435 }
436
437 static gchar *
438 djvu_text_copy (DjvuDocument *djvu_document,
439                 gint           page,
440                 EvRectangle  *rectangle)
441 {
442         miniexp_t page_text;
443         gchar    *text = NULL;
444
445         while ((page_text =
446                 ddjvu_document_get_pagetext (djvu_document->d_document,
447                                              page, "char")) == miniexp_dummy)
448                 djvu_handle_events (djvu_document, TRUE, NULL);
449
450         if (page_text != miniexp_nil) {
451                 DjvuTextPage *page = djvu_text_page_new (page_text);
452                 
453                 text = djvu_text_page_copy (page, rectangle);
454                 djvu_text_page_free (page);
455                 ddjvu_miniexp_release (djvu_document->d_document, page_text);
456         }
457
458         return text;
459 }
460
461 static gchar *
462 djvu_selection_get_selected_text (EvSelection     *selection,
463                                   EvRenderContext *rc,
464                                   EvSelectionStyle style,
465                                   EvRectangle     *points)
466 {
467         DjvuDocument *djvu_document = DJVU_DOCUMENT (selection);
468         double width, height;
469         EvRectangle rectangle;
470         gchar *text;
471              
472         djvu_document_get_page_size (EV_DOCUMENT (djvu_document),
473                                      rc->page, &width, &height);                
474         rectangle.x1 = points->x1 / SCALE_FACTOR;
475         rectangle.y1 = (height - points->y2) / SCALE_FACTOR;
476         rectangle.x2 = points->x2 / SCALE_FACTOR;
477         rectangle.y2 = (height - points->y1) / SCALE_FACTOR;
478                 
479         text = djvu_text_copy (djvu_document, rc->page->index, &rectangle);
480       
481         if (text == NULL)
482                 text = g_strdup ("");
483                 
484         return text;
485 }
486
487 static void
488 djvu_selection_iface_init (EvSelectionIface *iface)
489 {
490         iface->get_selected_text = djvu_selection_get_selected_text;
491 }
492
493 static void
494 djvu_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
495                                          EvRenderContext      *rc, 
496                                          gint                 *width,
497                                          gint                 *height)
498 {
499         DjvuDocument *djvu_document = DJVU_DOCUMENT (document); 
500         gdouble page_width, page_height;
501         
502         djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page,
503                                      &page_width, &page_height);
504
505         if (rc->rotation == 90 || rc->rotation == 270) {
506                 *width = (gint) (page_height * rc->scale);
507                 *height = (gint) (page_width * rc->scale);
508         } else {
509                 *width = (gint) (page_width * rc->scale);
510                 *height = (gint) (page_height * rc->scale);
511         }
512 }
513
514 static GdkPixbuf *
515 djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
516                                         EvRenderContext      *rc,
517                                         gboolean              border)
518 {
519         DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
520         GdkPixbuf *pixbuf, *rotated_pixbuf;
521         gdouble page_width, page_height;
522         gint thumb_width, thumb_height;
523         guchar *pixels;
524         
525         g_return_val_if_fail (djvu_document->d_document, NULL);
526
527         djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page,
528                                      &page_width, &page_height);
529         
530         thumb_width = (gint) (page_width * rc->scale);
531         thumb_height = (gint) (page_height * rc->scale);
532
533         pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
534                                  thumb_width, thumb_height);
535         gdk_pixbuf_fill (pixbuf, 0xffffffff);
536         pixels = gdk_pixbuf_get_pixels (pixbuf);
537         
538         while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page->index, 1) < DDJVU_JOB_OK)
539                 djvu_handle_events(djvu_document, TRUE, NULL);
540                     
541         ddjvu_thumbnail_render (djvu_document->d_document, rc->page->index, 
542                                 &thumb_width, &thumb_height,
543                                 djvu_document->thumbs_format,
544                                 gdk_pixbuf_get_rowstride (pixbuf), 
545                                 (gchar *)pixels);
546
547         rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation);
548         g_object_unref (pixbuf);
549
550         if (border) {
551               GdkPixbuf *tmp_pixbuf = rotated_pixbuf;
552               
553               rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
554               g_object_unref (tmp_pixbuf);
555         }
556         
557         return rotated_pixbuf;
558 }
559
560 static void
561 djvu_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
562 {
563         iface->get_thumbnail = djvu_document_thumbnails_get_thumbnail;
564         iface->get_dimensions = djvu_document_thumbnails_get_dimensions;
565 }
566
567 /* EvFileExporterIface */
568 static void
569 djvu_document_file_exporter_begin (EvFileExporter        *exporter,
570                                    EvFileExporterContext *fc)
571 {
572         DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
573         
574         if (djvu_document->ps_filename)
575                 g_free (djvu_document->ps_filename);    
576         djvu_document->ps_filename = g_strdup (fc->filename);
577
578         g_string_assign (djvu_document->opts, "-page=");
579 }
580
581 static void
582 djvu_document_file_exporter_do_page (EvFileExporter  *exporter,
583                                      EvRenderContext *rc)
584 {
585         DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
586         
587         g_string_append_printf (djvu_document->opts, "%d,", (rc->page->index) + 1); 
588 }
589
590 static void
591 djvu_document_file_exporter_end (EvFileExporter *exporter)
592 {
593         int d_optc = 1; 
594         const char *d_optv[d_optc];
595
596         DjvuDocument *djvu_document = DJVU_DOCUMENT (exporter);
597
598         FILE *fn = fopen (djvu_document->ps_filename, "w");
599         if (fn == NULL) {
600                 g_warning ("Cannot open file ā€œ%sā€.", djvu_document->ps_filename);
601                 return;
602         }
603         
604         d_optv[0] = djvu_document->opts->str; 
605
606         ddjvu_job_t * job = ddjvu_document_print(djvu_document->d_document, fn, d_optc, d_optv);
607         while (!ddjvu_job_done(job)) {  
608                 djvu_handle_events (djvu_document, TRUE, NULL);
609         }
610
611         fclose(fn); 
612 }
613
614 static EvFileExporterCapabilities
615 djvu_document_file_exporter_get_capabilities (EvFileExporter *exporter)
616 {
617         return  EV_FILE_EXPORTER_CAN_PAGE_SET |
618                 EV_FILE_EXPORTER_CAN_COPIES |
619                 EV_FILE_EXPORTER_CAN_COLLATE |
620                 EV_FILE_EXPORTER_CAN_REVERSE |
621                 EV_FILE_EXPORTER_CAN_GENERATE_PS;
622 }
623
624 static void
625 djvu_document_file_exporter_iface_init (EvFileExporterIface *iface)
626 {
627         iface->begin = djvu_document_file_exporter_begin;
628         iface->do_page = djvu_document_file_exporter_do_page;
629         iface->end = djvu_document_file_exporter_end;
630         iface->get_capabilities = djvu_document_file_exporter_get_capabilities;
631 }
632
633 static void
634 djvu_document_init (DjvuDocument *djvu_document)
635 {
636         guint masks[4] = { 0xff0000, 0xff00, 0xff, 0xff000000 };
637         
638         djvu_document->d_context = ddjvu_context_create ("Evince");
639         djvu_document->d_format = ddjvu_format_create (DDJVU_FORMAT_RGBMASK32, 4, masks);
640         ddjvu_format_set_row_order (djvu_document->d_format, 1);
641
642         djvu_document->thumbs_format = ddjvu_format_create (DDJVU_FORMAT_RGB24, 0, 0);
643         ddjvu_format_set_row_order (djvu_document->thumbs_format, 1);
644
645         djvu_document->ps_filename = NULL;
646         djvu_document->opts = g_string_new ("");
647         
648         djvu_document->d_document = NULL;
649 }
650
651 static GList *
652 djvu_document_find_find_text (EvDocumentFind   *document,
653                               EvPage           *page,
654                               const char       *text,
655                               gboolean          case_sensitive)
656 {
657         DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
658         miniexp_t page_text;
659         gdouble width, height;
660         GList *matches = NULL, *l;
661
662         g_return_val_if_fail (text != NULL, NULL);
663
664         while ((page_text = ddjvu_document_get_pagetext (djvu_document->d_document,
665                                                          page->index,
666                                                          "char")) == miniexp_dummy)
667                 djvu_handle_events (djvu_document, TRUE, NULL);
668
669         if (page_text != miniexp_nil) {
670                 DjvuTextPage *tpage = djvu_text_page_new (page_text);
671                 
672                 djvu_text_page_prepare_search (tpage, case_sensitive);
673                 if (tpage->links->len > 0) {
674                         djvu_text_page_search (tpage, text);
675                         matches = tpage->results;
676                 }
677                 djvu_text_page_free (tpage);
678                 ddjvu_miniexp_release (djvu_document->d_document, page_text);
679         }
680
681         if (!matches)
682                 return NULL;
683
684         document_get_page_size (djvu_document, page->index, &width, &height);
685         for (l = matches; l && l->data; l = g_list_next (l)) {
686                 EvRectangle *r = (EvRectangle *)l->data;
687                 gdouble      tmp;
688
689                 tmp = r->y1;
690                 
691                 r->x1 *= SCALE_FACTOR;
692                 r->x2 *= SCALE_FACTOR;
693
694                 tmp = r->y1;
695                 r->y1 = height - r->y2 * SCALE_FACTOR;
696                 r->y2 = height - tmp * SCALE_FACTOR;
697         }
698         
699
700         return matches;
701 }
702
703 static void
704 djvu_document_find_iface_init (EvDocumentFindIface *iface)
705 {
706         iface->find_text = djvu_document_find_find_text;
707 }
708
709 static GList *
710 djvu_document_links_get_links (EvDocumentLinks *document_links,
711                                gint             page)
712 {
713         return djvu_links_get_links (document_links, page, SCALE_FACTOR);
714 }
715
716 static void
717 djvu_document_document_links_iface_init  (EvDocumentLinksIface *iface)
718 {
719         iface->has_document_links = djvu_links_has_document_links;
720         iface->get_links_model = djvu_links_get_links_model;
721         iface->get_links = djvu_document_links_get_links;
722         iface->find_link_dest = djvu_links_find_link_dest;
723 }