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-annotations.h"
49 #include "ev-selection.h"
50 #include "ev-transition-effect.h"
51 #include "ev-attachment.h"
54 #if (defined (HAVE_POPPLER_PAGE_RENDER)) && (defined (HAVE_CAIRO_PDF) || defined (HAVE_CAIRO_PS))
55 #define HAVE_CAIRO_PRINT
59 PdfDocument *document;
68 EvFileExporterFormat format;
78 #ifdef HAVE_CAIRO_PRINT
81 PopplerPSFile *ps_file;
85 struct _PdfDocumentClass
87 GObjectClass parent_class;
92 GObject parent_instance;
94 PopplerDocument *document;
98 PopplerFontInfo *font_info;
99 PopplerFontsIter *fonts_iter;
100 int fonts_scanned_pages;
102 PdfDocumentSearch *search;
103 PdfPrintContext *print_ctx;
108 static void pdf_document_document_iface_init (EvDocumentIface *iface);
109 static void pdf_document_security_iface_init (EvDocumentSecurityIface *iface);
110 static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
111 static void pdf_document_document_links_iface_init (EvDocumentLinksIface *iface);
112 static void pdf_document_document_images_iface_init (EvDocumentImagesIface *iface);
113 static void pdf_document_document_forms_iface_init (EvDocumentFormsIface *iface);
114 static void pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface);
115 static void pdf_document_document_layers_iface_init (EvDocumentLayersIface *iface);
116 static void pdf_document_document_annotations_iface_init (EvDocumentAnnotationsIface *iface);
117 static void pdf_document_find_iface_init (EvDocumentFindIface *iface);
118 static void pdf_document_file_exporter_iface_init (EvFileExporterIface *iface);
119 static void pdf_selection_iface_init (EvSelectionIface *iface);
120 static void pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface);
121 static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
125 static int pdf_document_get_n_pages (EvDocument *document);
127 static EvLinkDest *ev_link_dest_from_dest (PdfDocument *pdf_document,
129 static EvLink *ev_link_from_action (PdfDocument *pdf_document,
130 PopplerAction *action);
131 static void pdf_document_search_free (PdfDocumentSearch *search);
132 static void pdf_print_context_free (PdfPrintContext *ctx);
134 EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
136 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
137 pdf_document_security_iface_init);
138 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
139 pdf_document_document_thumbnails_iface_init);
140 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
141 pdf_document_document_links_iface_init);
142 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES,
143 pdf_document_document_images_iface_init);
144 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FORMS,
145 pdf_document_document_forms_iface_init);
146 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS,
147 pdf_document_document_fonts_iface_init);
148 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LAYERS,
149 pdf_document_document_layers_iface_init);
150 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ANNOTATIONS,
151 pdf_document_document_annotations_iface_init);
152 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
153 pdf_document_find_iface_init);
154 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
155 pdf_document_file_exporter_iface_init);
156 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION,
157 pdf_selection_iface_init);
158 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
159 pdf_document_page_transition_iface_init);
163 pdf_document_search_free (PdfDocumentSearch *search)
165 PdfDocument *pdf_document = search->document;
169 if (search->idle != 0)
170 g_source_remove (search->idle);
172 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
173 for (i = 0; i < n_pages; i++) {
174 g_list_foreach (search->pages[i], (GFunc) g_free, NULL);
175 g_list_free (search->pages[i]);
177 g_free (search->pages);
179 g_free (search->text);
184 pdf_document_dispose (GObject *object)
186 PdfDocument *pdf_document = PDF_DOCUMENT(object);
188 if (pdf_document->print_ctx) {
189 pdf_print_context_free (pdf_document->print_ctx);
190 pdf_document->print_ctx = NULL;
193 if (pdf_document->search) {
194 pdf_document_search_free (pdf_document->search);
195 pdf_document->search = NULL;
198 if (pdf_document->document) {
199 g_object_unref (pdf_document->document);
202 if (pdf_document->font_info) {
203 poppler_font_info_free (pdf_document->font_info);
206 if (pdf_document->fonts_iter) {
207 poppler_fonts_iter_free (pdf_document->fonts_iter);
210 if (pdf_document->layers) {
211 g_list_foreach (pdf_document->layers, (GFunc)g_object_unref, NULL);
212 g_list_free (pdf_document->layers);
215 G_OBJECT_CLASS (pdf_document_parent_class)->dispose (object);
219 pdf_document_class_init (PdfDocumentClass *klass)
221 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
223 g_object_class->dispose = pdf_document_dispose;
227 pdf_document_init (PdfDocument *pdf_document)
229 pdf_document->password = NULL;
233 convert_error (GError *poppler_error,
236 if (poppler_error == NULL)
239 if (poppler_error->domain == POPPLER_ERROR) {
240 /* convert poppler errors into EvDocument errors */
241 gint code = EV_DOCUMENT_ERROR_INVALID;
242 if (poppler_error->code == POPPLER_ERROR_INVALID)
243 code = EV_DOCUMENT_ERROR_INVALID;
244 else if (poppler_error->code == POPPLER_ERROR_ENCRYPTED)
245 code = EV_DOCUMENT_ERROR_ENCRYPTED;
247 g_set_error_literal (error,
250 poppler_error->message);
252 g_error_free (poppler_error);
254 g_propagate_error (error, poppler_error);
261 pdf_document_save (EvDocument *document,
265 PdfDocument *pdf_document = PDF_DOCUMENT (document);
267 GError *poppler_error = NULL;
269 if (pdf_document->modified) {
270 retval = poppler_document_save (pdf_document->document,
271 uri, &poppler_error);
273 retval = poppler_document_save_a_copy (pdf_document->document,
274 uri, &poppler_error);
278 convert_error (poppler_error, error);
284 pdf_document_load (EvDocument *document,
288 GError *poppler_error = NULL;
289 PdfDocument *pdf_document = PDF_DOCUMENT (document);
291 pdf_document->document =
292 poppler_document_new_from_file (uri, pdf_document->password, &poppler_error);
294 if (pdf_document->document == NULL) {
295 convert_error (poppler_error, error);
303 pdf_document_get_n_pages (EvDocument *document)
305 return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document);
309 pdf_document_get_page (EvDocument *document,
312 PdfDocument *pdf_document = PDF_DOCUMENT (document);
313 PopplerPage *poppler_page;
316 poppler_page = poppler_document_get_page (pdf_document->document, index);
317 page = ev_page_new (index);
318 page->backend_page = (EvBackendPage)g_object_ref (poppler_page);
319 page->backend_destroy_func = (EvBackendPageDestroyFunc)g_object_unref;
320 g_object_unref (poppler_page);
326 pdf_document_get_page_size (EvDocument *document,
331 g_return_if_fail (POPPLER_IS_PAGE (page->backend_page));
333 poppler_page_get_size (POPPLER_PAGE (page->backend_page), width, height);
337 pdf_document_get_page_label (EvDocument *document,
342 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
344 g_object_get (G_OBJECT (page->backend_page),
351 pdf_document_has_attachments (EvDocument *document)
353 PdfDocument *pdf_document;
355 pdf_document = PDF_DOCUMENT (document);
357 return poppler_document_has_attachments (pdf_document->document);
360 struct SaveToBufferData {
366 attachment_save_to_buffer_callback (const gchar *buf,
371 struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
375 if (sdata->len + count > sdata->max) {
376 new_max = MAX (sdata->max * 2, sdata->len + count);
377 new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
379 sdata->buffer = new_buffer;
380 sdata->max = new_max;
383 memcpy (sdata->buffer + sdata->len, buf, count);
390 attachment_save_to_buffer (PopplerAttachment *attachment,
395 static const gint initial_max = 1024;
396 struct SaveToBufferData sdata;
401 sdata.buffer = (gchar *) g_malloc (initial_max);
402 sdata.max = initial_max;
405 if (! poppler_attachment_save_to_callback (attachment,
406 attachment_save_to_buffer_callback,
409 g_free (sdata.buffer);
413 *buffer = sdata.buffer;
414 *buffer_size = sdata.len;
420 pdf_document_get_attachments (EvDocument *document)
422 PdfDocument *pdf_document;
425 GList *retval = NULL;
427 pdf_document = PDF_DOCUMENT (document);
429 if (!pdf_document_has_attachments (document))
432 attachments = poppler_document_get_attachments (pdf_document->document);
434 for (list = attachments; list; list = list->next) {
435 PopplerAttachment *attachment;
436 EvAttachment *ev_attachment;
439 GError *error = NULL;
441 attachment = (PopplerAttachment *) list->data;
443 if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
444 ev_attachment = ev_attachment_new (attachment->name,
445 attachment->description,
450 retval = g_list_prepend (retval, ev_attachment);
453 g_warning ("%s", error->message);
454 g_error_free (error);
460 g_object_unref (attachment);
463 return g_list_reverse (retval);
466 static cairo_surface_t *
467 pdf_page_render (PopplerPage *page,
472 cairo_surface_t *surface;
474 #ifdef HAVE_POPPLER_PAGE_RENDER
477 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
479 memset (cairo_image_surface_get_data (surface), 0xff,
480 cairo_image_surface_get_height (surface) *
481 cairo_image_surface_get_stride (surface));
483 cr = cairo_create (surface);
484 switch (rc->rotation) {
486 cairo_translate (cr, width, 0);
489 cairo_translate (cr, width, height);
492 cairo_translate (cr, 0, height);
495 cairo_translate (cr, 0, 0);
497 cairo_scale (cr, rc->scale, rc->scale);
498 cairo_rotate (cr, rc->rotation * G_PI / 180.0);
499 poppler_page_render (page, cr);
501 #else /* HAVE_POPPLER_PAGE_RENDER */
504 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
508 poppler_page_render_to_pixbuf (page,
514 surface = ev_document_misc_surface_from_pixbuf (pixbuf);
515 g_object_unref (pixbuf);
516 #endif /* HAVE_POPPLER_PAGE_RENDER */
521 static cairo_surface_t *
522 pdf_document_render (EvDocument *document,
525 PdfDocument *pdf_document;
526 PopplerPage *poppler_page;
527 double width_points, height_points;
530 poppler_page = POPPLER_PAGE (rc->page->backend_page);
532 poppler_page_get_size (poppler_page,
533 &width_points, &height_points);
535 if (rc->rotation == 90 || rc->rotation == 270) {
536 width = (int) ((height_points * rc->scale) + 0.5);
537 height = (int) ((width_points * rc->scale) + 0.5);
539 width = (int) ((width_points * rc->scale) + 0.5);
540 height = (int) ((height_points * rc->scale) + 0.5);
543 return pdf_page_render (poppler_page,
547 /* EvDocumentSecurity */
550 pdf_document_has_document_security (EvDocumentSecurity *document_security)
552 /* FIXME: do we really need to have this? */
557 pdf_document_set_password (EvDocumentSecurity *document_security,
558 const char *password)
560 PdfDocument *document = PDF_DOCUMENT (document_security);
562 if (document->password)
563 g_free (document->password);
565 document->password = g_strdup (password);
568 static EvDocumentInfo *
569 pdf_document_get_info (EvDocument *document)
571 EvDocumentInfo *info;
572 PopplerPageLayout layout;
573 PopplerPageMode mode;
574 PopplerViewerPreferences view_prefs;
575 PopplerPermissions permissions;
578 info = g_new0 (EvDocumentInfo, 1);
580 info->fields_mask = EV_DOCUMENT_INFO_TITLE |
581 EV_DOCUMENT_INFO_FORMAT |
582 EV_DOCUMENT_INFO_AUTHOR |
583 EV_DOCUMENT_INFO_SUBJECT |
584 EV_DOCUMENT_INFO_KEYWORDS |
585 EV_DOCUMENT_INFO_LAYOUT |
586 EV_DOCUMENT_INFO_START_MODE |
587 EV_DOCUMENT_INFO_PERMISSIONS |
588 EV_DOCUMENT_INFO_UI_HINTS |
589 EV_DOCUMENT_INFO_CREATOR |
590 EV_DOCUMENT_INFO_PRODUCER |
591 EV_DOCUMENT_INFO_CREATION_DATE |
592 EV_DOCUMENT_INFO_MOD_DATE |
593 EV_DOCUMENT_INFO_LINEARIZED |
594 EV_DOCUMENT_INFO_N_PAGES |
595 EV_DOCUMENT_INFO_SECURITY |
596 EV_DOCUMENT_INFO_PAPER_SIZE;
598 g_object_get (PDF_DOCUMENT (document)->document,
599 "title", &(info->title),
600 "format", &(info->format),
601 "author", &(info->author),
602 "subject", &(info->subject),
603 "keywords", &(info->keywords),
605 "page-layout", &layout,
606 "viewer-preferences", &view_prefs,
607 "permissions", &permissions,
608 "creator", &(info->creator),
609 "producer", &(info->producer),
610 "creation-date", &(info->creation_date),
611 "mod-date", &(info->modified_date),
612 "linearized", &(info->linearized),
615 info->n_pages = ev_document_get_n_pages (document);
617 if (info->n_pages > 0) {
618 page = ev_document_get_page (document, 0);
619 ev_document_get_page_size (document, page,
620 &(info->paper_width),
621 &(info->paper_height));
622 g_object_unref (page);
626 info->paper_width = info->paper_width / 72.0f * 25.4f;
627 info->paper_height = info->paper_height / 72.0f * 25.4f;
631 case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
632 info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
634 case POPPLER_PAGE_LAYOUT_ONE_COLUMN:
635 info->layout = EV_DOCUMENT_LAYOUT_ONE_COLUMN;
637 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_LEFT:
638 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_LEFT;
640 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
641 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
642 case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
643 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
645 case POPPLER_PAGE_LAYOUT_TWO_PAGE_RIGHT:
646 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_RIGHT;
653 case POPPLER_PAGE_MODE_NONE:
654 info->mode = EV_DOCUMENT_MODE_NONE;
656 case POPPLER_PAGE_MODE_USE_THUMBS:
657 info->mode = EV_DOCUMENT_MODE_USE_THUMBS;
659 case POPPLER_PAGE_MODE_USE_OC:
660 info->mode = EV_DOCUMENT_MODE_USE_OC;
662 case POPPLER_PAGE_MODE_FULL_SCREEN:
663 info->mode = EV_DOCUMENT_MODE_FULL_SCREEN;
665 case POPPLER_PAGE_MODE_USE_ATTACHMENTS:
666 info->mode = EV_DOCUMENT_MODE_USE_ATTACHMENTS;
672 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_TOOLBAR) {
673 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_TOOLBAR;
675 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_MENUBAR) {
676 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_MENUBAR;
678 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_WINDOWUI) {
679 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_WINDOWUI;
681 if (view_prefs & POPPLER_VIEWER_PREFERENCES_FIT_WINDOW) {
682 info->ui_hints |= EV_DOCUMENT_UI_HINT_FIT_WINDOW;
684 if (view_prefs & POPPLER_VIEWER_PREFERENCES_CENTER_WINDOW) {
685 info->ui_hints |= EV_DOCUMENT_UI_HINT_CENTER_WINDOW;
687 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DISPLAY_DOC_TITLE) {
688 info->ui_hints |= EV_DOCUMENT_UI_HINT_DISPLAY_DOC_TITLE;
690 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL) {
691 info->ui_hints |= EV_DOCUMENT_UI_HINT_DIRECTION_RTL;
694 info->permissions = 0;
695 if (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT) {
696 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT;
698 if (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY) {
699 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY;
701 if (permissions & POPPLER_PERMISSIONS_OK_TO_COPY) {
702 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_COPY;
704 if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) {
705 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES;
708 if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
709 /* translators: this is the document security state */
710 info->security = g_strdup (_("Yes"));
712 /* translators: this is the document security state */
713 info->security = g_strdup (_("No"));
720 pdf_document_document_iface_init (EvDocumentIface *iface)
722 iface->save = pdf_document_save;
723 iface->load = pdf_document_load;
724 iface->get_n_pages = pdf_document_get_n_pages;
725 iface->get_page = pdf_document_get_page;
726 iface->get_page_size = pdf_document_get_page_size;
727 iface->get_page_label = pdf_document_get_page_label;
728 iface->has_attachments = pdf_document_has_attachments;
729 iface->get_attachments = pdf_document_get_attachments;
730 iface->render = pdf_document_render;
731 iface->get_info = pdf_document_get_info;
735 pdf_document_security_iface_init (EvDocumentSecurityIface *iface)
737 iface->has_document_security = pdf_document_has_document_security;
738 iface->set_password = pdf_document_set_password;
742 pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts)
744 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
747 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
749 return (double)pdf_document->fonts_scanned_pages / (double)n_pages;
753 pdf_document_fonts_scan (EvDocumentFonts *document_fonts,
756 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
759 g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE);
761 if (pdf_document->font_info == NULL) {
762 pdf_document->font_info = poppler_font_info_new (pdf_document->document);
765 if (pdf_document->fonts_iter) {
766 poppler_fonts_iter_free (pdf_document->fonts_iter);
769 pdf_document->fonts_scanned_pages += n_pages;
771 result = poppler_font_info_scan (pdf_document->font_info, n_pages,
772 &pdf_document->fonts_iter);
774 pdf_document->fonts_scanned_pages = 0;
775 poppler_font_info_free (pdf_document->font_info);
776 pdf_document->font_info = NULL;
783 font_type_to_string (PopplerFontType type)
786 case POPPLER_FONT_TYPE_TYPE1:
788 case POPPLER_FONT_TYPE_TYPE1C:
790 case POPPLER_FONT_TYPE_TYPE3:
792 case POPPLER_FONT_TYPE_TRUETYPE:
793 return _("TrueType");
794 case POPPLER_FONT_TYPE_CID_TYPE0:
795 return _("Type 1 (CID)");
796 case POPPLER_FONT_TYPE_CID_TYPE0C:
797 return _("Type 1C (CID)");
798 case POPPLER_FONT_TYPE_CID_TYPE2:
799 return _("TrueType (CID)");
801 return _("Unknown font type");
806 pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
809 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
810 PopplerFontsIter *iter = pdf_document->fonts_iter;
812 g_return_if_fail (PDF_IS_DOCUMENT (document_fonts));
818 GtkTreeIter list_iter;
821 const char *embedded;
824 name = poppler_fonts_iter_get_name (iter);
830 type = font_type_to_string (
831 poppler_fonts_iter_get_font_type (iter));
833 if (poppler_fonts_iter_is_embedded (iter)) {
834 if (poppler_fonts_iter_is_subset (iter))
835 embedded = _("Embedded subset");
837 embedded = _("Embedded");
839 embedded = _("Not embedded");
842 details = g_markup_printf_escaped ("%s\n%s", type, embedded);
844 gtk_list_store_append (GTK_LIST_STORE (model), &list_iter);
845 gtk_list_store_set (GTK_LIST_STORE (model), &list_iter,
846 EV_DOCUMENT_FONTS_COLUMN_NAME, name,
847 EV_DOCUMENT_FONTS_COLUMN_DETAILS, details,
851 } while (poppler_fonts_iter_next (iter));
855 pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface)
857 iface->fill_model = pdf_document_fonts_fill_model;
858 iface->scan = pdf_document_fonts_scan;
859 iface->get_progress = pdf_document_fonts_get_progress;
863 pdf_document_links_has_document_links (EvDocumentLinks *document_links)
865 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
866 PopplerIndexIter *iter;
868 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
870 iter = poppler_index_iter_new (pdf_document->document);
873 poppler_index_iter_free (iter);
879 ev_link_dest_from_dest (PdfDocument *pdf_document,
882 EvLinkDest *ev_dest = NULL;
883 const char *unimplemented_dest = NULL;
885 g_assert (dest != NULL);
887 switch (dest->type) {
888 case POPPLER_DEST_XYZ: {
889 PopplerPage *poppler_page;
892 poppler_page = poppler_document_get_page (pdf_document->document,
893 MAX (0, dest->page_num - 1));
894 poppler_page_get_size (poppler_page, NULL, &height);
895 ev_dest = ev_link_dest_new_xyz (dest->page_num - 1,
897 height - MIN (height, dest->top),
902 g_object_unref (poppler_page);
905 case POPPLER_DEST_FIT:
906 ev_dest = ev_link_dest_new_fit (dest->page_num - 1);
908 case POPPLER_DEST_FITH: {
909 PopplerPage *poppler_page;
912 poppler_page = poppler_document_get_page (pdf_document->document,
913 MAX (0, dest->page_num - 1));
914 poppler_page_get_size (poppler_page, NULL, &height);
915 ev_dest = ev_link_dest_new_fith (dest->page_num - 1,
916 height - MIN (height, dest->top),
918 g_object_unref (poppler_page);
921 case POPPLER_DEST_FITV:
922 ev_dest = ev_link_dest_new_fitv (dest->page_num - 1,
926 case POPPLER_DEST_FITR: {
927 PopplerPage *poppler_page;
930 poppler_page = poppler_document_get_page (pdf_document->document,
931 MAX (0, dest->page_num - 1));
932 poppler_page_get_size (poppler_page, NULL, &height);
933 ev_dest = ev_link_dest_new_fitr (dest->page_num - 1,
935 height - MIN (height, dest->bottom),
937 height - MIN (height, dest->top));
938 g_object_unref (poppler_page);
941 case POPPLER_DEST_FITB:
942 unimplemented_dest = "POPPLER_DEST_FITB";
944 case POPPLER_DEST_FITBH:
945 unimplemented_dest = "POPPLER_DEST_FITBH";
947 case POPPLER_DEST_FITBV:
948 unimplemented_dest = "POPPLER_DEST_FITBV";
950 case POPPLER_DEST_NAMED:
951 ev_dest = ev_link_dest_new_named (dest->named_dest);
953 case POPPLER_DEST_UNKNOWN:
954 unimplemented_dest = "POPPLER_DEST_UNKNOWN";
958 if (unimplemented_dest) {
959 g_warning ("Unimplemented destination: %s, please post a "
960 "bug report in Evince bugzilla "
961 "(http://bugzilla.gnome.org) with a testcase.",
966 ev_dest = ev_link_dest_new_page (dest->page_num - 1);
972 ev_link_from_action (PdfDocument *pdf_document,
973 PopplerAction *action)
976 EvLinkAction *ev_action = NULL;
977 const char *unimplemented_action = NULL;
979 switch (action->type) {
980 case POPPLER_ACTION_NONE:
982 case POPPLER_ACTION_GOTO_DEST: {
985 dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest);
986 ev_action = ev_link_action_new_dest (dest);
989 case POPPLER_ACTION_GOTO_REMOTE: {
992 dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest);
993 ev_action = ev_link_action_new_remote (dest,
994 action->goto_remote.file_name);
998 case POPPLER_ACTION_LAUNCH:
999 ev_action = ev_link_action_new_launch (action->launch.file_name,
1000 action->launch.params);
1002 case POPPLER_ACTION_URI:
1003 ev_action = ev_link_action_new_external_uri (action->uri.uri);
1005 case POPPLER_ACTION_NAMED:
1006 ev_action = ev_link_action_new_named (action->named.named_dest);
1008 case POPPLER_ACTION_MOVIE:
1009 unimplemented_action = "POPPLER_ACTION_MOVIE";
1011 case POPPLER_ACTION_UNKNOWN:
1012 unimplemented_action = "POPPLER_ACTION_UNKNOWN";
1015 if (unimplemented_action) {
1016 g_warning ("Unimplemented action: %s, please post a bug report "
1017 "in Evince bugzilla (http://bugzilla.gnome.org) "
1018 "with a testcase.", unimplemented_action);
1021 link = ev_link_new (action->any.title, ev_action);
1027 build_tree (PdfDocument *pdf_document,
1028 GtkTreeModel *model,
1029 GtkTreeIter *parent,
1030 PopplerIndexIter *iter)
1034 GtkTreeIter tree_iter;
1035 PopplerIndexIter *child;
1036 PopplerAction *action;
1037 EvLink *link = NULL;
1041 action = poppler_index_iter_get_action (iter);
1042 expand = poppler_index_iter_is_open (iter);
1047 switch (action->type) {
1048 case POPPLER_ACTION_GOTO_DEST: {
1049 /* For bookmarks, solve named destinations */
1050 if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
1052 EvLinkDest *ev_dest = NULL;
1053 EvLinkAction *ev_action;
1055 dest = poppler_document_find_dest (pdf_document->document,
1056 action->goto_dest.dest->named_dest);
1058 link = ev_link_from_action (pdf_document, action);
1062 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1063 poppler_dest_free (dest);
1065 ev_action = ev_link_action_new_dest (ev_dest);
1066 link = ev_link_new (action->any.title, ev_action);
1068 link = ev_link_from_action (pdf_document, action);
1073 link = ev_link_from_action (pdf_document, action);
1077 if (!link || strlen (ev_link_get_title (link)) <= 0) {
1078 poppler_action_free (action);
1080 g_object_unref (link);
1085 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
1086 title_markup = g_markup_escape_text (ev_link_get_title (link), -1);
1088 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
1089 EV_DOCUMENT_LINKS_COLUMN_MARKUP, title_markup,
1090 EV_DOCUMENT_LINKS_COLUMN_LINK, link,
1091 EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand,
1094 g_free (title_markup);
1095 g_object_unref (link);
1097 child = poppler_index_iter_get_child (iter);
1099 build_tree (pdf_document, model, &tree_iter, child);
1100 poppler_index_iter_free (child);
1101 poppler_action_free (action);
1103 } while (poppler_index_iter_next (iter));
1106 static GtkTreeModel *
1107 pdf_document_links_get_links_model (EvDocumentLinks *document_links)
1109 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1110 GtkTreeModel *model = NULL;
1111 PopplerIndexIter *iter;
1113 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
1115 iter = poppler_index_iter_new (pdf_document->document);
1116 /* Create the model if we have items*/
1118 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
1123 build_tree (pdf_document, model, NULL, iter);
1124 poppler_index_iter_free (iter);
1131 pdf_document_links_get_links (EvDocumentLinks *document_links,
1134 PdfDocument *pdf_document;
1135 PopplerPage *poppler_page;
1136 GList *retval = NULL;
1137 GList *mapping_list;
1141 pdf_document = PDF_DOCUMENT (document_links);
1142 poppler_page = poppler_document_get_page (pdf_document->document,
1144 mapping_list = poppler_page_get_link_mapping (poppler_page);
1145 poppler_page_get_size (poppler_page, NULL, &height);
1147 for (list = mapping_list; list; list = list->next) {
1148 PopplerLinkMapping *link_mapping;
1149 EvLinkMapping *ev_link_mapping;
1151 link_mapping = (PopplerLinkMapping *)list->data;
1152 ev_link_mapping = g_new (EvLinkMapping, 1);
1153 ev_link_mapping->link = ev_link_from_action (pdf_document,
1154 link_mapping->action);
1155 ev_link_mapping->x1 = link_mapping->area.x1;
1156 ev_link_mapping->x2 = link_mapping->area.x2;
1157 /* Invert this for X-style coordinates */
1158 ev_link_mapping->y1 = height - link_mapping->area.y2;
1159 ev_link_mapping->y2 = height - link_mapping->area.y1;
1161 retval = g_list_prepend (retval, ev_link_mapping);
1164 poppler_page_free_link_mapping (mapping_list);
1165 g_object_unref (poppler_page);
1167 return g_list_reverse (retval);
1171 pdf_document_links_find_link_dest (EvDocumentLinks *document_links,
1172 const gchar *link_name)
1174 PdfDocument *pdf_document;
1176 EvLinkDest *ev_dest = NULL;
1178 pdf_document = PDF_DOCUMENT (document_links);
1179 dest = poppler_document_find_dest (pdf_document->document,
1182 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1183 poppler_dest_free (dest);
1190 pdf_document_document_links_iface_init (EvDocumentLinksIface *iface)
1192 iface->has_document_links = pdf_document_links_has_document_links;
1193 iface->get_links_model = pdf_document_links_get_links_model;
1194 iface->get_links = pdf_document_links_get_links;
1195 iface->find_link_dest = pdf_document_links_find_link_dest;
1199 pdf_document_images_get_image_mapping (EvDocumentImages *document_images,
1202 GList *retval = NULL;
1203 PdfDocument *pdf_document;
1204 PopplerPage *poppler_page;
1205 GList *mapping_list;
1208 pdf_document = PDF_DOCUMENT (document_images);
1209 poppler_page = poppler_document_get_page (pdf_document->document, page);
1210 mapping_list = poppler_page_get_image_mapping (poppler_page);
1212 for (list = mapping_list; list; list = list->next) {
1213 PopplerImageMapping *image_mapping;
1214 EvImageMapping *ev_image_mapping;
1216 image_mapping = (PopplerImageMapping *)list->data;
1218 ev_image_mapping = g_new (EvImageMapping, 1);
1220 ev_image_mapping->image = ev_image_new (page, image_mapping->image_id);
1221 ev_image_mapping->x1 = image_mapping->area.x1;
1222 ev_image_mapping->x2 = image_mapping->area.x2;
1223 ev_image_mapping->y1 = image_mapping->area.y1;
1224 ev_image_mapping->y2 = image_mapping->area.y2;
1226 retval = g_list_prepend (retval, ev_image_mapping);
1229 poppler_page_free_image_mapping (mapping_list);
1230 g_object_unref (poppler_page);
1232 return g_list_reverse (retval);
1236 pdf_document_images_get_image (EvDocumentImages *document_images,
1239 PdfDocument *pdf_document;
1240 PopplerPage *poppler_page;
1241 cairo_surface_t *surface;
1242 GdkPixbuf *retval = NULL;
1244 pdf_document = PDF_DOCUMENT (document_images);
1245 poppler_page = poppler_document_get_page (pdf_document->document,
1246 ev_image_get_page (image));
1248 surface = poppler_page_get_image (poppler_page, ev_image_get_id (image));
1250 retval = ev_document_misc_pixbuf_from_surface (surface);
1251 cairo_surface_destroy (surface);
1254 g_object_unref (poppler_page);
1260 pdf_document_document_images_iface_init (EvDocumentImagesIface *iface)
1262 iface->get_image_mapping = pdf_document_images_get_image_mapping;
1263 iface->get_image = pdf_document_images_get_image;
1267 make_thumbnail_for_page (PopplerPage *poppler_page,
1268 EvRenderContext *rc,
1274 #ifdef POPPLER_WITH_GDK
1275 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
1277 gdk_pixbuf_fill (pixbuf, 0xffffffff);
1279 ev_document_fc_mutex_lock ();
1280 poppler_page_render_to_pixbuf (poppler_page, 0, 0,
1282 rc->scale, rc->rotation, pixbuf);
1283 ev_document_fc_mutex_unlock ();
1285 cairo_surface_t *surface;
1287 ev_document_fc_mutex_lock ();
1288 surface = pdf_page_render (poppler_page, width, height, rc);
1289 ev_document_fc_mutex_unlock ();
1291 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1292 cairo_surface_destroy (surface);
1293 #endif /* POPPLER_WITH_GDK */
1299 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1300 EvRenderContext *rc,
1303 PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1304 PopplerPage *poppler_page;
1305 GdkPixbuf *pixbuf = NULL;
1306 GdkPixbuf *border_pixbuf;
1309 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1311 pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document),
1312 rc, &width, &height);
1314 #ifdef POPPLER_WITH_GDK
1315 pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page);
1317 cairo_surface_t *surface;
1319 surface = poppler_page_get_thumbnail (poppler_page);
1321 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1322 cairo_surface_destroy (surface);
1324 #endif /* POPPLER_WITH_GDK */
1326 if (pixbuf != NULL) {
1327 int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ?
1328 gdk_pixbuf_get_height (pixbuf) :
1329 gdk_pixbuf_get_width (pixbuf);
1331 if (thumb_width == width) {
1332 GdkPixbuf *rotated_pixbuf;
1334 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
1335 (GdkPixbufRotation) (360 - rc->rotation));
1336 g_object_unref (pixbuf);
1337 pixbuf = rotated_pixbuf;
1339 /* The provided thumbnail has a different size */
1340 g_object_unref (pixbuf);
1341 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1344 /* There is no provided thumbnail. We need to make one. */
1345 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1348 if (border && pixbuf) {
1349 border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
1350 g_object_unref (pixbuf);
1351 pixbuf = border_pixbuf;
1358 pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
1359 EvRenderContext *rc,
1363 double page_width, page_height;
1365 poppler_page_get_size (POPPLER_PAGE (rc->page->backend_page),
1366 &page_width, &page_height);
1368 *width = (gint) MAX (page_width * rc->scale, 1);
1369 *height = (gint) MAX (page_height * rc->scale, 1);
1371 if (rc->rotation == 90 || rc->rotation == 270) {
1381 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
1383 iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
1384 iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
1389 pdf_document_find_find_text (EvDocumentFind *document_find,
1392 gboolean case_sensitive)
1395 PopplerPage *poppler_page;
1398 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1399 g_return_val_if_fail (text != NULL, NULL);
1401 poppler_page = POPPLER_PAGE (page->backend_page);
1403 matches = poppler_page_find_text (poppler_page, text);
1407 poppler_page_get_size (poppler_page, NULL, &height);
1408 for (l = matches; l && l->data; l = g_list_next (l)) {
1409 PopplerRectangle *rect = (PopplerRectangle *)l->data;
1413 rect->y1 = height - rect->y2;
1414 rect->y2 = height - tmp;
1421 pdf_document_find_iface_init (EvDocumentFindIface *iface)
1423 iface->find_text = pdf_document_find_find_text;
1427 pdf_print_context_free (PdfPrintContext *ctx)
1432 #ifdef HAVE_CAIRO_PRINT
1434 cairo_destroy (ctx->cr);
1439 poppler_ps_file_free (ctx->ps_file);
1440 ctx->ps_file = NULL;
1447 pdf_document_file_exporter_begin (EvFileExporter *exporter,
1448 EvFileExporterContext *fc)
1450 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1451 PdfPrintContext *ctx;
1452 #ifdef HAVE_CAIRO_PRINT
1453 gdouble width, height;
1454 cairo_surface_t *surface = NULL;
1457 if (pdf_document->print_ctx)
1458 pdf_print_context_free (pdf_document->print_ctx);
1459 pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
1460 ctx = pdf_document->print_ctx;
1461 ctx->format = fc->format;
1463 #ifdef HAVE_CAIRO_PRINT
1464 ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
1466 ctx->paper_width = fc->paper_width;
1467 ctx->paper_height = fc->paper_height;
1469 switch (fc->pages_per_sheet) {
1497 ctx->pages_printed = 0;
1499 switch (fc->format) {
1500 case EV_FILE_FORMAT_PS:
1501 #ifdef HAVE_CAIRO_PS
1502 surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1505 case EV_FILE_FORMAT_PDF:
1506 #ifdef HAVE_CAIRO_PDF
1507 surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1511 g_assert_not_reached ();
1514 ctx->cr = cairo_create (surface);
1515 cairo_surface_destroy (surface);
1517 #else /* HAVE_CAIRO_PRINT */
1518 if (ctx->format == EV_FILE_FORMAT_PS) {
1519 ctx->ps_file = poppler_ps_file_new (pdf_document->document,
1520 fc->filename, fc->first_page,
1521 fc->last_page - fc->first_page + 1);
1522 poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
1523 poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
1525 #endif /* HAVE_CAIRO_PRINT */
1529 pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
1531 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1532 PdfPrintContext *ctx = pdf_document->print_ctx;
1534 g_return_if_fail (pdf_document->print_ctx != NULL);
1536 ctx->pages_printed = 0;
1538 #ifdef HAVE_CAIRO_PRINT
1539 if (ctx->paper_width > ctx->paper_height) {
1540 if (ctx->format == EV_FILE_FORMAT_PS) {
1541 cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
1544 } else if (ctx->format == EV_FILE_FORMAT_PDF) {
1545 cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
1550 #endif /* HAVE_CAIRO_PRINT */
1554 pdf_document_file_exporter_do_page (EvFileExporter *exporter,
1555 EvRenderContext *rc)
1557 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1558 PdfPrintContext *ctx = pdf_document->print_ctx;
1559 PopplerPage *poppler_page;
1560 #ifdef HAVE_CAIRO_PRINT
1561 gdouble page_width, page_height;
1564 gdouble width, height;
1565 gdouble pwidth, pheight;
1566 gdouble xscale, yscale;
1569 g_return_if_fail (pdf_document->print_ctx != NULL);
1571 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1573 #ifdef HAVE_CAIRO_PRINT
1574 x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
1575 y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
1576 poppler_page_get_size (poppler_page, &page_width, &page_height);
1578 if (page_width > page_height && page_width > ctx->paper_width) {
1584 /* Use always portrait mode and rotate when necessary */
1585 if (ctx->paper_width > ctx->paper_height) {
1586 width = ctx->paper_height;
1587 height = ctx->paper_width;
1590 width = ctx->paper_width;
1591 height = ctx->paper_height;
1594 if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
1607 page_width = page_height;
1611 pwidth = width / ctx->pages_x;
1612 pheight = height / ctx->pages_y;
1614 if ((page_width > pwidth || page_height > pheight) ||
1615 (page_width < pwidth && page_height < pheight)) {
1616 xscale = pwidth / page_width;
1617 yscale = pheight / page_height;
1619 if (yscale < xscale) {
1626 xscale = yscale = 1;
1631 cairo_save (ctx->cr);
1633 cairo_matrix_t matrix;
1635 cairo_translate (ctx->cr, (2 * y + 1) * pwidth, 0);
1636 cairo_matrix_init (&matrix,
1640 cairo_transform (ctx->cr, &matrix);
1643 cairo_translate (ctx->cr,
1644 x * (rotate ? pheight : pwidth),
1645 y * (rotate ? pwidth : pheight));
1646 cairo_scale (ctx->cr, xscale, yscale);
1648 poppler_page_render_for_printing (poppler_page, ctx->cr);
1650 ctx->pages_printed++;
1652 cairo_restore (ctx->cr);
1653 #else /* HAVE_CAIRO_PRINT */
1654 if (ctx->format == EV_FILE_FORMAT_PS)
1655 poppler_page_render_to_ps (poppler_page, ctx->ps_file);
1656 #endif /* HAVE_CAIRO_PRINT */
1660 pdf_document_file_exporter_end_page (EvFileExporter *exporter)
1662 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1663 PdfPrintContext *ctx = pdf_document->print_ctx;
1665 g_return_if_fail (pdf_document->print_ctx != NULL);
1667 #ifdef HAVE_CAIRO_PRINT
1668 cairo_show_page (ctx->cr);
1673 pdf_document_file_exporter_end (EvFileExporter *exporter)
1675 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1677 pdf_print_context_free (pdf_document->print_ctx);
1678 pdf_document->print_ctx = NULL;
1681 static EvFileExporterCapabilities
1682 pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter)
1684 return (EvFileExporterCapabilities) (
1685 EV_FILE_EXPORTER_CAN_PAGE_SET |
1686 EV_FILE_EXPORTER_CAN_COPIES |
1687 EV_FILE_EXPORTER_CAN_COLLATE |
1688 EV_FILE_EXPORTER_CAN_REVERSE |
1689 EV_FILE_EXPORTER_CAN_SCALE |
1690 #ifdef HAVE_CAIRO_PRINT
1691 #ifdef HAVE_POPPLER_PAGE_RENDER
1692 EV_FILE_EXPORTER_CAN_NUMBER_UP |
1696 #ifdef HAVE_CAIRO_PDF
1697 #ifdef HAVE_POPPLER_PAGE_RENDER
1698 EV_FILE_EXPORTER_CAN_GENERATE_PDF |
1701 EV_FILE_EXPORTER_CAN_GENERATE_PS);
1705 pdf_document_file_exporter_iface_init (EvFileExporterIface *iface)
1707 iface->begin = pdf_document_file_exporter_begin;
1708 iface->begin_page = pdf_document_file_exporter_begin_page;
1709 iface->do_page = pdf_document_file_exporter_do_page;
1710 iface->end_page = pdf_document_file_exporter_end_page;
1711 iface->end = pdf_document_file_exporter_end;
1712 iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
1716 pdf_selection_render_selection (EvSelection *selection,
1717 EvRenderContext *rc,
1718 cairo_surface_t **surface,
1719 EvRectangle *points,
1720 EvRectangle *old_points,
1721 EvSelectionStyle style,
1725 PopplerPage *poppler_page;
1726 double width_points, height_points;
1729 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1731 poppler_page_get_size (poppler_page,
1732 &width_points, &height_points);
1733 width = (int) ((width_points * rc->scale) + 0.5);
1734 height = (int) ((height_points * rc->scale) + 0.5);
1736 #ifdef HAVE_POPPLER_PAGE_RENDER
1738 PopplerColor text_color, base_color;
1740 text_color.red = text->red;
1741 text_color.green = text->green;
1742 text_color.blue = text->blue;
1744 base_color.red = base->red;
1745 base_color.green = base->green;
1746 base_color.blue = base->blue;
1748 if (*surface == NULL) {
1749 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1754 cr = cairo_create (*surface);
1755 cairo_scale (cr, rc->scale, rc->scale);
1756 cairo_surface_set_device_offset (*surface, 0, 0);
1757 memset (cairo_image_surface_get_data (*surface), 0x00,
1758 cairo_image_surface_get_height (*surface) *
1759 cairo_image_surface_get_stride (*surface));
1760 poppler_page_render_selection (poppler_page,
1762 (PopplerRectangle *)points,
1763 (PopplerRectangle *)old_points,
1764 (PopplerSelectionStyle)style,
1768 #else /* HAVE_POPPLER_PAGE_RENDER */
1771 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
1775 poppler_page_render_selection_to_pixbuf (poppler_page,
1776 rc->scale, rc->rotation, pixbuf,
1777 (PopplerRectangle *)points,
1778 (PopplerRectangle *)old_points,
1779 (PopplerSelectionStyle)style,
1783 cairo_surface_destroy (*surface);
1784 *surface = ev_document_misc_surface_from_pixbuf (pixbuf);
1785 g_object_unref (pixbuf);
1786 #endif /* HAVE_POPPLER_PAGE_RENDER */
1790 pdf_selection_get_selected_text (EvSelection *selection,
1791 EvRenderContext *rc,
1792 EvSelectionStyle style,
1793 EvRectangle *points)
1795 PopplerPage *poppler_page;
1800 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1802 poppler_page_get_size (poppler_page, NULL, &height);
1804 r.y1 = height - points->y2;
1806 r.y2 = height - points->y1;
1808 retval = poppler_page_get_text (poppler_page,
1809 (PopplerSelectionStyle)style,
1816 create_gdk_region_from_poppler_region (GList *region)
1821 retval = gdk_region_new ();
1823 for (l = region; l; l = g_list_next (l)) {
1824 PopplerRectangle *rectangle;
1827 rectangle = (PopplerRectangle *)l->data;
1829 rect.x = (gint) rectangle->x1;
1830 rect.y = (gint) rectangle->y1;
1831 rect.width = (gint) (rectangle->x2 - rectangle->x1);
1832 rect.height = (gint) (rectangle->y2 - rectangle->y1);
1833 gdk_region_union_with_rect (retval, &rect);
1835 poppler_rectangle_free (rectangle);
1842 pdf_selection_get_selection_region (EvSelection *selection,
1843 EvRenderContext *rc,
1844 EvSelectionStyle style,
1845 EvRectangle *points)
1847 PopplerPage *poppler_page;
1851 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1853 region = poppler_page_get_selection_region (poppler_page,
1855 (PopplerSelectionStyle)style,
1856 (PopplerRectangle *) points);
1857 retval = create_gdk_region_from_poppler_region (region);
1858 g_list_free (region);
1864 pdf_selection_get_selection_map (EvSelection *selection,
1865 EvRenderContext *rc)
1867 PopplerPage *poppler_page;
1868 PopplerRectangle points;
1872 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1876 poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
1878 region = poppler_page_get_selection_region (poppler_page, 1.0,
1879 POPPLER_SELECTION_GLYPH,
1881 retval = create_gdk_region_from_poppler_region (region);
1882 g_list_free (region);
1888 pdf_selection_iface_init (EvSelectionIface *iface)
1890 iface->render_selection = pdf_selection_render_selection;
1891 iface->get_selected_text = pdf_selection_get_selected_text;
1892 iface->get_selection_region = pdf_selection_get_selection_region;
1893 iface->get_selection_map = pdf_selection_get_selection_map;
1896 /* Page Transitions */
1898 pdf_document_get_page_duration (EvDocumentTransition *trans,
1901 PdfDocument *pdf_document;
1902 PopplerPage *poppler_page;
1903 gdouble duration = -1;
1905 pdf_document = PDF_DOCUMENT (trans);
1906 poppler_page = poppler_document_get_page (pdf_document->document, page);
1910 duration = poppler_page_get_duration (poppler_page);
1911 g_object_unref (poppler_page);
1916 static EvTransitionEffect *
1917 pdf_document_get_effect (EvDocumentTransition *trans,
1920 PdfDocument *pdf_document;
1921 PopplerPage *poppler_page;
1922 PopplerPageTransition *page_transition;
1923 EvTransitionEffect *effect;
1925 pdf_document = PDF_DOCUMENT (trans);
1926 poppler_page = poppler_document_get_page (pdf_document->document, page);
1931 page_transition = poppler_page_get_transition (poppler_page);
1933 if (!page_transition) {
1934 g_object_unref (poppler_page);
1938 /* enums in PopplerPageTransition match the EvTransitionEffect ones */
1939 effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
1940 "alignment", page_transition->alignment,
1941 "direction", page_transition->direction,
1942 "duration", page_transition->duration,
1943 "angle", page_transition->angle,
1944 "scale", page_transition->scale,
1945 "rectangular", page_transition->rectangular,
1948 poppler_page_transition_free (page_transition);
1949 g_object_unref (poppler_page);
1955 pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
1957 iface->get_page_duration = pdf_document_get_page_duration;
1958 iface->get_effect = pdf_document_get_effect;
1963 pdf_document_get_crop_box (EvDocument *document,
1967 PdfDocument *pdf_document;
1968 PopplerPage *poppler_page;
1969 PopplerRectangle poppler_rect;
1971 pdf_document = PDF_DOCUMENT (document);
1972 poppler_page = poppler_document_get_page (pdf_document->document, page);
1973 poppler_page_get_crop_box (poppler_page, &poppler_rect);
1974 rect->x1 = poppler_rect.x1;
1975 rect->x2 = poppler_rect.x2;
1976 rect->y1 = poppler_rect.y1;
1977 rect->y2 = poppler_rect.y2;
1980 static EvFormField *
1981 ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
1983 EvFormField *ev_field = NULL;
1986 gboolean is_read_only;
1988 id = poppler_form_field_get_id (poppler_field);
1989 font_size = poppler_form_field_get_font_size (poppler_field);
1990 is_read_only = poppler_form_field_is_read_only (poppler_field);
1992 switch (poppler_form_field_get_field_type (poppler_field)) {
1993 case POPPLER_FORM_FIELD_TEXT: {
1994 EvFormFieldText *field_text;
1995 EvFormFieldTextType ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
1997 switch (poppler_form_field_text_get_text_type (poppler_field)) {
1998 case POPPLER_FORM_TEXT_NORMAL:
1999 ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2001 case POPPLER_FORM_TEXT_MULTILINE:
2002 ev_text_type = EV_FORM_FIELD_TEXT_MULTILINE;
2004 case POPPLER_FORM_TEXT_FILE_SELECT:
2005 ev_text_type = EV_FORM_FIELD_TEXT_FILE_SELECT;
2009 ev_field = ev_form_field_text_new (id, ev_text_type);
2010 field_text = EV_FORM_FIELD_TEXT (ev_field);
2012 field_text->do_spell_check = poppler_form_field_text_do_spell_check (poppler_field);
2013 field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
2014 field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
2015 field_text->is_password = poppler_form_field_text_is_password (poppler_field);
2016 field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
2017 field_text->text = poppler_form_field_text_get_text (poppler_field);
2021 case POPPLER_FORM_FIELD_BUTTON: {
2022 EvFormFieldButton *field_button;
2023 EvFormFieldButtonType ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2025 switch (poppler_form_field_button_get_button_type (poppler_field)) {
2026 case POPPLER_FORM_BUTTON_PUSH:
2027 ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2029 case POPPLER_FORM_BUTTON_CHECK:
2030 ev_button_type = EV_FORM_FIELD_BUTTON_CHECK;
2032 case POPPLER_FORM_BUTTON_RADIO:
2033 ev_button_type = EV_FORM_FIELD_BUTTON_RADIO;
2037 ev_field = ev_form_field_button_new (id, ev_button_type);
2038 field_button = EV_FORM_FIELD_BUTTON (ev_field);
2040 field_button->state = poppler_form_field_button_get_state (poppler_field);
2043 case POPPLER_FORM_FIELD_CHOICE: {
2044 EvFormFieldChoice *field_choice;
2045 EvFormFieldChoiceType ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2047 switch (poppler_form_field_choice_get_choice_type (poppler_field)) {
2048 case POPPLER_FORM_CHOICE_COMBO:
2049 ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2051 case EV_FORM_FIELD_CHOICE_LIST:
2052 ev_choice_type = EV_FORM_FIELD_CHOICE_LIST;
2056 ev_field = ev_form_field_choice_new (id, ev_choice_type);
2057 field_choice = EV_FORM_FIELD_CHOICE (ev_field);
2059 field_choice->is_editable = poppler_form_field_choice_is_editable (poppler_field);
2060 field_choice->multi_select = poppler_form_field_choice_can_select_multiple (poppler_field);
2061 field_choice->do_spell_check = poppler_form_field_choice_do_spell_check (poppler_field);
2062 field_choice->commit_on_sel_change = poppler_form_field_choice_commit_on_change (poppler_field);
2064 /* TODO: we need poppler_form_field_choice_get_selected_items in poppler
2065 field_choice->selected_items = poppler_form_field_choice_get_selected_items (poppler_field);*/
2066 if (field_choice->is_editable)
2067 field_choice->text = poppler_form_field_choice_get_text (poppler_field);
2070 case POPPLER_FORM_FIELD_SIGNATURE:
2072 ev_field = ev_form_field_signature_new (id);
2074 case POPPLER_FORM_FIELD_UNKNOWN:
2078 ev_field->font_size = font_size;
2079 ev_field->is_read_only = is_read_only;
2085 pdf_document_forms_get_form_fields (EvDocumentForms *document,
2088 PopplerPage *poppler_page;
2089 GList *retval = NULL;
2094 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2096 poppler_page = POPPLER_PAGE (page->backend_page);
2097 fields = poppler_page_get_form_field_mapping (poppler_page);
2098 poppler_page_get_size (poppler_page, NULL, &height);
2100 for (list = fields; list; list = list->next) {
2101 PopplerFormFieldMapping *mapping;
2102 EvFormFieldMapping *field_mapping;
2103 EvFormField *ev_field;
2105 mapping = (PopplerFormFieldMapping *)list->data;
2107 ev_field = ev_form_field_from_poppler_field (mapping->field);
2111 field_mapping = g_new0 (EvFormFieldMapping, 1);
2112 field_mapping->x1 = mapping->area.x1;
2113 field_mapping->x2 = mapping->area.x2;
2114 field_mapping->y1 = height - mapping->area.y2;
2115 field_mapping->y2 = height - mapping->area.y1;
2116 field_mapping->field = ev_field;
2117 field_mapping->field->page = EV_PAGE (g_object_ref (page));
2119 g_object_set_data_full (G_OBJECT (ev_field),
2121 g_object_ref (mapping->field),
2122 (GDestroyNotify) g_object_unref);
2124 retval = g_list_prepend (retval, field_mapping);
2127 poppler_page_free_form_field_mapping (fields);
2129 return g_list_reverse (retval);
2133 pdf_document_forms_form_field_text_get_text (EvDocumentForms *document,
2137 PopplerFormField *poppler_field;
2140 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2144 text = poppler_form_field_text_get_text (poppler_field);
2150 pdf_document_forms_form_field_text_set_text (EvDocumentForms *document,
2154 PopplerFormField *poppler_field;
2156 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2160 poppler_form_field_text_set_text (poppler_field, text);
2161 PDF_DOCUMENT (document)->modified = TRUE;
2165 pdf_document_forms_form_field_button_set_state (EvDocumentForms *document,
2169 PopplerFormField *poppler_field;
2171 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2175 poppler_form_field_button_set_state (poppler_field, state);
2176 PDF_DOCUMENT (document)->modified = TRUE;
2180 pdf_document_forms_form_field_button_get_state (EvDocumentForms *document,
2183 PopplerFormField *poppler_field;
2186 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2190 state = poppler_form_field_button_get_state (poppler_field);
2196 pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document,
2200 PopplerFormField *poppler_field;
2203 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2207 text = poppler_form_field_choice_get_item (poppler_field, index);
2213 pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document,
2216 PopplerFormField *poppler_field;
2219 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2223 n_items = poppler_form_field_choice_get_n_items (poppler_field);
2229 pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document,
2233 PopplerFormField *poppler_field;
2236 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2240 selected = poppler_form_field_choice_is_item_selected (poppler_field, index);
2246 pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document,
2250 PopplerFormField *poppler_field;
2252 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2256 poppler_form_field_choice_select_item (poppler_field, index);
2257 PDF_DOCUMENT (document)->modified = TRUE;
2261 pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document,
2265 PopplerFormField *poppler_field;
2267 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2271 poppler_form_field_choice_toggle_item (poppler_field, index);
2272 PDF_DOCUMENT (document)->modified = TRUE;
2276 pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document,
2279 PopplerFormField *poppler_field;
2281 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2285 poppler_form_field_choice_unselect_all (poppler_field);
2286 PDF_DOCUMENT (document)->modified = TRUE;
2290 pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document,
2294 PopplerFormField *poppler_field;
2296 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2300 poppler_form_field_choice_set_text (poppler_field, text);
2301 PDF_DOCUMENT (document)->modified = TRUE;
2305 pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document,
2308 PopplerFormField *poppler_field;
2311 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2315 text = poppler_form_field_choice_get_text (poppler_field);
2321 pdf_document_document_forms_iface_init (EvDocumentFormsIface *iface)
2323 iface->get_form_fields = pdf_document_forms_get_form_fields;
2324 iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
2325 iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
2326 iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
2327 iface->form_field_button_get_state = pdf_document_forms_form_field_button_get_state;
2328 iface->form_field_choice_get_item = pdf_document_forms_form_field_choice_get_item;
2329 iface->form_field_choice_get_n_items = pdf_document_forms_form_field_choice_get_n_items;
2330 iface->form_field_choice_is_item_selected = pdf_document_forms_form_field_choice_is_item_selected;
2331 iface->form_field_choice_select_item = pdf_document_forms_form_field_choice_select_item;
2332 iface->form_field_choice_toggle_item = pdf_document_forms_form_field_choice_toggle_item;
2333 iface->form_field_choice_unselect_all = pdf_document_forms_form_field_choice_unselect_all;
2334 iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
2335 iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;
2340 poppler_annot_color_to_gdk_color (PopplerAnnot *poppler_annot,
2343 PopplerColor *poppler_color;
2345 poppler_color = poppler_annot_get_color (poppler_annot);
2346 if (poppler_color) {
2347 color->red = poppler_color->red;
2348 color->green = poppler_color->green;
2349 color->blue = poppler_color->blue;
2351 g_free (poppler_color);
2352 } /* TODO: else use a default color */
2355 static EvAnnotation *
2356 ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
2359 EvAnnotation *ev_annot = NULL;
2360 const gchar *unimplemented_annot = NULL;
2362 switch (poppler_annot_get_annot_type (poppler_annot)) {
2363 case POPPLER_ANNOT_TEXT:
2364 PopplerAnnotText *poppler_text;
2365 EvAnnotationText *ev_annot_text;
2367 poppler_text = POPPLER_ANNOT_TEXT (poppler_annot);
2369 ev_annot = ev_annotation_text_new (page);
2371 ev_annot_text = EV_ANNOTATION_TEXT (ev_annot);
2372 ev_annot_text->is_open = poppler_annot_text_get_is_open (poppler_text);
2375 case POPPLER_ANNOT_LINK:
2376 case POPPLER_ANNOT_WIDGET:
2377 /* Ignore link and widgets annots since they are already handled */
2380 GEnumValue *enum_value;
2382 enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ANNOT_TYPE),
2383 poppler_annot_get_annot_type (poppler_annot));
2384 unimplemented_annot = enum_value ? enum_value->value_name : "Unknown annotation";
2388 if (unimplemented_annot) {
2389 g_warning ("Unimplemented annotation: %s, please post a "
2390 "bug report in Evince bugzilla "
2391 "(http://bugzilla.gnome.org) with a testcase.",
2392 unimplemented_annot);
2396 ev_annot->contents = poppler_annot_get_contents (poppler_annot);
2397 ev_annot->name = poppler_annot_get_name (poppler_annot);
2398 ev_annot->modified = poppler_annot_get_modified (poppler_annot);
2399 poppler_annot_color_to_gdk_color (poppler_annot, &ev_annot->color);
2401 if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
2402 PopplerAnnotMarkup *markup;
2406 PopplerRectangle poppler_rect;
2408 markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2410 if (poppler_annot_markup_get_popup_rectangle (markup, &poppler_rect)) {
2411 EvRectangle ev_rect;
2414 poppler_page_get_size (POPPLER_PAGE (page->backend_page),
2416 ev_rect.x1 = poppler_rect.x1;
2417 ev_rect.x2 = poppler_rect.x2;
2418 ev_rect.y1 = height - poppler_rect.y2;
2419 ev_rect.y2 = height - poppler_rect.y1;
2421 g_object_set (ev_annot, "rectangle", &ev_rect, NULL);
2424 label = poppler_annot_markup_get_label (markup);
2425 opacity = poppler_annot_markup_get_opacity (markup);
2426 is_open = poppler_annot_markup_get_popup_is_open (markup);
2428 g_object_set (ev_annot,
2442 pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annotations,
2445 GList *retval = NULL;
2446 PdfDocument *pdf_document;
2447 PopplerPage *poppler_page;
2453 pdf_document = PDF_DOCUMENT (document_annotations);
2454 poppler_page = POPPLER_PAGE (page->backend_page);
2455 annots = poppler_page_get_annot_mapping (poppler_page);
2456 poppler_page_get_size (poppler_page, NULL, &height);
2458 for (list = annots; list; list = list->next) {
2459 PopplerAnnotMapping *mapping;
2460 EvAnnotationMapping *annot_mapping;
2461 EvAnnotation *ev_annot;
2463 mapping = (PopplerAnnotMapping *)list->data;
2465 ev_annot = ev_annot_from_poppler_annot (mapping->annot, page);
2471 /* Make sure annot has a unique name */
2472 if (!ev_annot->name)
2473 ev_annot->name = g_strdup_printf ("annot-%d-%d", page->index, i);
2475 annot_mapping = g_new0 (EvAnnotationMapping, 1);
2476 annot_mapping->x1 = mapping->area.x1;
2477 annot_mapping->x2 = mapping->area.x2;
2478 annot_mapping->y1 = height - mapping->area.y2;
2479 annot_mapping->y2 = height - mapping->area.y1;
2480 annot_mapping->annotation = ev_annot;
2482 g_object_set_data_full (G_OBJECT (ev_annot),
2484 g_object_ref (mapping->annot),
2485 (GDestroyNotify) g_object_unref);
2487 retval = g_list_prepend (retval, annot_mapping);
2490 poppler_page_free_annot_mapping (annots);
2492 return g_list_reverse (retval);
2496 pdf_document_annotations_annotation_set_contents (EvDocumentAnnotations *document,
2497 EvAnnotation *annot,
2498 const gchar *contents)
2500 PopplerAnnot *poppler_annot;
2502 poppler_annot = POPPLER_ANNOT (g_object_get_data (G_OBJECT (annot), "poppler-annot"));
2506 poppler_annot_set_contents (poppler_annot, contents);
2507 PDF_DOCUMENT (document)->modified = TRUE;
2511 pdf_document_document_annotations_iface_init (EvDocumentAnnotationsIface *iface)
2513 iface->get_annotations = pdf_document_annotations_get_annotations;
2514 iface->annotation_set_contents = pdf_document_annotations_annotation_set_contents;
2519 pdf_document_layers_has_layers (EvDocumentLayers *document)
2521 #ifdef HAVE_POPPLER_LAYERS_ITER_NEW
2522 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2523 PopplerLayersIter *iter;
2525 iter = poppler_layers_iter_new (pdf_document->document);
2528 poppler_layers_iter_free (iter);
2533 #endif /* HAVE_POPPLER_LAYERS_ITER_NEW */
2536 #ifdef HAVE_POPPLER_LAYERS_ITER_NEW
2538 build_layers_tree (PdfDocument *pdf_document,
2539 GtkTreeModel *model,
2540 GtkTreeIter *parent,
2541 PopplerLayersIter *iter)
2544 GtkTreeIter tree_iter;
2545 PopplerLayersIter *child;
2546 PopplerLayer *layer;
2547 EvLayer *ev_layer = NULL;
2552 layer = poppler_layers_iter_get_layer (iter);
2554 markup = g_markup_escape_text (poppler_layer_get_title (layer), -1);
2555 visible = poppler_layer_is_visible (layer);
2556 rb_group = poppler_layer_get_radio_button_group_id (layer);
2557 pdf_document->layers = g_list_append (pdf_document->layers,
2558 g_object_ref (layer));
2559 ev_layer = ev_layer_new (g_list_length (pdf_document->layers) - 1,
2560 poppler_layer_is_parent (layer),
2565 title = poppler_layers_iter_get_title (iter);
2566 markup = g_markup_escape_text (title, -1);
2573 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
2574 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
2575 EV_DOCUMENT_LAYERS_COLUMN_TITLE, markup,
2576 EV_DOCUMENT_LAYERS_COLUMN_VISIBLE, visible,
2577 EV_DOCUMENT_LAYERS_COLUMN_ENABLED, TRUE, /* FIXME */
2578 EV_DOCUMENT_LAYERS_COLUMN_SHOWTOGGLE, (layer != NULL),
2579 EV_DOCUMENT_LAYERS_COLUMN_RBGROUP, rb_group,
2580 EV_DOCUMENT_LAYERS_COLUMN_LAYER, ev_layer,
2583 g_object_unref (ev_layer);
2586 child = poppler_layers_iter_get_child (iter);
2588 build_layers_tree (pdf_document, model, &tree_iter, child);
2589 poppler_layers_iter_free (child);
2590 } while (poppler_layers_iter_next (iter));
2592 #endif /* HAVE_POPPLER_LAYERS_ITER_NEW */
2594 static GtkTreeModel *
2595 pdf_document_layers_get_layers (EvDocumentLayers *document)
2597 GtkTreeModel *model = NULL;
2598 #ifdef HAVE_POPPLER_LAYERS_ITER_NEW
2599 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2600 PopplerLayersIter *iter;
2602 iter = poppler_layers_iter_new (pdf_document->document);
2604 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LAYERS_N_COLUMNS,
2605 G_TYPE_STRING, /* TITLE */
2606 G_TYPE_OBJECT, /* LAYER */
2607 G_TYPE_BOOLEAN, /* VISIBLE */
2608 G_TYPE_BOOLEAN, /* ENABLED */
2609 G_TYPE_BOOLEAN, /* SHOWTOGGLE */
2610 G_TYPE_INT); /* RBGROUP */
2611 build_layers_tree (pdf_document, model, NULL, iter);
2612 poppler_layers_iter_free (iter);
2620 pdf_document_layers_show_layer (EvDocumentLayers *document,
2623 #ifdef HAVE_POPPLER_LAYERS_ITER_NEW
2624 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2625 guint layer_id = ev_layer_get_id (layer);
2627 poppler_layer_show (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2630 #endif /* HAVE_POPPLER_LAYERS_ITER_NEW */
2634 pdf_document_layers_hide_layer (EvDocumentLayers *document,
2637 #ifdef HAVE_POPPLER_LAYERS_ITER_NEW
2638 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2639 guint layer_id = ev_layer_get_id (layer);
2641 poppler_layer_hide (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2644 #endif /* HAVE_POPPLER_LAYERS_ITER_NEW */
2648 pdf_document_layers_layer_is_visible (EvDocumentLayers *document,
2651 #ifdef HAVE_POPPLER_LAYERS_ITER_NEW
2652 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2653 guint layer_id = ev_layer_get_id (layer);
2655 return poppler_layer_is_visible (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2658 #endif /* HAVE_POPPLER_LAYERS_ITER_NEW */
2662 pdf_document_document_layers_iface_init (EvDocumentLayersIface *iface)
2664 iface->has_layers = pdf_document_layers_has_layers;
2665 iface->get_layers = pdf_document_layers_get_layers;
2666 iface->show_layer = pdf_document_layers_show_layer;
2667 iface->hide_layer = pdf_document_layers_hide_layer;
2668 iface->layer_is_visible = pdf_document_layers_layer_is_visible;