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.
26 #include <poppler-document.h>
27 #include <poppler-page.h>
29 #include <cairo-pdf.h>
34 #include <glib/gi18n-lib.h>
36 #include "ev-poppler.h"
37 #include "ev-file-exporter.h"
38 #include "ev-document-find.h"
39 #include "ev-document-misc.h"
40 #include "ev-document-links.h"
41 #include "ev-document-images.h"
42 #include "ev-document-fonts.h"
43 #include "ev-document-security.h"
44 #include "ev-document-thumbnails.h"
45 #include "ev-document-transition.h"
46 #include "ev-document-forms.h"
47 #include "ev-document-layers.h"
48 #include "ev-document-print.h"
49 #include "ev-document-annotations.h"
50 #include "ev-selection.h"
51 #include "ev-transition-effect.h"
52 #include "ev-attachment.h"
55 #if (defined (HAVE_POPPLER_PAGE_RENDER)) && (defined (HAVE_CAIRO_PDF) || defined (HAVE_CAIRO_PS))
56 #define HAVE_CAIRO_PRINT
60 PdfDocument *document;
69 EvFileExporterFormat format;
79 #ifdef HAVE_CAIRO_PRINT
82 PopplerPSFile *ps_file;
86 struct _PdfDocumentClass
88 GObjectClass parent_class;
93 GObject parent_instance;
95 PopplerDocument *document;
99 PopplerFontInfo *font_info;
100 PopplerFontsIter *fonts_iter;
101 int fonts_scanned_pages;
103 PdfDocumentSearch *search;
104 PdfPrintContext *print_ctx;
109 static void pdf_document_document_iface_init (EvDocumentIface *iface);
110 static void pdf_document_security_iface_init (EvDocumentSecurityIface *iface);
111 static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
112 static void pdf_document_document_links_iface_init (EvDocumentLinksIface *iface);
113 static void pdf_document_document_images_iface_init (EvDocumentImagesIface *iface);
114 static void pdf_document_document_forms_iface_init (EvDocumentFormsIface *iface);
115 static void pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface);
116 static void pdf_document_document_layers_iface_init (EvDocumentLayersIface *iface);
117 #ifdef HAVE_POPPLER_PAGE_RENDER
118 static void pdf_document_document_print_iface_init (EvDocumentPrintIface *iface);
120 static void pdf_document_document_annotations_iface_init (EvDocumentAnnotationsIface *iface);
121 static void pdf_document_find_iface_init (EvDocumentFindIface *iface);
122 static void pdf_document_file_exporter_iface_init (EvFileExporterIface *iface);
123 static void pdf_selection_iface_init (EvSelectionIface *iface);
124 static void pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface);
125 static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
129 static int pdf_document_get_n_pages (EvDocument *document);
131 static EvLinkDest *ev_link_dest_from_dest (PdfDocument *pdf_document,
133 static EvLink *ev_link_from_action (PdfDocument *pdf_document,
134 PopplerAction *action);
135 static void pdf_document_search_free (PdfDocumentSearch *search);
136 static void pdf_print_context_free (PdfPrintContext *ctx);
138 EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
140 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
141 pdf_document_security_iface_init);
142 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
143 pdf_document_document_thumbnails_iface_init);
144 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
145 pdf_document_document_links_iface_init);
146 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES,
147 pdf_document_document_images_iface_init);
148 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FORMS,
149 pdf_document_document_forms_iface_init);
150 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS,
151 pdf_document_document_fonts_iface_init);
152 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LAYERS,
153 pdf_document_document_layers_iface_init);
154 #ifdef HAVE_POPPLER_PAGE_RENDER
155 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_PRINT,
156 pdf_document_document_print_iface_init);
158 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ANNOTATIONS,
159 pdf_document_document_annotations_iface_init);
160 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
161 pdf_document_find_iface_init);
162 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
163 pdf_document_file_exporter_iface_init);
164 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION,
165 pdf_selection_iface_init);
166 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
167 pdf_document_page_transition_iface_init);
171 pdf_document_search_free (PdfDocumentSearch *search)
173 PdfDocument *pdf_document = search->document;
177 if (search->idle != 0)
178 g_source_remove (search->idle);
180 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
181 for (i = 0; i < n_pages; i++) {
182 g_list_foreach (search->pages[i], (GFunc) g_free, NULL);
183 g_list_free (search->pages[i]);
185 g_free (search->pages);
187 g_free (search->text);
192 pdf_document_dispose (GObject *object)
194 PdfDocument *pdf_document = PDF_DOCUMENT(object);
196 if (pdf_document->print_ctx) {
197 pdf_print_context_free (pdf_document->print_ctx);
198 pdf_document->print_ctx = NULL;
201 if (pdf_document->search) {
202 pdf_document_search_free (pdf_document->search);
203 pdf_document->search = NULL;
206 if (pdf_document->document) {
207 g_object_unref (pdf_document->document);
210 if (pdf_document->font_info) {
211 poppler_font_info_free (pdf_document->font_info);
214 if (pdf_document->fonts_iter) {
215 poppler_fonts_iter_free (pdf_document->fonts_iter);
218 if (pdf_document->layers) {
219 g_list_foreach (pdf_document->layers, (GFunc)g_object_unref, NULL);
220 g_list_free (pdf_document->layers);
223 G_OBJECT_CLASS (pdf_document_parent_class)->dispose (object);
227 pdf_document_class_init (PdfDocumentClass *klass)
229 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
231 g_object_class->dispose = pdf_document_dispose;
235 pdf_document_init (PdfDocument *pdf_document)
237 pdf_document->password = NULL;
241 convert_error (GError *poppler_error,
244 if (poppler_error == NULL)
247 if (poppler_error->domain == POPPLER_ERROR) {
248 /* convert poppler errors into EvDocument errors */
249 gint code = EV_DOCUMENT_ERROR_INVALID;
250 if (poppler_error->code == POPPLER_ERROR_INVALID)
251 code = EV_DOCUMENT_ERROR_INVALID;
252 else if (poppler_error->code == POPPLER_ERROR_ENCRYPTED)
253 code = EV_DOCUMENT_ERROR_ENCRYPTED;
255 g_set_error_literal (error,
258 poppler_error->message);
260 g_error_free (poppler_error);
262 g_propagate_error (error, poppler_error);
269 pdf_document_save (EvDocument *document,
273 PdfDocument *pdf_document = PDF_DOCUMENT (document);
275 GError *poppler_error = NULL;
277 if (pdf_document->modified) {
278 retval = poppler_document_save (pdf_document->document,
279 uri, &poppler_error);
281 retval = poppler_document_save_a_copy (pdf_document->document,
282 uri, &poppler_error);
286 convert_error (poppler_error, error);
292 pdf_document_load (EvDocument *document,
296 GError *poppler_error = NULL;
297 PdfDocument *pdf_document = PDF_DOCUMENT (document);
299 pdf_document->document =
300 poppler_document_new_from_file (uri, pdf_document->password, &poppler_error);
302 if (pdf_document->document == NULL) {
303 convert_error (poppler_error, error);
311 pdf_document_get_n_pages (EvDocument *document)
313 return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document);
317 pdf_document_get_page (EvDocument *document,
320 PdfDocument *pdf_document = PDF_DOCUMENT (document);
321 PopplerPage *poppler_page;
324 poppler_page = poppler_document_get_page (pdf_document->document, index);
325 page = ev_page_new (index);
326 page->backend_page = (EvBackendPage)g_object_ref (poppler_page);
327 page->backend_destroy_func = (EvBackendPageDestroyFunc)g_object_unref;
328 g_object_unref (poppler_page);
334 pdf_document_get_page_size (EvDocument *document,
339 g_return_if_fail (POPPLER_IS_PAGE (page->backend_page));
341 poppler_page_get_size (POPPLER_PAGE (page->backend_page), width, height);
345 pdf_document_get_page_label (EvDocument *document,
350 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
352 g_object_get (G_OBJECT (page->backend_page),
359 pdf_document_has_attachments (EvDocument *document)
361 PdfDocument *pdf_document;
363 pdf_document = PDF_DOCUMENT (document);
365 return poppler_document_has_attachments (pdf_document->document);
368 struct SaveToBufferData {
374 attachment_save_to_buffer_callback (const gchar *buf,
379 struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
383 if (sdata->len + count > sdata->max) {
384 new_max = MAX (sdata->max * 2, sdata->len + count);
385 new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
387 sdata->buffer = new_buffer;
388 sdata->max = new_max;
391 memcpy (sdata->buffer + sdata->len, buf, count);
398 attachment_save_to_buffer (PopplerAttachment *attachment,
403 static const gint initial_max = 1024;
404 struct SaveToBufferData sdata;
409 sdata.buffer = (gchar *) g_malloc (initial_max);
410 sdata.max = initial_max;
413 if (! poppler_attachment_save_to_callback (attachment,
414 attachment_save_to_buffer_callback,
417 g_free (sdata.buffer);
421 *buffer = sdata.buffer;
422 *buffer_size = sdata.len;
428 pdf_document_get_attachments (EvDocument *document)
430 PdfDocument *pdf_document;
433 GList *retval = NULL;
435 pdf_document = PDF_DOCUMENT (document);
437 if (!pdf_document_has_attachments (document))
440 attachments = poppler_document_get_attachments (pdf_document->document);
442 for (list = attachments; list; list = list->next) {
443 PopplerAttachment *attachment;
444 EvAttachment *ev_attachment;
447 GError *error = NULL;
449 attachment = (PopplerAttachment *) list->data;
451 if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
452 ev_attachment = ev_attachment_new (attachment->name,
453 attachment->description,
458 retval = g_list_prepend (retval, ev_attachment);
461 g_warning ("%s", error->message);
462 g_error_free (error);
468 g_object_unref (attachment);
471 return g_list_reverse (retval);
474 static cairo_surface_t *
475 pdf_page_render (PopplerPage *page,
480 cairo_surface_t *surface;
482 #ifdef HAVE_POPPLER_PAGE_RENDER
485 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
487 memset (cairo_image_surface_get_data (surface), 0xff,
488 cairo_image_surface_get_height (surface) *
489 cairo_image_surface_get_stride (surface));
491 cr = cairo_create (surface);
492 switch (rc->rotation) {
494 cairo_translate (cr, width, 0);
497 cairo_translate (cr, width, height);
500 cairo_translate (cr, 0, height);
503 cairo_translate (cr, 0, 0);
505 cairo_scale (cr, rc->scale, rc->scale);
506 cairo_rotate (cr, rc->rotation * G_PI / 180.0);
507 poppler_page_render (page, cr);
509 #else /* HAVE_POPPLER_PAGE_RENDER */
512 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
516 poppler_page_render_to_pixbuf (page,
522 surface = ev_document_misc_surface_from_pixbuf (pixbuf);
523 g_object_unref (pixbuf);
524 #endif /* HAVE_POPPLER_PAGE_RENDER */
529 static cairo_surface_t *
530 pdf_document_render (EvDocument *document,
533 PdfDocument *pdf_document;
534 PopplerPage *poppler_page;
535 double width_points, height_points;
538 poppler_page = POPPLER_PAGE (rc->page->backend_page);
540 poppler_page_get_size (poppler_page,
541 &width_points, &height_points);
543 if (rc->rotation == 90 || rc->rotation == 270) {
544 width = (int) ((height_points * rc->scale) + 0.5);
545 height = (int) ((width_points * rc->scale) + 0.5);
547 width = (int) ((width_points * rc->scale) + 0.5);
548 height = (int) ((height_points * rc->scale) + 0.5);
551 return pdf_page_render (poppler_page,
555 /* EvDocumentSecurity */
558 pdf_document_has_document_security (EvDocumentSecurity *document_security)
560 /* FIXME: do we really need to have this? */
565 pdf_document_set_password (EvDocumentSecurity *document_security,
566 const char *password)
568 PdfDocument *document = PDF_DOCUMENT (document_security);
570 if (document->password)
571 g_free (document->password);
573 document->password = g_strdup (password);
576 static EvDocumentInfo *
577 pdf_document_get_info (EvDocument *document)
579 EvDocumentInfo *info;
580 PopplerPageLayout layout;
581 PopplerPageMode mode;
582 PopplerViewerPreferences view_prefs;
583 PopplerPermissions permissions;
586 info = g_new0 (EvDocumentInfo, 1);
588 info->fields_mask = EV_DOCUMENT_INFO_TITLE |
589 EV_DOCUMENT_INFO_FORMAT |
590 EV_DOCUMENT_INFO_AUTHOR |
591 EV_DOCUMENT_INFO_SUBJECT |
592 EV_DOCUMENT_INFO_KEYWORDS |
593 EV_DOCUMENT_INFO_LAYOUT |
594 EV_DOCUMENT_INFO_START_MODE |
595 EV_DOCUMENT_INFO_PERMISSIONS |
596 EV_DOCUMENT_INFO_UI_HINTS |
597 EV_DOCUMENT_INFO_CREATOR |
598 EV_DOCUMENT_INFO_PRODUCER |
599 EV_DOCUMENT_INFO_CREATION_DATE |
600 EV_DOCUMENT_INFO_MOD_DATE |
601 EV_DOCUMENT_INFO_LINEARIZED |
602 EV_DOCUMENT_INFO_N_PAGES |
603 EV_DOCUMENT_INFO_SECURITY |
604 EV_DOCUMENT_INFO_PAPER_SIZE;
606 g_object_get (PDF_DOCUMENT (document)->document,
607 "title", &(info->title),
608 "format", &(info->format),
609 "author", &(info->author),
610 "subject", &(info->subject),
611 "keywords", &(info->keywords),
613 "page-layout", &layout,
614 "viewer-preferences", &view_prefs,
615 "permissions", &permissions,
616 "creator", &(info->creator),
617 "producer", &(info->producer),
618 "creation-date", &(info->creation_date),
619 "mod-date", &(info->modified_date),
620 "linearized", &(info->linearized),
623 info->n_pages = ev_document_get_n_pages (document);
625 if (info->n_pages > 0) {
626 page = ev_document_get_page (document, 0);
627 ev_document_get_page_size (document, page,
628 &(info->paper_width),
629 &(info->paper_height));
630 g_object_unref (page);
634 info->paper_width = info->paper_width / 72.0f * 25.4f;
635 info->paper_height = info->paper_height / 72.0f * 25.4f;
639 case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
640 info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
642 case POPPLER_PAGE_LAYOUT_ONE_COLUMN:
643 info->layout = EV_DOCUMENT_LAYOUT_ONE_COLUMN;
645 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_LEFT:
646 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_LEFT;
648 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
649 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
650 case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
651 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
653 case POPPLER_PAGE_LAYOUT_TWO_PAGE_RIGHT:
654 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_RIGHT;
661 case POPPLER_PAGE_MODE_NONE:
662 info->mode = EV_DOCUMENT_MODE_NONE;
664 case POPPLER_PAGE_MODE_USE_THUMBS:
665 info->mode = EV_DOCUMENT_MODE_USE_THUMBS;
667 case POPPLER_PAGE_MODE_USE_OC:
668 info->mode = EV_DOCUMENT_MODE_USE_OC;
670 case POPPLER_PAGE_MODE_FULL_SCREEN:
671 info->mode = EV_DOCUMENT_MODE_FULL_SCREEN;
673 case POPPLER_PAGE_MODE_USE_ATTACHMENTS:
674 info->mode = EV_DOCUMENT_MODE_USE_ATTACHMENTS;
680 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_TOOLBAR) {
681 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_TOOLBAR;
683 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_MENUBAR) {
684 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_MENUBAR;
686 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_WINDOWUI) {
687 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_WINDOWUI;
689 if (view_prefs & POPPLER_VIEWER_PREFERENCES_FIT_WINDOW) {
690 info->ui_hints |= EV_DOCUMENT_UI_HINT_FIT_WINDOW;
692 if (view_prefs & POPPLER_VIEWER_PREFERENCES_CENTER_WINDOW) {
693 info->ui_hints |= EV_DOCUMENT_UI_HINT_CENTER_WINDOW;
695 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DISPLAY_DOC_TITLE) {
696 info->ui_hints |= EV_DOCUMENT_UI_HINT_DISPLAY_DOC_TITLE;
698 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL) {
699 info->ui_hints |= EV_DOCUMENT_UI_HINT_DIRECTION_RTL;
702 info->permissions = 0;
703 if (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT) {
704 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT;
706 if (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY) {
707 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY;
709 if (permissions & POPPLER_PERMISSIONS_OK_TO_COPY) {
710 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_COPY;
712 if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) {
713 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES;
716 if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
717 /* translators: this is the document security state */
718 info->security = g_strdup (_("Yes"));
720 /* translators: this is the document security state */
721 info->security = g_strdup (_("No"));
728 pdf_document_document_iface_init (EvDocumentIface *iface)
730 iface->save = pdf_document_save;
731 iface->load = pdf_document_load;
732 iface->get_n_pages = pdf_document_get_n_pages;
733 iface->get_page = pdf_document_get_page;
734 iface->get_page_size = pdf_document_get_page_size;
735 iface->get_page_label = pdf_document_get_page_label;
736 iface->has_attachments = pdf_document_has_attachments;
737 iface->get_attachments = pdf_document_get_attachments;
738 iface->render = pdf_document_render;
739 iface->get_info = pdf_document_get_info;
743 pdf_document_security_iface_init (EvDocumentSecurityIface *iface)
745 iface->has_document_security = pdf_document_has_document_security;
746 iface->set_password = pdf_document_set_password;
750 pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts)
752 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
755 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
757 return (double)pdf_document->fonts_scanned_pages / (double)n_pages;
761 pdf_document_fonts_scan (EvDocumentFonts *document_fonts,
764 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
767 g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE);
769 if (pdf_document->font_info == NULL) {
770 pdf_document->font_info = poppler_font_info_new (pdf_document->document);
773 if (pdf_document->fonts_iter) {
774 poppler_fonts_iter_free (pdf_document->fonts_iter);
777 pdf_document->fonts_scanned_pages += n_pages;
779 result = poppler_font_info_scan (pdf_document->font_info, n_pages,
780 &pdf_document->fonts_iter);
782 pdf_document->fonts_scanned_pages = 0;
783 poppler_font_info_free (pdf_document->font_info);
784 pdf_document->font_info = NULL;
791 font_type_to_string (PopplerFontType type)
794 case POPPLER_FONT_TYPE_TYPE1:
796 case POPPLER_FONT_TYPE_TYPE1C:
798 case POPPLER_FONT_TYPE_TYPE3:
800 case POPPLER_FONT_TYPE_TRUETYPE:
801 return _("TrueType");
802 case POPPLER_FONT_TYPE_CID_TYPE0:
803 return _("Type 1 (CID)");
804 case POPPLER_FONT_TYPE_CID_TYPE0C:
805 return _("Type 1C (CID)");
806 case POPPLER_FONT_TYPE_CID_TYPE2:
807 return _("TrueType (CID)");
809 return _("Unknown font type");
814 pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
817 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
818 PopplerFontsIter *iter = pdf_document->fonts_iter;
820 g_return_if_fail (PDF_IS_DOCUMENT (document_fonts));
826 GtkTreeIter list_iter;
829 const char *embedded;
832 name = poppler_fonts_iter_get_name (iter);
838 type = font_type_to_string (
839 poppler_fonts_iter_get_font_type (iter));
841 if (poppler_fonts_iter_is_embedded (iter)) {
842 if (poppler_fonts_iter_is_subset (iter))
843 embedded = _("Embedded subset");
845 embedded = _("Embedded");
847 embedded = _("Not embedded");
850 details = g_markup_printf_escaped ("%s\n%s", type, embedded);
852 gtk_list_store_append (GTK_LIST_STORE (model), &list_iter);
853 gtk_list_store_set (GTK_LIST_STORE (model), &list_iter,
854 EV_DOCUMENT_FONTS_COLUMN_NAME, name,
855 EV_DOCUMENT_FONTS_COLUMN_DETAILS, details,
859 } while (poppler_fonts_iter_next (iter));
863 pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface)
865 iface->fill_model = pdf_document_fonts_fill_model;
866 iface->scan = pdf_document_fonts_scan;
867 iface->get_progress = pdf_document_fonts_get_progress;
871 pdf_document_links_has_document_links (EvDocumentLinks *document_links)
873 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
874 PopplerIndexIter *iter;
876 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
878 iter = poppler_index_iter_new (pdf_document->document);
881 poppler_index_iter_free (iter);
887 ev_link_dest_from_dest (PdfDocument *pdf_document,
890 EvLinkDest *ev_dest = NULL;
891 const char *unimplemented_dest = NULL;
893 g_assert (dest != NULL);
895 switch (dest->type) {
896 case POPPLER_DEST_XYZ: {
897 PopplerPage *poppler_page;
900 poppler_page = poppler_document_get_page (pdf_document->document,
901 MAX (0, dest->page_num - 1));
902 poppler_page_get_size (poppler_page, NULL, &height);
903 ev_dest = ev_link_dest_new_xyz (dest->page_num - 1,
905 height - MIN (height, dest->top),
910 g_object_unref (poppler_page);
913 case POPPLER_DEST_FIT:
914 ev_dest = ev_link_dest_new_fit (dest->page_num - 1);
916 case POPPLER_DEST_FITH: {
917 PopplerPage *poppler_page;
920 poppler_page = poppler_document_get_page (pdf_document->document,
921 MAX (0, dest->page_num - 1));
922 poppler_page_get_size (poppler_page, NULL, &height);
923 ev_dest = ev_link_dest_new_fith (dest->page_num - 1,
924 height - MIN (height, dest->top),
926 g_object_unref (poppler_page);
929 case POPPLER_DEST_FITV:
930 ev_dest = ev_link_dest_new_fitv (dest->page_num - 1,
934 case POPPLER_DEST_FITR: {
935 PopplerPage *poppler_page;
938 poppler_page = poppler_document_get_page (pdf_document->document,
939 MAX (0, dest->page_num - 1));
940 poppler_page_get_size (poppler_page, NULL, &height);
941 ev_dest = ev_link_dest_new_fitr (dest->page_num - 1,
943 height - MIN (height, dest->bottom),
945 height - MIN (height, dest->top));
946 g_object_unref (poppler_page);
949 case POPPLER_DEST_FITB:
950 unimplemented_dest = "POPPLER_DEST_FITB";
952 case POPPLER_DEST_FITBH:
953 unimplemented_dest = "POPPLER_DEST_FITBH";
955 case POPPLER_DEST_FITBV:
956 unimplemented_dest = "POPPLER_DEST_FITBV";
958 case POPPLER_DEST_NAMED:
959 ev_dest = ev_link_dest_new_named (dest->named_dest);
961 case POPPLER_DEST_UNKNOWN:
962 unimplemented_dest = "POPPLER_DEST_UNKNOWN";
966 if (unimplemented_dest) {
967 g_warning ("Unimplemented destination: %s, please post a "
968 "bug report in Evince bugzilla "
969 "(http://bugzilla.gnome.org) with a testcase.",
974 ev_dest = ev_link_dest_new_page (dest->page_num - 1);
980 ev_link_from_action (PdfDocument *pdf_document,
981 PopplerAction *action)
984 EvLinkAction *ev_action = NULL;
985 const char *unimplemented_action = NULL;
987 switch (action->type) {
988 case POPPLER_ACTION_NONE:
990 case POPPLER_ACTION_GOTO_DEST: {
993 dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest);
994 ev_action = ev_link_action_new_dest (dest);
997 case POPPLER_ACTION_GOTO_REMOTE: {
1000 dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest);
1001 ev_action = ev_link_action_new_remote (dest,
1002 action->goto_remote.file_name);
1006 case POPPLER_ACTION_LAUNCH:
1007 ev_action = ev_link_action_new_launch (action->launch.file_name,
1008 action->launch.params);
1010 case POPPLER_ACTION_URI:
1011 ev_action = ev_link_action_new_external_uri (action->uri.uri);
1013 case POPPLER_ACTION_NAMED:
1014 ev_action = ev_link_action_new_named (action->named.named_dest);
1016 case POPPLER_ACTION_MOVIE:
1017 unimplemented_action = "POPPLER_ACTION_MOVIE";
1019 case POPPLER_ACTION_UNKNOWN:
1020 unimplemented_action = "POPPLER_ACTION_UNKNOWN";
1023 if (unimplemented_action) {
1024 g_warning ("Unimplemented action: %s, please post a bug report "
1025 "in Evince bugzilla (http://bugzilla.gnome.org) "
1026 "with a testcase.", unimplemented_action);
1029 link = ev_link_new (action->any.title, ev_action);
1035 build_tree (PdfDocument *pdf_document,
1036 GtkTreeModel *model,
1037 GtkTreeIter *parent,
1038 PopplerIndexIter *iter)
1042 GtkTreeIter tree_iter;
1043 PopplerIndexIter *child;
1044 PopplerAction *action;
1045 EvLink *link = NULL;
1049 action = poppler_index_iter_get_action (iter);
1050 expand = poppler_index_iter_is_open (iter);
1055 switch (action->type) {
1056 case POPPLER_ACTION_GOTO_DEST: {
1057 /* For bookmarks, solve named destinations */
1058 if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
1060 EvLinkDest *ev_dest = NULL;
1061 EvLinkAction *ev_action;
1063 dest = poppler_document_find_dest (pdf_document->document,
1064 action->goto_dest.dest->named_dest);
1066 link = ev_link_from_action (pdf_document, action);
1070 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1071 poppler_dest_free (dest);
1073 ev_action = ev_link_action_new_dest (ev_dest);
1074 link = ev_link_new (action->any.title, ev_action);
1076 link = ev_link_from_action (pdf_document, action);
1081 link = ev_link_from_action (pdf_document, action);
1085 if (!link || strlen (ev_link_get_title (link)) <= 0) {
1086 poppler_action_free (action);
1088 g_object_unref (link);
1093 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
1094 title_markup = g_markup_escape_text (ev_link_get_title (link), -1);
1096 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
1097 EV_DOCUMENT_LINKS_COLUMN_MARKUP, title_markup,
1098 EV_DOCUMENT_LINKS_COLUMN_LINK, link,
1099 EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand,
1102 g_free (title_markup);
1103 g_object_unref (link);
1105 child = poppler_index_iter_get_child (iter);
1107 build_tree (pdf_document, model, &tree_iter, child);
1108 poppler_index_iter_free (child);
1109 poppler_action_free (action);
1111 } while (poppler_index_iter_next (iter));
1114 static GtkTreeModel *
1115 pdf_document_links_get_links_model (EvDocumentLinks *document_links)
1117 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1118 GtkTreeModel *model = NULL;
1119 PopplerIndexIter *iter;
1121 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
1123 iter = poppler_index_iter_new (pdf_document->document);
1124 /* Create the model if we have items*/
1126 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
1131 build_tree (pdf_document, model, NULL, iter);
1132 poppler_index_iter_free (iter);
1139 pdf_document_links_get_links (EvDocumentLinks *document_links,
1142 PdfDocument *pdf_document;
1143 PopplerPage *poppler_page;
1144 GList *retval = NULL;
1145 GList *mapping_list;
1149 pdf_document = PDF_DOCUMENT (document_links);
1150 poppler_page = poppler_document_get_page (pdf_document->document,
1152 mapping_list = poppler_page_get_link_mapping (poppler_page);
1153 poppler_page_get_size (poppler_page, NULL, &height);
1155 for (list = mapping_list; list; list = list->next) {
1156 PopplerLinkMapping *link_mapping;
1157 EvLinkMapping *ev_link_mapping;
1159 link_mapping = (PopplerLinkMapping *)list->data;
1160 ev_link_mapping = g_new (EvLinkMapping, 1);
1161 ev_link_mapping->link = ev_link_from_action (pdf_document,
1162 link_mapping->action);
1163 ev_link_mapping->x1 = link_mapping->area.x1;
1164 ev_link_mapping->x2 = link_mapping->area.x2;
1165 /* Invert this for X-style coordinates */
1166 ev_link_mapping->y1 = height - link_mapping->area.y2;
1167 ev_link_mapping->y2 = height - link_mapping->area.y1;
1169 retval = g_list_prepend (retval, ev_link_mapping);
1172 poppler_page_free_link_mapping (mapping_list);
1173 g_object_unref (poppler_page);
1175 return g_list_reverse (retval);
1179 pdf_document_links_find_link_dest (EvDocumentLinks *document_links,
1180 const gchar *link_name)
1182 PdfDocument *pdf_document;
1184 EvLinkDest *ev_dest = NULL;
1186 pdf_document = PDF_DOCUMENT (document_links);
1187 dest = poppler_document_find_dest (pdf_document->document,
1190 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1191 poppler_dest_free (dest);
1198 pdf_document_document_links_iface_init (EvDocumentLinksIface *iface)
1200 iface->has_document_links = pdf_document_links_has_document_links;
1201 iface->get_links_model = pdf_document_links_get_links_model;
1202 iface->get_links = pdf_document_links_get_links;
1203 iface->find_link_dest = pdf_document_links_find_link_dest;
1207 pdf_document_images_get_image_mapping (EvDocumentImages *document_images,
1210 GList *retval = NULL;
1211 PdfDocument *pdf_document;
1212 PopplerPage *poppler_page;
1213 GList *mapping_list;
1216 pdf_document = PDF_DOCUMENT (document_images);
1217 poppler_page = poppler_document_get_page (pdf_document->document, page);
1218 mapping_list = poppler_page_get_image_mapping (poppler_page);
1220 for (list = mapping_list; list; list = list->next) {
1221 PopplerImageMapping *image_mapping;
1222 EvImageMapping *ev_image_mapping;
1224 image_mapping = (PopplerImageMapping *)list->data;
1226 ev_image_mapping = g_new (EvImageMapping, 1);
1228 ev_image_mapping->image = ev_image_new (page, image_mapping->image_id);
1229 ev_image_mapping->x1 = image_mapping->area.x1;
1230 ev_image_mapping->x2 = image_mapping->area.x2;
1231 ev_image_mapping->y1 = image_mapping->area.y1;
1232 ev_image_mapping->y2 = image_mapping->area.y2;
1234 retval = g_list_prepend (retval, ev_image_mapping);
1237 poppler_page_free_image_mapping (mapping_list);
1238 g_object_unref (poppler_page);
1240 return g_list_reverse (retval);
1244 pdf_document_images_get_image (EvDocumentImages *document_images,
1247 GdkPixbuf *retval = NULL;
1248 #ifdef HAVE_POPPLER_PAGE_GET_IMAGE
1249 PdfDocument *pdf_document;
1250 PopplerPage *poppler_page;
1251 cairo_surface_t *surface;
1253 pdf_document = PDF_DOCUMENT (document_images);
1254 poppler_page = poppler_document_get_page (pdf_document->document,
1255 ev_image_get_page (image));
1257 surface = poppler_page_get_image (poppler_page, ev_image_get_id (image));
1259 retval = ev_document_misc_pixbuf_from_surface (surface);
1260 cairo_surface_destroy (surface);
1263 g_object_unref (poppler_page);
1269 pdf_document_document_images_iface_init (EvDocumentImagesIface *iface)
1271 iface->get_image_mapping = pdf_document_images_get_image_mapping;
1272 iface->get_image = pdf_document_images_get_image;
1276 make_thumbnail_for_page (PopplerPage *poppler_page,
1277 EvRenderContext *rc,
1283 #ifdef POPPLER_WITH_GDK
1284 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
1286 gdk_pixbuf_fill (pixbuf, 0xffffffff);
1288 ev_document_fc_mutex_lock ();
1289 poppler_page_render_to_pixbuf (poppler_page, 0, 0,
1291 rc->scale, rc->rotation, pixbuf);
1292 ev_document_fc_mutex_unlock ();
1294 cairo_surface_t *surface;
1296 ev_document_fc_mutex_lock ();
1297 surface = pdf_page_render (poppler_page, width, height, rc);
1298 ev_document_fc_mutex_unlock ();
1300 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1301 cairo_surface_destroy (surface);
1302 #endif /* POPPLER_WITH_GDK */
1308 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1309 EvRenderContext *rc,
1312 PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1313 PopplerPage *poppler_page;
1314 GdkPixbuf *pixbuf = NULL;
1315 GdkPixbuf *border_pixbuf;
1318 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1320 pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document),
1321 rc, &width, &height);
1323 #ifdef POPPLER_WITH_GDK
1324 pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page);
1326 cairo_surface_t *surface;
1328 surface = poppler_page_get_thumbnail (poppler_page);
1330 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1331 cairo_surface_destroy (surface);
1333 #endif /* POPPLER_WITH_GDK */
1335 if (pixbuf != NULL) {
1336 int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ?
1337 gdk_pixbuf_get_height (pixbuf) :
1338 gdk_pixbuf_get_width (pixbuf);
1340 if (thumb_width == width) {
1341 GdkPixbuf *rotated_pixbuf;
1343 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
1344 (GdkPixbufRotation) (360 - rc->rotation));
1345 g_object_unref (pixbuf);
1346 pixbuf = rotated_pixbuf;
1348 /* The provided thumbnail has a different size */
1349 g_object_unref (pixbuf);
1350 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1353 /* There is no provided thumbnail. We need to make one. */
1354 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1357 if (border && pixbuf) {
1358 border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
1359 g_object_unref (pixbuf);
1360 pixbuf = border_pixbuf;
1367 pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
1368 EvRenderContext *rc,
1372 double page_width, page_height;
1374 poppler_page_get_size (POPPLER_PAGE (rc->page->backend_page),
1375 &page_width, &page_height);
1377 *width = (gint) MAX (page_width * rc->scale, 1);
1378 *height = (gint) MAX (page_height * rc->scale, 1);
1380 if (rc->rotation == 90 || rc->rotation == 270) {
1390 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
1392 iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
1393 iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
1398 pdf_document_find_find_text (EvDocumentFind *document_find,
1401 gboolean case_sensitive)
1404 PopplerPage *poppler_page;
1407 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1408 g_return_val_if_fail (text != NULL, NULL);
1410 poppler_page = POPPLER_PAGE (page->backend_page);
1412 matches = poppler_page_find_text (poppler_page, text);
1416 poppler_page_get_size (poppler_page, NULL, &height);
1417 for (l = matches; l && l->data; l = g_list_next (l)) {
1418 PopplerRectangle *rect = (PopplerRectangle *)l->data;
1422 rect->y1 = height - rect->y2;
1423 rect->y2 = height - tmp;
1430 pdf_document_find_iface_init (EvDocumentFindIface *iface)
1432 iface->find_text = pdf_document_find_find_text;
1436 pdf_print_context_free (PdfPrintContext *ctx)
1441 #ifdef HAVE_CAIRO_PRINT
1443 cairo_destroy (ctx->cr);
1448 poppler_ps_file_free (ctx->ps_file);
1449 ctx->ps_file = NULL;
1456 pdf_document_file_exporter_begin (EvFileExporter *exporter,
1457 EvFileExporterContext *fc)
1459 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1460 PdfPrintContext *ctx;
1461 #ifdef HAVE_CAIRO_PRINT
1462 gdouble width, height;
1463 cairo_surface_t *surface = NULL;
1466 if (pdf_document->print_ctx)
1467 pdf_print_context_free (pdf_document->print_ctx);
1468 pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
1469 ctx = pdf_document->print_ctx;
1470 ctx->format = fc->format;
1472 #ifdef HAVE_CAIRO_PRINT
1473 ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
1475 ctx->paper_width = fc->paper_width;
1476 ctx->paper_height = fc->paper_height;
1478 switch (fc->pages_per_sheet) {
1506 ctx->pages_printed = 0;
1508 switch (fc->format) {
1509 case EV_FILE_FORMAT_PS:
1510 #ifdef HAVE_CAIRO_PS
1511 surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1514 case EV_FILE_FORMAT_PDF:
1515 #ifdef HAVE_CAIRO_PDF
1516 surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1520 g_assert_not_reached ();
1523 ctx->cr = cairo_create (surface);
1524 cairo_surface_destroy (surface);
1526 #else /* HAVE_CAIRO_PRINT */
1527 if (ctx->format == EV_FILE_FORMAT_PS) {
1528 ctx->ps_file = poppler_ps_file_new (pdf_document->document,
1529 fc->filename, fc->first_page,
1530 fc->last_page - fc->first_page + 1);
1531 poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
1532 poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
1534 #endif /* HAVE_CAIRO_PRINT */
1538 pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
1540 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1541 PdfPrintContext *ctx = pdf_document->print_ctx;
1543 g_return_if_fail (pdf_document->print_ctx != NULL);
1545 ctx->pages_printed = 0;
1547 #ifdef HAVE_CAIRO_PRINT
1548 if (ctx->paper_width > ctx->paper_height) {
1549 if (ctx->format == EV_FILE_FORMAT_PS) {
1550 cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
1553 } else if (ctx->format == EV_FILE_FORMAT_PDF) {
1554 cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
1559 #endif /* HAVE_CAIRO_PRINT */
1563 pdf_document_file_exporter_do_page (EvFileExporter *exporter,
1564 EvRenderContext *rc)
1566 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1567 PdfPrintContext *ctx = pdf_document->print_ctx;
1568 PopplerPage *poppler_page;
1569 #ifdef HAVE_CAIRO_PRINT
1570 gdouble page_width, page_height;
1573 gdouble width, height;
1574 gdouble pwidth, pheight;
1575 gdouble xscale, yscale;
1578 g_return_if_fail (pdf_document->print_ctx != NULL);
1580 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1582 #ifdef HAVE_CAIRO_PRINT
1583 x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
1584 y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
1585 poppler_page_get_size (poppler_page, &page_width, &page_height);
1587 if (page_width > page_height && page_width > ctx->paper_width) {
1593 /* Use always portrait mode and rotate when necessary */
1594 if (ctx->paper_width > ctx->paper_height) {
1595 width = ctx->paper_height;
1596 height = ctx->paper_width;
1599 width = ctx->paper_width;
1600 height = ctx->paper_height;
1603 if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
1616 page_width = page_height;
1620 pwidth = width / ctx->pages_x;
1621 pheight = height / ctx->pages_y;
1623 if ((page_width > pwidth || page_height > pheight) ||
1624 (page_width < pwidth && page_height < pheight)) {
1625 xscale = pwidth / page_width;
1626 yscale = pheight / page_height;
1628 if (yscale < xscale) {
1635 xscale = yscale = 1;
1640 cairo_save (ctx->cr);
1642 cairo_matrix_t matrix;
1644 cairo_translate (ctx->cr, (2 * y + 1) * pwidth, 0);
1645 cairo_matrix_init (&matrix,
1649 cairo_transform (ctx->cr, &matrix);
1652 cairo_translate (ctx->cr,
1653 x * (rotate ? pheight : pwidth),
1654 y * (rotate ? pwidth : pheight));
1655 cairo_scale (ctx->cr, xscale, yscale);
1657 poppler_page_render_for_printing (poppler_page, ctx->cr);
1659 ctx->pages_printed++;
1661 cairo_restore (ctx->cr);
1662 #else /* HAVE_CAIRO_PRINT */
1663 if (ctx->format == EV_FILE_FORMAT_PS)
1664 poppler_page_render_to_ps (poppler_page, ctx->ps_file);
1665 #endif /* HAVE_CAIRO_PRINT */
1669 pdf_document_file_exporter_end_page (EvFileExporter *exporter)
1671 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1672 PdfPrintContext *ctx = pdf_document->print_ctx;
1674 g_return_if_fail (pdf_document->print_ctx != NULL);
1676 #ifdef HAVE_CAIRO_PRINT
1677 cairo_show_page (ctx->cr);
1682 pdf_document_file_exporter_end (EvFileExporter *exporter)
1684 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1686 pdf_print_context_free (pdf_document->print_ctx);
1687 pdf_document->print_ctx = NULL;
1690 static EvFileExporterCapabilities
1691 pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter)
1693 return (EvFileExporterCapabilities) (
1694 EV_FILE_EXPORTER_CAN_PAGE_SET |
1695 EV_FILE_EXPORTER_CAN_COPIES |
1696 EV_FILE_EXPORTER_CAN_COLLATE |
1697 EV_FILE_EXPORTER_CAN_REVERSE |
1698 EV_FILE_EXPORTER_CAN_SCALE |
1699 #ifdef HAVE_CAIRO_PRINT
1700 #ifdef HAVE_POPPLER_PAGE_RENDER
1701 EV_FILE_EXPORTER_CAN_NUMBER_UP |
1705 #ifdef HAVE_CAIRO_PDF
1706 #ifdef HAVE_POPPLER_PAGE_RENDER
1707 EV_FILE_EXPORTER_CAN_GENERATE_PDF |
1710 EV_FILE_EXPORTER_CAN_GENERATE_PS);
1714 pdf_document_file_exporter_iface_init (EvFileExporterIface *iface)
1716 iface->begin = pdf_document_file_exporter_begin;
1717 iface->begin_page = pdf_document_file_exporter_begin_page;
1718 iface->do_page = pdf_document_file_exporter_do_page;
1719 iface->end_page = pdf_document_file_exporter_end_page;
1720 iface->end = pdf_document_file_exporter_end;
1721 iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
1724 #ifdef HAVE_POPPLER_PAGE_RENDER
1725 /* EvDocumentPrint */
1727 pdf_document_print_print_page (EvDocumentPrint *document,
1731 PdfDocument *pdf_document = PDF_DOCUMENT (document);
1733 poppler_page_render_for_printing (POPPLER_PAGE (page->backend_page), cr);
1737 pdf_document_document_print_iface_init (EvDocumentPrintIface *iface)
1739 iface->print_page = pdf_document_print_print_page;
1741 #endif /* HAVE_POPPLER_PAGE_RENDER */
1744 pdf_selection_render_selection (EvSelection *selection,
1745 EvRenderContext *rc,
1746 cairo_surface_t **surface,
1747 EvRectangle *points,
1748 EvRectangle *old_points,
1749 EvSelectionStyle style,
1753 PopplerPage *poppler_page;
1754 double width_points, height_points;
1757 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1759 poppler_page_get_size (poppler_page,
1760 &width_points, &height_points);
1761 width = (int) ((width_points * rc->scale) + 0.5);
1762 height = (int) ((height_points * rc->scale) + 0.5);
1764 #ifdef HAVE_POPPLER_PAGE_RENDER
1766 PopplerColor text_color, base_color;
1768 text_color.red = text->red;
1769 text_color.green = text->green;
1770 text_color.blue = text->blue;
1772 base_color.red = base->red;
1773 base_color.green = base->green;
1774 base_color.blue = base->blue;
1776 if (*surface == NULL) {
1777 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1782 cr = cairo_create (*surface);
1783 cairo_scale (cr, rc->scale, rc->scale);
1784 cairo_surface_set_device_offset (*surface, 0, 0);
1785 memset (cairo_image_surface_get_data (*surface), 0x00,
1786 cairo_image_surface_get_height (*surface) *
1787 cairo_image_surface_get_stride (*surface));
1788 poppler_page_render_selection (poppler_page,
1790 (PopplerRectangle *)points,
1791 (PopplerRectangle *)old_points,
1792 (PopplerSelectionStyle)style,
1796 #else /* HAVE_POPPLER_PAGE_RENDER */
1799 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
1803 poppler_page_render_selection_to_pixbuf (poppler_page,
1804 rc->scale, rc->rotation, pixbuf,
1805 (PopplerRectangle *)points,
1806 (PopplerRectangle *)old_points,
1807 (PopplerSelectionStyle)style,
1811 cairo_surface_destroy (*surface);
1812 *surface = ev_document_misc_surface_from_pixbuf (pixbuf);
1813 g_object_unref (pixbuf);
1814 #endif /* HAVE_POPPLER_PAGE_RENDER */
1818 pdf_selection_get_selected_text (EvSelection *selection,
1819 EvRenderContext *rc,
1820 EvSelectionStyle style,
1821 EvRectangle *points)
1823 PopplerPage *poppler_page;
1828 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1830 poppler_page_get_size (poppler_page, NULL, &height);
1832 r.y1 = height - points->y2;
1834 r.y2 = height - points->y1;
1836 retval = poppler_page_get_text (poppler_page,
1837 (PopplerSelectionStyle)style,
1844 create_gdk_region_from_poppler_region (GList *region)
1849 retval = gdk_region_new ();
1851 for (l = region; l; l = g_list_next (l)) {
1852 PopplerRectangle *rectangle;
1855 rectangle = (PopplerRectangle *)l->data;
1857 rect.x = (gint) rectangle->x1;
1858 rect.y = (gint) rectangle->y1;
1859 rect.width = (gint) (rectangle->x2 - rectangle->x1);
1860 rect.height = (gint) (rectangle->y2 - rectangle->y1);
1861 gdk_region_union_with_rect (retval, &rect);
1863 poppler_rectangle_free (rectangle);
1870 pdf_selection_get_selection_region (EvSelection *selection,
1871 EvRenderContext *rc,
1872 EvSelectionStyle style,
1873 EvRectangle *points)
1875 PopplerPage *poppler_page;
1879 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1881 region = poppler_page_get_selection_region (poppler_page,
1883 (PopplerSelectionStyle)style,
1884 (PopplerRectangle *) points);
1885 retval = create_gdk_region_from_poppler_region (region);
1886 g_list_free (region);
1892 pdf_selection_get_selection_map (EvSelection *selection,
1893 EvRenderContext *rc)
1895 PopplerPage *poppler_page;
1896 PopplerRectangle points;
1900 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1904 poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
1906 region = poppler_page_get_selection_region (poppler_page, 1.0,
1907 POPPLER_SELECTION_GLYPH,
1909 retval = create_gdk_region_from_poppler_region (region);
1910 g_list_free (region);
1916 pdf_selection_iface_init (EvSelectionIface *iface)
1918 iface->render_selection = pdf_selection_render_selection;
1919 iface->get_selected_text = pdf_selection_get_selected_text;
1920 iface->get_selection_region = pdf_selection_get_selection_region;
1921 iface->get_selection_map = pdf_selection_get_selection_map;
1924 /* Page Transitions */
1926 pdf_document_get_page_duration (EvDocumentTransition *trans,
1929 PdfDocument *pdf_document;
1930 PopplerPage *poppler_page;
1931 gdouble duration = -1;
1933 pdf_document = PDF_DOCUMENT (trans);
1934 poppler_page = poppler_document_get_page (pdf_document->document, page);
1938 duration = poppler_page_get_duration (poppler_page);
1939 g_object_unref (poppler_page);
1944 static EvTransitionEffect *
1945 pdf_document_get_effect (EvDocumentTransition *trans,
1948 PdfDocument *pdf_document;
1949 PopplerPage *poppler_page;
1950 PopplerPageTransition *page_transition;
1951 EvTransitionEffect *effect;
1953 pdf_document = PDF_DOCUMENT (trans);
1954 poppler_page = poppler_document_get_page (pdf_document->document, page);
1959 page_transition = poppler_page_get_transition (poppler_page);
1961 if (!page_transition) {
1962 g_object_unref (poppler_page);
1966 /* enums in PopplerPageTransition match the EvTransitionEffect ones */
1967 effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
1968 "alignment", page_transition->alignment,
1969 "direction", page_transition->direction,
1970 "duration", page_transition->duration,
1971 "angle", page_transition->angle,
1972 "scale", page_transition->scale,
1973 "rectangular", page_transition->rectangular,
1976 poppler_page_transition_free (page_transition);
1977 g_object_unref (poppler_page);
1983 pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
1985 iface->get_page_duration = pdf_document_get_page_duration;
1986 iface->get_effect = pdf_document_get_effect;
1991 pdf_document_get_crop_box (EvDocument *document,
1995 PdfDocument *pdf_document;
1996 PopplerPage *poppler_page;
1997 PopplerRectangle poppler_rect;
1999 pdf_document = PDF_DOCUMENT (document);
2000 poppler_page = poppler_document_get_page (pdf_document->document, page);
2001 poppler_page_get_crop_box (poppler_page, &poppler_rect);
2002 rect->x1 = poppler_rect.x1;
2003 rect->x2 = poppler_rect.x2;
2004 rect->y1 = poppler_rect.y1;
2005 rect->y2 = poppler_rect.y2;
2008 static EvFormField *
2009 ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
2011 EvFormField *ev_field = NULL;
2014 gboolean is_read_only;
2016 id = poppler_form_field_get_id (poppler_field);
2017 font_size = poppler_form_field_get_font_size (poppler_field);
2018 is_read_only = poppler_form_field_is_read_only (poppler_field);
2020 switch (poppler_form_field_get_field_type (poppler_field)) {
2021 case POPPLER_FORM_FIELD_TEXT: {
2022 EvFormFieldText *field_text;
2023 EvFormFieldTextType ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2025 switch (poppler_form_field_text_get_text_type (poppler_field)) {
2026 case POPPLER_FORM_TEXT_NORMAL:
2027 ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2029 case POPPLER_FORM_TEXT_MULTILINE:
2030 ev_text_type = EV_FORM_FIELD_TEXT_MULTILINE;
2032 case POPPLER_FORM_TEXT_FILE_SELECT:
2033 ev_text_type = EV_FORM_FIELD_TEXT_FILE_SELECT;
2037 ev_field = ev_form_field_text_new (id, ev_text_type);
2038 field_text = EV_FORM_FIELD_TEXT (ev_field);
2040 field_text->do_spell_check = poppler_form_field_text_do_spell_check (poppler_field);
2041 field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
2042 field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
2043 field_text->is_password = poppler_form_field_text_is_password (poppler_field);
2044 field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
2045 field_text->text = poppler_form_field_text_get_text (poppler_field);
2049 case POPPLER_FORM_FIELD_BUTTON: {
2050 EvFormFieldButton *field_button;
2051 EvFormFieldButtonType ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2053 switch (poppler_form_field_button_get_button_type (poppler_field)) {
2054 case POPPLER_FORM_BUTTON_PUSH:
2055 ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2057 case POPPLER_FORM_BUTTON_CHECK:
2058 ev_button_type = EV_FORM_FIELD_BUTTON_CHECK;
2060 case POPPLER_FORM_BUTTON_RADIO:
2061 ev_button_type = EV_FORM_FIELD_BUTTON_RADIO;
2065 ev_field = ev_form_field_button_new (id, ev_button_type);
2066 field_button = EV_FORM_FIELD_BUTTON (ev_field);
2068 field_button->state = poppler_form_field_button_get_state (poppler_field);
2071 case POPPLER_FORM_FIELD_CHOICE: {
2072 EvFormFieldChoice *field_choice;
2073 EvFormFieldChoiceType ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2075 switch (poppler_form_field_choice_get_choice_type (poppler_field)) {
2076 case POPPLER_FORM_CHOICE_COMBO:
2077 ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2079 case EV_FORM_FIELD_CHOICE_LIST:
2080 ev_choice_type = EV_FORM_FIELD_CHOICE_LIST;
2084 ev_field = ev_form_field_choice_new (id, ev_choice_type);
2085 field_choice = EV_FORM_FIELD_CHOICE (ev_field);
2087 field_choice->is_editable = poppler_form_field_choice_is_editable (poppler_field);
2088 field_choice->multi_select = poppler_form_field_choice_can_select_multiple (poppler_field);
2089 field_choice->do_spell_check = poppler_form_field_choice_do_spell_check (poppler_field);
2090 field_choice->commit_on_sel_change = poppler_form_field_choice_commit_on_change (poppler_field);
2092 /* TODO: we need poppler_form_field_choice_get_selected_items in poppler
2093 field_choice->selected_items = poppler_form_field_choice_get_selected_items (poppler_field);*/
2094 if (field_choice->is_editable)
2095 field_choice->text = poppler_form_field_choice_get_text (poppler_field);
2098 case POPPLER_FORM_FIELD_SIGNATURE:
2100 ev_field = ev_form_field_signature_new (id);
2102 case POPPLER_FORM_FIELD_UNKNOWN:
2106 ev_field->font_size = font_size;
2107 ev_field->is_read_only = is_read_only;
2113 pdf_document_forms_get_form_fields (EvDocumentForms *document,
2116 PopplerPage *poppler_page;
2117 GList *retval = NULL;
2122 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2124 poppler_page = POPPLER_PAGE (page->backend_page);
2125 fields = poppler_page_get_form_field_mapping (poppler_page);
2126 poppler_page_get_size (poppler_page, NULL, &height);
2128 for (list = fields; list; list = list->next) {
2129 PopplerFormFieldMapping *mapping;
2130 EvFormFieldMapping *field_mapping;
2131 EvFormField *ev_field;
2133 mapping = (PopplerFormFieldMapping *)list->data;
2135 ev_field = ev_form_field_from_poppler_field (mapping->field);
2139 field_mapping = g_new0 (EvFormFieldMapping, 1);
2140 field_mapping->x1 = mapping->area.x1;
2141 field_mapping->x2 = mapping->area.x2;
2142 field_mapping->y1 = height - mapping->area.y2;
2143 field_mapping->y2 = height - mapping->area.y1;
2144 field_mapping->field = ev_field;
2145 field_mapping->field->page = EV_PAGE (g_object_ref (page));
2147 g_object_set_data_full (G_OBJECT (ev_field),
2149 g_object_ref (mapping->field),
2150 (GDestroyNotify) g_object_unref);
2152 retval = g_list_prepend (retval, field_mapping);
2155 poppler_page_free_form_field_mapping (fields);
2157 return g_list_reverse (retval);
2161 pdf_document_forms_form_field_text_get_text (EvDocumentForms *document,
2165 PopplerFormField *poppler_field;
2168 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2172 text = poppler_form_field_text_get_text (poppler_field);
2178 pdf_document_forms_form_field_text_set_text (EvDocumentForms *document,
2182 PopplerFormField *poppler_field;
2184 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2188 poppler_form_field_text_set_text (poppler_field, text);
2189 PDF_DOCUMENT (document)->modified = TRUE;
2193 pdf_document_forms_form_field_button_set_state (EvDocumentForms *document,
2197 PopplerFormField *poppler_field;
2199 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2203 poppler_form_field_button_set_state (poppler_field, state);
2204 PDF_DOCUMENT (document)->modified = TRUE;
2208 pdf_document_forms_form_field_button_get_state (EvDocumentForms *document,
2211 PopplerFormField *poppler_field;
2214 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2218 state = poppler_form_field_button_get_state (poppler_field);
2224 pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document,
2228 PopplerFormField *poppler_field;
2231 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2235 text = poppler_form_field_choice_get_item (poppler_field, index);
2241 pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document,
2244 PopplerFormField *poppler_field;
2247 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2251 n_items = poppler_form_field_choice_get_n_items (poppler_field);
2257 pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document,
2261 PopplerFormField *poppler_field;
2264 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2268 selected = poppler_form_field_choice_is_item_selected (poppler_field, index);
2274 pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document,
2278 PopplerFormField *poppler_field;
2280 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2284 poppler_form_field_choice_select_item (poppler_field, index);
2285 PDF_DOCUMENT (document)->modified = TRUE;
2289 pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document,
2293 PopplerFormField *poppler_field;
2295 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2299 poppler_form_field_choice_toggle_item (poppler_field, index);
2300 PDF_DOCUMENT (document)->modified = TRUE;
2304 pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document,
2307 PopplerFormField *poppler_field;
2309 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2313 poppler_form_field_choice_unselect_all (poppler_field);
2314 PDF_DOCUMENT (document)->modified = TRUE;
2318 pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document,
2322 PopplerFormField *poppler_field;
2324 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2328 poppler_form_field_choice_set_text (poppler_field, text);
2329 PDF_DOCUMENT (document)->modified = TRUE;
2333 pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document,
2336 PopplerFormField *poppler_field;
2339 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2343 text = poppler_form_field_choice_get_text (poppler_field);
2349 pdf_document_document_forms_iface_init (EvDocumentFormsIface *iface)
2351 iface->get_form_fields = pdf_document_forms_get_form_fields;
2352 iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
2353 iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
2354 iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
2355 iface->form_field_button_get_state = pdf_document_forms_form_field_button_get_state;
2356 iface->form_field_choice_get_item = pdf_document_forms_form_field_choice_get_item;
2357 iface->form_field_choice_get_n_items = pdf_document_forms_form_field_choice_get_n_items;
2358 iface->form_field_choice_is_item_selected = pdf_document_forms_form_field_choice_is_item_selected;
2359 iface->form_field_choice_select_item = pdf_document_forms_form_field_choice_select_item;
2360 iface->form_field_choice_toggle_item = pdf_document_forms_form_field_choice_toggle_item;
2361 iface->form_field_choice_unselect_all = pdf_document_forms_form_field_choice_unselect_all;
2362 iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
2363 iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;
2368 poppler_annot_color_to_gdk_color (PopplerAnnot *poppler_annot,
2371 PopplerColor *poppler_color;
2373 poppler_color = poppler_annot_get_color (poppler_annot);
2374 if (poppler_color) {
2375 color->red = poppler_color->red;
2376 color->green = poppler_color->green;
2377 color->blue = poppler_color->blue;
2379 g_free (poppler_color);
2380 } /* TODO: else use a default color */
2383 static EvAnnotation *
2384 ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
2387 EvAnnotation *ev_annot = NULL;
2388 const gchar *unimplemented_annot = NULL;
2390 switch (poppler_annot_get_annot_type (poppler_annot)) {
2391 case POPPLER_ANNOT_TEXT:
2392 PopplerAnnotText *poppler_text;
2393 EvAnnotationText *ev_annot_text;
2395 poppler_text = POPPLER_ANNOT_TEXT (poppler_annot);
2397 ev_annot = ev_annotation_text_new (page);
2399 ev_annot_text = EV_ANNOTATION_TEXT (ev_annot);
2400 ev_annot_text->is_open = poppler_annot_text_get_is_open (poppler_text);
2403 case POPPLER_ANNOT_LINK:
2404 case POPPLER_ANNOT_WIDGET:
2405 /* Ignore link and widgets annots since they are already handled */
2408 GEnumValue *enum_value;
2410 enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ANNOT_TYPE),
2411 poppler_annot_get_annot_type (poppler_annot));
2412 unimplemented_annot = enum_value ? enum_value->value_name : "Unknown annotation";
2416 if (unimplemented_annot) {
2417 g_warning ("Unimplemented annotation: %s, please post a "
2418 "bug report in Evince bugzilla "
2419 "(http://bugzilla.gnome.org) with a testcase.",
2420 unimplemented_annot);
2424 ev_annot->contents = poppler_annot_get_contents (poppler_annot);
2425 ev_annot->name = poppler_annot_get_name (poppler_annot);
2426 ev_annot->modified = poppler_annot_get_modified (poppler_annot);
2427 poppler_annot_color_to_gdk_color (poppler_annot, &ev_annot->color);
2429 if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
2430 PopplerAnnotMarkup *markup;
2434 PopplerRectangle poppler_rect;
2436 markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2438 if (poppler_annot_markup_get_popup_rectangle (markup, &poppler_rect)) {
2439 EvRectangle ev_rect;
2442 poppler_page_get_size (POPPLER_PAGE (page->backend_page),
2444 ev_rect.x1 = poppler_rect.x1;
2445 ev_rect.x2 = poppler_rect.x2;
2446 ev_rect.y1 = height - poppler_rect.y2;
2447 ev_rect.y2 = height - poppler_rect.y1;
2449 g_object_set (ev_annot, "rectangle", &ev_rect, NULL);
2452 label = poppler_annot_markup_get_label (markup);
2453 opacity = poppler_annot_markup_get_opacity (markup);
2454 is_open = poppler_annot_markup_get_popup_is_open (markup);
2456 g_object_set (ev_annot,
2470 pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annotations,
2473 GList *retval = NULL;
2474 PdfDocument *pdf_document;
2475 PopplerPage *poppler_page;
2481 pdf_document = PDF_DOCUMENT (document_annotations);
2482 poppler_page = POPPLER_PAGE (page->backend_page);
2483 annots = poppler_page_get_annot_mapping (poppler_page);
2484 poppler_page_get_size (poppler_page, NULL, &height);
2486 for (list = annots; list; list = list->next) {
2487 PopplerAnnotMapping *mapping;
2488 EvAnnotationMapping *annot_mapping;
2489 EvAnnotation *ev_annot;
2491 mapping = (PopplerAnnotMapping *)list->data;
2493 ev_annot = ev_annot_from_poppler_annot (mapping->annot, page);
2499 /* Make sure annot has a unique name */
2500 if (!ev_annot->name)
2501 ev_annot->name = g_strdup_printf ("annot-%d-%d", page->index, i);
2503 annot_mapping = g_new0 (EvAnnotationMapping, 1);
2504 annot_mapping->x1 = mapping->area.x1;
2505 annot_mapping->x2 = mapping->area.x2;
2506 annot_mapping->y1 = height - mapping->area.y2;
2507 annot_mapping->y2 = height - mapping->area.y1;
2508 annot_mapping->annotation = ev_annot;
2510 g_object_set_data_full (G_OBJECT (ev_annot),
2512 g_object_ref (mapping->annot),
2513 (GDestroyNotify) g_object_unref);
2515 retval = g_list_prepend (retval, annot_mapping);
2518 poppler_page_free_annot_mapping (annots);
2520 return g_list_reverse (retval);
2524 pdf_document_annotations_annotation_set_contents (EvDocumentAnnotations *document,
2525 EvAnnotation *annot,
2526 const gchar *contents)
2528 PopplerAnnot *poppler_annot;
2530 poppler_annot = POPPLER_ANNOT (g_object_get_data (G_OBJECT (annot), "poppler-annot"));
2534 poppler_annot_set_contents (poppler_annot, contents);
2535 PDF_DOCUMENT (document)->modified = TRUE;
2539 pdf_document_document_annotations_iface_init (EvDocumentAnnotationsIface *iface)
2541 iface->get_annotations = pdf_document_annotations_get_annotations;
2542 iface->annotation_set_contents = pdf_document_annotations_annotation_set_contents;
2547 pdf_document_layers_has_layers (EvDocumentLayers *document)
2549 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2550 PopplerLayersIter *iter;
2552 iter = poppler_layers_iter_new (pdf_document->document);
2555 poppler_layers_iter_free (iter);
2561 build_layers_tree (PdfDocument *pdf_document,
2562 GtkTreeModel *model,
2563 GtkTreeIter *parent,
2564 PopplerLayersIter *iter)
2567 GtkTreeIter tree_iter;
2568 PopplerLayersIter *child;
2569 PopplerLayer *layer;
2570 EvLayer *ev_layer = NULL;
2575 layer = poppler_layers_iter_get_layer (iter);
2577 markup = g_markup_escape_text (poppler_layer_get_title (layer), -1);
2578 visible = poppler_layer_is_visible (layer);
2579 rb_group = poppler_layer_get_radio_button_group_id (layer);
2580 pdf_document->layers = g_list_append (pdf_document->layers,
2581 g_object_ref (layer));
2582 ev_layer = ev_layer_new (g_list_length (pdf_document->layers) - 1,
2583 poppler_layer_is_parent (layer),
2588 title = poppler_layers_iter_get_title (iter);
2589 markup = g_markup_escape_text (title, -1);
2596 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
2597 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
2598 EV_DOCUMENT_LAYERS_COLUMN_TITLE, markup,
2599 EV_DOCUMENT_LAYERS_COLUMN_VISIBLE, visible,
2600 EV_DOCUMENT_LAYERS_COLUMN_ENABLED, TRUE, /* FIXME */
2601 EV_DOCUMENT_LAYERS_COLUMN_SHOWTOGGLE, (layer != NULL),
2602 EV_DOCUMENT_LAYERS_COLUMN_RBGROUP, rb_group,
2603 EV_DOCUMENT_LAYERS_COLUMN_LAYER, ev_layer,
2606 g_object_unref (ev_layer);
2609 child = poppler_layers_iter_get_child (iter);
2611 build_layers_tree (pdf_document, model, &tree_iter, child);
2612 poppler_layers_iter_free (child);
2613 } while (poppler_layers_iter_next (iter));
2616 static GtkTreeModel *
2617 pdf_document_layers_get_layers (EvDocumentLayers *document)
2619 GtkTreeModel *model = NULL;
2620 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2621 PopplerLayersIter *iter;
2623 iter = poppler_layers_iter_new (pdf_document->document);
2625 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LAYERS_N_COLUMNS,
2626 G_TYPE_STRING, /* TITLE */
2627 G_TYPE_OBJECT, /* LAYER */
2628 G_TYPE_BOOLEAN, /* VISIBLE */
2629 G_TYPE_BOOLEAN, /* ENABLED */
2630 G_TYPE_BOOLEAN, /* SHOWTOGGLE */
2631 G_TYPE_INT); /* RBGROUP */
2632 build_layers_tree (pdf_document, model, NULL, iter);
2633 poppler_layers_iter_free (iter);
2639 pdf_document_layers_show_layer (EvDocumentLayers *document,
2642 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2643 guint layer_id = ev_layer_get_id (layer);
2645 poppler_layer_show (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2649 pdf_document_layers_hide_layer (EvDocumentLayers *document,
2652 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2653 guint layer_id = ev_layer_get_id (layer);
2655 poppler_layer_hide (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2659 pdf_document_layers_layer_is_visible (EvDocumentLayers *document,
2662 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2663 guint layer_id = ev_layer_get_id (layer);
2665 return poppler_layer_is_visible (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2669 pdf_document_document_layers_iface_init (EvDocumentLayersIface *iface)
2671 iface->has_layers = pdf_document_layers_has_layers;
2672 iface->get_layers = pdf_document_layers_get_layers;
2673 iface->show_layer = pdf_document_layers_show_layer;
2674 iface->hide_layer = pdf_document_layers_hide_layer;
2675 iface->layer_is_visible = pdf_document_layers_layer_is_visible;