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-misc.h"
29 #include "ev-document-thumbnails.h"
31 #include "GlobalParams.h"
32 #include "GDKSplashOutputDev.h"
35 #include "UnicodeMap.h"
36 #include "GlobalParams.h"
39 #include "goo/GList.h"
40 #include "PSOutputDev.h"
49 PdfDocument *document;
53 /* full results are only possible for the rendered current page */
55 GArray *current_page_results;
56 guchar *other_page_flags; /* length n_pages + 1, first element ignored */
57 int start_page; /* skip this one as we iterate, since we did it first */
58 int search_page; /* the page we're searching now */
59 TextOutputDev *output_dev;
62 typedef struct _PdfDocumentClass PdfDocumentClass;
64 #define PDF_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDF_TYPE_DOCUMENT, PdfDocumentClass))
65 #define PDF_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDF_TYPE_DOCUMENT))
66 #define PDF_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDF_TYPE_DOCUMENT, PdfDocumentClass))
68 struct _PdfDocumentClass
70 GObjectClass parent_class;
75 GObject parent_instance;
83 GDKSplashOutputDev *out;
90 PdfDocumentSearch *search;
93 static void pdf_document_document_bookmarks_iface_init (EvDocumentBookmarksIface *iface);
94 static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
95 static void pdf_document_document_iface_init (EvDocumentIface *iface);
96 static void pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface);
97 static void pdf_document_find_iface_init (EvDocumentFindIface *iface);
98 static void pdf_document_search_free (PdfDocumentSearch *search);
99 static void pdf_document_search_page_changed (PdfDocumentSearch *search);
101 G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
103 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
104 pdf_document_document_iface_init);
105 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_BOOKMARKS,
106 pdf_document_document_bookmarks_iface_init);
107 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
108 pdf_document_document_thumbnails_iface_init);
109 G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER,
110 pdf_document_ps_exporter_iface_init);
111 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
112 pdf_document_find_iface_init);
116 document_validate_page (PdfDocument *pdf_document)
118 if (!pdf_document->page_valid) {
119 pdf_document->doc->displayPage (pdf_document->out, pdf_document->page,
120 72 * pdf_document->scale,
121 72 * pdf_document->scale,
124 pdf_document->page_valid = TRUE;
126 /* Update the search results available to the app since
127 * we only provide full results on the current page
129 if (pdf_document->search)
130 pdf_document_search_page_changed (pdf_document->search);
133 return pdf_document->page_valid;
137 pdf_document_load (EvDocument *document,
141 PdfDocument *pdf_document = PDF_DOCUMENT (document);
149 globalParams = new GlobalParams("/etc/xpdfrc");
150 globalParams->setupBaseFontsFc(NULL);
153 if (! pdf_document->umap) {
154 enc = new GString("UTF-8");
155 pdf_document->umap = globalParams->getUnicodeMap(enc);
156 pdf_document->umap->incRefCnt ();
160 filename = g_filename_from_uri (uri, NULL, error);
164 filename_g = new GString (filename);
167 // open the PDF file, assumes ownership of filename_g
168 newDoc = new PDFDoc(filename_g, 0, 0);
170 if (!newDoc->isOk()) {
171 err = newDoc->getErrorCode();
174 /* FIXME: Add a real error enum to EvDocument */
175 g_set_error (error, G_FILE_ERROR,
177 "Failed to load document (error %d) '%s'\n",
184 if (pdf_document->doc)
185 delete pdf_document->doc;
186 pdf_document->doc = newDoc;
188 pdf_document->page = 1;
190 if (pdf_document->out)
191 pdf_document->out->startDoc(pdf_document->doc->getXRef());
193 pdf_document->page_valid = FALSE;
195 g_object_notify (G_OBJECT (pdf_document), "title");
201 pdf_document_get_n_pages (EvDocument *document)
203 PdfDocument *pdf_document = PDF_DOCUMENT (document);
205 if (pdf_document->doc)
206 return pdf_document->doc->getNumPages();
212 pdf_document_set_page (EvDocument *document,
215 PdfDocument *pdf_document = PDF_DOCUMENT (document);
217 page = CLAMP (page, 1, ev_document_get_n_pages (document));
219 if (page != pdf_document->page) {
220 pdf_document->page = page;
221 pdf_document->page_valid = FALSE;
224 ev_document_changed (document);
228 pdf_document_get_page (EvDocument *document)
230 PdfDocument *pdf_document = PDF_DOCUMENT (document);
232 return pdf_document->page;
236 redraw_callback (void *data)
238 /* Need to hook up through a EvDocument callback? */
242 pdf_document_set_target (EvDocument *document,
245 PdfDocument *pdf_document = PDF_DOCUMENT (document);
247 if (pdf_document->target != target) {
248 if (pdf_document->target)
249 g_object_unref (pdf_document->target);
251 pdf_document->target = target;
253 if (pdf_document->target)
254 g_object_ref (pdf_document->target);
256 if (pdf_document->out) {
257 delete pdf_document->out;
258 pdf_document->out = NULL;
261 if (pdf_document->target) {
262 pdf_document->out = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
263 redraw_callback, (void*) document);
265 if (pdf_document->doc)
266 pdf_document->out->startDoc(pdf_document->doc->getXRef());
270 pdf_document->page_valid = FALSE;
275 pdf_document_set_scale (EvDocument *document,
278 PdfDocument *pdf_document = PDF_DOCUMENT (document);
280 if (pdf_document->scale != scale) {
281 pdf_document->scale = scale;
282 pdf_document->page_valid = FALSE;
287 pdf_document_set_page_offset (EvDocument *document,
291 PdfDocument *pdf_document = PDF_DOCUMENT (document);
293 pdf_document->page_x_offset = x;
294 pdf_document->page_y_offset = y;
298 pdf_document_get_page_size (EvDocument *document,
302 PdfDocument *pdf_document = PDF_DOCUMENT (document);
304 if (document_validate_page (pdf_document)) {
306 *width = pdf_document->out->getBitmapWidth();
308 *height = pdf_document->out->getBitmapHeight();
318 pdf_document_render (EvDocument *document,
324 PdfDocument *pdf_document = PDF_DOCUMENT (document);
328 if (!document_validate_page (pdf_document) || !pdf_document->target)
331 page.x = pdf_document->page_x_offset;
332 page.y = pdf_document->page_y_offset;
333 page.width = pdf_document->out->getBitmapWidth();
334 page.height = pdf_document->out->getBitmapHeight();
338 draw.width = clip_width;
339 draw.height = clip_height;
341 if (gdk_rectangle_intersect (&page, &draw, &draw))
342 pdf_document->out->redraw (draw.x - page.x, draw.y - page.y,
343 pdf_document->target,
345 draw.width, draw.height);
349 pdf_document_search_emit_found (PdfDocumentSearch *search)
351 PdfDocument *pdf_document = search->document;
357 n_pages = ev_document_get_n_pages (EV_DOCUMENT (search->document));
358 if (search->search_page > search->start_page) {
359 pages_done = search->search_page - search->start_page;
360 } else if (search->search_page == search->start_page) {
361 pages_done = n_pages;
363 pages_done = n_pages - search->start_page + search->search_page;
366 tmp_results = g_array_new (FALSE, FALSE, sizeof (EvFindResult));
367 g_array_append_vals (tmp_results,
368 search->current_page_results->data,
369 search->current_page_results->len);
371 /* Now append a bogus element for each page that has a result in it,
372 * that is not the current page
375 while (i <= n_pages) {
376 if (i != pdf_document->page &&
377 search->other_page_flags[i]) {
382 /* Use bogus coordinates, again we can't get coordinates
383 * until this is the current page because TextOutputDev
386 result.highlight_area.x = -1;
387 result.highlight_area.y = -1;
388 result.highlight_area.width = 1;
389 result.highlight_area.height = 1;
391 g_array_append_val (tmp_results, result);
397 ev_document_find_found (EV_DOCUMENT_FIND (pdf_document),
398 (EvFindResult*) tmp_results->data,
400 pages_done / (double) n_pages);
402 g_array_free (tmp_results, TRUE);
406 pdf_document_search_page_changed (PdfDocumentSearch *search)
408 PdfDocument *pdf_document = search->document;
411 int xMin, yMin, xMax, yMax;
413 current_page = pdf_document->page;
415 if (!pdf_document->page_valid) {
416 /* we can't do anything until displayPage() */
417 search->current_page = -1;
421 if (search->current_page == current_page)
424 /* We need to create current_page_results for the new current page */
425 g_array_set_size (search->current_page_results, 0);
427 if (pdf_document->out->findText (search->ucs4, search->ucs4_len,
428 gTrue, gTrue, // startAtTop, stopAtBottom
429 gFalse, gFalse, // startAtLast, stopAtLast
430 &xMin, &yMin, &xMax, &yMax)) {
431 result.page_num = pdf_document->page;
433 result.highlight_area.x = xMin;
434 result.highlight_area.y = yMin;
435 result.highlight_area.width = xMax - xMin;
436 result.highlight_area.height = yMax - yMin;
438 g_array_append_val (search->current_page_results, result);
439 /* Now find further results */
441 while (pdf_document->out->findText (search->ucs4, search->ucs4_len,
444 &xMin, &yMin, &xMax, &yMax)) {
446 result.page_num = pdf_document->page;
448 result.highlight_area.x = xMin;
449 result.highlight_area.y = yMin;
450 result.highlight_area.width = xMax - xMin;
451 result.highlight_area.height = yMax - yMin;
453 g_array_append_val (search->current_page_results, result);
457 /* needed for the initial current page since we don't search
460 search->other_page_flags[current_page] =
461 search->current_page_results->len > 0;
463 pdf_document_search_emit_found (search);
467 pdf_document_search_idle_callback (void *data)
469 PdfDocumentSearch *search = (PdfDocumentSearch*) data;
470 PdfDocument *pdf_document = search->document;
472 double xMin, yMin, xMax, yMax;
474 /* Note that PDF page count is 1 through n_pages INCLUSIVE
475 * like a real book. We are looking to add one result for each
476 * page with a match, because the coordinates are meaningless
477 * with TextOutputDev, so we just want to flag matching pages
478 * and then when the user switches to the current page, we
479 * will emit "found" again with the real results.
481 n_pages = ev_document_get_n_pages (EV_DOCUMENT (search->document));
483 if (search->search_page == search->start_page) {
487 if (search->output_dev == 0) {
488 /* First time through here... */
489 search->output_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
490 if (!search->output_dev->isOk()) {
495 pdf_document->doc->displayPage (search->output_dev,
497 72, 72, 0, gTrue, gFalse);
499 if (search->output_dev->findText (search->ucs4,
501 gTrue, gTrue, // startAtTop, stopAtBottom
502 gFalse, gFalse, // startAtLast, stopAtLast
503 &xMin, &yMin, &xMax, &yMax)) {
504 /* This page has results */
505 search->other_page_flags[search->search_page] = TRUE;
508 search->search_page += 1;
509 if (search->search_page > n_pages) {
511 search->search_page = 1;
514 /* We do this even if nothing was found, to update the percent complete */
515 pdf_document_search_emit_found (search);
521 search->idle = 0; /* will return FALSE to remove */
526 pdf_document_find_begin (EvDocumentFind *document,
527 const char *search_string,
528 gboolean case_sensitive)
530 PdfDocument *pdf_document = PDF_DOCUMENT (document);
531 PdfDocumentSearch *search;
536 /* FIXME handle case_sensitive (right now XPDF
537 * code is always case insensitive for ASCII
538 * and case sensitive for all other languaages)
541 g_assert (sizeof (gunichar) == sizeof (Unicode));
542 ucs4 = g_utf8_to_ucs4_fast (search_string, -1,
545 if (pdf_document->search &&
546 pdf_document->search->ucs4_len == ucs4_len &&
547 memcmp (pdf_document->search->ucs4,
549 sizeof (gunichar) * ucs4_len) == 0) {
550 /* Search is unchanged */
555 if (pdf_document->search) {
556 pdf_document_search_free (pdf_document->search);
557 pdf_document->search = NULL;
560 search = g_new0 (PdfDocumentSearch, 1);
563 search->ucs4_len = ucs4_len;
565 search->current_page_results = g_array_new (FALSE,
567 sizeof (EvFindResult));
568 n_pages = ev_document_get_n_pages (EV_DOCUMENT (document));
570 /* This is an array of bool; with the first value ignored
571 * so we can index by the based-at-1 page numbers
573 search->other_page_flags = g_new0 (guchar, n_pages + 1);
575 search->document = pdf_document;
577 /* We add at low priority so the progress bar repaints */
578 search->idle = g_idle_add_full (G_PRIORITY_LOW,
579 pdf_document_search_idle_callback,
583 search->output_dev = 0;
585 search->start_page = pdf_document->page;
586 search->search_page = search->start_page + 1;
587 if (search->search_page > n_pages)
588 search->search_page = 1;
590 search->current_page = -1;
592 pdf_document->search = search;
594 /* Update for the current page right away */
595 pdf_document_search_page_changed (search);
599 pdf_document_find_cancel (EvDocumentFind *document)
601 PdfDocument *pdf_document = PDF_DOCUMENT (document);
603 if (pdf_document->search) {
604 pdf_document_search_free (pdf_document->search);
605 pdf_document->search = NULL;
610 pdf_document_search_free (PdfDocumentSearch *search)
612 if (search->idle != 0)
613 g_source_remove (search->idle);
615 if (search->output_dev)
616 delete search->output_dev;
618 g_array_free (search->current_page_results, TRUE);
619 g_free (search->other_page_flags);
621 g_free (search->ucs4);
626 pdf_document_ps_export_begin (EvPSExporter *exporter, const char *filename)
628 PdfDocument *document = PDF_DOCUMENT (exporter);
630 if (document->ps_out)
631 delete document->ps_out;
633 document->ps_out = new PSOutputDev ((char *)filename, document->doc->getXRef(),
634 document->doc->getCatalog(), 1,
635 ev_document_get_n_pages (EV_DOCUMENT (document)),
640 pdf_document_ps_export_do_page (EvPSExporter *exporter, int page)
642 PdfDocument *document = PDF_DOCUMENT (exporter);
644 document->doc->displayPage (document->ps_out, page,
645 72.0, 72.0, 0, gTrue, gFalse);
649 pdf_document_ps_export_end (EvPSExporter *exporter)
651 PdfDocument *document = PDF_DOCUMENT (exporter);
653 delete document->ps_out;
654 document->ps_out = NULL;
658 /* EvDocumentBookmarks Implementation */
661 /* goo GList, not glib */
668 unicode_to_char (OutlineItem *outline_item,
672 gchar buf[8]; /* 8 is enough for mapping an unicode char to a string */
675 for (i = 0; i < outline_item->getTitleLength(); ++i) {
676 n = uMap->mapUnicode(outline_item->getTitle()[i], buf, sizeof(buf));
680 return g_strdup (gstr.getCString ());
685 pdf_document_bookmarks_has_document_bookmarks (EvDocumentBookmarks *document_bookmarks)
687 PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
690 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
692 outline = pdf_document->doc->getOutline();
693 if (outline->getItems() != NULL &&
694 outline->getItems()->getLength() > 0)
700 static EvDocumentBookmarksIter *
701 pdf_document_bookmarks_begin_read (EvDocumentBookmarks *document_bookmarks)
703 PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
708 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), NULL);
710 outline = pdf_document->doc->getOutline();
711 items = outline->getItems();
715 iter = g_new0 (BookmarksIter, 1);
720 return (EvDocumentBookmarksIter *) iter;
724 pdf_document_bookmarks_get_values (EvDocumentBookmarks *document_bookmarks,
725 EvDocumentBookmarksIter *bookmarks_iter,
727 EvDocumentBookmarksType *type,
730 PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
731 BookmarksIter *iter = (BookmarksIter *)bookmarks_iter;
733 LinkAction *link_action;
734 LinkDest *link_dest = NULL;
735 LinkURI *link_uri = NULL;
736 LinkGoTo *link_goto = NULL;
742 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
743 g_return_val_if_fail (iter != NULL, FALSE);
744 g_return_val_if_fail (title != NULL, FALSE);
745 g_return_val_if_fail (type != NULL, FALSE);
746 g_return_val_if_fail (page != NULL, FALSE);
748 anItem = (OutlineItem *)iter->items->get(iter->index);
749 link_action = anItem->getAction ();
750 link_title = anItem->getTitle ();
753 switch (link_action->getKind ()) {
756 link_goto = dynamic_cast <LinkGoTo *> (link_action);
757 link_dest = link_goto->getDest ();
758 named_dest = link_goto->getNamedDest ();
760 /* Wow! This seems excessively slow on large
761 * documents. I need to investigate more... -jrb */
762 if (link_dest != NULL) {
763 link_dest = link_dest->copy ();
764 } else if (named_dest != NULL) {
765 named_dest = named_dest->copy ();
766 link_dest = pdf_document->doc->findDest (named_dest);
769 if (link_dest != NULL) {
770 if (link_dest->isPageRef ()) {
771 page_ref = link_dest->getPageRef ();
772 page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen);
774 page_num = link_dest->getPageNum ();
782 link_uri = dynamic_cast <LinkURI *> (link_action);
788 g_warning ("Unknown link action type: %d", link_action->getKind ());
791 *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
792 } else if (link_title) {
793 *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
796 *type = EV_DOCUMENT_BOOKMARKS_TYPE_LINK;
802 static EvDocumentBookmarksIter *
803 pdf_document_bookmarks_get_child (EvDocumentBookmarks *document_bookmarks,
804 EvDocumentBookmarksIter *bookmarks_iter)
806 BookmarksIter *iter = (BookmarksIter *)bookmarks_iter;
807 BookmarksIter *child_iter;
810 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
812 anItem = (OutlineItem *)iter->items->get(iter->index);
814 if (! (anItem->hasKids() && anItem->getKids()) )
817 child_iter = g_new0 (BookmarksIter, 1);
818 child_iter->index = 0;
819 child_iter->level = iter->level + 1;
820 child_iter->items = anItem->getKids ();
821 g_assert (child_iter->items);
823 return (EvDocumentBookmarksIter *) child_iter;
827 pdf_document_bookmarks_next (EvDocumentBookmarks *document_bookmarks,
828 EvDocumentBookmarksIter *bookmarks_iter)
830 BookmarksIter *iter = (BookmarksIter *) bookmarks_iter;
832 g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
835 if (iter->index >= iter->items->getLength())
842 pdf_document_bookmarks_free_iter (EvDocumentBookmarks *document_bookmarks,
843 EvDocumentBookmarksIter *iter)
845 g_return_if_fail (PDF_IS_DOCUMENT (document_bookmarks));
846 g_return_if_fail (iter != NULL);
848 /* FIXME: Should I close all the nodes?? Free them? */
853 pdf_document_finalize (GObject *object)
855 PdfDocument *pdf_document = PDF_DOCUMENT (object);
857 if (pdf_document->umap) {
858 pdf_document->umap->decRefCnt ();
859 pdf_document->umap = NULL;
862 if (pdf_document->search)
863 pdf_document_search_free (pdf_document->search);
865 if (pdf_document->target)
866 g_object_unref (pdf_document->target);
868 if (pdf_document->out)
869 delete pdf_document->out;
870 if (pdf_document->ps_out)
871 delete pdf_document->ps_out;
872 if (pdf_document->doc)
873 delete pdf_document->doc;
878 pdf_document_set_property (GObject *object,
893 has_unicode_marker (GString *string)
895 return ((string->getChar (0) & 0xff) == 0xfe &&
896 (string->getChar (1) & 0xff) == 0xff);
900 pdf_info_dict_get_string (Dict *info_dict, const gchar *key) {
905 g_return_val_if_fail (info_dict != NULL, NULL);
906 g_return_val_if_fail (key != NULL, NULL);
908 if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) {
910 return g_strdup (_("Unknown"));
913 value = obj.getString ();
915 if (has_unicode_marker (value)) {
916 result = g_convert (value->getCString () + 2,
917 value->getLength () - 2,
918 "UTF-8", "UTF-16BE", NULL, NULL, NULL);
920 result = g_strndup (value->getCString (), value->getLength ());
929 pdf_document_get_title (PdfDocument *pdf_document)
934 pdf_document->doc->getDocInfo (&info);
936 if (info.isDict ()) {
937 title = pdf_info_dict_get_string (info.getDict(), "Title");
944 pdf_document_get_property (GObject *object,
949 PdfDocument *pdf_document = PDF_DOCUMENT (object);
955 title = pdf_document_get_title (pdf_document);
956 g_value_set_string (value, title);
963 pdf_document_class_init (PdfDocumentClass *klass)
965 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
967 gobject_class->finalize = pdf_document_finalize;
968 gobject_class->get_property = pdf_document_get_property;
969 gobject_class->set_property = pdf_document_set_property;
971 g_object_class_override_property (gobject_class, PROP_TITLE, "title");
975 pdf_document_document_iface_init (EvDocumentIface *iface)
977 iface->load = pdf_document_load;
978 iface->get_n_pages = pdf_document_get_n_pages;
979 iface->set_page = pdf_document_set_page;
980 iface->get_page = pdf_document_get_page;
981 iface->set_scale = pdf_document_set_scale;
982 iface->set_target = pdf_document_set_target;
983 iface->set_page_offset = pdf_document_set_page_offset;
984 iface->get_page_size = pdf_document_get_page_size;
985 iface->render = pdf_document_render;
989 pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface)
991 iface->begin = pdf_document_ps_export_begin;
992 iface->do_page = pdf_document_ps_export_do_page;
993 iface->end = pdf_document_ps_export_end;
998 pdf_document_find_iface_init (EvDocumentFindIface *iface)
1000 iface->begin = pdf_document_find_begin;
1001 iface->cancel = pdf_document_find_cancel;
1005 pdf_document_document_bookmarks_iface_init (EvDocumentBookmarksIface *iface)
1007 iface->has_document_bookmarks = pdf_document_bookmarks_has_document_bookmarks;
1008 iface->begin_read = pdf_document_bookmarks_begin_read;
1009 iface->get_values = pdf_document_bookmarks_get_values;
1010 iface->get_child = pdf_document_bookmarks_get_child;
1011 iface->next = pdf_document_bookmarks_next;
1012 iface->free_iter = pdf_document_bookmarks_free_iter;
1017 pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
1018 gdouble scale_factor,
1024 GDKSplashOutputDev *output;
1028 pixmap = gdk_pixmap_new (pdf_document->target,
1031 output = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
1033 output->startDoc (pdf_document->doc->getXRef());
1034 pdf_document->doc->displayPage (output,
1039 output->redraw (0, 0,
1043 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1049 gdk_drawable_unref (pixmap);
1052 shadow = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
1053 g_object_unref (pixbuf);
1059 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1063 PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1064 GdkPixbuf *thumbnail;
1067 Thumb *thumb = NULL;
1068 gboolean have_ethumbs = FALSE;
1072 /* getPage seems to want page + 1 for some reason; */
1073 the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
1074 the_page->getThumb(&the_thumb);
1076 page_ratio = the_page->getHeight () / the_page->getWidth ();
1077 dest_height = (gint) (width * page_ratio);
1080 if (!(the_thumb.isNull () || the_thumb.isNone())) {
1081 /* Build the thumbnail object */
1082 thumb = new Thumb(pdf_document->doc->getXRef (),
1085 have_ethumbs = thumb->ok();
1090 GdkPixbuf *tmp_pixbuf;
1092 data = thumb->getPixbufData();
1093 tmp_pixbuf = gdk_pixbuf_new_from_data (data,
1098 thumb->getHeight (),
1099 thumb->getWidth () * 3,
1101 /* FIXME: do we want to check that the thumb's size isn't ridiculous?? */
1102 thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
1103 g_object_unref (tmp_pixbuf);
1105 gdouble scale_factor;
1107 scale_factor = (gdouble)width / the_page->getWidth ();
1109 thumbnail = pdf_document_thumbnails_get_page_pixbuf (pdf_document,
1119 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
1121 iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
1126 pdf_document_init (PdfDocument *pdf_document)
1128 pdf_document->page = 1;
1129 pdf_document->page_x_offset = 0;
1130 pdf_document->page_y_offset = 0;
1131 pdf_document->scale = 1.;
1133 pdf_document->page_valid = FALSE;