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.
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)
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.
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.
20 #include <glib/gi18n.h>
22 #include "gpdf-g-switch.h"
23 #include "pdf-document.h"
24 #include "ev-ps-exporter.h"
25 #include "ev-document-find.h"
26 #include "gpdf-g-switch.h"
27 #include "ev-document-bookmarks.h"
28 #include "ev-document-thumbnails.h"
30 #include "GlobalParams.h"
31 #include "GDKSplashOutputDev.h"
34 #include "UnicodeMap.h"
35 #include "GlobalParams.h"
38 #include "goo/GList.h"
39 #include "PSOutputDev.h"
48 PdfDocument *document;
52 /* full results are only possible for the rendered current page */
54 GArray *current_page_results;
55 guchar *other_page_flags; /* length n_pages + 1, first element ignored */
56 int start_page; /* skip this one as we iterate, since we did it first */
57 int search_page; /* the page we're searching now */
58 TextOutputDev *output_dev;
61 typedef struct _PdfDocumentClass PdfDocumentClass;
63 #define PDF_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDF_TYPE_DOCUMENT, PdfDocumentClass))
64 #define PDF_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDF_TYPE_DOCUMENT))
65 #define PDF_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDF_TYPE_DOCUMENT, PdfDocumentClass))
67 struct _PdfDocumentClass
69 GObjectClass parent_class;
74 GObject parent_instance;
82 GDKSplashOutputDev *out;
89 PdfDocumentSearch *search;
92 static void pdf_document_document_bookmarks_iface_init (EvDocumentBookmarksIface *iface);
93 static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
94 static void pdf_document_document_iface_init (EvDocumentIface *iface);
95 static void pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface);
96 static void pdf_document_find_iface_init (EvDocumentFindIface *iface);
97 static void pdf_document_search_free (PdfDocumentSearch *search);
98 static void pdf_document_search_page_changed (PdfDocumentSearch *search);
100 G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
102 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
103 pdf_document_document_iface_init);
104 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_BOOKMARKS,
105 pdf_document_document_bookmarks_iface_init);
106 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
107 pdf_document_document_thumbnails_iface_init);
108 G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER,
109 pdf_document_ps_exporter_iface_init);
110 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
111 pdf_document_find_iface_init);
115 document_validate_page (PdfDocument *pdf_document)
117 if (!pdf_document->page_valid) {
118 pdf_document->doc->displayPage (pdf_document->out, pdf_document->page,
119 72 * pdf_document->scale,
120 72 * pdf_document->scale,
123 pdf_document->page_valid = TRUE;
125 /* Update the search results available to the app since
126 * we only provide full results on the current page
128 if (pdf_document->search)
129 pdf_document_search_page_changed (pdf_document->search);
132 return pdf_document->page_valid;
136 pdf_document_load (EvDocument *document,
140 PdfDocument *pdf_document = PDF_DOCUMENT (document);
148 globalParams = new GlobalParams("/etc/xpdfrc");
149 globalParams->setupBaseFontsFc(NULL);
152 if (! pdf_document->umap) {
153 enc = new GString("UTF-8");
154 pdf_document->umap = globalParams->getUnicodeMap(enc);
155 pdf_document->umap->incRefCnt ();
159 filename = g_filename_from_uri (uri, NULL, error);
163 filename_g = new GString (filename);
166 // open the PDF file, assumes ownership of filename_g
167 newDoc = new PDFDoc(filename_g, 0, 0);
169 if (!newDoc->isOk()) {
170 err = newDoc->getErrorCode();
173 /* FIXME: Add a real error enum to EvDocument */
174 g_set_error (error, G_FILE_ERROR,
176 "Failed to load document (error %d) '%s'\n",
183 if (pdf_document->doc)
184 delete pdf_document->doc;
185 pdf_document->doc = newDoc;
187 pdf_document->page = 1;
189 if (pdf_document->out)
190 pdf_document->out->startDoc(pdf_document->doc->getXRef());
192 pdf_document->page_valid = FALSE;
194 g_object_notify (G_OBJECT (pdf_document), "title");
200 pdf_document_get_n_pages (EvDocument *document)
202 PdfDocument *pdf_document = PDF_DOCUMENT (document);
204 if (pdf_document->doc)
205 return pdf_document->doc->getNumPages();
211 pdf_document_set_page (EvDocument *document,
214 PdfDocument *pdf_document = PDF_DOCUMENT (document);
216 page = CLAMP (page, 1, ev_document_get_n_pages (document));
218 if (page != pdf_document->page) {
219 pdf_document->page = page;
220 pdf_document->page_valid = FALSE;
223 ev_document_changed (document);
227 pdf_document_get_page (EvDocument *document)
229 PdfDocument *pdf_document = PDF_DOCUMENT (document);
231 return pdf_document->page;
235 redraw_callback (void *data)
237 /* Need to hook up through a EvDocument callback? */
241 pdf_document_set_target (EvDocument *document,
244 PdfDocument *pdf_document = PDF_DOCUMENT (document);
246 if (pdf_document->target != target) {
247 if (pdf_document->target)
248 g_object_unref (pdf_document->target);
250 pdf_document->target = target;
252 if (pdf_document->target)
253 g_object_ref (pdf_document->target);
255 if (pdf_document->out) {
256 delete pdf_document->out;
257 pdf_document->out = NULL;
260 if (pdf_document->target) {
261 pdf_document->out = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
262 redraw_callback, (void*) document);
264 if (pdf_document->doc)
265 pdf_document->out->startDoc(pdf_document->doc->getXRef());
269 pdf_document->page_valid = FALSE;
274 pdf_document_set_scale (EvDocument *document,
277 PdfDocument *pdf_document = PDF_DOCUMENT (document);
279 if (pdf_document->scale != scale) {
280 pdf_document->scale = scale;
281 pdf_document->page_valid = FALSE;
286 pdf_document_set_page_offset (EvDocument *document,
290 PdfDocument *pdf_document = PDF_DOCUMENT (document);
292 pdf_document->page_x_offset = x;
293 pdf_document->page_y_offset = y;
297 pdf_document_get_page_size (EvDocument *document,
301 PdfDocument *pdf_document = PDF_DOCUMENT (document);
303 if (document_validate_page (pdf_document)) {
305 *width = pdf_document->out->getBitmapWidth();
307 *height = pdf_document->out->getBitmapHeight();
317 pdf_document_render (EvDocument *document,
323 PdfDocument *pdf_document = PDF_DOCUMENT (document);
327 if (!document_validate_page (pdf_document) || !pdf_document->target)
330 page.x = pdf_document->page_x_offset;
331 page.y = pdf_document->page_y_offset;
332 page.width = pdf_document->out->getBitmapWidth();
333 page.height = pdf_document->out->getBitmapHeight();
337 draw.width = clip_width;
338 draw.height = clip_height;
340 if (gdk_rectangle_intersect (&page, &draw, &draw))
341 pdf_document->out->redraw (draw.x - page.x, draw.y - page.y,
342 pdf_document->target,
344 draw.width, draw.height);
348 pdf_document_search_emit_found (PdfDocumentSearch *search)
350 PdfDocument *pdf_document = search->document;
356 n_pages = ev_document_get_n_pages (EV_DOCUMENT (search->document));
357 if (search->search_page > search->start_page) {
358 pages_done = search->search_page - search->start_page;
359 } else if (search->search_page == search->start_page) {
360 pages_done = n_pages;
362 pages_done = n_pages - search->start_page + search->search_page;
365 tmp_results = g_array_new (FALSE, FALSE, sizeof (EvFindResult));
366 g_array_append_vals (tmp_results,
367 search->current_page_results->data,
368 search->current_page_results->len);
370 /* Now append a bogus element for each page that has a result in it,
371 * that is not the current page
374 while (i <= n_pages) {
375 if (i != pdf_document->page &&
376 search->other_page_flags[i]) {
381 /* Use bogus coordinates, again we can't get coordinates
382 * until this is the current page because TextOutputDev
385 result.highlight_area.x = -1;
386 result.highlight_area.y = -1;
387 result.highlight_area.width = 1;
388 result.highlight_area.height = 1;
390 g_array_append_val (tmp_results, result);
396 ev_document_find_found (EV_DOCUMENT_FIND (pdf_document),
397 (EvFindResult*) tmp_results->data,
399 pages_done / (double) n_pages);
401 g_array_free (tmp_results, TRUE);
405 pdf_document_search_page_changed (PdfDocumentSearch *search)
407 PdfDocument *pdf_document = search->document;
410 int xMin, yMin, xMax, yMax;
412 current_page = pdf_document->page;
414 if (!pdf_document->page_valid) {
415 /* we can't do anything until displayPage() */
416 search->current_page = -1;
420 if (search->current_page == current_page)
423 /* We need to create current_page_results for the new current page */
424 g_array_set_size (search->current_page_results, 0);
426 if (pdf_document->out->findText (search->ucs4, search->ucs4_len,
427 gTrue, gTrue, // startAtTop, stopAtBottom
428 gFalse, gFalse, // startAtLast, stopAtLast
429 &xMin, &yMin, &xMax, &yMax)) {
430 result.page_num = pdf_document->page;
432 result.highlight_area.x = xMin;
433 result.highlight_area.y = yMin;
434 result.highlight_area.width = xMax - xMin;
435 result.highlight_area.height = yMax - yMin;
437 g_array_append_val (search->current_page_results, result);
438 /* Now find further results */
440 while (pdf_document->out->findText (search->ucs4, search->ucs4_len,
443 &xMin, &yMin, &xMax, &yMax)) {
445 result.page_num = pdf_document->page;
447 result.highlight_area.x = xMin;
448 result.highlight_area.y = yMin;
449 result.highlight_area.width = xMax - xMin;
450 result.highlight_area.height = yMax - yMin;
452 g_array_append_val (search->current_page_results, result);
456 /* needed for the initial current page since we don't search
459 search->other_page_flags[current_page] =
460 search->current_page_results->len > 0;
462 pdf_document_search_emit_found (search);
466 pdf_document_search_idle_callback (void *data)
468 PdfDocumentSearch *search = (PdfDocumentSearch*) data;
469 PdfDocument *pdf_document = search->document;
471 double xMin, yMin, xMax, yMax;
473 /* Note that PDF page count is 1 through n_pages INCLUSIVE
474 * like a real book. We are looking to add one result for each
475 * page with a match, because the coordinates are meaningless
476 * with TextOutputDev, so we just want to flag matching pages
477 * and then when the user switches to the current page, we
478 * will emit "found" again with the real results.
480 n_pages = ev_document_get_n_pages (EV_DOCUMENT (search->document));
482 if (search->search_page == search->start_page) {
486 if (search->output_dev == 0) {
487 /* First time through here... */
488 search->output_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
489 if (!search->output_dev->isOk()) {
494 pdf_document->doc->displayPage (search->output_dev,
496 72, 72, 0, gTrue, gFalse);
498 if (search->output_dev->findText (search->ucs4,
500 gTrue, gTrue, // startAtTop, stopAtBottom
501 gFalse, gFalse, // startAtLast, stopAtLast
502 &xMin, &yMin, &xMax, &yMax)) {
503 /* This page has results */
504 search->other_page_flags[search->search_page] = TRUE;
507 search->search_page += 1;
508 if (search->search_page > n_pages) {
510 search->search_page = 1;
513 /* We do this even if nothing was found, to update the percent complete */
514 pdf_document_search_emit_found (search);
520 search->idle = 0; /* will return FALSE to remove */
525 pdf_document_find_begin (EvDocumentFind *document,
526 const char *search_string,
527 gboolean case_sensitive)
529 PdfDocument *pdf_document = PDF_DOCUMENT (document);
530 PdfDocumentSearch *search;
535 /* FIXME handle case_sensitive (right now XPDF
536 * code is always case insensitive for ASCII
537 * and case sensitive for all other languaages)
540 g_assert (sizeof (gunichar) == sizeof (Unicode));
541 ucs4 = g_utf8_to_ucs4_fast (search_string, -1,
544 if (pdf_document->search &&
545 pdf_document->search->ucs4_len == ucs4_len &&
546 memcmp (pdf_document->search->ucs4,
548 sizeof (gunichar) * ucs4_len) == 0) {
549 /* Search is unchanged */
554 if (pdf_document->search) {
555 pdf_document_search_free (pdf_document->search);
556 pdf_document->search = NULL;
559 search = g_new0 (PdfDocumentSearch, 1);
562 search->ucs4_len = ucs4_len;
564 search->current_page_results = g_array_new (FALSE,
566 sizeof (EvFindResult));
567 n_pages = ev_document_get_n_pages (EV_DOCUMENT (document));
569 /* This is an array of bool; with the first value ignored
570 * so we can index by the based-at-1 page numbers
572 search->other_page_flags = g_new0 (guchar, n_pages + 1);
574 search->document = pdf_document;
576 /* We add at low priority so the progress bar repaints */
577 search->idle = g_idle_add_full (G_PRIORITY_LOW,
578 pdf_document_search_idle_callback,
582 search->output_dev = 0;
584 search->start_page = pdf_document->page;
585 search->search_page = search->start_page + 1;
586 if (search->search_page > n_pages)
587 search->search_page = 1;
589 search->current_page = -1;
591 pdf_document->search = search;
593 /* Update for the current page right away */
594 pdf_document_search_page_changed (search);
598 pdf_document_find_cancel (EvDocumentFind *document)
600 PdfDocument *pdf_document = PDF_DOCUMENT (document);
602 if (pdf_document->search) {
603 pdf_document_search_free (pdf_document->search);
604 pdf_document->search = NULL;
609 pdf_document_search_free (PdfDocumentSearch *search)
611 if (search->idle != 0)
612 g_source_remove (search->idle);
614 if (search->output_dev)
615 delete search->output_dev;
617 g_array_free (search->current_page_results, TRUE);
618 g_free (search->other_page_flags);
620 g_free (search->ucs4);
625 pdf_document_ps_export_begin (EvPSExporter *exporter, const char *filename)
627 PdfDocument *document = PDF_DOCUMENT (exporter);
629 if (document->ps_out)
630 delete document->ps_out;
632 document->ps_out = new PSOutputDev ((char *)filename, document->doc->getXRef(),
633 document->doc->getCatalog(), 1,
634 ev_document_get_n_pages (EV_DOCUMENT (document)),
639 pdf_document_ps_export_do_page (EvPSExporter *exporter, int page)
641 PdfDocument *document = PDF_DOCUMENT (exporter);
643 document->doc->displayPage (document->ps_out, page,
644 72.0, 72.0, 0, gTrue, gFalse);
648 pdf_document_ps_export_end (EvPSExporter *exporter)
650 PdfDocument *document = PDF_DOCUMENT (exporter);
652 delete document->ps_out;
653 document->ps_out = NULL;
657 /* EvDocumentBookmarks Implementation */
660 /* goo GList, not glib */
667 unicode_to_char (OutlineItem *outline_item,
671 gchar buf[8]; /* 8 is enough for mapping an unicode char to a string */
674 for (i = 0; i < outline_item->getTitleLength(); ++i) {
675 n = uMap->mapUnicode(outline_item->getTitle()[i], buf, sizeof(buf));
679 return g_strdup (gstr.getCString ());
684 pdf_document_bookmarks_has_document_bookmarks (EvDocumentBookmarks *document_bookmarks)
686 PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
689 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
691 outline = pdf_document->doc->getOutline();
692 if (outline->getItems() != NULL &&
693 outline->getItems()->getLength() > 0)
699 static EvDocumentBookmarksIter *
700 pdf_document_bookmarks_begin_read (EvDocumentBookmarks *document_bookmarks)
702 PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
707 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), NULL);
709 outline = pdf_document->doc->getOutline();
710 items = outline->getItems();
714 iter = g_new0 (BookmarksIter, 1);
719 return (EvDocumentBookmarksIter *) iter;
723 pdf_document_bookmarks_get_values (EvDocumentBookmarks *document_bookmarks,
724 EvDocumentBookmarksIter *bookmarks_iter,
726 EvDocumentBookmarksType *type,
729 PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
730 BookmarksIter *iter = (BookmarksIter *)bookmarks_iter;
732 LinkAction *link_action;
733 LinkDest *link_dest = NULL;
734 LinkURI *link_uri = NULL;
735 LinkGoTo *link_goto = NULL;
741 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
742 g_return_val_if_fail (iter != NULL, FALSE);
743 g_return_val_if_fail (title != NULL, FALSE);
744 g_return_val_if_fail (type != NULL, FALSE);
745 g_return_val_if_fail (page != NULL, FALSE);
747 anItem = (OutlineItem *)iter->items->get(iter->index);
748 link_action = anItem->getAction ();
749 link_title = anItem->getTitle ();
752 switch (link_action->getKind ()) {
755 link_goto = dynamic_cast <LinkGoTo *> (link_action);
756 link_dest = link_goto->getDest ();
757 named_dest = link_goto->getNamedDest ();
759 /* Wow! This seems excessively slow on large
760 * documents. I need to investigate more... -jrb */
761 if (link_dest != NULL) {
762 link_dest = link_dest->copy ();
763 } else if (named_dest != NULL) {
764 named_dest = named_dest->copy ();
765 link_dest = pdf_document->doc->findDest (named_dest);
768 if (link_dest != NULL) {
769 if (link_dest->isPageRef ()) {
770 page_ref = link_dest->getPageRef ();
771 page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen);
773 page_num = link_dest->getPageNum ();
781 link_uri = dynamic_cast <LinkURI *> (link_action);
787 g_warning ("Unknown link action type: %d", link_action->getKind ());
790 *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
791 } else if (link_title) {
792 *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
795 *type = EV_DOCUMENT_BOOKMARKS_TYPE_LINK;
801 static EvDocumentBookmarksIter *
802 pdf_document_bookmarks_get_child (EvDocumentBookmarks *document_bookmarks,
803 EvDocumentBookmarksIter *bookmarks_iter)
805 BookmarksIter *iter = (BookmarksIter *)bookmarks_iter;
806 BookmarksIter *child_iter;
809 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
811 anItem = (OutlineItem *)iter->items->get(iter->index);
813 if (! (anItem->hasKids() && anItem->getKids()) )
816 child_iter = g_new0 (BookmarksIter, 1);
817 child_iter->index = 0;
818 child_iter->level = iter->level + 1;
819 child_iter->items = anItem->getKids ();
820 g_assert (child_iter->items);
822 return (EvDocumentBookmarksIter *) child_iter;
826 pdf_document_bookmarks_next (EvDocumentBookmarks *document_bookmarks,
827 EvDocumentBookmarksIter *bookmarks_iter)
829 BookmarksIter *iter = (BookmarksIter *) bookmarks_iter;
831 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
834 if (iter->index >= iter->items->getLength())
841 pdf_document_bookmarks_free_iter (EvDocumentBookmarks *document_bookmarks,
842 EvDocumentBookmarksIter *iter)
844 g_return_if_fail (PDF_IS_DOCUMENT (document_bookmarks));
845 g_return_if_fail (iter != NULL);
847 /* FIXME: Should I close all the nodes?? Free them? */
852 pdf_document_finalize (GObject *object)
854 PdfDocument *pdf_document = PDF_DOCUMENT (object);
856 if (pdf_document->umap) {
857 pdf_document->umap->decRefCnt ();
858 pdf_document->umap = NULL;
861 if (pdf_document->search)
862 pdf_document_search_free (pdf_document->search);
864 if (pdf_document->target)
865 g_object_unref (pdf_document->target);
867 if (pdf_document->out)
868 delete pdf_document->out;
869 if (pdf_document->ps_out)
870 delete pdf_document->ps_out;
871 if (pdf_document->doc)
872 delete pdf_document->doc;
877 pdf_document_set_property (GObject *object,
892 has_unicode_marker (GString *string)
894 return ((string->getChar (0) & 0xff) == 0xfe &&
895 (string->getChar (1) & 0xff) == 0xff);
899 pdf_info_dict_get_string (Dict *info_dict, const gchar *key) {
904 g_return_val_if_fail (info_dict != NULL, NULL);
905 g_return_val_if_fail (key != NULL, NULL);
907 if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) {
909 return g_strdup (_("Unknown"));
912 value = obj.getString ();
914 if (has_unicode_marker (value)) {
915 result = g_convert (value->getCString () + 2,
916 value->getLength () - 2,
917 "UTF-8", "UTF-16BE", NULL, NULL, NULL);
919 result = g_strndup (value->getCString (), value->getLength ());
928 pdf_document_get_title (PdfDocument *pdf_document)
933 pdf_document->doc->getDocInfo (&info);
935 if (info.isDict ()) {
936 title = pdf_info_dict_get_string (info.getDict(), "Title");
943 pdf_document_get_property (GObject *object,
948 PdfDocument *pdf_document = PDF_DOCUMENT (object);
954 title = pdf_document_get_title (pdf_document);
955 g_value_set_string (value, title);
962 pdf_document_class_init (PdfDocumentClass *klass)
964 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
966 gobject_class->finalize = pdf_document_finalize;
967 gobject_class->get_property = pdf_document_get_property;
968 gobject_class->set_property = pdf_document_set_property;
970 g_object_class_override_property (gobject_class, PROP_TITLE, "title");
974 pdf_document_document_iface_init (EvDocumentIface *iface)
976 iface->load = pdf_document_load;
977 iface->get_n_pages = pdf_document_get_n_pages;
978 iface->set_page = pdf_document_set_page;
979 iface->get_page = pdf_document_get_page;
980 iface->set_scale = pdf_document_set_scale;
981 iface->set_target = pdf_document_set_target;
982 iface->set_page_offset = pdf_document_set_page_offset;
983 iface->get_page_size = pdf_document_get_page_size;
984 iface->render = pdf_document_render;
988 pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface)
990 iface->begin = pdf_document_ps_export_begin;
991 iface->do_page = pdf_document_ps_export_do_page;
992 iface->end = pdf_document_ps_export_end;
997 pdf_document_find_iface_init (EvDocumentFindIface *iface)
999 iface->begin = pdf_document_find_begin;
1000 iface->cancel = pdf_document_find_cancel;
1004 pdf_document_document_bookmarks_iface_init (EvDocumentBookmarksIface *iface)
1006 iface->has_document_bookmarks = pdf_document_bookmarks_has_document_bookmarks;
1007 iface->begin_read = pdf_document_bookmarks_begin_read;
1008 iface->get_values = pdf_document_bookmarks_get_values;
1009 iface->get_child = pdf_document_bookmarks_get_child;
1010 iface->next = pdf_document_bookmarks_next;
1011 iface->free_iter = pdf_document_bookmarks_free_iter;
1016 pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
1017 gdouble scale_factor,
1023 GDKSplashOutputDev *output;
1026 pixmap = gdk_pixmap_new (pdf_document->target,
1029 output = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
1031 output->startDoc (pdf_document->doc->getXRef());
1032 pdf_document->doc->displayPage (output,
1037 output->redraw (0, 0,
1041 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1047 gdk_drawable_unref (pixmap);
1053 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1057 PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1058 GdkPixbuf *thumbnail;
1061 Thumb *thumb = NULL;
1062 gboolean have_ethumbs = FALSE;
1064 /* getPage seems to want page + 1 for some reason; */
1065 the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
1066 the_page->getThumb(&the_thumb);
1068 if (!(the_thumb.isNull () || the_thumb.isNone())) {
1069 /* Build the thumbnail object */
1070 thumb = new Thumb(pdf_document->doc->getXRef (),
1073 have_ethumbs = thumb->ok();
1078 GdkPixbuf *tmp_pixbuf;
1080 data = thumb->getPixbufData();
1081 /* FISME: scale the image if it's not an appropriate size */
1082 tmp_pixbuf = gdk_pixbuf_new_from_data (data,
1087 thumb->getHeight (),
1088 thumb->getWidth () * 3,
1091 thumbnail = tmp_pixbuf;
1094 gdouble scale_factor;
1097 page_ratio = the_page->getHeight () / the_page->getWidth ();
1098 scale_factor = (gdouble)width / the_page->getWidth ();
1099 dest_height = (gint) (width * page_ratio);
1101 thumbnail = pdf_document_thumbnails_get_page_pixbuf (pdf_document,
1107 /* FIXME: Actually get the image... */
1113 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
1115 iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
1120 pdf_document_init (PdfDocument *pdf_document)
1122 pdf_document->page = 1;
1123 pdf_document->page_x_offset = 0;
1124 pdf_document->page_y_offset = 0;
1125 pdf_document->scale = 1.;
1127 pdf_document->page_valid = FALSE;