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