]> www.fi.muni.cz Git - evince.git/blob - pdf/pdf-document.cc
merge evince-threads branch
[evince.git] / pdf / pdf-document.cc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* pdfdocument.h: Implementation of EvDocument for PDF
3  * Copyright (C) 2004, Red Hat, Inc.
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 <glib/gi18n.h>
21
22 #include "pdf-document.h"
23 #include "ev-ps-exporter.h"
24 #include "ev-document-find.h"
25 #include "ev-document-misc.h"
26 #include "ev-document-links.h"
27 #include "ev-document-security.h"
28 #include "ev-document-thumbnails.h"
29
30 #include <goo/GooList.h>
31 #include <splash/SplashBitmap.h>
32 #include <GlobalParams.h>
33 #include <PDFDoc.h>
34 #include <Outline.h>
35 #include <ErrorCodes.h>
36 #include <UnicodeMap.h>
37 #include <GfxState.h>
38 #include <PSOutputDev.h>
39
40 #include "Thumb.h"
41 #include "GDKSplashOutputDev.h"
42
43 enum {
44         PROP_0,
45         PROP_TITLE
46 };
47
48 typedef struct
49 {
50         PdfDocument *document;
51         gunichar *ucs4;
52         glong ucs4_len;
53         guint idle;
54         /* full results are only possible for the rendered current page */
55         int current_page;
56         GArray *current_page_results;
57         int *other_page_flags; /* length n_pages + 1, first element ignored */
58         int start_page;   /* skip this one as we iterate, since we did it first */
59         int search_page;  /* the page we're searching now */
60         TextOutputDev *output_dev;
61 } PdfDocumentSearch;
62
63 typedef struct _PdfDocumentClass PdfDocumentClass;
64
65 #define PDF_DOCUMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), PDF_TYPE_DOCUMENT, PdfDocumentClass))
66 #define PDF_IS_DOCUMENT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), PDF_TYPE_DOCUMENT))
67 #define PDF_DOCUMENT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), PDF_TYPE_DOCUMENT, PdfDocumentClass))
68
69 struct _PdfDocumentClass
70 {
71         GObjectClass parent_class;
72 };
73
74 struct _PdfDocument
75 {
76         GObject parent_instance;
77
78         int page;
79         int page_x_offset;
80         int page_y_offset;
81         double scale;
82         GdkDrawable *target;
83
84         GDKSplashOutputDev *out;
85         PSOutputDev *ps_out;
86         PDFDoc *doc;
87         Links *links;
88         UnicodeMap *umap;
89
90         gchar *password;
91
92         PdfDocumentSearch *search;
93 };
94
95 static EvLink *build_link_from_action (PdfDocument *pdf_document,
96                                        LinkAction  *link_action,
97                                        const char  *title);
98
99 static void pdf_document_document_links_iface_init      (EvDocumentLinksIface      *iface);
100 static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
101 static void pdf_document_document_iface_init            (EvDocumentIface           *iface);
102 static void pdf_document_ps_exporter_iface_init         (EvPSExporterIface         *iface);
103 static void pdf_document_find_iface_init                (EvDocumentFindIface       *iface);
104 static void pdf_document_security_iface_init            (EvDocumentSecurityIface   *iface);
105 static void pdf_document_search_free                    (PdfDocumentSearch         *search);
106 static void pdf_document_search_page_changed            (PdfDocumentSearch         *search);
107
108 static GdkPixbuf *bitmap_to_pixbuf (SplashBitmap *bitmap,
109                                     GdkPixbuf    *target,
110                                     gint          x_offset,
111                                     gint          y_offset);
112
113
114 G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
115                          {
116                                  G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
117                                                         pdf_document_document_iface_init);
118                                  G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
119                                                         pdf_document_document_links_iface_init);
120                                  G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
121                                                         pdf_document_document_thumbnails_iface_init);
122                                  G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER,
123                                                         pdf_document_ps_exporter_iface_init);
124                                  G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
125                                                         pdf_document_find_iface_init);
126                                  G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
127                                                         pdf_document_security_iface_init);
128                          });
129
130 static void
131 document_init_links (PdfDocument *pdf_document)
132 {
133         Page *page;
134         Object obj;
135
136         if (pdf_document->links) {
137                 delete pdf_document->links;
138         }
139         page = pdf_document->doc->getCatalog ()->getPage (pdf_document->page);
140         pdf_document->links = new Links (page->getAnnots (&obj),
141                                          pdf_document->doc->getCatalog ()->getBaseURI ());
142         obj.free ();
143 }
144
145 static void
146 document_display_page (PdfDocument *pdf_document)
147 {
148         if (pdf_document->out != NULL) {
149                 pdf_document->doc->displayPage (pdf_document->out, pdf_document->page,
150                                                 72 * pdf_document->scale,
151                                                 72 * pdf_document->scale,
152                                                 0, gTrue, gTrue);
153
154                 document_init_links (pdf_document);
155
156                 /* Update the search results available to the app since
157                  * we only provide full results on the current page
158                  */
159                 if (pdf_document->search)
160                         pdf_document_search_page_changed (pdf_document->search);
161         }
162 }
163
164 static gboolean
165 pdf_document_load (EvDocument  *document,
166                    const char  *uri,
167                    GError     **error)
168 {
169         PdfDocument *pdf_document = PDF_DOCUMENT (document);
170         PDFDoc *newDoc;
171         int err;
172         char *filename;
173         GooString *filename_g;
174         GooString *enc;
175
176         if (!globalParams) {
177                 globalParams = new GlobalParams("/etc/xpdfrc");
178                 globalParams->setupBaseFontsFc(NULL);
179         }
180
181         if (! pdf_document->umap) {
182                 enc = new GooString("UTF-8");
183                 pdf_document->umap = globalParams->getUnicodeMap(enc);
184                 pdf_document->umap->incRefCnt ();
185                 delete enc;
186         }
187
188         filename = g_filename_from_uri (uri, NULL, error);
189         if (!filename)
190                 return FALSE;
191
192         filename_g = new GooString (filename);
193         g_free (filename);
194
195         // open the PDF file, assumes ownership of filename_g
196         GooString *password = NULL;
197         if (pdf_document->password)
198                 password = new GooString (pdf_document->password);
199         newDoc = new PDFDoc(filename_g, password, password);
200         if (password)
201                 delete password;
202
203         if (!newDoc->isOk()) {
204                 err = newDoc->getErrorCode();
205                 delete newDoc;
206                 if (err == errEncrypted) {
207                         g_set_error (error, EV_DOCUMENT_ERROR,
208                                      EV_DOCUMENT_ERROR_ENCRYPTED,
209                                      "Document is encrypted.");
210                 } else {
211                         g_set_error (error, G_FILE_ERROR,
212                                      G_FILE_ERROR_FAILED,
213                                      "Failed to load document (error %d) '%s'\n",
214                                      err,
215                                      uri);
216                 }
217
218                 return FALSE;
219         }
220
221         if (pdf_document->doc)
222                 delete pdf_document->doc;
223         pdf_document->doc = newDoc;
224
225         pdf_document->page = 1;
226
227         if (pdf_document->out)
228                 pdf_document->out->startDoc(pdf_document->doc->getXRef());
229
230         g_object_notify (G_OBJECT (pdf_document), "title");
231
232         return TRUE;
233 }
234
235 static gboolean
236 pdf_document_save (EvDocument  *document,
237                    const char  *uri,
238                    GError     **error)
239 {
240         PdfDocument *pdf_document = PDF_DOCUMENT (document);
241         char *filename;
242         gboolean retval = FALSE;
243
244         filename = g_filename_from_uri (uri, NULL, error);
245         if (filename != NULL) {
246                 GooString *fname = new GooString (filename);
247
248                 retval = pdf_document->doc->saveAs (fname);
249         }
250
251         return retval;
252 }
253
254 static int
255 pdf_document_get_n_pages (EvDocument  *document)
256 {
257         PdfDocument *pdf_document = PDF_DOCUMENT (document);
258
259         if (pdf_document->doc)
260                 return pdf_document->doc->getNumPages();
261         else
262                 return 1;
263 }
264
265 static void
266 pdf_document_set_page (EvDocument  *document,
267                        int          page)
268 {
269         PdfDocument *pdf_document = PDF_DOCUMENT (document);
270
271         page = CLAMP (page, 1, pdf_document_get_n_pages (document));
272
273         if (page != pdf_document->page) {
274                 pdf_document->page = page;
275                 document_display_page (pdf_document);
276                 ev_document_page_changed (EV_DOCUMENT (pdf_document));
277         }
278 }
279
280 static int
281 pdf_document_get_page (EvDocument  *document)
282 {
283         PdfDocument *pdf_document = PDF_DOCUMENT (document);
284
285         return pdf_document->page;
286 }
287
288 static void
289 redraw_callback (void *data)
290 {
291         /* Need to hook up through a EvDocument callback? */
292 }
293
294 static void
295 pdf_document_set_target (EvDocument  *document,
296                          GdkDrawable *target)
297 {
298         PdfDocument *pdf_document = PDF_DOCUMENT (document);
299
300         if (pdf_document->target != target) {
301                 if (pdf_document->target)
302                         g_object_unref (pdf_document->target);
303
304                 pdf_document->target = target;
305
306                 if (pdf_document->target)
307                         g_object_ref (pdf_document->target);
308
309                 if (pdf_document->out) {
310                         delete pdf_document->out;
311                         pdf_document->out = NULL;
312                 }
313
314                 if (pdf_document->target) {
315                         pdf_document->out = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
316                                                          redraw_callback, (void*) document);
317
318                         if (pdf_document->doc)
319                                 pdf_document->out->startDoc(pdf_document->doc->getXRef());
320
321                         document_display_page (pdf_document);
322                 }
323         }
324 }
325
326 static void
327 pdf_document_set_scale (EvDocument  *document,
328                         double       scale)
329 {
330         PdfDocument *pdf_document = PDF_DOCUMENT (document);
331
332         if (pdf_document->scale != scale) {
333                 pdf_document->scale = scale;
334                 document_display_page (pdf_document);
335                 ev_document_scale_changed (EV_DOCUMENT (pdf_document));
336         }
337 }
338
339 static void
340 pdf_document_set_page_offset (EvDocument  *document,
341                               int          x,
342                               int          y)
343 {
344         PdfDocument *pdf_document = PDF_DOCUMENT (document);
345
346         pdf_document->page_x_offset = x;
347         pdf_document->page_y_offset = y;
348 }
349
350 static gint
351 canonical_multiple_of_90 (gint n)
352 {
353         while (n >= 360) {
354                 n -= 360;
355         }
356         while (n < 0) {
357                 n += 360;
358         }
359
360         return 90 * (gint)((n / 90.0) + .5);
361 }
362
363 static void
364 pdf_document_get_page_size (EvDocument   *document,
365                             int           page,
366                             int          *width,
367                             int          *height)
368 {
369         PdfDocument *pdf_document = PDF_DOCUMENT (document);
370         Page *doc_page;
371         int page_width = 1, page_height = 1;
372         double scale = pdf_document->scale;
373
374         if (page == -1)
375                 page = pdf_document->page;
376
377         doc_page = pdf_document->doc->getCatalog ()->getPage (page);
378
379         if (page) {
380                 int page_rotate;
381
382                 page_rotate = canonical_multiple_of_90 (doc_page->getRotate ());
383                 if (page_rotate == 90 || page_rotate == 270) {
384                         page_width = (int) ((doc_page->getHeight () * scale) + 0.5);
385                         page_height = (int) ((doc_page->getWidth () * scale) + 0.5);
386                 } else /* if (page_rotate == 0 || page_rotate == 180) */ {
387                         page_width = (int) ((doc_page->getWidth () * scale) + 0.5);
388                         page_height = (int) ((doc_page->getHeight () * scale) + 0.5);
389                 }
390         }
391
392         if (width) *width = page_width;
393         if (height) *height = page_height;
394 }
395
396 static void
397 pdf_document_render (EvDocument  *document,
398                      int          clip_x,
399                      int          clip_y,
400                      int          clip_width,
401                      int          clip_height)
402 {
403         PdfDocument *pdf_document = PDF_DOCUMENT (document);
404         GdkRectangle page;
405         GdkRectangle draw;
406
407         if (!pdf_document->target)
408                 return;
409
410         page.x = pdf_document->page_x_offset;
411         page.y = pdf_document->page_y_offset;
412         page.width = pdf_document->out->getBitmapWidth();
413         page.height = pdf_document->out->getBitmapHeight();
414
415         draw.x = clip_x;
416         draw.y = clip_y;
417         draw.width = clip_width;
418         draw.height = clip_height;
419
420         if (gdk_rectangle_intersect (&page, &draw, &draw))
421                 pdf_document->out->redraw (draw.x - page.x, draw.y - page.y,
422                                            pdf_document->target,
423                                            draw.x, draw.y,
424                                            draw.width, draw.height);
425 }
426
427
428
429 static GdkPixbuf *
430 pdf_document_render_pixbuf (EvDocument *document)
431 {
432         PdfDocument *pdf_document = PDF_DOCUMENT (document);
433         SplashOutputDev *output;
434         GdkPixbuf *pixbuf;
435         SplashColor color;
436
437         color.rgb8 = splashMakeRGB8 (255, 255, 255);
438
439         output = new SplashOutputDev (splashModeRGB8, gFalse, color);
440         output->startDoc (pdf_document->doc->getXRef());
441
442         pdf_document->doc->displayPage (output,
443                                         pdf_document->page,
444                                         72*pdf_document->scale,
445                                         72*pdf_document->scale,
446                                         0, gTrue, gFalse);
447
448         pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
449                                  FALSE, 8,
450                                  output->getBitmap()->getWidth(),
451                                  output->getBitmap()->getHeight());
452
453         bitmap_to_pixbuf (output->getBitmap(), pixbuf, 0, 0);
454         delete output;
455
456         return pixbuf;
457 }
458
459 double
460 pdf_document_find_get_progress (EvDocumentFind *document_find)
461 {
462         PdfDocumentSearch *search;
463         int n_pages, pages_done;
464
465         search = PDF_DOCUMENT (document_find)->search;
466
467         if (search == NULL) {
468                 return 0;
469         }
470
471         n_pages = pdf_document_get_n_pages (EV_DOCUMENT (document_find));
472         if (search->search_page > search->start_page) {
473                 pages_done = search->search_page - search->start_page + 1;
474         } else if (search->search_page == search->start_page) {
475                 pages_done = n_pages;
476         } else {
477                 pages_done = n_pages - search->start_page + search->search_page;
478         }
479
480         return pages_done / (double) n_pages;
481 }
482
483 int
484 pdf_document_find_page_has_results (EvDocumentFind *document_find,
485                                     int             page)
486 {
487         PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
488
489         g_return_val_if_fail (search != NULL, FALSE);
490
491         return search->other_page_flags[page];
492 }
493
494 int
495 pdf_document_find_get_n_results (EvDocumentFind *document_find)
496 {
497         PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
498
499         if (search) {
500                 return search->current_page_results->len;
501         } else {
502                 return 0;
503         }
504 }
505
506 gboolean
507 pdf_document_find_get_result (EvDocumentFind *document_find,
508                               int             n_result,
509                               GdkRectangle   *rectangle)
510 {
511         PdfDocument *pdf_document = PDF_DOCUMENT (document_find);
512         PdfDocumentSearch *search = pdf_document->search;
513         GdkRectangle r;
514
515         if (search != NULL &&
516             n_result < search->current_page_results->len) {
517                 r = g_array_index (search->current_page_results,
518                                    GdkRectangle, n_result);
519
520                 rectangle->x = r.x + pdf_document->page_x_offset;
521                 rectangle->y = r.y + pdf_document->page_y_offset;
522                 rectangle->width = r.width;
523                 rectangle->height = r.height;
524
525                 return TRUE;
526         } else {
527                 return FALSE;
528         }
529 }
530
531 static void
532 pdf_document_search_page_changed (PdfDocumentSearch   *search)
533 {
534         PdfDocument *pdf_document = search->document;
535         int current_page;
536         GdkRectangle result;
537         int xMin, yMin, xMax, yMax;
538
539         current_page = pdf_document->page;
540
541         if (search->current_page == current_page)
542                 return;
543
544         /* We need to create current_page_results for the new current page */
545         g_array_set_size (search->current_page_results, 0);
546
547         if (pdf_document->out->findText (search->ucs4, search->ucs4_len,
548                                          gTrue, gTrue, // startAtTop, stopAtBottom
549                                          gFalse, gFalse, // startAtLast, stopAtLast
550                                          &xMin, &yMin, &xMax, &yMax)) {
551                 result.x = xMin;
552                 result.y = yMin;
553                 result.width = xMax - xMin;
554                 result.height = yMax - yMin;
555
556                 g_array_append_val (search->current_page_results, result);
557                 /* Now find further results */
558
559                 while (pdf_document->out->findText (search->ucs4, search->ucs4_len,
560                                                     gFalse, gTrue,
561                                                     gTrue, gFalse,
562                                                     &xMin, &yMin, &xMax, &yMax)) {
563                         result.x = xMin;
564                         result.y = yMin;
565                         result.width = xMax - xMin;
566                         result.height = yMax - yMin;
567
568                         g_array_append_val (search->current_page_results, result);
569                 }
570         }
571 }
572
573 static gboolean
574 pdf_document_search_idle_callback (void *data)
575 {
576         PdfDocumentSearch *search = (PdfDocumentSearch*) data;
577         PdfDocument *pdf_document = search->document;
578         int n_pages, changed_page;
579         double xMin, yMin, xMax, yMax;
580
581         /* Note that PDF page count is 1 through n_pages INCLUSIVE
582          * like a real book. We are looking to add one result for each
583          * page with a match, because the coordinates are meaningless
584          * with TextOutputDev, so we just want to flag matching pages
585          * and then when the user switches to the current page, we
586          * will emit "found" again with the real results.
587          */
588         n_pages = pdf_document_get_n_pages (EV_DOCUMENT (search->document));
589
590         if (search->output_dev == 0) {
591                 /* First time through here... */
592                 search->output_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
593                 if (!search->output_dev->isOk()) {
594                         goto end_search;
595                 }
596         }
597
598         pdf_document->doc->displayPage (search->output_dev,
599                                         search->search_page,
600                                         72, 72, 0, gTrue, gFalse);
601
602         if (search->output_dev->findText (search->ucs4,
603                                           search->ucs4_len,
604                                           gTrue, gTrue, // startAtTop, stopAtBottom
605                                           gFalse, gFalse, // startAtLast, stopAtLast
606                                           &xMin, &yMin, &xMax, &yMax)) {
607                 /* This page has results */
608                 search->other_page_flags[search->search_page] = 1;
609         } else {
610                 search->other_page_flags[search->search_page] = 0;
611         }
612
613         changed_page = search->start_page;
614
615         search->search_page += 1;
616         if (search->search_page > n_pages) {
617                 /* wrap around */
618                 search->search_page = 1;
619         }
620
621         if (search->search_page != search->start_page) {
622                 ev_document_find_changed (EV_DOCUMENT_FIND (pdf_document),
623                                           changed_page);
624                 return TRUE;
625         }
626
627 end_search:
628         /* We're done. */
629         search->idle = 0; /* will return FALSE to remove */
630         return FALSE;
631 }
632
633 static void
634 pdf_document_find_begin (EvDocumentFind   *document,
635                          const char       *search_string,
636                          gboolean          case_sensitive)
637 {
638         PdfDocument *pdf_document = PDF_DOCUMENT (document);
639         PdfDocumentSearch *search;
640         int n_pages, i;
641         gunichar *ucs4;
642         glong ucs4_len;
643
644         /* FIXME handle case_sensitive (right now XPDF
645          * code is always case insensitive for ASCII
646          * and case sensitive for all other languaages)
647          */
648
649         g_assert (sizeof (gunichar) == sizeof (Unicode));
650         ucs4 = g_utf8_to_ucs4_fast (search_string, -1,
651                                     &ucs4_len);
652
653         if (pdf_document->search &&
654             pdf_document->search->ucs4_len == ucs4_len &&
655             memcmp (pdf_document->search->ucs4,
656                     ucs4,
657                     sizeof (gunichar) * ucs4_len) == 0) {
658                 /* Search is unchanged */
659                 g_free (ucs4);
660                 return;
661         }
662
663         if (pdf_document->search) {
664                 pdf_document_search_free (pdf_document->search);
665                 pdf_document->search = NULL;
666         }
667
668         search = g_new0 (PdfDocumentSearch, 1);
669
670         search->ucs4 = ucs4;
671         search->ucs4_len = ucs4_len;
672
673         search->current_page_results = g_array_new (FALSE,
674                                                     FALSE,
675                                                     sizeof (GdkRectangle));
676         n_pages = pdf_document_get_n_pages (EV_DOCUMENT (document));
677
678         search->other_page_flags = g_new0 (int, n_pages + 1);
679         for (i = 0; i <= n_pages; i++) {
680                 search->other_page_flags[i] = -1;
681         }
682
683         search->document = pdf_document;
684
685         /* We add at low priority so the progress bar repaints */
686         search->idle = g_idle_add_full (G_PRIORITY_LOW,
687                                         pdf_document_search_idle_callback,
688                                         search,
689                                         NULL);
690
691         search->output_dev = 0;
692
693         search->start_page = pdf_document->page;
694         search->search_page = search->start_page;
695
696         search->current_page = -1;
697
698         pdf_document->search = search;
699
700         /* Update for the current page right away */
701         pdf_document_search_page_changed (search);
702 }
703
704 static void
705 pdf_document_find_cancel (EvDocumentFind *document)
706 {
707         PdfDocument *pdf_document = PDF_DOCUMENT (document);
708
709         if (pdf_document->search) {
710                 pdf_document_search_free (pdf_document->search);
711                 pdf_document->search = NULL;
712         }
713 }
714
715 static void
716 pdf_document_search_free (PdfDocumentSearch   *search)
717 {
718         if (search->idle != 0)
719                 g_source_remove (search->idle);
720
721         if (search->output_dev)
722                 delete search->output_dev;
723
724         g_array_free (search->current_page_results, TRUE);
725         g_free (search->other_page_flags);
726
727         g_free (search->ucs4);
728         g_free (search);
729 }
730
731 static gboolean
732 pdf_document_has_document_security (EvDocumentSecurity *document_security)
733 {
734         /* FIXME: do we really need to have this? */
735         return FALSE;
736 }
737
738 static void
739 pdf_document_set_password (EvDocumentSecurity *document_security,
740                            const char         *password)
741 {
742         PdfDocument *document = PDF_DOCUMENT (document_security);
743
744         if (document->password)
745                 g_free (document->password);
746
747         document->password = g_strdup (password);
748 }
749
750 static void
751 pdf_document_ps_export_begin (EvPSExporter *exporter, const char *filename)
752 {
753         PdfDocument *document = PDF_DOCUMENT (exporter);
754
755         if (document->ps_out)
756                 delete document->ps_out;
757
758         document->ps_out = new PSOutputDev ((char *)filename, document->doc->getXRef(),
759                                             document->doc->getCatalog(), 1,
760                                             pdf_document_get_n_pages (EV_DOCUMENT (document)),
761                                             psModePS);
762 }
763
764 static void
765 pdf_document_ps_export_do_page (EvPSExporter *exporter, int page)
766 {
767         PdfDocument *document = PDF_DOCUMENT (exporter);
768
769         document->doc->displayPage (document->ps_out, page,
770                                     72.0, 72.0, 0, gTrue, gFalse);
771 }
772
773 static void
774 pdf_document_ps_export_end (EvPSExporter *exporter)
775 {
776         PdfDocument *document = PDF_DOCUMENT (exporter);
777
778         delete document->ps_out;
779         document->ps_out = NULL;
780 }
781
782
783 /* EvDocumentLinks Implementation */
784 typedef struct
785 {
786         GooList *items;
787         int index;
788         int level;
789 } LinksIter;
790
791 static gchar *
792 unicode_to_char (OutlineItem *outline_item,
793                  UnicodeMap *uMap)
794 {
795         GooString gstr;
796         gchar buf[8]; /* 8 is enough for mapping an unicode char to a string */
797         int i, n;
798
799         for (i = 0; i < outline_item->getTitleLength(); ++i) {
800                 n = uMap->mapUnicode(outline_item->getTitle()[i], buf, sizeof(buf));
801                 gstr.append(buf, n);
802         }
803
804         return g_strdup (gstr.getCString ());
805 }
806
807
808 static gboolean
809 pdf_document_links_has_document_links (EvDocumentLinks *document_links)
810 {
811         PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
812         Outline *outline;
813
814         g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
815
816         outline = pdf_document->doc->getOutline();
817         if (outline->getItems() != NULL &&
818             outline->getItems()->getLength() > 0)
819                 return TRUE;
820
821         return FALSE;
822 }
823
824 static void
825 build_tree (PdfDocument  *pdf_document,
826             GtkTreeModel *model,
827             GtkTreeIter  *parent,
828             GooList      *items)
829 {
830         int i;
831
832         for (i = 0; i < items->getLength (); i++) {
833                 OutlineItem *item;
834                 GtkTreeIter iter;
835                 LinkAction *link_action;
836                 gchar *title;
837                 EvLink *link;
838                 
839                 item = (OutlineItem *)items->get (i);
840                 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
841
842                 link_action = item->getAction ();
843                 title = unicode_to_char (item, pdf_document->umap);
844                 link = build_link_from_action (pdf_document, link_action, title);
845
846                 gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
847                                     EV_DOCUMENT_LINKS_COLUMN_MARKUP, title,
848                                     EV_DOCUMENT_LINKS_COLUMN_LINK, link,
849                                     -1);
850
851                 item->open ();
852                 if (item->hasKids () && item->getKids ()) {
853                         build_tree (pdf_document,
854                                     model,
855                                     &iter,
856                                     item->getKids ());
857                 }
858         }
859 }
860
861 static GtkTreeModel *
862 pdf_document_links_get_links_model (EvDocumentLinks *document_links)
863 {
864         PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
865         GtkTreeModel *model = NULL;
866         Outline *outline;
867         GooList *items;
868
869         g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
870
871         outline = pdf_document->doc->getOutline();
872         items = outline->getItems();
873
874         /* Create the model iff we have items*/
875         if (items != NULL) {
876                 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
877                                                              G_TYPE_STRING,
878                                                              G_TYPE_POINTER);
879                 build_tree (pdf_document, model, NULL, items);
880         }
881
882         return model;
883 }
884
885 static EvLink *
886 build_link_from_action (PdfDocument *pdf_document,
887                         LinkAction  *link_action,
888                         const char  *title)
889 {
890         EvLink *link = NULL;
891
892         if (link_action == NULL) {
893                 link = ev_link_new_title (title);
894         } else if (link_action->getKind () == actionGoToR) {
895                 g_warning ("actionGoToR links not implemented");
896         } else if (link_action->getKind () == actionLaunch) {
897                 g_warning ("actionLaunch links not implemented");
898         } else if (link_action->getKind () == actionNamed) {
899                 g_warning ("actionNamed links not implemented");
900         } else if (link_action->getKind () == actionMovie) {
901                 g_warning ("actionMovie links not implemented");
902         } else if (link_action->getKind () == actionGoTo) {
903                 LinkDest *link_dest;
904                 LinkGoTo *link_goto;
905                 Ref page_ref;
906                 gint page_num = 0;
907                 GooString *named_dest;
908
909                 link_goto = dynamic_cast <LinkGoTo *> (link_action);
910                 link_dest = link_goto->getDest ();
911                 named_dest = link_goto->getNamedDest ();
912
913                 /* Wow!  This seems excessively slow on large
914                  * documents. I need to investigate more... -jrb */
915                 if (link_dest != NULL) {
916                         link_dest = link_dest->copy ();
917                 } else if (named_dest != NULL) {
918                         named_dest = named_dest->copy ();
919                         link_dest = pdf_document->doc->findDest (named_dest);
920                         delete named_dest;
921                 }
922                 if (link_dest != NULL) {
923                         if (link_dest->isPageRef ()) {
924                                 page_ref = link_dest->getPageRef ();
925                                 page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen);
926                         } else {
927                                 page_num = link_dest->getPageNum ();
928                         }
929                         delete link_dest;
930                 }
931
932                 link = ev_link_new_page (title, page_num);
933         } else if (link_action->getKind () == actionURI) {
934                 LinkURI *link_uri;
935
936                 link_uri = dynamic_cast <LinkURI *> (link_action);
937                 link = ev_link_new_external
938                         (title, link_uri->getURI()->getCString());
939         } else if (link_action->getKind () == actionUnknown) {
940                 LinkUnknown *link_unknown;
941
942                 link_unknown = dynamic_cast <LinkUnknown *> (link_action);
943
944                 g_warning ("Unknown link type %s",
945                            link_unknown->getAction()->getCString());
946         }
947
948         if (link == NULL) {
949                 link = ev_link_new_title (title);
950         }
951
952         return link;
953 }
954
955
956 #if 0
957 static EvDocumentLinksIter *
958 pdf_document_links_begin_read (EvDocumentLinks *document_links)
959 {
960         PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
961         Outline *outline;
962         LinksIter *iter;
963         GooList *items;
964
965         g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
966
967         outline = pdf_document->doc->getOutline();
968         items = outline->getItems();
969         if (! items)
970                 return NULL;
971
972         iter = g_new0 (LinksIter, 1);
973         iter->items = items;
974         iter->index = 0;
975         iter->level = 0;
976
977         return (EvDocumentLinksIter *) iter;
978 }
979
980 /* FIXME This returns a new object every time, probably we should cache it
981    in the iter */
982 static EvLink *
983 pdf_document_links_get_link (EvDocumentLinks      *document_links,
984                              EvDocumentLinksIter  *links_iter)
985 {
986         PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
987         LinksIter *iter = (LinksIter *)links_iter;
988         OutlineItem *anItem;
989         LinkAction *link_action;
990         Unicode *link_title;
991         const char *title;
992
993         g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
994         g_return_val_if_fail (iter != NULL, FALSE);
995
996         anItem = (OutlineItem *)iter->items->get(iter->index);
997         link_action = anItem->getAction ();
998         link_title = anItem->getTitle ();
999         title = unicode_to_char (anItem, pdf_document->umap);
1000
1001         return build_link_from_action (pdf_document, link_action, title);
1002 }
1003
1004 static EvDocumentLinksIter *
1005 pdf_document_links_get_child (EvDocumentLinks     *document_links,
1006                               EvDocumentLinksIter *links_iter)
1007 {
1008         LinksIter *iter = (LinksIter *)links_iter;
1009         LinksIter *child_iter;
1010         OutlineItem *anItem;
1011
1012         g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
1013
1014         anItem = (OutlineItem *)iter->items->get(iter->index);
1015         anItem->open ();
1016         if (! (anItem->hasKids() && anItem->getKids()) )
1017                 return NULL;
1018
1019         child_iter = g_new0 (LinksIter, 1);
1020         child_iter->index = 0;
1021         child_iter->level = iter->level + 1;
1022         child_iter->items = anItem->getKids ();
1023         g_assert (child_iter->items);
1024
1025         return (EvDocumentLinksIter *) child_iter;
1026 }
1027
1028 static gboolean
1029 pdf_document_links_next (EvDocumentLinks     *document_links,
1030                          EvDocumentLinksIter *links_iter)
1031 {
1032         LinksIter *iter = (LinksIter *) links_iter;
1033
1034         g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
1035
1036         iter->index++;
1037         if (iter->index >= iter->items->getLength())
1038                 return FALSE;
1039
1040         return TRUE;
1041 }
1042
1043 static void
1044 pdf_document_links_free_iter (EvDocumentLinks     *document_links,
1045                               EvDocumentLinksIter *iter)
1046 {
1047         g_return_if_fail (PDF_IS_DOCUMENT (document_links));
1048         g_return_if_fail (iter != NULL);
1049
1050         /* FIXME: Should I close all the nodes?? Free them? */
1051         g_free (iter);
1052 }
1053 #endif
1054
1055 static void
1056 pdf_document_finalize (GObject *object)
1057 {
1058         PdfDocument *pdf_document = PDF_DOCUMENT (object);
1059
1060         if (pdf_document->links) {
1061                 delete pdf_document->links;
1062         }
1063
1064         if (pdf_document->umap) {
1065                 pdf_document->umap->decRefCnt ();
1066                 pdf_document->umap = NULL;
1067         }
1068
1069         if (pdf_document->search)
1070                 pdf_document_search_free (pdf_document->search);
1071
1072         if (pdf_document->target)
1073                 g_object_unref (pdf_document->target);
1074
1075         if (pdf_document->out)
1076                 delete pdf_document->out;
1077         if (pdf_document->ps_out)
1078                 delete pdf_document->ps_out;
1079         if (pdf_document->doc)
1080                 delete pdf_document->doc;
1081
1082 }
1083
1084 static void
1085 pdf_document_set_property (GObject *object,
1086                            guint prop_id,
1087                            const GValue *value,
1088                            GParamSpec *pspec)
1089 {
1090         switch (prop_id)
1091
1092         {
1093                 case PROP_TITLE:
1094                         /* read only */
1095                         break;
1096         }
1097 }
1098
1099 static gboolean
1100 has_unicode_marker (GooString *string)
1101 {
1102         return ((string->getChar (0) & 0xff) == 0xfe &&
1103                 (string->getChar (1) & 0xff) == 0xff);
1104 }
1105
1106 static gchar *
1107 pdf_info_dict_get_string (Dict *info_dict, const gchar *key) {
1108         Object obj;
1109         GooString *value;
1110         gchar *result;
1111
1112         g_return_val_if_fail (info_dict != NULL, NULL);
1113         g_return_val_if_fail (key != NULL, NULL);
1114
1115         if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) {
1116                 obj.free ();
1117                 return NULL;
1118         }
1119
1120         value = obj.getString ();
1121
1122         if (has_unicode_marker (value)) {
1123                 result = g_convert (value->getCString () + 2,
1124                                     value->getLength () - 2,
1125                                     "UTF-8", "UTF-16BE", NULL, NULL, NULL);
1126         } else {
1127                 result = g_strndup (value->getCString (), value->getLength ());
1128         }
1129
1130         obj.free ();
1131
1132         return result;
1133 }
1134
1135 static char *
1136 pdf_document_get_title (PdfDocument *pdf_document)
1137 {
1138         char *title = NULL;
1139         Object info;
1140
1141         if (pdf_document->doc == NULL)
1142                 return NULL;
1143         pdf_document->doc->getDocInfo (&info);
1144
1145         if (info.isDict ()) {
1146                 title = pdf_info_dict_get_string (info.getDict(), "Title");
1147         }
1148
1149         return title;
1150 }
1151
1152 static char *
1153 pdf_document_get_text (EvDocument *document, GdkRectangle *rect)
1154 {
1155         PdfDocument *pdf_document = PDF_DOCUMENT (document);
1156         GooString *sel_text = new GooString;
1157         const char *text;
1158         int x1, y1, x2, y2;
1159
1160         x1 = rect->x - pdf_document->page_x_offset;
1161         y1 = rect->y - pdf_document->page_y_offset;
1162         x2 = x1 + rect->width;
1163         y2 = y1 + rect->height;
1164
1165         sel_text = pdf_document->out->getText (x1, y1, x2, y2);
1166         text = sel_text->getCString ();
1167
1168         return text ? g_strdup (text) : NULL;
1169 }
1170
1171 static EvLink *
1172 pdf_document_get_link (EvDocument *document, int x, int y)
1173 {
1174         PdfDocument *pdf_document = PDF_DOCUMENT (document);
1175         LinkAction *action;
1176         double link_x, link_y;
1177
1178         if (pdf_document->links == NULL) {
1179                 return NULL;
1180         }
1181
1182         /* Offset */
1183         link_x = x - pdf_document->page_x_offset;
1184         link_y = y - pdf_document->page_y_offset;
1185
1186         /* Inverse y */
1187         link_y = pdf_document->out->getBitmapHeight() - link_y;
1188
1189         /* Zoom */
1190         link_x = link_x / pdf_document->scale;
1191         link_y = link_y / pdf_document->scale;
1192
1193         action = pdf_document->links->find (link_x, link_y);
1194
1195         if (action) {
1196                 return build_link_from_action (pdf_document, action, "");
1197         } else {
1198                 return NULL;
1199         }
1200 }
1201
1202 static void
1203 pdf_document_get_property (GObject *object,
1204                            guint prop_id,
1205                            GValue *value,
1206                            GParamSpec *pspec)
1207 {
1208         PdfDocument *pdf_document = PDF_DOCUMENT (object);
1209         char *title;
1210
1211         switch (prop_id)
1212         {
1213                 case PROP_TITLE:
1214                         title = pdf_document_get_title (pdf_document);
1215                         g_value_set_string (value, title);
1216                         g_free (title);
1217                         break;
1218         }
1219 }
1220
1221 static void
1222 pdf_document_class_init (PdfDocumentClass *klass)
1223 {
1224         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1225
1226         gobject_class->finalize = pdf_document_finalize;
1227         gobject_class->get_property = pdf_document_get_property;
1228         gobject_class->set_property = pdf_document_set_property;
1229
1230         g_object_class_override_property (gobject_class, PROP_TITLE, "title");
1231 }
1232
1233 static void
1234 pdf_document_document_iface_init (EvDocumentIface *iface)
1235 {
1236         iface->load = pdf_document_load;
1237         iface->save = pdf_document_save;
1238         iface->get_text = pdf_document_get_text;
1239         iface->get_link = pdf_document_get_link;
1240         iface->get_n_pages = pdf_document_get_n_pages;
1241         iface->set_page = pdf_document_set_page;
1242         iface->get_page = pdf_document_get_page;
1243         iface->set_scale = pdf_document_set_scale;
1244         iface->set_target = pdf_document_set_target;
1245         iface->set_page_offset = pdf_document_set_page_offset;
1246         iface->get_page_size = pdf_document_get_page_size;
1247         iface->render = pdf_document_render;
1248         iface->render_pixbuf = pdf_document_render_pixbuf;
1249 }
1250
1251 static void
1252 pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface)
1253 {
1254         iface->begin = pdf_document_ps_export_begin;
1255         iface->do_page = pdf_document_ps_export_do_page;
1256         iface->end = pdf_document_ps_export_end;
1257 }
1258
1259
1260 static void
1261 pdf_document_find_iface_init (EvDocumentFindIface *iface)
1262 {
1263         iface->begin = pdf_document_find_begin;
1264         iface->get_n_results = pdf_document_find_get_n_results;
1265         iface->get_result = pdf_document_find_get_result;
1266         iface->page_has_results = pdf_document_find_page_has_results;
1267         iface->get_progress = pdf_document_find_get_progress;
1268         iface->cancel = pdf_document_find_cancel;
1269 }
1270
1271 static void
1272 pdf_document_security_iface_init (EvDocumentSecurityIface *iface)
1273 {
1274         iface->has_document_security = pdf_document_has_document_security;
1275         iface->set_password = pdf_document_set_password;
1276 }
1277
1278 static void
1279 pdf_document_document_links_iface_init (EvDocumentLinksIface *iface)
1280 {
1281         iface->has_document_links = pdf_document_links_has_document_links;
1282         iface->get_links_model = pdf_document_links_get_links_model;
1283 }
1284
1285 /* Thumbnails */
1286
1287 static GdkPixbuf *
1288 bitmap_to_pixbuf (SplashBitmap *bitmap,
1289                   GdkPixbuf    *target,
1290                   gint          x_offset,
1291                   gint          y_offset)
1292 {
1293         gint width;
1294         gint height;
1295         SplashColorPtr dataPtr;
1296         int x, y;
1297
1298         gboolean target_has_alpha;
1299         gint target_rowstride;
1300         guchar *target_data;
1301
1302         width = bitmap->getWidth ();
1303         height = bitmap->getHeight ();
1304
1305         if (width + x_offset > gdk_pixbuf_get_width (target))
1306                 width = gdk_pixbuf_get_width (target) - x_offset;
1307         if (height + y_offset > gdk_pixbuf_get_height (target))
1308                 height = gdk_pixbuf_get_height (target) - x_offset;
1309
1310         target_has_alpha = gdk_pixbuf_get_has_alpha (target);
1311         target_rowstride = gdk_pixbuf_get_rowstride (target);
1312         target_data = gdk_pixbuf_get_pixels (target);
1313
1314         dataPtr = bitmap->getDataPtr ();
1315
1316         for (y = 0; y < height; y++) {
1317                 SplashRGB8 *p;
1318                 SplashRGB8 rgb;
1319                 guchar *q;
1320
1321                 p = dataPtr.rgb8 + y * width;
1322                 q = target_data + ((y + y_offset) * target_rowstride +
1323                                    x_offset * (target_has_alpha?4:3));
1324                 for (x = 0; x < width; x++) {
1325                         rgb = *p++;
1326
1327                         *q++ = splashRGB8R (rgb);
1328                         *q++ = splashRGB8G (rgb);
1329                         *q++ = splashRGB8B (rgb);
1330
1331                         if (target_has_alpha)
1332                                 q++;
1333                 }
1334         }
1335
1336         return target;
1337 }
1338
1339
1340 static GdkPixbuf *
1341 pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
1342                                          gdouble      scale_factor,
1343                                          gint         page_num,
1344                                          gint         width,
1345                                          gint         height,
1346                                          gboolean     border)
1347 {
1348         SplashOutputDev *output;
1349         GdkPixbuf *pixbuf;
1350         SplashColor color;
1351
1352         color.rgb8 = splashMakeRGB8 (255, 255, 255);
1353
1354         output = new SplashOutputDev (splashModeRGB8, gFalse, color);
1355         output->startDoc (pdf_document->doc->getXRef());
1356         pdf_document->doc->displayPage (output,
1357                                         page_num,
1358                                         72*scale_factor,
1359                                         72*scale_factor,
1360                                         0, gTrue, gFalse);
1361
1362         width = output->getBitmap()->getWidth();
1363         height = output->getBitmap()->getHeight();
1364
1365         if (border) {
1366                 pixbuf = ev_document_misc_get_thumbnail_frame (width, height, NULL);
1367                 bitmap_to_pixbuf (output->getBitmap(), pixbuf, 1, 1);
1368         } else {
1369                 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
1370                                          width, height);
1371                 gdk_pixbuf_fill (pixbuf, 0xffffffff);
1372                 bitmap_to_pixbuf (output->getBitmap(), pixbuf, 0, 0);
1373         }
1374
1375         delete output;
1376
1377         return pixbuf;
1378 }
1379
1380 static void
1381 pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
1382                                         gint                  page,
1383                                         gint                  size,
1384                                         gint                 *width,
1385                                         gint                 *height)
1386 {
1387         PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1388         Page *the_page;
1389         Object the_thumb;
1390         Thumb *thumb = NULL;
1391
1392         the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
1393         the_page->getThumb (&the_thumb);
1394
1395         if (!(the_thumb.isNull () || the_thumb.isNone())) {
1396                 /* Build the thumbnail object */
1397                 thumb = new Thumb(pdf_document->doc->getXRef (),
1398                                   &the_thumb);
1399
1400                 *width = thumb->getWidth ();
1401                 *height = thumb->getHeight ();
1402         } else {
1403                 double page_width, page_height;
1404
1405                 page_width = the_page->getWidth ();
1406                 page_height = the_page->getHeight ();
1407
1408                 if (page_width > page_height) {
1409                         *width = size;
1410                         *height = (int) (size * page_height / page_width);
1411                 } else {
1412                         *width = (int) (size * page_width / page_height);
1413                         *height = size;
1414                 }
1415         }
1416 }
1417
1418 static GdkPixbuf *
1419 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1420                                        gint                  page,
1421                                        gint                  size,
1422                                        gboolean              border)
1423 {
1424         PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1425         GdkPixbuf *thumbnail;
1426         Page *the_page;
1427         Object the_thumb;
1428         Thumb *thumb = NULL;
1429         gboolean have_ethumbs = FALSE;
1430
1431         the_page = pdf_document->doc->getCatalog ()->getPage (page);
1432         the_page->getThumb(&the_thumb);
1433
1434         if (!(the_thumb.isNull () || the_thumb.isNone())) {
1435                 /* Build the thumbnail object */
1436                 thumb = new Thumb(pdf_document->doc->getXRef (),
1437                                   &the_thumb);
1438
1439                 have_ethumbs = thumb->ok();
1440         }
1441
1442         if (have_ethumbs) {
1443                 guchar *data;
1444                 GdkPixbuf *tmp_pixbuf;
1445
1446                 data = thumb->getPixbufData();
1447                 tmp_pixbuf = gdk_pixbuf_new_from_data (data,
1448                                                        GDK_COLORSPACE_RGB,
1449                                                        FALSE,
1450                                                        8,
1451                                                        thumb->getWidth (),
1452                                                        thumb->getHeight (),
1453                                                        thumb->getWidth () * 3,
1454                                                        NULL, NULL);
1455                 /* FIXME: do we want to check that the thumb's size isn't ridiculous?? */
1456                 thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
1457                 g_object_unref (tmp_pixbuf);
1458         } else {
1459                 int width, height;
1460                 double scale_factor;
1461         
1462                 pdf_document_thumbnails_get_dimensions (document_thumbnails, page, size,
1463                                                         &width, &height);
1464                 scale_factor = width / the_page->getWidth ();
1465                 thumbnail = pdf_document_thumbnails_get_page_pixbuf (pdf_document,
1466                                                                      scale_factor,
1467                                                                      page,
1468                                                                      width,
1469                                                                      height,
1470                                                                      border);
1471         }
1472
1473         return thumbnail;
1474 }
1475 static void
1476 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
1477 {
1478         iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
1479         iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
1480 }
1481
1482
1483 static void
1484 pdf_document_init (PdfDocument *pdf_document)
1485 {
1486         pdf_document->page = 1;
1487         pdf_document->page_x_offset = 0;
1488         pdf_document->page_y_offset = 0;
1489         pdf_document->scale = 1.;
1490
1491         pdf_document->password = NULL;
1492 }
1493