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.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-selection.h"
48 #include "ev-transition-effect.h"
49 #include "ev-attachment.h"
52 #if (defined (HAVE_POPPLER_PAGE_RENDER) || defined (HAVE_POPPLER_PAGE_RENDER_FOR_PRINTING)) && (defined (HAVE_CAIRO_PDF) || defined (HAVE_CAIRO_PS))
53 #define HAVE_CAIRO_PRINT
56 #if POPPLER_MAJOR_VERSION <= 6 || (POPPLER_MAJOR_VERSION == 7 && POPPLER_MINOR_VERSION < 2)
57 #define POPPLER_HAS_GDK
59 #ifdef POPPLER_WITH_GDK
60 #define POPPLER_HAS_GDK
65 PdfDocument *document;
74 EvFileExporterFormat format;
84 #ifdef HAVE_CAIRO_PRINT
87 PopplerPSFile *ps_file;
91 struct _PdfDocumentClass
93 GObjectClass parent_class;
98 GObject parent_instance;
100 PopplerDocument *document;
103 PopplerFontInfo *font_info;
104 PopplerFontsIter *fonts_iter;
105 int fonts_scanned_pages;
107 PdfDocumentSearch *search;
108 PdfPrintContext *print_ctx;
111 static void pdf_document_document_iface_init (EvDocumentIface *iface);
112 static void pdf_document_security_iface_init (EvDocumentSecurityIface *iface);
113 static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
114 static void pdf_document_document_links_iface_init (EvDocumentLinksIface *iface);
115 static void pdf_document_document_images_iface_init (EvDocumentImagesIface *iface);
116 static void pdf_document_document_forms_iface_init (EvDocumentFormsIface *iface);
117 static void pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface);
118 static void pdf_document_find_iface_init (EvDocumentFindIface *iface);
119 static void pdf_document_file_exporter_iface_init (EvFileExporterIface *iface);
120 static void pdf_selection_iface_init (EvSelectionIface *iface);
121 static void pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface);
122 static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
126 static int pdf_document_get_n_pages (EvDocument *document);
128 static EvLinkDest *ev_link_dest_from_dest (PdfDocument *pdf_document,
130 static EvLink *ev_link_from_action (PdfDocument *pdf_document,
131 PopplerAction *action);
132 static void pdf_document_search_free (PdfDocumentSearch *search);
133 static void pdf_print_context_free (PdfPrintContext *ctx);
135 EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
137 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
138 pdf_document_security_iface_init);
139 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
140 pdf_document_document_thumbnails_iface_init);
141 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
142 pdf_document_document_links_iface_init);
143 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES,
144 pdf_document_document_images_iface_init);
145 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FORMS,
146 pdf_document_document_forms_iface_init);
147 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS,
148 pdf_document_document_fonts_iface_init);
149 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
150 pdf_document_find_iface_init);
151 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
152 pdf_document_file_exporter_iface_init);
153 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION,
154 pdf_selection_iface_init);
155 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
156 pdf_document_page_transition_iface_init);
160 set_rc_data (PdfDocument *pdf_document,
163 if (rc->data == NULL) {
164 rc->data = poppler_document_get_page (pdf_document->document,
166 rc->destroy = g_object_unref;
168 g_assert (rc->page == poppler_page_get_index (POPPLER_PAGE (rc->data)));
173 pdf_document_search_free (PdfDocumentSearch *search)
175 PdfDocument *pdf_document = search->document;
179 if (search->idle != 0)
180 g_source_remove (search->idle);
182 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
183 for (i = 0; i < n_pages; i++) {
184 g_list_foreach (search->pages[i], (GFunc) g_free, NULL);
185 g_list_free (search->pages[i]);
187 g_free (search->pages);
189 g_free (search->text);
194 pdf_document_dispose (GObject *object)
196 PdfDocument *pdf_document = PDF_DOCUMENT(object);
198 if (pdf_document->print_ctx) {
199 pdf_print_context_free (pdf_document->print_ctx);
200 pdf_document->print_ctx = NULL;
203 if (pdf_document->search) {
204 pdf_document_search_free (pdf_document->search);
205 pdf_document->search = NULL;
208 if (pdf_document->document) {
209 g_object_unref (pdf_document->document);
212 if (pdf_document->font_info) {
213 poppler_font_info_free (pdf_document->font_info);
216 if (pdf_document->fonts_iter) {
217 poppler_fonts_iter_free (pdf_document->fonts_iter);
220 G_OBJECT_CLASS (pdf_document_parent_class)->dispose (object);
224 pdf_document_class_init (PdfDocumentClass *klass)
226 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
228 g_object_class->dispose = pdf_document_dispose;
232 pdf_document_init (PdfDocument *pdf_document)
234 pdf_document->password = NULL;
238 convert_error (GError *poppler_error,
241 if (poppler_error == NULL)
244 if (poppler_error->domain == POPPLER_ERROR) {
245 /* convert poppler errors into EvDocument errors */
246 gint code = EV_DOCUMENT_ERROR_INVALID;
247 if (poppler_error->code == POPPLER_ERROR_INVALID)
248 code = EV_DOCUMENT_ERROR_INVALID;
249 else if (poppler_error->code == POPPLER_ERROR_ENCRYPTED)
250 code = EV_DOCUMENT_ERROR_ENCRYPTED;
256 poppler_error->message,
259 g_propagate_error (error, poppler_error);
266 pdf_document_save (EvDocument *document,
271 GError *poppler_error = NULL;
273 retval = poppler_document_save (PDF_DOCUMENT (document)->document,
277 convert_error (poppler_error, error);
283 pdf_document_load (EvDocument *document,
287 GError *poppler_error = NULL;
288 PdfDocument *pdf_document = PDF_DOCUMENT (document);
290 pdf_document->document =
291 poppler_document_new_from_file (uri, pdf_document->password, &poppler_error);
293 if (pdf_document->document == NULL) {
294 convert_error (poppler_error, error);
302 pdf_document_get_n_pages (EvDocument *document)
304 return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document);
308 pdf_document_get_page_size (EvDocument *document,
313 PdfDocument *pdf_document = PDF_DOCUMENT (document);
314 PopplerPage *poppler_page;
316 poppler_page = poppler_document_get_page (pdf_document->document, page);
317 poppler_page_get_size (poppler_page, width, height);
318 g_object_unref (poppler_page);
322 pdf_document_get_page_label (EvDocument *document,
325 PopplerPage *poppler_page;
328 poppler_page = poppler_document_get_page (PDF_DOCUMENT (document)->document,
331 g_object_get (G_OBJECT (poppler_page),
334 g_object_unref (poppler_page);
340 pdf_document_has_attachments (EvDocument *document)
342 PdfDocument *pdf_document;
344 pdf_document = PDF_DOCUMENT (document);
346 return poppler_document_has_attachments (pdf_document->document);
349 struct SaveToBufferData {
355 attachment_save_to_buffer_callback (const gchar *buf,
360 struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
364 if (sdata->len + count > sdata->max) {
365 new_max = MAX (sdata->max * 2, sdata->len + count);
366 new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
368 sdata->buffer = new_buffer;
369 sdata->max = new_max;
372 memcpy (sdata->buffer + sdata->len, buf, count);
379 attachment_save_to_buffer (PopplerAttachment *attachment,
384 static const gint initial_max = 1024;
385 struct SaveToBufferData sdata;
390 sdata.buffer = (gchar *) g_malloc (initial_max);
391 sdata.max = initial_max;
394 if (! poppler_attachment_save_to_callback (attachment,
395 attachment_save_to_buffer_callback,
398 g_free (sdata.buffer);
402 *buffer = sdata.buffer;
403 *buffer_size = sdata.len;
409 pdf_document_get_attachments (EvDocument *document)
411 PdfDocument *pdf_document;
414 GList *retval = NULL;
416 pdf_document = PDF_DOCUMENT (document);
418 if (!pdf_document_has_attachments (document))
421 attachments = poppler_document_get_attachments (pdf_document->document);
423 for (list = attachments; list; list = list->next) {
424 PopplerAttachment *attachment;
425 EvAttachment *ev_attachment;
428 GError *error = NULL;
430 attachment = (PopplerAttachment *) list->data;
432 if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
433 ev_attachment = ev_attachment_new (attachment->name,
434 attachment->description,
439 retval = g_list_prepend (retval, ev_attachment);
442 g_warning ("%s", error->message);
443 g_error_free (error);
449 g_object_unref (attachment);
452 return g_list_reverse (retval);
455 static cairo_surface_t *
456 pdf_page_render (PopplerPage *page,
461 cairo_surface_t *surface;
463 #ifdef HAVE_POPPLER_PAGE_RENDER
466 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
468 memset (cairo_image_surface_get_data (surface), 0xff,
469 cairo_image_surface_get_height (surface) *
470 cairo_image_surface_get_stride (surface));
472 cr = cairo_create (surface);
473 switch (rc->rotation) {
475 cairo_translate (cr, width, 0);
478 cairo_translate (cr, width, height);
481 cairo_translate (cr, 0, height);
484 cairo_translate (cr, 0, 0);
486 cairo_scale (cr, rc->scale, rc->scale);
487 cairo_rotate (cr, rc->rotation * G_PI / 180.0);
488 poppler_page_render (page, cr);
490 #else /* HAVE_POPPLER_PAGE_RENDER */
493 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
497 poppler_page_render_to_pixbuf (page,
503 surface = ev_document_misc_surface_from_pixbuf (pixbuf);
504 g_object_unref (pixbuf);
505 #endif /* HAVE_POPPLER_PAGE_RENDER */
510 static cairo_surface_t *
511 pdf_document_render (EvDocument *document,
514 PdfDocument *pdf_document;
515 double width_points, height_points;
518 pdf_document = PDF_DOCUMENT (document);
520 set_rc_data (pdf_document, rc);
522 poppler_page_get_size (POPPLER_PAGE (rc->data),
523 &width_points, &height_points);
525 if (rc->rotation == 90 || rc->rotation == 270) {
526 width = (int) ((height_points * rc->scale) + 0.5);
527 height = (int) ((width_points * rc->scale) + 0.5);
529 width = (int) ((width_points * rc->scale) + 0.5);
530 height = (int) ((height_points * rc->scale) + 0.5);
533 return pdf_page_render (POPPLER_PAGE (rc->data),
537 /* EvDocumentSecurity */
540 pdf_document_has_document_security (EvDocumentSecurity *document_security)
542 /* FIXME: do we really need to have this? */
547 pdf_document_set_password (EvDocumentSecurity *document_security,
548 const char *password)
550 PdfDocument *document = PDF_DOCUMENT (document_security);
552 if (document->password)
553 g_free (document->password);
555 document->password = g_strdup (password);
558 static EvDocumentInfo *
559 pdf_document_get_info (EvDocument *document)
561 EvDocumentInfo *info;
562 PopplerPageLayout layout;
563 PopplerPageMode mode;
564 PopplerViewerPreferences view_prefs;
565 PopplerPermissions permissions;
567 info = g_new0 (EvDocumentInfo, 1);
569 info->fields_mask = EV_DOCUMENT_INFO_TITLE |
570 EV_DOCUMENT_INFO_FORMAT |
571 EV_DOCUMENT_INFO_AUTHOR |
572 EV_DOCUMENT_INFO_SUBJECT |
573 EV_DOCUMENT_INFO_KEYWORDS |
574 EV_DOCUMENT_INFO_LAYOUT |
575 EV_DOCUMENT_INFO_START_MODE |
576 EV_DOCUMENT_INFO_PERMISSIONS |
577 EV_DOCUMENT_INFO_UI_HINTS |
578 EV_DOCUMENT_INFO_CREATOR |
579 EV_DOCUMENT_INFO_PRODUCER |
580 EV_DOCUMENT_INFO_CREATION_DATE |
581 EV_DOCUMENT_INFO_MOD_DATE |
582 EV_DOCUMENT_INFO_LINEARIZED |
583 EV_DOCUMENT_INFO_N_PAGES |
584 EV_DOCUMENT_INFO_SECURITY |
585 EV_DOCUMENT_INFO_PAPER_SIZE;
587 g_object_get (PDF_DOCUMENT (document)->document,
588 "title", &(info->title),
589 "format", &(info->format),
590 "author", &(info->author),
591 "subject", &(info->subject),
592 "keywords", &(info->keywords),
594 "page-layout", &layout,
595 "viewer-preferences", &view_prefs,
596 "permissions", &permissions,
597 "creator", &(info->creator),
598 "producer", &(info->producer),
599 "creation-date", &(info->creation_date),
600 "mod-date", &(info->modified_date),
601 "linearized", &(info->linearized),
604 pdf_document_get_page_size(document, 0,
605 &(info->paper_width),
606 &(info->paper_height));
609 info->paper_width = info->paper_width / 72.0f * 25.4f;
610 info->paper_height = info->paper_height / 72.0f * 25.4f;
613 case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
614 info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
616 case POPPLER_PAGE_LAYOUT_ONE_COLUMN:
617 info->layout = EV_DOCUMENT_LAYOUT_ONE_COLUMN;
619 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_LEFT:
620 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_LEFT;
622 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
623 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
624 case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
625 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
627 case POPPLER_PAGE_LAYOUT_TWO_PAGE_RIGHT:
628 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_RIGHT;
635 case POPPLER_PAGE_MODE_NONE:
636 info->mode = EV_DOCUMENT_MODE_NONE;
638 case POPPLER_PAGE_MODE_USE_THUMBS:
639 info->mode = EV_DOCUMENT_MODE_USE_THUMBS;
641 case POPPLER_PAGE_MODE_USE_OC:
642 info->mode = EV_DOCUMENT_MODE_USE_OC;
644 case POPPLER_PAGE_MODE_FULL_SCREEN:
645 info->mode = EV_DOCUMENT_MODE_FULL_SCREEN;
647 case POPPLER_PAGE_MODE_USE_ATTACHMENTS:
648 info->mode = EV_DOCUMENT_MODE_USE_ATTACHMENTS;
654 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_TOOLBAR) {
655 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_TOOLBAR;
657 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_MENUBAR) {
658 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_MENUBAR;
660 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_WINDOWUI) {
661 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_WINDOWUI;
663 if (view_prefs & POPPLER_VIEWER_PREFERENCES_FIT_WINDOW) {
664 info->ui_hints |= EV_DOCUMENT_UI_HINT_FIT_WINDOW;
666 if (view_prefs & POPPLER_VIEWER_PREFERENCES_CENTER_WINDOW) {
667 info->ui_hints |= EV_DOCUMENT_UI_HINT_CENTER_WINDOW;
669 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DISPLAY_DOC_TITLE) {
670 info->ui_hints |= EV_DOCUMENT_UI_HINT_DISPLAY_DOC_TITLE;
672 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL) {
673 info->ui_hints |= EV_DOCUMENT_UI_HINT_DIRECTION_RTL;
676 info->permissions = 0;
677 if (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT) {
678 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT;
680 if (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY) {
681 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY;
683 if (permissions & POPPLER_PERMISSIONS_OK_TO_COPY) {
684 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_COPY;
686 if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) {
687 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES;
690 info->n_pages = ev_document_get_n_pages (document);
692 if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
693 /* translators: this is the document security state */
694 info->security = g_strdup (_("Yes"));
696 /* translators: this is the document security state */
697 info->security = g_strdup (_("No"));
704 pdf_document_document_iface_init (EvDocumentIface *iface)
706 iface->save = pdf_document_save;
707 iface->load = pdf_document_load;
708 iface->get_n_pages = pdf_document_get_n_pages;
709 iface->get_page_size = pdf_document_get_page_size;
710 iface->get_page_label = pdf_document_get_page_label;
711 iface->has_attachments = pdf_document_has_attachments;
712 iface->get_attachments = pdf_document_get_attachments;
713 iface->render = pdf_document_render;
714 iface->get_info = pdf_document_get_info;
718 pdf_document_security_iface_init (EvDocumentSecurityIface *iface)
720 iface->has_document_security = pdf_document_has_document_security;
721 iface->set_password = pdf_document_set_password;
725 pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts)
727 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
730 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
732 return (double)pdf_document->fonts_scanned_pages / (double)n_pages;
736 pdf_document_fonts_scan (EvDocumentFonts *document_fonts,
739 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
742 g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE);
744 if (pdf_document->font_info == NULL) {
745 pdf_document->font_info = poppler_font_info_new (pdf_document->document);
748 if (pdf_document->fonts_iter) {
749 poppler_fonts_iter_free (pdf_document->fonts_iter);
752 pdf_document->fonts_scanned_pages += n_pages;
754 result = poppler_font_info_scan (pdf_document->font_info, n_pages,
755 &pdf_document->fonts_iter);
757 pdf_document->fonts_scanned_pages = 0;
758 poppler_font_info_free (pdf_document->font_info);
759 pdf_document->font_info = NULL;
766 font_type_to_string (PopplerFontType type)
769 case POPPLER_FONT_TYPE_TYPE1:
771 case POPPLER_FONT_TYPE_TYPE1C:
773 case POPPLER_FONT_TYPE_TYPE3:
775 case POPPLER_FONT_TYPE_TRUETYPE:
776 return _("TrueType");
777 case POPPLER_FONT_TYPE_CID_TYPE0:
778 return _("Type 1 (CID)");
779 case POPPLER_FONT_TYPE_CID_TYPE0C:
780 return _("Type 1C (CID)");
781 case POPPLER_FONT_TYPE_CID_TYPE2:
782 return _("TrueType (CID)");
784 return _("Unknown font type");
789 pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
792 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
793 PopplerFontsIter *iter = pdf_document->fonts_iter;
795 g_return_if_fail (PDF_IS_DOCUMENT (document_fonts));
801 GtkTreeIter list_iter;
804 const char *embedded;
807 name = poppler_fonts_iter_get_name (iter);
813 type = font_type_to_string (
814 poppler_fonts_iter_get_font_type (iter));
816 if (poppler_fonts_iter_is_embedded (iter)) {
817 if (poppler_fonts_iter_is_subset (iter))
818 embedded = _("Embedded subset");
820 embedded = _("Embedded");
822 embedded = _("Not embedded");
825 details = g_markup_printf_escaped ("%s\n%s", type, embedded);
827 gtk_list_store_append (GTK_LIST_STORE (model), &list_iter);
828 gtk_list_store_set (GTK_LIST_STORE (model), &list_iter,
829 EV_DOCUMENT_FONTS_COLUMN_NAME, name,
830 EV_DOCUMENT_FONTS_COLUMN_DETAILS, details,
834 } while (poppler_fonts_iter_next (iter));
838 pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface)
840 iface->fill_model = pdf_document_fonts_fill_model;
841 iface->scan = pdf_document_fonts_scan;
842 iface->get_progress = pdf_document_fonts_get_progress;
846 pdf_document_links_has_document_links (EvDocumentLinks *document_links)
848 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
849 PopplerIndexIter *iter;
851 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
853 iter = poppler_index_iter_new (pdf_document->document);
856 poppler_index_iter_free (iter);
862 ev_link_dest_from_dest (PdfDocument *pdf_document,
865 EvLinkDest *ev_dest = NULL;
866 const char *unimplemented_dest = NULL;
868 g_assert (dest != NULL);
870 switch (dest->type) {
871 case POPPLER_DEST_XYZ: {
872 PopplerPage *poppler_page;
875 poppler_page = poppler_document_get_page (pdf_document->document,
876 MAX (0, dest->page_num - 1));
877 poppler_page_get_size (poppler_page, NULL, &height);
878 ev_dest = ev_link_dest_new_xyz (dest->page_num - 1,
885 g_object_unref (poppler_page);
888 case POPPLER_DEST_FIT:
889 ev_dest = ev_link_dest_new_fit (dest->page_num - 1);
891 case POPPLER_DEST_FITH: {
892 PopplerPage *poppler_page;
895 poppler_page = poppler_document_get_page (pdf_document->document,
896 MAX (0, dest->page_num - 1));
897 poppler_page_get_size (poppler_page, NULL, &height);
898 ev_dest = ev_link_dest_new_fith (dest->page_num - 1,
901 g_object_unref (poppler_page);
904 case POPPLER_DEST_FITV:
905 ev_dest = ev_link_dest_new_fitv (dest->page_num - 1,
909 case POPPLER_DEST_FITR: {
910 PopplerPage *poppler_page;
913 poppler_page = poppler_document_get_page (pdf_document->document,
914 MAX (0, dest->page_num - 1));
915 poppler_page_get_size (poppler_page, NULL, &height);
916 ev_dest = ev_link_dest_new_fitr (dest->page_num - 1,
918 height - dest->bottom,
921 g_object_unref (poppler_page);
924 case POPPLER_DEST_FITB:
925 unimplemented_dest = "POPPLER_DEST_FITB";
927 case POPPLER_DEST_FITBH:
928 unimplemented_dest = "POPPLER_DEST_FITBH";
930 case POPPLER_DEST_FITBV:
931 unimplemented_dest = "POPPLER_DEST_FITBV";
933 case POPPLER_DEST_NAMED:
934 ev_dest = ev_link_dest_new_named (dest->named_dest);
936 case POPPLER_DEST_UNKNOWN:
937 unimplemented_dest = "POPPLER_DEST_UNKNOWN";
941 if (unimplemented_dest) {
942 g_warning ("Unimplemented destination: %s, please post a "
943 "bug report in Evince bugzilla "
944 "(http://bugzilla.gnome.org) with a testcase.",
949 ev_dest = ev_link_dest_new_page (dest->page_num - 1);
955 ev_link_from_action (PdfDocument *pdf_document,
956 PopplerAction *action)
959 EvLinkAction *ev_action = NULL;
960 const char *unimplemented_action = NULL;
962 switch (action->type) {
963 case POPPLER_ACTION_GOTO_DEST: {
966 dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest);
967 ev_action = ev_link_action_new_dest (dest);
970 case POPPLER_ACTION_GOTO_REMOTE: {
973 dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest);
974 ev_action = ev_link_action_new_remote (dest,
975 action->goto_remote.file_name);
979 case POPPLER_ACTION_LAUNCH:
980 ev_action = ev_link_action_new_launch (action->launch.file_name,
981 action->launch.params);
983 case POPPLER_ACTION_URI:
984 ev_action = ev_link_action_new_external_uri (action->uri.uri);
986 case POPPLER_ACTION_NAMED:
987 ev_action = ev_link_action_new_named (action->named.named_dest);
989 case POPPLER_ACTION_MOVIE:
990 unimplemented_action = "POPPLER_ACTION_MOVIE";
992 case POPPLER_ACTION_UNKNOWN:
993 unimplemented_action = "POPPLER_ACTION_UNKNOWN";
996 if (unimplemented_action) {
997 g_warning ("Unimplemented action: %s, please post a bug report "
998 "in Evince bugzilla (http://bugzilla.gnome.org) "
999 "with a testcase.", unimplemented_action);
1002 link = ev_link_new (action->any.title, ev_action);
1008 build_tree (PdfDocument *pdf_document,
1009 GtkTreeModel *model,
1010 GtkTreeIter *parent,
1011 PopplerIndexIter *iter)
1015 GtkTreeIter tree_iter;
1016 PopplerIndexIter *child;
1017 PopplerAction *action;
1018 EvLink *link = NULL;
1022 action = poppler_index_iter_get_action (iter);
1023 expand = poppler_index_iter_is_open (iter);
1028 switch (action->type) {
1029 case POPPLER_ACTION_GOTO_DEST: {
1030 /* For bookmarks, solve named destinations */
1031 if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
1033 EvLinkDest *ev_dest = NULL;
1034 EvLinkAction *ev_action;
1036 dest = poppler_document_find_dest (pdf_document->document,
1037 action->goto_dest.dest->named_dest);
1039 link = ev_link_from_action (pdf_document, action);
1043 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1044 poppler_dest_free (dest);
1046 ev_action = ev_link_action_new_dest (ev_dest);
1047 link = ev_link_new (action->any.title, ev_action);
1049 link = ev_link_from_action (pdf_document, action);
1054 link = ev_link_from_action (pdf_document, action);
1058 if (!link || strlen (ev_link_get_title (link)) <= 0) {
1059 poppler_action_free (action);
1061 g_object_unref (link);
1066 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
1067 title_markup = g_markup_escape_text (ev_link_get_title (link), -1);
1069 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
1070 EV_DOCUMENT_LINKS_COLUMN_MARKUP, title_markup,
1071 EV_DOCUMENT_LINKS_COLUMN_LINK, link,
1072 EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand,
1075 g_free (title_markup);
1076 g_object_unref (link);
1078 child = poppler_index_iter_get_child (iter);
1080 build_tree (pdf_document, model, &tree_iter, child);
1081 poppler_index_iter_free (child);
1082 poppler_action_free (action);
1084 } while (poppler_index_iter_next (iter));
1087 static GtkTreeModel *
1088 pdf_document_links_get_links_model (EvDocumentLinks *document_links)
1090 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1091 GtkTreeModel *model = NULL;
1092 PopplerIndexIter *iter;
1094 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
1096 iter = poppler_index_iter_new (pdf_document->document);
1097 /* Create the model if we have items*/
1099 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
1104 build_tree (pdf_document, model, NULL, iter);
1105 poppler_index_iter_free (iter);
1112 pdf_document_links_get_links (EvDocumentLinks *document_links,
1115 PdfDocument *pdf_document;
1116 PopplerPage *poppler_page;
1117 GList *retval = NULL;
1118 GList *mapping_list;
1122 pdf_document = PDF_DOCUMENT (document_links);
1123 poppler_page = poppler_document_get_page (pdf_document->document,
1125 mapping_list = poppler_page_get_link_mapping (poppler_page);
1126 poppler_page_get_size (poppler_page, NULL, &height);
1128 for (list = mapping_list; list; list = list->next) {
1129 PopplerLinkMapping *link_mapping;
1130 EvLinkMapping *ev_link_mapping;
1132 link_mapping = (PopplerLinkMapping *)list->data;
1133 ev_link_mapping = g_new (EvLinkMapping, 1);
1134 ev_link_mapping->link = ev_link_from_action (pdf_document,
1135 link_mapping->action);
1136 ev_link_mapping->x1 = link_mapping->area.x1;
1137 ev_link_mapping->x2 = link_mapping->area.x2;
1138 /* Invert this for X-style coordinates */
1139 ev_link_mapping->y1 = height - link_mapping->area.y2;
1140 ev_link_mapping->y2 = height - link_mapping->area.y1;
1142 retval = g_list_prepend (retval, ev_link_mapping);
1145 poppler_page_free_link_mapping (mapping_list);
1146 g_object_unref (poppler_page);
1148 return g_list_reverse (retval);
1152 pdf_document_links_find_link_dest (EvDocumentLinks *document_links,
1153 const gchar *link_name)
1155 PdfDocument *pdf_document;
1157 EvLinkDest *ev_dest = NULL;
1159 pdf_document = PDF_DOCUMENT (document_links);
1160 dest = poppler_document_find_dest (pdf_document->document,
1163 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1164 poppler_dest_free (dest);
1171 pdf_document_document_links_iface_init (EvDocumentLinksIface *iface)
1173 iface->has_document_links = pdf_document_links_has_document_links;
1174 iface->get_links_model = pdf_document_links_get_links_model;
1175 iface->get_links = pdf_document_links_get_links;
1176 iface->find_link_dest = pdf_document_links_find_link_dest;
1180 pdf_document_images_get_image_mapping (EvDocumentImages *document_images,
1183 GList *retval = NULL;
1184 PdfDocument *pdf_document;
1185 PopplerPage *poppler_page;
1186 GList *mapping_list;
1189 pdf_document = PDF_DOCUMENT (document_images);
1190 poppler_page = poppler_document_get_page (pdf_document->document, page);
1191 mapping_list = poppler_page_get_image_mapping (poppler_page);
1193 for (list = mapping_list; list; list = list->next) {
1194 PopplerImageMapping *image_mapping;
1195 EvImageMapping *ev_image_mapping;
1197 image_mapping = (PopplerImageMapping *)list->data;
1199 ev_image_mapping = g_new (EvImageMapping, 1);
1200 #ifdef HAVE_POPPLER_PAGE_GET_IMAGE
1201 ev_image_mapping->image = ev_image_new (page, image_mapping->image_id);
1202 #elif POPPLER_HAS_CAIRO
1203 ev_image_mapping->image = ev_image_new_from_pixbuf (image_mapping->image);
1205 ev_image_mapping->x1 = image_mapping->area.x1;
1206 ev_image_mapping->x2 = image_mapping->area.x2;
1207 ev_image_mapping->y1 = image_mapping->area.y1;
1208 ev_image_mapping->y2 = image_mapping->area.y2;
1210 retval = g_list_prepend (retval, ev_image_mapping);
1213 poppler_page_free_image_mapping (mapping_list);
1214 g_object_unref (poppler_page);
1216 return g_list_reverse (retval);
1220 pdf_document_images_get_image (EvDocumentImages *document_images,
1223 #ifdef HAVE_POPPLER_PAGE_GET_IMAGE
1224 PdfDocument *pdf_document;
1225 PopplerPage *poppler_page;
1226 cairo_surface_t *surface;
1227 GdkPixbuf *retval = NULL;
1229 pdf_document = PDF_DOCUMENT (document_images);
1230 poppler_page = poppler_document_get_page (pdf_document->document,
1231 ev_image_get_page (image));
1233 surface = poppler_page_get_image (poppler_page, ev_image_get_id (image));
1235 retval = ev_document_misc_pixbuf_from_surface (surface);
1236 cairo_surface_destroy (surface);
1239 g_object_unref (poppler_page);
1243 return GDK_PIXBUF (g_object_ref (ev_image_get_pixbuf (image)));
1244 #endif /* HAVE_POPPLER_PAGE_GET_IMAGE */
1248 pdf_document_document_images_iface_init (EvDocumentImagesIface *iface)
1250 iface->get_image_mapping = pdf_document_images_get_image_mapping;
1251 iface->get_image = pdf_document_images_get_image;
1255 make_thumbnail_for_page (PdfDocument *pdf_document,
1256 PopplerPage *poppler_page,
1257 EvRenderContext *rc)
1262 pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document),
1263 rc, &width, &height);
1264 #ifdef POPPLER_HAS_GDK
1265 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
1267 gdk_pixbuf_fill (pixbuf, 0xffffffff);
1269 ev_document_fc_mutex_lock ();
1270 poppler_page_render_to_pixbuf (poppler_page, 0, 0,
1272 rc->scale, rc->rotation, pixbuf);
1273 ev_document_fc_mutex_unlock ();
1275 cairo_surface_t *surface;
1277 ev_document_fc_mutex_lock ();
1278 surface = pdf_page_render (poppler_page, width, height, rc);
1279 ev_document_fc_mutex_unlock ();
1281 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1282 cairo_surface_destroy (surface);
1283 #endif /* POPPLER_HAS_GDK */
1289 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1290 EvRenderContext *rc,
1293 PdfDocument *pdf_document;
1294 PopplerPage *poppler_page;
1295 GdkPixbuf *pixbuf = NULL;
1296 GdkPixbuf *border_pixbuf;
1298 pdf_document = PDF_DOCUMENT (document_thumbnails);
1300 poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
1301 g_return_val_if_fail (poppler_page != NULL, NULL);
1303 #if POPPLER_MAJOR_VERSION <= 6 || (POPPLER_MAJOR_VERSION == 7 && POPPLER_MINOR_VERSION < 2)
1304 pixbuf = poppler_page_get_thumbnail (poppler_page);
1306 #ifdef POPPLER_HAS_GDK
1307 pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page);
1309 cairo_surface_t *surface;
1311 surface = poppler_page_get_thumbnail (poppler_page);
1313 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1314 cairo_surface_destroy (surface);
1320 /* Rotate provided thumbnail if needed */
1321 GdkPixbuf *rotated_pixbuf;
1323 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
1324 (GdkPixbufRotation) (360 - rc->rotation));
1325 g_object_unref (pixbuf);
1326 pixbuf = rotated_pixbuf;
1328 /* There is no provided thumbnail. We need to make one. */
1329 pixbuf = make_thumbnail_for_page (pdf_document, poppler_page, rc);
1333 border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
1334 g_object_unref (pixbuf);
1335 pixbuf = border_pixbuf;
1338 g_object_unref (poppler_page);
1344 pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
1345 EvRenderContext *rc,
1349 PdfDocument *pdf_document;
1350 PopplerPage *poppler_page;
1353 pdf_document = PDF_DOCUMENT (document_thumbnails);
1354 poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
1356 g_return_if_fail (poppler_page != NULL);
1358 has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height);
1361 double page_width, page_height;
1363 poppler_page_get_size (poppler_page, &page_width, &page_height);
1365 *width = (gint) MAX (page_width * rc->scale, 1);
1366 *height = (gint) MAX (page_height * rc->scale, 1);
1369 if (rc->rotation == 90 || rc->rotation == 270) {
1377 g_object_unref (poppler_page);
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_search_idle_callback (void *data)
1391 PdfDocumentSearch *search = (PdfDocumentSearch*) data;
1392 PdfDocument *pdf_document = search->document;
1397 page = poppler_document_get_page (search->document->document,
1398 search->search_page);
1400 ev_document_doc_mutex_lock ();
1401 matches = poppler_page_find_text (page, search->text);
1402 ev_document_doc_mutex_unlock ();
1404 g_object_unref (page);
1406 search->pages[search->search_page] = matches;
1407 ev_document_find_changed (EV_DOCUMENT_FIND (pdf_document),
1408 search->search_page);
1410 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (search->document));
1411 search->search_page += 1;
1412 if (search->search_page == n_pages) {
1414 search->search_page = 0;
1417 if (search->search_page != search->start_page) {
1422 search->idle = 0; /* will return FALSE to remove */
1427 static PdfDocumentSearch *
1428 pdf_document_search_new (PdfDocument *pdf_document,
1432 PdfDocumentSearch *search;
1436 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
1438 search = g_new0 (PdfDocumentSearch, 1);
1440 search->text = g_strdup (text);
1441 search->pages = g_new0 (GList *, n_pages);
1442 search->document = pdf_document;
1444 /* We add at low priority so the progress bar repaints */
1445 search->idle = g_idle_add_full (G_PRIORITY_LOW,
1446 pdf_document_search_idle_callback,
1450 search->start_page = start_page;
1451 search->search_page = start_page;
1457 pdf_document_find_begin (EvDocumentFind *document,
1459 const char *search_string,
1460 gboolean case_sensitive)
1462 PdfDocument *pdf_document = PDF_DOCUMENT (document);
1464 /* FIXME handle case_sensitive (right now XPDF
1465 * code is always case insensitive for ASCII
1466 * and case sensitive for all other languaages)
1469 if (pdf_document->search &&
1470 strcmp (search_string, pdf_document->search->text) == 0)
1473 if (pdf_document->search)
1474 pdf_document_search_free (pdf_document->search);
1476 pdf_document->search = pdf_document_search_new (pdf_document,
1482 pdf_document_find_get_n_results (EvDocumentFind *document_find, int page)
1484 PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
1487 return g_list_length (search->pages[page]);
1494 pdf_document_find_get_result (EvDocumentFind *document_find,
1497 EvRectangle *rectangle)
1499 PdfDocument *pdf_document = PDF_DOCUMENT (document_find);
1500 PdfDocumentSearch *search = pdf_document->search;
1501 PopplerPage *poppler_page;
1502 PopplerRectangle *r;
1508 r = (PopplerRectangle *) g_list_nth_data (search->pages[page],
1513 poppler_page = poppler_document_get_page (pdf_document->document, page);
1514 poppler_page_get_size (poppler_page, NULL, &height);
1515 rectangle->x1 = r->x1;
1516 rectangle->y1 = height - r->y2;
1517 rectangle->x2 = r->x2;
1518 rectangle->y2 = height - r->y1;
1519 g_object_unref (poppler_page);
1525 pdf_document_find_page_has_results (EvDocumentFind *document_find,
1528 PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
1530 return search && search->pages[page] != NULL;
1534 pdf_document_find_get_progress (EvDocumentFind *document_find)
1536 PdfDocumentSearch *search;
1537 int n_pages, pages_done;
1539 search = PDF_DOCUMENT (document_find)->search;
1541 if (search == NULL) {
1545 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (document_find));
1546 if (search->search_page > search->start_page) {
1547 pages_done = search->search_page - search->start_page + 1;
1548 } else if (search->search_page == search->start_page) {
1549 pages_done = n_pages;
1551 pages_done = n_pages - search->start_page + search->search_page;
1554 return pages_done / (double) n_pages;
1558 pdf_document_find_cancel (EvDocumentFind *document)
1560 PdfDocument *pdf_document = PDF_DOCUMENT (document);
1562 if (pdf_document->search) {
1563 pdf_document_search_free (pdf_document->search);
1564 pdf_document->search = NULL;
1569 pdf_document_find_iface_init (EvDocumentFindIface *iface)
1571 iface->begin = pdf_document_find_begin;
1572 iface->get_n_results = pdf_document_find_get_n_results;
1573 iface->get_result = pdf_document_find_get_result;
1574 iface->page_has_results = pdf_document_find_page_has_results;
1575 iface->get_progress = pdf_document_find_get_progress;
1576 iface->cancel = pdf_document_find_cancel;
1580 pdf_print_context_free (PdfPrintContext *ctx)
1585 #ifdef HAVE_CAIRO_PRINT
1587 cairo_destroy (ctx->cr);
1592 poppler_ps_file_free (ctx->ps_file);
1593 ctx->ps_file = NULL;
1600 pdf_document_file_exporter_begin (EvFileExporter *exporter,
1601 EvFileExporterContext *fc)
1603 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1604 PdfPrintContext *ctx;
1605 #ifdef HAVE_CAIRO_PRINT
1606 gdouble width, height;
1607 cairo_surface_t *surface = NULL;
1610 if (pdf_document->print_ctx)
1611 pdf_print_context_free (pdf_document->print_ctx);
1612 pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
1613 ctx = pdf_document->print_ctx;
1614 ctx->format = fc->format;
1616 #ifdef HAVE_CAIRO_PRINT
1617 ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
1619 ctx->paper_width = fc->paper_width;
1620 ctx->paper_height = fc->paper_height;
1622 switch (fc->pages_per_sheet) {
1650 ctx->pages_printed = 0;
1652 switch (fc->format) {
1653 case EV_FILE_FORMAT_PS:
1654 #ifdef HAVE_CAIRO_PS
1655 surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1658 case EV_FILE_FORMAT_PDF:
1659 #ifdef HAVE_CAIRO_PDF
1660 surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1664 g_assert_not_reached ();
1667 ctx->cr = cairo_create (surface);
1668 cairo_surface_destroy (surface);
1670 #else /* HAVE_CAIRO_PRINT */
1671 if (ctx->format == EV_FILE_FORMAT_PS) {
1672 ctx->ps_file = poppler_ps_file_new (pdf_document->document,
1673 fc->filename, fc->first_page,
1674 fc->last_page - fc->first_page + 1);
1675 poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
1676 poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
1678 #endif /* HAVE_CAIRO_PRINT */
1682 pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
1684 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1685 PdfPrintContext *ctx = pdf_document->print_ctx;
1687 g_return_if_fail (pdf_document->print_ctx != NULL);
1689 ctx->pages_printed = 0;
1691 #ifdef HAVE_CAIRO_PRINT
1692 if (ctx->paper_width > ctx->paper_height) {
1693 if (ctx->format == EV_FILE_FORMAT_PS) {
1694 cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
1697 } else if (ctx->format == EV_FILE_FORMAT_PDF) {
1698 cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
1703 #endif /* HAVE_CAIRO_PRINT */
1707 pdf_document_file_exporter_do_page (EvFileExporter *exporter,
1708 EvRenderContext *rc)
1710 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1711 PdfPrintContext *ctx = pdf_document->print_ctx;
1712 PopplerPage *poppler_page;
1713 #ifdef HAVE_CAIRO_PRINT
1714 gdouble page_width, page_height;
1716 gboolean rotate, landscape;
1717 gdouble width, height;
1718 gdouble pwidth, pheight;
1719 gdouble xscale, yscale;
1722 g_return_if_fail (pdf_document->print_ctx != NULL);
1724 poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
1726 #ifdef HAVE_CAIRO_PRINT
1727 x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
1728 y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
1729 poppler_page_get_size (poppler_page, &page_width, &page_height);
1731 if (page_width > page_height && page_width > ctx->paper_width) {
1737 landscape = (ctx->paper_width > ctx->paper_height);
1739 /* Use always portrait mode and rotate when necessary */
1740 if (ctx->paper_width > ctx->paper_height) {
1741 width = ctx->paper_height;
1742 height = ctx->paper_width;
1745 width = ctx->paper_width;
1746 height = ctx->paper_height;
1749 if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
1762 page_width = page_height;
1766 pwidth = width / ctx->pages_x;
1767 pheight = height / ctx->pages_y;
1769 if ((page_width > pwidth || page_height > pheight) ||
1770 (page_width < pwidth && page_height < pheight)) {
1771 xscale = pwidth / page_width;
1772 yscale = pheight / page_height;
1774 if (yscale < xscale) {
1781 xscale = yscale = 1;
1786 cairo_save (ctx->cr);
1788 cairo_matrix_t matrix;
1790 cairo_translate (ctx->cr, width, 0);
1791 cairo_matrix_init (&matrix,
1795 cairo_transform (ctx->cr, &matrix);
1798 cairo_translate (ctx->cr,
1799 x * (rotate ? pheight : pwidth),
1800 y * (rotate ? pwidth : pheight));
1801 cairo_scale (ctx->cr, xscale, yscale);
1803 #ifdef HAVE_POPPLER_PAGE_RENDER_FOR_PRINTING
1804 poppler_page_render_for_printing (poppler_page, ctx->cr);
1806 #ifdef HAVE_POPPLER_PAGE_RENDER
1807 poppler_page_render (poppler_page, ctx->cr);
1811 ctx->pages_printed++;
1813 cairo_restore (ctx->cr);
1814 #else /* HAVE_CAIRO_PRINT */
1815 if (ctx->format == EV_FILE_FORMAT_PS)
1816 poppler_page_render_to_ps (poppler_page, ctx->ps_file);
1817 #endif /* HAVE_CAIRO_PRINT */
1819 g_object_unref (poppler_page);
1823 pdf_document_file_exporter_end_page (EvFileExporter *exporter)
1825 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1826 PdfPrintContext *ctx = pdf_document->print_ctx;
1828 g_return_if_fail (pdf_document->print_ctx != NULL);
1830 #ifdef HAVE_CAIRO_PRINT
1831 cairo_show_page (ctx->cr);
1836 pdf_document_file_exporter_end (EvFileExporter *exporter)
1838 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1840 pdf_print_context_free (pdf_document->print_ctx);
1841 pdf_document->print_ctx = NULL;
1844 static EvFileExporterCapabilities
1845 pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter)
1847 return (EvFileExporterCapabilities) (
1848 EV_FILE_EXPORTER_CAN_PAGE_SET |
1849 EV_FILE_EXPORTER_CAN_COPIES |
1850 EV_FILE_EXPORTER_CAN_COLLATE |
1851 EV_FILE_EXPORTER_CAN_REVERSE |
1852 EV_FILE_EXPORTER_CAN_SCALE |
1853 #ifdef HAVE_CAIRO_PRINT
1854 #ifdef HAVE_POPPLER_PAGE_RENDER
1855 #if GTK_CHECK_VERSION (2, 11, 1)
1856 EV_FILE_EXPORTER_CAN_NUMBER_UP |
1861 #ifdef HAVE_CAIRO_PDF
1862 #ifdef HAVE_POPPLER_PAGE_RENDER
1863 EV_FILE_EXPORTER_CAN_GENERATE_PDF |
1866 EV_FILE_EXPORTER_CAN_GENERATE_PS);
1870 pdf_document_file_exporter_iface_init (EvFileExporterIface *iface)
1872 iface->begin = pdf_document_file_exporter_begin;
1873 iface->begin_page = pdf_document_file_exporter_begin_page;
1874 iface->do_page = pdf_document_file_exporter_do_page;
1875 iface->end_page = pdf_document_file_exporter_end_page;
1876 iface->end = pdf_document_file_exporter_end;
1877 iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
1881 pdf_selection_render_selection (EvSelection *selection,
1882 EvRenderContext *rc,
1883 cairo_surface_t **surface,
1884 EvRectangle *points,
1885 EvRectangle *old_points,
1886 EvSelectionStyle style,
1890 PdfDocument *pdf_document;
1891 double width_points, height_points;
1894 pdf_document = PDF_DOCUMENT (selection);
1895 set_rc_data (pdf_document, rc);
1897 poppler_page_get_size (POPPLER_PAGE (rc->data),
1898 &width_points, &height_points);
1899 width = (int) ((width_points * rc->scale) + 0.5);
1900 height = (int) ((height_points * rc->scale) + 0.5);
1902 #ifdef HAVE_POPPLER_PAGE_RENDER
1905 #if POPPLER_MAJOR_VERSION <= 6 || (POPPLER_MAJOR_VERSION == 7 && POPPLER_MINOR_VERSION < 2)
1906 GdkColor text_color, base_color;
1911 PopplerColor text_color, base_color;
1913 text_color.red = text->red;
1914 text_color.green = text->green;
1915 text_color.blue = text->blue;
1917 base_color.red = base->red;
1918 base_color.green = base->green;
1919 base_color.blue = base->blue;
1922 if (*surface == NULL) {
1923 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1928 cr = cairo_create (*surface);
1929 cairo_scale (cr, rc->scale, rc->scale);
1930 cairo_surface_set_device_offset (*surface, 0, 0);
1931 memset (cairo_image_surface_get_data (*surface), 0x00,
1932 cairo_image_surface_get_height (*surface) *
1933 cairo_image_surface_get_stride (*surface));
1934 poppler_page_render_selection (POPPLER_PAGE (rc->data),
1936 (PopplerRectangle *)points,
1937 (PopplerRectangle *)old_points,
1938 (PopplerSelectionStyle)style,
1942 #else /* HAVE_POPPLER_PAGE_RENDER */
1945 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
1949 poppler_page_render_selection_to_pixbuf (POPPLER_PAGE (rc->data),
1950 rc->scale, rc->rotation, pixbuf,
1951 (PopplerRectangle *)points,
1952 (PopplerRectangle *)old_points,
1953 (PopplerSelectionStyle)style,
1957 cairo_surface_destroy (*surface);
1958 *surface = ev_document_misc_surface_from_pixbuf (pixbuf);
1959 g_object_unref (pixbuf);
1960 #endif /* HAVE_POPPLER_PAGE_RENDER */
1964 pdf_selection_get_selected_text (EvSelection *selection,
1965 EvRenderContext *rc,
1966 EvSelectionStyle style,
1967 EvRectangle *points)
1969 PdfDocument *pdf_document = PDF_DOCUMENT (selection);
1970 PopplerPage *poppler_page;
1975 poppler_page = poppler_document_get_page (pdf_document->document, rc->page);
1976 g_return_val_if_fail (poppler_page != NULL, NULL);
1978 poppler_page_get_size (poppler_page, NULL, &height);
1980 r.y1 = height - points->y2;
1982 r.y2 = height - points->y1;
1984 retval = poppler_page_get_text (poppler_page,
1985 (PopplerSelectionStyle)style,
1988 g_object_unref (poppler_page);
1994 create_gdk_region_from_poppler_region (GList *region)
1999 retval = gdk_region_new ();
2001 for (l = region; l; l = g_list_next (l)) {
2002 PopplerRectangle *rectangle;
2005 rectangle = (PopplerRectangle *)l->data;
2007 rect.x = (gint) rectangle->x1;
2008 rect.y = (gint) rectangle->y1;
2009 rect.width = (gint) (rectangle->x2 - rectangle->x1);
2010 rect.height = (gint) (rectangle->y2 - rectangle->y1);
2011 gdk_region_union_with_rect (retval, &rect);
2013 poppler_rectangle_free (rectangle);
2020 pdf_selection_get_selection_region (EvSelection *selection,
2021 EvRenderContext *rc,
2022 EvSelectionStyle style,
2023 EvRectangle *points)
2025 PdfDocument *pdf_document;
2028 pdf_document = PDF_DOCUMENT (selection);
2030 set_rc_data (pdf_document, rc);
2032 #if POPPLER_MAJOR_VERSION <= 6 || (POPPLER_MAJOR_VERSION == 7 && POPPLER_MINOR_VERSION < 2)
2033 retval = poppler_page_get_selection_region (POPPLER_PAGE (rc->data),
2035 (PopplerSelectionStyle)style,
2036 (PopplerRectangle *) points);
2040 region = poppler_page_get_selection_region (POPPLER_PAGE (rc->data),
2042 (PopplerSelectionStyle)style,
2043 (PopplerRectangle *) points);
2044 retval = create_gdk_region_from_poppler_region (region);
2045 g_list_free (region);
2052 pdf_selection_get_selection_map (EvSelection *selection,
2053 EvRenderContext *rc)
2055 PdfDocument *pdf_document;
2056 PopplerPage *poppler_page;
2057 PopplerRectangle points;
2061 pdf_document = PDF_DOCUMENT (selection);
2062 poppler_page = poppler_document_get_page (pdf_document->document,
2067 poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
2069 #if POPPLER_MAJOR_VERSION <= 6 || (POPPLER_MAJOR_VERSION == 7 && POPPLER_MINOR_VERSION < 2)
2070 retval = poppler_page_get_selection_region (poppler_page, 1.0,
2071 POPPLER_SELECTION_GLYPH,
2074 region = poppler_page_get_selection_region (poppler_page, 1.0,
2075 POPPLER_SELECTION_GLYPH,
2077 retval = create_gdk_region_from_poppler_region (region);
2078 g_list_free (region);
2080 g_object_unref (poppler_page);
2086 pdf_selection_iface_init (EvSelectionIface *iface)
2088 iface->render_selection = pdf_selection_render_selection;
2089 iface->get_selected_text = pdf_selection_get_selected_text;
2090 iface->get_selection_region = pdf_selection_get_selection_region;
2091 iface->get_selection_map = pdf_selection_get_selection_map;
2094 /* Page Transitions */
2096 pdf_document_get_page_duration (EvDocumentTransition *trans,
2099 PdfDocument *pdf_document;
2100 PopplerPage *poppler_page;
2101 gdouble duration = -1;
2103 pdf_document = PDF_DOCUMENT (trans);
2104 poppler_page = poppler_document_get_page (pdf_document->document, page);
2108 duration = poppler_page_get_duration (poppler_page);
2109 g_object_unref (poppler_page);
2114 static EvTransitionEffect *
2115 pdf_document_get_effect (EvDocumentTransition *trans,
2118 PdfDocument *pdf_document;
2119 PopplerPage *poppler_page;
2120 PopplerPageTransition *page_transition;
2121 EvTransitionEffect *effect;
2123 pdf_document = PDF_DOCUMENT (trans);
2124 poppler_page = poppler_document_get_page (pdf_document->document, page);
2129 page_transition = poppler_page_get_transition (poppler_page);
2131 if (!page_transition) {
2132 g_object_unref (poppler_page);
2136 /* enums in PopplerPageTransition match the EvTransitionEffect ones */
2137 effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
2138 "alignment", page_transition->alignment,
2139 "direction", page_transition->direction,
2140 "duration", page_transition->duration,
2141 "angle", page_transition->angle,
2142 "scale", page_transition->scale,
2143 "rectangular", page_transition->rectangular,
2146 poppler_page_transition_free (page_transition);
2147 g_object_unref (poppler_page);
2153 pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
2155 iface->get_page_duration = pdf_document_get_page_duration;
2156 iface->get_effect = pdf_document_get_effect;
2161 pdf_document_get_crop_box (EvDocument *document,
2165 PdfDocument *pdf_document;
2166 PopplerPage *poppler_page;
2167 PopplerRectangle poppler_rect;
2169 pdf_document = PDF_DOCUMENT (document);
2170 poppler_page = poppler_document_get_page (pdf_document->document, page);
2171 poppler_page_get_crop_box (poppler_page, &poppler_rect);
2172 rect->x1 = poppler_rect.x1;
2173 rect->x2 = poppler_rect.x2;
2174 rect->y1 = poppler_rect.y1;
2175 rect->y2 = poppler_rect.y2;
2178 static EvFormField *
2179 ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
2181 EvFormField *ev_field = NULL;
2184 gboolean is_read_only;
2186 id = poppler_form_field_get_id (poppler_field);
2187 font_size = poppler_form_field_get_font_size (poppler_field);
2188 is_read_only = poppler_form_field_is_read_only (poppler_field);
2190 switch (poppler_form_field_get_field_type (poppler_field)) {
2191 case POPPLER_FORM_FIELD_TEXT: {
2192 EvFormFieldText *field_text;
2193 EvFormFieldTextType ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2195 switch (poppler_form_field_text_get_text_type (poppler_field)) {
2196 case POPPLER_FORM_TEXT_NORMAL:
2197 ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2199 case POPPLER_FORM_TEXT_MULTILINE:
2200 ev_text_type = EV_FORM_FIELD_TEXT_MULTILINE;
2202 case POPPLER_FORM_TEXT_FILE_SELECT:
2203 ev_text_type = EV_FORM_FIELD_TEXT_FILE_SELECT;
2207 ev_field = ev_form_field_text_new (id, ev_text_type);
2208 field_text = EV_FORM_FIELD_TEXT (ev_field);
2210 field_text->do_spell_check = poppler_form_field_text_do_spell_check (poppler_field);
2211 field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
2212 field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
2213 field_text->is_password = poppler_form_field_text_is_password (poppler_field);
2214 field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
2215 field_text->text = poppler_form_field_text_get_text (poppler_field);
2219 case POPPLER_FORM_FIELD_BUTTON: {
2220 EvFormFieldButton *field_button;
2221 EvFormFieldButtonType ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2223 switch (poppler_form_field_button_get_button_type (poppler_field)) {
2224 case POPPLER_FORM_BUTTON_PUSH:
2225 ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2227 case POPPLER_FORM_BUTTON_CHECK:
2228 ev_button_type = EV_FORM_FIELD_BUTTON_CHECK;
2230 case POPPLER_FORM_BUTTON_RADIO:
2231 ev_button_type = EV_FORM_FIELD_BUTTON_RADIO;
2235 ev_field = ev_form_field_button_new (id, ev_button_type);
2236 field_button = EV_FORM_FIELD_BUTTON (ev_field);
2238 field_button->state = poppler_form_field_button_get_state (poppler_field);
2241 case POPPLER_FORM_FIELD_CHOICE: {
2242 EvFormFieldChoice *field_choice;
2243 EvFormFieldChoiceType ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2245 switch (poppler_form_field_choice_get_choice_type (poppler_field)) {
2246 case POPPLER_FORM_CHOICE_COMBO:
2247 ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2249 case EV_FORM_FIELD_CHOICE_LIST:
2250 ev_choice_type = EV_FORM_FIELD_CHOICE_LIST;
2254 ev_field = ev_form_field_choice_new (id, ev_choice_type);
2255 field_choice = EV_FORM_FIELD_CHOICE (ev_field);
2257 field_choice->is_editable = poppler_form_field_choice_is_editable (poppler_field);
2258 field_choice->multi_select = poppler_form_field_choice_can_select_multiple (poppler_field);
2259 field_choice->do_spell_check = poppler_form_field_choice_do_spell_check (poppler_field);
2260 field_choice->commit_on_sel_change = poppler_form_field_choice_commit_on_change (poppler_field);
2262 /* TODO: we need poppler_form_field_choice_get_selected_items in poppler
2263 field_choice->selected_items = poppler_form_field_choice_get_selected_items (poppler_field);*/
2264 if (field_choice->is_editable)
2265 field_choice->text = poppler_form_field_choice_get_text (poppler_field);
2268 case POPPLER_FORM_FIELD_SIGNATURE:
2270 ev_field = ev_form_field_signature_new (id);
2272 case POPPLER_FORM_FIELD_UNKNOWN:
2276 ev_field->font_size = font_size;
2277 ev_field->is_read_only = is_read_only;
2283 pdf_document_forms_get_form_fields (EvDocumentForms *document,
2286 PdfDocument *pdf_document;
2287 PopplerPage *poppler_page;
2288 GList *retval = NULL;
2293 pdf_document = PDF_DOCUMENT (document);
2294 poppler_page = poppler_document_get_page (pdf_document->document, page);
2295 fields = poppler_page_get_form_field_mapping (poppler_page);
2296 poppler_page_get_size (poppler_page, NULL, &height);
2298 for (list = fields; list; list = list->next) {
2299 PopplerFormFieldMapping *mapping;
2300 EvFormFieldMapping *field_mapping;
2301 EvFormField *ev_field;
2303 mapping = (PopplerFormFieldMapping *)list->data;
2305 ev_field = ev_form_field_from_poppler_field (mapping->field);
2309 field_mapping = g_new0 (EvFormFieldMapping, 1);
2310 field_mapping->x1 = mapping->area.x1;
2311 field_mapping->x2 = mapping->area.x2;
2312 field_mapping->y1 = height - mapping->area.y2;
2313 field_mapping->y2 = height - mapping->area.y1;
2314 field_mapping->field = ev_field;
2315 field_mapping->field->page = page;
2317 retval = g_list_prepend (retval, field_mapping);
2320 poppler_page_free_form_field_mapping (fields);
2321 g_object_unref (poppler_page);
2323 return g_list_reverse (retval);
2327 pdf_document_forms_form_field_text_get_text (EvDocumentForms *document,
2331 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2332 PopplerFormField *poppler_field;
2335 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2339 text = poppler_form_field_text_get_text (poppler_field);
2340 g_object_unref (poppler_field);
2346 pdf_document_forms_form_field_text_set_text (EvDocumentForms *document,
2350 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2351 PopplerFormField *poppler_field;
2353 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2356 poppler_form_field_text_set_text (poppler_field, text);
2357 g_object_unref (poppler_field);
2361 pdf_document_forms_form_field_button_set_state (EvDocumentForms *document,
2365 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2366 PopplerFormField *poppler_field;
2368 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2372 poppler_form_field_button_set_state (poppler_field, state);
2373 g_object_unref (poppler_field);
2377 pdf_document_forms_form_field_button_get_state (EvDocumentForms *document,
2380 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2381 PopplerFormField *poppler_field;
2384 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2388 state = poppler_form_field_button_get_state (poppler_field);
2389 g_object_unref (poppler_field);
2395 pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document,
2399 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2400 PopplerFormField *poppler_field;
2403 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2407 text = poppler_form_field_choice_get_item (poppler_field, index);
2408 g_object_unref (poppler_field);
2414 pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document,
2417 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2418 PopplerFormField *poppler_field;
2421 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2425 n_items = poppler_form_field_choice_get_n_items (poppler_field);
2426 g_object_unref (poppler_field);
2432 pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document,
2436 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2437 PopplerFormField *poppler_field;
2440 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2444 selected = poppler_form_field_choice_is_item_selected (poppler_field, index);
2445 g_object_unref (poppler_field);
2451 pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document,
2455 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2456 PopplerFormField *poppler_field;
2458 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2462 poppler_form_field_choice_select_item (poppler_field, index);
2463 g_object_unref (poppler_field);
2467 pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document,
2471 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2472 PopplerFormField *poppler_field;
2474 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2478 poppler_form_field_choice_toggle_item (poppler_field, index);
2479 g_object_unref (poppler_field);
2483 pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document,
2486 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2487 PopplerFormField *poppler_field;
2489 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2493 poppler_form_field_choice_unselect_all (poppler_field);
2494 g_object_unref (poppler_field);
2498 pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document,
2502 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2503 PopplerFormField *poppler_field;
2505 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2509 poppler_form_field_choice_set_text (poppler_field, text);
2510 g_object_unref (poppler_field);
2514 pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document,
2517 PdfDocument *pdf_document = PDF_DOCUMENT (document);
2518 PopplerFormField *poppler_field;
2521 poppler_field = poppler_document_get_form_field (pdf_document->document, field->id);
2525 text = poppler_form_field_choice_get_text (poppler_field);
2526 g_object_unref (poppler_field);
2532 pdf_document_document_forms_iface_init (EvDocumentFormsIface *iface)
2534 iface->get_form_fields = pdf_document_forms_get_form_fields;
2535 iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
2536 iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
2537 iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
2538 iface->form_field_button_get_state = pdf_document_forms_form_field_button_get_state;
2539 iface->form_field_choice_get_item = pdf_document_forms_form_field_choice_get_item;
2540 iface->form_field_choice_get_n_items = pdf_document_forms_form_field_choice_get_n_items;
2541 iface->form_field_choice_is_item_selected = pdf_document_forms_form_field_choice_is_item_selected;
2542 iface->form_field_choice_select_item = pdf_document_forms_form_field_choice_select_item;
2543 iface->form_field_choice_toggle_item = pdf_document_forms_form_field_choice_toggle_item;
2544 iface->form_field_choice_unselect_all = pdf_document_forms_form_field_choice_unselect_all;
2545 iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
2546 iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;