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 GdkPixbuf *retval = NULL;
1240 #ifdef HAVE_POPPLER_PAGE_GET_IMAGE
1241 PdfDocument *pdf_document;
1242 PopplerPage *poppler_page;
1243 cairo_surface_t *surface;
1245 pdf_document = PDF_DOCUMENT (document_images);
1246 poppler_page = poppler_document_get_page (pdf_document->document,
1247 ev_image_get_page (image));
1249 surface = poppler_page_get_image (poppler_page, ev_image_get_id (image));
1251 retval = ev_document_misc_pixbuf_from_surface (surface);
1252 cairo_surface_destroy (surface);
1255 g_object_unref (poppler_page);
1261 pdf_document_document_images_iface_init (EvDocumentImagesIface *iface)
1263 iface->get_image_mapping = pdf_document_images_get_image_mapping;
1264 iface->get_image = pdf_document_images_get_image;
1268 make_thumbnail_for_page (PopplerPage *poppler_page,
1269 EvRenderContext *rc,
1275 #ifdef POPPLER_WITH_GDK
1276 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
1278 gdk_pixbuf_fill (pixbuf, 0xffffffff);
1280 ev_document_fc_mutex_lock ();
1281 poppler_page_render_to_pixbuf (poppler_page, 0, 0,
1283 rc->scale, rc->rotation, pixbuf);
1284 ev_document_fc_mutex_unlock ();
1286 cairo_surface_t *surface;
1288 ev_document_fc_mutex_lock ();
1289 surface = pdf_page_render (poppler_page, width, height, rc);
1290 ev_document_fc_mutex_unlock ();
1292 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1293 cairo_surface_destroy (surface);
1294 #endif /* POPPLER_WITH_GDK */
1300 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1301 EvRenderContext *rc,
1304 PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1305 PopplerPage *poppler_page;
1306 GdkPixbuf *pixbuf = NULL;
1307 GdkPixbuf *border_pixbuf;
1310 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1312 pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document),
1313 rc, &width, &height);
1315 #ifdef POPPLER_WITH_GDK
1316 pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page);
1318 cairo_surface_t *surface;
1320 surface = poppler_page_get_thumbnail (poppler_page);
1322 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1323 cairo_surface_destroy (surface);
1325 #endif /* POPPLER_WITH_GDK */
1327 if (pixbuf != NULL) {
1328 int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ?
1329 gdk_pixbuf_get_height (pixbuf) :
1330 gdk_pixbuf_get_width (pixbuf);
1332 if (thumb_width == width) {
1333 GdkPixbuf *rotated_pixbuf;
1335 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
1336 (GdkPixbufRotation) (360 - rc->rotation));
1337 g_object_unref (pixbuf);
1338 pixbuf = rotated_pixbuf;
1340 /* The provided thumbnail has a different size */
1341 g_object_unref (pixbuf);
1342 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1345 /* There is no provided thumbnail. We need to make one. */
1346 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1349 if (border && pixbuf) {
1350 border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
1351 g_object_unref (pixbuf);
1352 pixbuf = border_pixbuf;
1359 pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
1360 EvRenderContext *rc,
1364 double page_width, page_height;
1366 poppler_page_get_size (POPPLER_PAGE (rc->page->backend_page),
1367 &page_width, &page_height);
1369 *width = (gint) MAX (page_width * rc->scale, 1);
1370 *height = (gint) MAX (page_height * rc->scale, 1);
1372 if (rc->rotation == 90 || rc->rotation == 270) {
1382 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
1384 iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
1385 iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
1390 pdf_document_find_find_text (EvDocumentFind *document_find,
1393 gboolean case_sensitive)
1396 PopplerPage *poppler_page;
1399 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1400 g_return_val_if_fail (text != NULL, NULL);
1402 poppler_page = POPPLER_PAGE (page->backend_page);
1404 matches = poppler_page_find_text (poppler_page, text);
1408 poppler_page_get_size (poppler_page, NULL, &height);
1409 for (l = matches; l && l->data; l = g_list_next (l)) {
1410 PopplerRectangle *rect = (PopplerRectangle *)l->data;
1414 rect->y1 = height - rect->y2;
1415 rect->y2 = height - tmp;
1422 pdf_document_find_iface_init (EvDocumentFindIface *iface)
1424 iface->find_text = pdf_document_find_find_text;
1428 pdf_print_context_free (PdfPrintContext *ctx)
1433 #ifdef HAVE_CAIRO_PRINT
1435 cairo_destroy (ctx->cr);
1440 poppler_ps_file_free (ctx->ps_file);
1441 ctx->ps_file = NULL;
1448 pdf_document_file_exporter_begin (EvFileExporter *exporter,
1449 EvFileExporterContext *fc)
1451 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1452 PdfPrintContext *ctx;
1453 #ifdef HAVE_CAIRO_PRINT
1454 gdouble width, height;
1455 cairo_surface_t *surface = NULL;
1458 if (pdf_document->print_ctx)
1459 pdf_print_context_free (pdf_document->print_ctx);
1460 pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
1461 ctx = pdf_document->print_ctx;
1462 ctx->format = fc->format;
1464 #ifdef HAVE_CAIRO_PRINT
1465 ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
1467 ctx->paper_width = fc->paper_width;
1468 ctx->paper_height = fc->paper_height;
1470 switch (fc->pages_per_sheet) {
1498 ctx->pages_printed = 0;
1500 switch (fc->format) {
1501 case EV_FILE_FORMAT_PS:
1502 #ifdef HAVE_CAIRO_PS
1503 surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1506 case EV_FILE_FORMAT_PDF:
1507 #ifdef HAVE_CAIRO_PDF
1508 surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1512 g_assert_not_reached ();
1515 ctx->cr = cairo_create (surface);
1516 cairo_surface_destroy (surface);
1518 #else /* HAVE_CAIRO_PRINT */
1519 if (ctx->format == EV_FILE_FORMAT_PS) {
1520 ctx->ps_file = poppler_ps_file_new (pdf_document->document,
1521 fc->filename, fc->first_page,
1522 fc->last_page - fc->first_page + 1);
1523 poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
1524 poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
1526 #endif /* HAVE_CAIRO_PRINT */
1530 pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
1532 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1533 PdfPrintContext *ctx = pdf_document->print_ctx;
1535 g_return_if_fail (pdf_document->print_ctx != NULL);
1537 ctx->pages_printed = 0;
1539 #ifdef HAVE_CAIRO_PRINT
1540 if (ctx->paper_width > ctx->paper_height) {
1541 if (ctx->format == EV_FILE_FORMAT_PS) {
1542 cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
1545 } else if (ctx->format == EV_FILE_FORMAT_PDF) {
1546 cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
1551 #endif /* HAVE_CAIRO_PRINT */
1555 pdf_document_file_exporter_do_page (EvFileExporter *exporter,
1556 EvRenderContext *rc)
1558 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1559 PdfPrintContext *ctx = pdf_document->print_ctx;
1560 PopplerPage *poppler_page;
1561 #ifdef HAVE_CAIRO_PRINT
1562 gdouble page_width, page_height;
1565 gdouble width, height;
1566 gdouble pwidth, pheight;
1567 gdouble xscale, yscale;
1570 g_return_if_fail (pdf_document->print_ctx != NULL);
1572 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1574 #ifdef HAVE_CAIRO_PRINT
1575 x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
1576 y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
1577 poppler_page_get_size (poppler_page, &page_width, &page_height);
1579 if (page_width > page_height && page_width > ctx->paper_width) {
1585 /* Use always portrait mode and rotate when necessary */
1586 if (ctx->paper_width > ctx->paper_height) {
1587 width = ctx->paper_height;
1588 height = ctx->paper_width;
1591 width = ctx->paper_width;
1592 height = ctx->paper_height;
1595 if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
1608 page_width = page_height;
1612 pwidth = width / ctx->pages_x;
1613 pheight = height / ctx->pages_y;
1615 if ((page_width > pwidth || page_height > pheight) ||
1616 (page_width < pwidth && page_height < pheight)) {
1617 xscale = pwidth / page_width;
1618 yscale = pheight / page_height;
1620 if (yscale < xscale) {
1627 xscale = yscale = 1;
1632 cairo_save (ctx->cr);
1634 cairo_matrix_t matrix;
1636 cairo_translate (ctx->cr, (2 * y + 1) * pwidth, 0);
1637 cairo_matrix_init (&matrix,
1641 cairo_transform (ctx->cr, &matrix);
1644 cairo_translate (ctx->cr,
1645 x * (rotate ? pheight : pwidth),
1646 y * (rotate ? pwidth : pheight));
1647 cairo_scale (ctx->cr, xscale, yscale);
1649 poppler_page_render_for_printing (poppler_page, ctx->cr);
1651 ctx->pages_printed++;
1653 cairo_restore (ctx->cr);
1654 #else /* HAVE_CAIRO_PRINT */
1655 if (ctx->format == EV_FILE_FORMAT_PS)
1656 poppler_page_render_to_ps (poppler_page, ctx->ps_file);
1657 #endif /* HAVE_CAIRO_PRINT */
1661 pdf_document_file_exporter_end_page (EvFileExporter *exporter)
1663 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1664 PdfPrintContext *ctx = pdf_document->print_ctx;
1666 g_return_if_fail (pdf_document->print_ctx != NULL);
1668 #ifdef HAVE_CAIRO_PRINT
1669 cairo_show_page (ctx->cr);
1674 pdf_document_file_exporter_end (EvFileExporter *exporter)
1676 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1678 pdf_print_context_free (pdf_document->print_ctx);
1679 pdf_document->print_ctx = NULL;
1682 static EvFileExporterCapabilities
1683 pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter)
1685 return (EvFileExporterCapabilities) (
1686 EV_FILE_EXPORTER_CAN_PAGE_SET |
1687 EV_FILE_EXPORTER_CAN_COPIES |
1688 EV_FILE_EXPORTER_CAN_COLLATE |
1689 EV_FILE_EXPORTER_CAN_REVERSE |
1690 EV_FILE_EXPORTER_CAN_SCALE |
1691 #ifdef HAVE_CAIRO_PRINT
1692 #ifdef HAVE_POPPLER_PAGE_RENDER
1693 EV_FILE_EXPORTER_CAN_NUMBER_UP |
1697 #ifdef HAVE_CAIRO_PDF
1698 #ifdef HAVE_POPPLER_PAGE_RENDER
1699 EV_FILE_EXPORTER_CAN_GENERATE_PDF |
1702 EV_FILE_EXPORTER_CAN_GENERATE_PS);
1706 pdf_document_file_exporter_iface_init (EvFileExporterIface *iface)
1708 iface->begin = pdf_document_file_exporter_begin;
1709 iface->begin_page = pdf_document_file_exporter_begin_page;
1710 iface->do_page = pdf_document_file_exporter_do_page;
1711 iface->end_page = pdf_document_file_exporter_end_page;
1712 iface->end = pdf_document_file_exporter_end;
1713 iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
1717 pdf_selection_render_selection (EvSelection *selection,
1718 EvRenderContext *rc,
1719 cairo_surface_t **surface,
1720 EvRectangle *points,
1721 EvRectangle *old_points,
1722 EvSelectionStyle style,
1726 PopplerPage *poppler_page;
1727 double width_points, height_points;
1730 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1732 poppler_page_get_size (poppler_page,
1733 &width_points, &height_points);
1734 width = (int) ((width_points * rc->scale) + 0.5);
1735 height = (int) ((height_points * rc->scale) + 0.5);
1737 #ifdef HAVE_POPPLER_PAGE_RENDER
1739 PopplerColor text_color, base_color;
1741 text_color.red = text->red;
1742 text_color.green = text->green;
1743 text_color.blue = text->blue;
1745 base_color.red = base->red;
1746 base_color.green = base->green;
1747 base_color.blue = base->blue;
1749 if (*surface == NULL) {
1750 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1755 cr = cairo_create (*surface);
1756 cairo_scale (cr, rc->scale, rc->scale);
1757 cairo_surface_set_device_offset (*surface, 0, 0);
1758 memset (cairo_image_surface_get_data (*surface), 0x00,
1759 cairo_image_surface_get_height (*surface) *
1760 cairo_image_surface_get_stride (*surface));
1761 poppler_page_render_selection (poppler_page,
1763 (PopplerRectangle *)points,
1764 (PopplerRectangle *)old_points,
1765 (PopplerSelectionStyle)style,
1769 #else /* HAVE_POPPLER_PAGE_RENDER */
1772 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
1776 poppler_page_render_selection_to_pixbuf (poppler_page,
1777 rc->scale, rc->rotation, pixbuf,
1778 (PopplerRectangle *)points,
1779 (PopplerRectangle *)old_points,
1780 (PopplerSelectionStyle)style,
1784 cairo_surface_destroy (*surface);
1785 *surface = ev_document_misc_surface_from_pixbuf (pixbuf);
1786 g_object_unref (pixbuf);
1787 #endif /* HAVE_POPPLER_PAGE_RENDER */
1791 pdf_selection_get_selected_text (EvSelection *selection,
1792 EvRenderContext *rc,
1793 EvSelectionStyle style,
1794 EvRectangle *points)
1796 PopplerPage *poppler_page;
1801 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1803 poppler_page_get_size (poppler_page, NULL, &height);
1805 r.y1 = height - points->y2;
1807 r.y2 = height - points->y1;
1809 retval = poppler_page_get_text (poppler_page,
1810 (PopplerSelectionStyle)style,
1817 create_gdk_region_from_poppler_region (GList *region)
1822 retval = gdk_region_new ();
1824 for (l = region; l; l = g_list_next (l)) {
1825 PopplerRectangle *rectangle;
1828 rectangle = (PopplerRectangle *)l->data;
1830 rect.x = (gint) rectangle->x1;
1831 rect.y = (gint) rectangle->y1;
1832 rect.width = (gint) (rectangle->x2 - rectangle->x1);
1833 rect.height = (gint) (rectangle->y2 - rectangle->y1);
1834 gdk_region_union_with_rect (retval, &rect);
1836 poppler_rectangle_free (rectangle);
1843 pdf_selection_get_selection_region (EvSelection *selection,
1844 EvRenderContext *rc,
1845 EvSelectionStyle style,
1846 EvRectangle *points)
1848 PopplerPage *poppler_page;
1852 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1854 region = poppler_page_get_selection_region (poppler_page,
1856 (PopplerSelectionStyle)style,
1857 (PopplerRectangle *) points);
1858 retval = create_gdk_region_from_poppler_region (region);
1859 g_list_free (region);
1865 pdf_selection_get_selection_map (EvSelection *selection,
1866 EvRenderContext *rc)
1868 PopplerPage *poppler_page;
1869 PopplerRectangle points;
1873 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1877 poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
1879 region = poppler_page_get_selection_region (poppler_page, 1.0,
1880 POPPLER_SELECTION_GLYPH,
1882 retval = create_gdk_region_from_poppler_region (region);
1883 g_list_free (region);
1889 pdf_selection_iface_init (EvSelectionIface *iface)
1891 iface->render_selection = pdf_selection_render_selection;
1892 iface->get_selected_text = pdf_selection_get_selected_text;
1893 iface->get_selection_region = pdf_selection_get_selection_region;
1894 iface->get_selection_map = pdf_selection_get_selection_map;
1897 /* Page Transitions */
1899 pdf_document_get_page_duration (EvDocumentTransition *trans,
1902 PdfDocument *pdf_document;
1903 PopplerPage *poppler_page;
1904 gdouble duration = -1;
1906 pdf_document = PDF_DOCUMENT (trans);
1907 poppler_page = poppler_document_get_page (pdf_document->document, page);
1911 duration = poppler_page_get_duration (poppler_page);
1912 g_object_unref (poppler_page);
1917 static EvTransitionEffect *
1918 pdf_document_get_effect (EvDocumentTransition *trans,
1921 PdfDocument *pdf_document;
1922 PopplerPage *poppler_page;
1923 PopplerPageTransition *page_transition;
1924 EvTransitionEffect *effect;
1926 pdf_document = PDF_DOCUMENT (trans);
1927 poppler_page = poppler_document_get_page (pdf_document->document, page);
1932 page_transition = poppler_page_get_transition (poppler_page);
1934 if (!page_transition) {
1935 g_object_unref (poppler_page);
1939 /* enums in PopplerPageTransition match the EvTransitionEffect ones */
1940 effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
1941 "alignment", page_transition->alignment,
1942 "direction", page_transition->direction,
1943 "duration", page_transition->duration,
1944 "angle", page_transition->angle,
1945 "scale", page_transition->scale,
1946 "rectangular", page_transition->rectangular,
1949 poppler_page_transition_free (page_transition);
1950 g_object_unref (poppler_page);
1956 pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
1958 iface->get_page_duration = pdf_document_get_page_duration;
1959 iface->get_effect = pdf_document_get_effect;
1964 pdf_document_get_crop_box (EvDocument *document,
1968 PdfDocument *pdf_document;
1969 PopplerPage *poppler_page;
1970 PopplerRectangle poppler_rect;
1972 pdf_document = PDF_DOCUMENT (document);
1973 poppler_page = poppler_document_get_page (pdf_document->document, page);
1974 poppler_page_get_crop_box (poppler_page, &poppler_rect);
1975 rect->x1 = poppler_rect.x1;
1976 rect->x2 = poppler_rect.x2;
1977 rect->y1 = poppler_rect.y1;
1978 rect->y2 = poppler_rect.y2;
1981 static EvFormField *
1982 ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
1984 EvFormField *ev_field = NULL;
1987 gboolean is_read_only;
1989 id = poppler_form_field_get_id (poppler_field);
1990 font_size = poppler_form_field_get_font_size (poppler_field);
1991 is_read_only = poppler_form_field_is_read_only (poppler_field);
1993 switch (poppler_form_field_get_field_type (poppler_field)) {
1994 case POPPLER_FORM_FIELD_TEXT: {
1995 EvFormFieldText *field_text;
1996 EvFormFieldTextType ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
1998 switch (poppler_form_field_text_get_text_type (poppler_field)) {
1999 case POPPLER_FORM_TEXT_NORMAL:
2000 ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2002 case POPPLER_FORM_TEXT_MULTILINE:
2003 ev_text_type = EV_FORM_FIELD_TEXT_MULTILINE;
2005 case POPPLER_FORM_TEXT_FILE_SELECT:
2006 ev_text_type = EV_FORM_FIELD_TEXT_FILE_SELECT;
2010 ev_field = ev_form_field_text_new (id, ev_text_type);
2011 field_text = EV_FORM_FIELD_TEXT (ev_field);
2013 field_text->do_spell_check = poppler_form_field_text_do_spell_check (poppler_field);
2014 field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
2015 field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
2016 field_text->is_password = poppler_form_field_text_is_password (poppler_field);
2017 field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
2018 field_text->text = poppler_form_field_text_get_text (poppler_field);
2022 case POPPLER_FORM_FIELD_BUTTON: {
2023 EvFormFieldButton *field_button;
2024 EvFormFieldButtonType ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2026 switch (poppler_form_field_button_get_button_type (poppler_field)) {
2027 case POPPLER_FORM_BUTTON_PUSH:
2028 ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2030 case POPPLER_FORM_BUTTON_CHECK:
2031 ev_button_type = EV_FORM_FIELD_BUTTON_CHECK;
2033 case POPPLER_FORM_BUTTON_RADIO:
2034 ev_button_type = EV_FORM_FIELD_BUTTON_RADIO;
2038 ev_field = ev_form_field_button_new (id, ev_button_type);
2039 field_button = EV_FORM_FIELD_BUTTON (ev_field);
2041 field_button->state = poppler_form_field_button_get_state (poppler_field);
2044 case POPPLER_FORM_FIELD_CHOICE: {
2045 EvFormFieldChoice *field_choice;
2046 EvFormFieldChoiceType ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2048 switch (poppler_form_field_choice_get_choice_type (poppler_field)) {
2049 case POPPLER_FORM_CHOICE_COMBO:
2050 ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2052 case EV_FORM_FIELD_CHOICE_LIST:
2053 ev_choice_type = EV_FORM_FIELD_CHOICE_LIST;
2057 ev_field = ev_form_field_choice_new (id, ev_choice_type);
2058 field_choice = EV_FORM_FIELD_CHOICE (ev_field);
2060 field_choice->is_editable = poppler_form_field_choice_is_editable (poppler_field);
2061 field_choice->multi_select = poppler_form_field_choice_can_select_multiple (poppler_field);
2062 field_choice->do_spell_check = poppler_form_field_choice_do_spell_check (poppler_field);
2063 field_choice->commit_on_sel_change = poppler_form_field_choice_commit_on_change (poppler_field);
2065 /* TODO: we need poppler_form_field_choice_get_selected_items in poppler
2066 field_choice->selected_items = poppler_form_field_choice_get_selected_items (poppler_field);*/
2067 if (field_choice->is_editable)
2068 field_choice->text = poppler_form_field_choice_get_text (poppler_field);
2071 case POPPLER_FORM_FIELD_SIGNATURE:
2073 ev_field = ev_form_field_signature_new (id);
2075 case POPPLER_FORM_FIELD_UNKNOWN:
2079 ev_field->font_size = font_size;
2080 ev_field->is_read_only = is_read_only;
2086 pdf_document_forms_get_form_fields (EvDocumentForms *document,
2089 PopplerPage *poppler_page;
2090 GList *retval = NULL;
2095 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2097 poppler_page = POPPLER_PAGE (page->backend_page);
2098 fields = poppler_page_get_form_field_mapping (poppler_page);
2099 poppler_page_get_size (poppler_page, NULL, &height);
2101 for (list = fields; list; list = list->next) {
2102 PopplerFormFieldMapping *mapping;
2103 EvFormFieldMapping *field_mapping;
2104 EvFormField *ev_field;
2106 mapping = (PopplerFormFieldMapping *)list->data;
2108 ev_field = ev_form_field_from_poppler_field (mapping->field);
2112 field_mapping = g_new0 (EvFormFieldMapping, 1);
2113 field_mapping->x1 = mapping->area.x1;
2114 field_mapping->x2 = mapping->area.x2;
2115 field_mapping->y1 = height - mapping->area.y2;
2116 field_mapping->y2 = height - mapping->area.y1;
2117 field_mapping->field = ev_field;
2118 field_mapping->field->page = EV_PAGE (g_object_ref (page));
2120 g_object_set_data_full (G_OBJECT (ev_field),
2122 g_object_ref (mapping->field),
2123 (GDestroyNotify) g_object_unref);
2125 retval = g_list_prepend (retval, field_mapping);
2128 poppler_page_free_form_field_mapping (fields);
2130 return g_list_reverse (retval);
2134 pdf_document_forms_form_field_text_get_text (EvDocumentForms *document,
2138 PopplerFormField *poppler_field;
2141 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2145 text = poppler_form_field_text_get_text (poppler_field);
2151 pdf_document_forms_form_field_text_set_text (EvDocumentForms *document,
2155 PopplerFormField *poppler_field;
2157 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2161 poppler_form_field_text_set_text (poppler_field, text);
2162 PDF_DOCUMENT (document)->modified = TRUE;
2166 pdf_document_forms_form_field_button_set_state (EvDocumentForms *document,
2170 PopplerFormField *poppler_field;
2172 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2176 poppler_form_field_button_set_state (poppler_field, state);
2177 PDF_DOCUMENT (document)->modified = TRUE;
2181 pdf_document_forms_form_field_button_get_state (EvDocumentForms *document,
2184 PopplerFormField *poppler_field;
2187 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2191 state = poppler_form_field_button_get_state (poppler_field);
2197 pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document,
2201 PopplerFormField *poppler_field;
2204 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2208 text = poppler_form_field_choice_get_item (poppler_field, index);
2214 pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document,
2217 PopplerFormField *poppler_field;
2220 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2224 n_items = poppler_form_field_choice_get_n_items (poppler_field);
2230 pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document,
2234 PopplerFormField *poppler_field;
2237 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2241 selected = poppler_form_field_choice_is_item_selected (poppler_field, index);
2247 pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document,
2251 PopplerFormField *poppler_field;
2253 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2257 poppler_form_field_choice_select_item (poppler_field, index);
2258 PDF_DOCUMENT (document)->modified = TRUE;
2262 pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document,
2266 PopplerFormField *poppler_field;
2268 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2272 poppler_form_field_choice_toggle_item (poppler_field, index);
2273 PDF_DOCUMENT (document)->modified = TRUE;
2277 pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document,
2280 PopplerFormField *poppler_field;
2282 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2286 poppler_form_field_choice_unselect_all (poppler_field);
2287 PDF_DOCUMENT (document)->modified = TRUE;
2291 pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document,
2295 PopplerFormField *poppler_field;
2297 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2301 poppler_form_field_choice_set_text (poppler_field, text);
2302 PDF_DOCUMENT (document)->modified = TRUE;
2306 pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document,
2309 PopplerFormField *poppler_field;
2312 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2316 text = poppler_form_field_choice_get_text (poppler_field);
2322 pdf_document_document_forms_iface_init (EvDocumentFormsIface *iface)
2324 iface->get_form_fields = pdf_document_forms_get_form_fields;
2325 iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
2326 iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
2327 iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
2328 iface->form_field_button_get_state = pdf_document_forms_form_field_button_get_state;
2329 iface->form_field_choice_get_item = pdf_document_forms_form_field_choice_get_item;
2330 iface->form_field_choice_get_n_items = pdf_document_forms_form_field_choice_get_n_items;
2331 iface->form_field_choice_is_item_selected = pdf_document_forms_form_field_choice_is_item_selected;
2332 iface->form_field_choice_select_item = pdf_document_forms_form_field_choice_select_item;
2333 iface->form_field_choice_toggle_item = pdf_document_forms_form_field_choice_toggle_item;
2334 iface->form_field_choice_unselect_all = pdf_document_forms_form_field_choice_unselect_all;
2335 iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
2336 iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;
2341 poppler_annot_color_to_gdk_color (PopplerAnnot *poppler_annot,
2344 PopplerColor *poppler_color;
2346 poppler_color = poppler_annot_get_color (poppler_annot);
2347 if (poppler_color) {
2348 color->red = poppler_color->red;
2349 color->green = poppler_color->green;
2350 color->blue = poppler_color->blue;
2352 g_free (poppler_color);
2353 } /* TODO: else use a default color */
2356 static EvAnnotation *
2357 ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
2360 EvAnnotation *ev_annot = NULL;
2361 const gchar *unimplemented_annot = NULL;
2363 switch (poppler_annot_get_annot_type (poppler_annot)) {
2364 case POPPLER_ANNOT_TEXT:
2365 PopplerAnnotText *poppler_text;
2366 EvAnnotationText *ev_annot_text;
2368 poppler_text = POPPLER_ANNOT_TEXT (poppler_annot);
2370 ev_annot = ev_annotation_text_new (page);
2372 ev_annot_text = EV_ANNOTATION_TEXT (ev_annot);
2373 ev_annot_text->is_open = poppler_annot_text_get_is_open (poppler_text);
2376 case POPPLER_ANNOT_LINK:
2377 case POPPLER_ANNOT_WIDGET:
2378 /* Ignore link and widgets annots since they are already handled */
2381 GEnumValue *enum_value;
2383 enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ANNOT_TYPE),
2384 poppler_annot_get_annot_type (poppler_annot));
2385 unimplemented_annot = enum_value ? enum_value->value_name : "Unknown annotation";
2389 if (unimplemented_annot) {
2390 g_warning ("Unimplemented annotation: %s, please post a "
2391 "bug report in Evince bugzilla "
2392 "(http://bugzilla.gnome.org) with a testcase.",
2393 unimplemented_annot);
2397 ev_annot->contents = poppler_annot_get_contents (poppler_annot);
2398 ev_annot->name = poppler_annot_get_name (poppler_annot);
2399 ev_annot->modified = poppler_annot_get_modified (poppler_annot);
2400 poppler_annot_color_to_gdk_color (poppler_annot, &ev_annot->color);
2402 if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
2403 PopplerAnnotMarkup *markup;
2407 PopplerRectangle poppler_rect;
2409 markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2411 if (poppler_annot_markup_get_popup_rectangle (markup, &poppler_rect)) {
2412 EvRectangle ev_rect;
2415 poppler_page_get_size (POPPLER_PAGE (page->backend_page),
2417 ev_rect.x1 = poppler_rect.x1;
2418 ev_rect.x2 = poppler_rect.x2;
2419 ev_rect.y1 = height - poppler_rect.y2;
2420 ev_rect.y2 = height - poppler_rect.y1;
2422 g_object_set (ev_annot, "rectangle", &ev_rect, NULL);
2425 label = poppler_annot_markup_get_label (markup);
2426 opacity = poppler_annot_markup_get_opacity (markup);
2427 is_open = poppler_annot_markup_get_popup_is_open (markup);
2429 g_object_set (ev_annot,
2443 pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annotations,
2446 GList *retval = NULL;
2447 PdfDocument *pdf_document;
2448 PopplerPage *poppler_page;
2454 pdf_document = PDF_DOCUMENT (document_annotations);
2455 poppler_page = POPPLER_PAGE (page->backend_page);
2456 annots = poppler_page_get_annot_mapping (poppler_page);
2457 poppler_page_get_size (poppler_page, NULL, &height);
2459 for (list = annots; list; list = list->next) {
2460 PopplerAnnotMapping *mapping;
2461 EvAnnotationMapping *annot_mapping;
2462 EvAnnotation *ev_annot;
2464 mapping = (PopplerAnnotMapping *)list->data;
2466 ev_annot = ev_annot_from_poppler_annot (mapping->annot, page);
2472 /* Make sure annot has a unique name */
2473 if (!ev_annot->name)
2474 ev_annot->name = g_strdup_printf ("annot-%d-%d", page->index, i);
2476 annot_mapping = g_new0 (EvAnnotationMapping, 1);
2477 annot_mapping->x1 = mapping->area.x1;
2478 annot_mapping->x2 = mapping->area.x2;
2479 annot_mapping->y1 = height - mapping->area.y2;
2480 annot_mapping->y2 = height - mapping->area.y1;
2481 annot_mapping->annotation = ev_annot;
2483 g_object_set_data_full (G_OBJECT (ev_annot),
2485 g_object_ref (mapping->annot),
2486 (GDestroyNotify) g_object_unref);
2488 retval = g_list_prepend (retval, annot_mapping);
2491 poppler_page_free_annot_mapping (annots);
2493 return g_list_reverse (retval);
2497 pdf_document_annotations_annotation_set_contents (EvDocumentAnnotations *document,
2498 EvAnnotation *annot,
2499 const gchar *contents)
2501 PopplerAnnot *poppler_annot;
2503 poppler_annot = POPPLER_ANNOT (g_object_get_data (G_OBJECT (annot), "poppler-annot"));
2507 poppler_annot_set_contents (poppler_annot, contents);
2508 PDF_DOCUMENT (document)->modified = TRUE;
2512 pdf_document_document_annotations_iface_init (EvDocumentAnnotationsIface *iface)
2514 iface->get_annotations = pdf_document_annotations_get_annotations;
2515 iface->annotation_set_contents = pdf_document_annotations_annotation_set_contents;
2520 pdf_document_layers_has_layers (EvDocumentLayers *document)
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);
2534 build_layers_tree (PdfDocument *pdf_document,
2535 GtkTreeModel *model,
2536 GtkTreeIter *parent,
2537 PopplerLayersIter *iter)
2540 GtkTreeIter tree_iter;
2541 PopplerLayersIter *child;
2542 PopplerLayer *layer;
2543 EvLayer *ev_layer = NULL;
2548 layer = poppler_layers_iter_get_layer (iter);
2550 markup = g_markup_escape_text (poppler_layer_get_title (layer), -1);
2551 visible = poppler_layer_is_visible (layer);
2552 rb_group = poppler_layer_get_radio_button_group_id (layer);
2553 pdf_document->layers = g_list_append (pdf_document->layers,
2554 g_object_ref (layer));
2555 ev_layer = ev_layer_new (g_list_length (pdf_document->layers) - 1,
2556 poppler_layer_is_parent (layer),
2561 title = poppler_layers_iter_get_title (iter);
2562 markup = g_markup_escape_text (title, -1);
2569 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
2570 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
2571 EV_DOCUMENT_LAYERS_COLUMN_TITLE, markup,
2572 EV_DOCUMENT_LAYERS_COLUMN_VISIBLE, visible,
2573 EV_DOCUMENT_LAYERS_COLUMN_ENABLED, TRUE, /* FIXME */
2574 EV_DOCUMENT_LAYERS_COLUMN_SHOWTOGGLE, (layer != NULL),
2575 EV_DOCUMENT_LAYERS_COLUMN_RBGROUP, rb_group,
2576 EV_DOCUMENT_LAYERS_COLUMN_LAYER, ev_layer,
2579 g_object_unref (ev_layer);
2582 child = poppler_layers_iter_get_child (iter);
2584 build_layers_tree (pdf_document, model, &tree_iter, child);
2585 poppler_layers_iter_free (child);
2586 } while (poppler_layers_iter_next (iter));
2589 static GtkTreeModel *
2590 pdf_document_layers_get_layers (EvDocumentLayers *document)
2592 GtkTreeModel *model = NULL;
2593 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2594 PopplerLayersIter *iter;
2596 iter = poppler_layers_iter_new (pdf_document->document);
2598 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LAYERS_N_COLUMNS,
2599 G_TYPE_STRING, /* TITLE */
2600 G_TYPE_OBJECT, /* LAYER */
2601 G_TYPE_BOOLEAN, /* VISIBLE */
2602 G_TYPE_BOOLEAN, /* ENABLED */
2603 G_TYPE_BOOLEAN, /* SHOWTOGGLE */
2604 G_TYPE_INT); /* RBGROUP */
2605 build_layers_tree (pdf_document, model, NULL, iter);
2606 poppler_layers_iter_free (iter);
2612 pdf_document_layers_show_layer (EvDocumentLayers *document,
2615 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2616 guint layer_id = ev_layer_get_id (layer);
2618 poppler_layer_show (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2622 pdf_document_layers_hide_layer (EvDocumentLayers *document,
2625 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2626 guint layer_id = ev_layer_get_id (layer);
2628 poppler_layer_hide (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2632 pdf_document_layers_layer_is_visible (EvDocumentLayers *document,
2635 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2636 guint layer_id = ev_layer_get_id (layer);
2638 return poppler_layer_is_visible (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
2642 pdf_document_document_layers_iface_init (EvDocumentLayersIface *iface)
2644 iface->has_layers = pdf_document_layers_has_layers;
2645 iface->get_layers = pdf_document_layers_get_layers;
2646 iface->show_layer = pdf_document_layers_show_layer;
2647 iface->hide_layer = pdf_document_layers_hide_layer;
2648 iface->layer_is_visible = pdf_document_layers_layer_is_visible;