1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2009, Juanjo MarĂn <juanj.marin@juntadeandalucia.es>
5 * Copyright (C) 2004, Red Hat, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <poppler-document.h>
29 #include <poppler-page.h>
31 #include <cairo-pdf.h>
36 #include <glib/gi18n-lib.h>
38 #include "ev-poppler.h"
39 #include "ev-file-exporter.h"
40 #include "ev-document-find.h"
41 #include "ev-document-misc.h"
42 #include "ev-document-links.h"
43 #include "ev-document-images.h"
44 #include "ev-document-fonts.h"
45 #include "ev-document-security.h"
46 #include "ev-document-transition.h"
47 #include "ev-document-forms.h"
48 #include "ev-document-layers.h"
49 #include "ev-document-print.h"
50 #include "ev-document-annotations.h"
51 #include "ev-document-attachments.h"
52 #include "ev-document-text.h"
53 #include "ev-selection.h"
54 #include "ev-transition-effect.h"
55 #include "ev-attachment.h"
58 #include <libxml/tree.h>
59 #include <libxml/parser.h>
60 #include <libxml/xpath.h>
61 #include <libxml/xpathInternals.h>
63 #if (defined (HAVE_CAIRO_PDF) || defined (HAVE_CAIRO_PS))
64 #define HAVE_CAIRO_PRINT
67 /* fields from the XMP Rights Management Schema, XMP Specification Sept 2005, pag. 45 */
68 #define LICENSE_MARKED "/x:xmpmeta/rdf:RDF/rdf:Description/xmpRights:Marked"
69 #define LICENSE_TEXT "/x:xmpmeta/rdf:RDF/rdf:Description/dc:rights/rdf:Alt/rdf:li[lang('%s')]"
70 #define LICENSE_WEB_STATEMENT "/x:xmpmeta/rdf:RDF/rdf:Description/xmpRights:WebStatement"
71 /* license field from Creative Commons schema, http://creativecommons.org/ns */
72 #define LICENSE_URI "/x:xmpmeta/rdf:RDF/rdf:Description/cc:license/@rdf:resource"
75 EvFileExporterFormat format;
85 #ifdef HAVE_CAIRO_PRINT
88 PopplerPSFile *ps_file;
92 struct _PdfDocumentClass
94 EvDocumentClass parent_class;
99 EvDocument parent_instance;
101 PopplerDocument *document;
103 gboolean forms_modified;
104 gboolean annots_modified;
106 PopplerFontInfo *font_info;
107 PopplerFontsIter *fonts_iter;
108 int fonts_scanned_pages;
110 PdfPrintContext *print_ctx;
115 static void pdf_document_security_iface_init (EvDocumentSecurityInterface *iface);
116 static void pdf_document_document_links_iface_init (EvDocumentLinksInterface *iface);
117 static void pdf_document_document_images_iface_init (EvDocumentImagesInterface *iface);
118 static void pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface);
119 static void pdf_document_document_fonts_iface_init (EvDocumentFontsInterface *iface);
120 static void pdf_document_document_layers_iface_init (EvDocumentLayersInterface *iface);
121 static void pdf_document_document_print_iface_init (EvDocumentPrintInterface *iface);
122 static void pdf_document_document_annotations_iface_init (EvDocumentAnnotationsInterface *iface);
123 static void pdf_document_document_attachments_iface_init (EvDocumentAttachmentsInterface *iface);
124 static void pdf_document_find_iface_init (EvDocumentFindInterface *iface);
125 static void pdf_document_file_exporter_iface_init (EvFileExporterInterface *iface);
126 static void pdf_selection_iface_init (EvSelectionInterface *iface);
127 static void pdf_document_page_transition_iface_init (EvDocumentTransitionInterface *iface);
128 static void pdf_document_text_iface_init (EvDocumentTextInterface *iface);
129 static int pdf_document_get_n_pages (EvDocument *document);
131 static EvLinkDest *ev_link_dest_from_dest (PdfDocument *pdf_document,
133 static EvLink *ev_link_from_action (PdfDocument *pdf_document,
134 PopplerAction *action);
135 static void pdf_print_context_free (PdfPrintContext *ctx);
136 static gboolean attachment_save_to_buffer (PopplerAttachment *attachment,
141 EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
143 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
144 pdf_document_security_iface_init);
145 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
146 pdf_document_document_links_iface_init);
147 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES,
148 pdf_document_document_images_iface_init);
149 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FORMS,
150 pdf_document_document_forms_iface_init);
151 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS,
152 pdf_document_document_fonts_iface_init);
153 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LAYERS,
154 pdf_document_document_layers_iface_init);
155 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_PRINT,
156 pdf_document_document_print_iface_init);
157 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ANNOTATIONS,
158 pdf_document_document_annotations_iface_init);
159 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ATTACHMENTS,
160 pdf_document_document_attachments_iface_init);
161 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
162 pdf_document_find_iface_init);
163 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
164 pdf_document_file_exporter_iface_init);
165 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION,
166 pdf_selection_iface_init);
167 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
168 pdf_document_page_transition_iface_init);
169 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TEXT,
170 pdf_document_text_iface_init);
174 pdf_document_dispose (GObject *object)
176 PdfDocument *pdf_document = PDF_DOCUMENT(object);
178 if (pdf_document->print_ctx) {
179 pdf_print_context_free (pdf_document->print_ctx);
180 pdf_document->print_ctx = NULL;
183 if (pdf_document->annots) {
184 g_hash_table_destroy (pdf_document->annots);
185 pdf_document->annots = NULL;
188 if (pdf_document->document) {
189 g_object_unref (pdf_document->document);
192 if (pdf_document->font_info) {
193 poppler_font_info_free (pdf_document->font_info);
196 if (pdf_document->fonts_iter) {
197 poppler_fonts_iter_free (pdf_document->fonts_iter);
200 G_OBJECT_CLASS (pdf_document_parent_class)->dispose (object);
204 pdf_document_init (PdfDocument *pdf_document)
206 pdf_document->password = NULL;
210 convert_error (GError *poppler_error,
213 if (poppler_error == NULL)
216 if (poppler_error->domain == POPPLER_ERROR) {
217 /* convert poppler errors into EvDocument errors */
218 gint code = EV_DOCUMENT_ERROR_INVALID;
219 if (poppler_error->code == POPPLER_ERROR_INVALID)
220 code = EV_DOCUMENT_ERROR_INVALID;
221 else if (poppler_error->code == POPPLER_ERROR_ENCRYPTED)
222 code = EV_DOCUMENT_ERROR_ENCRYPTED;
224 g_set_error_literal (error,
227 poppler_error->message);
229 g_error_free (poppler_error);
231 g_propagate_error (error, poppler_error);
238 pdf_document_save (EvDocument *document,
242 PdfDocument *pdf_document = PDF_DOCUMENT (document);
244 GError *poppler_error = NULL;
246 if (pdf_document->forms_modified || pdf_document->annots_modified) {
247 retval = poppler_document_save (pdf_document->document,
248 uri, &poppler_error);
250 pdf_document->forms_modified = FALSE;
251 pdf_document->annots_modified = FALSE;
254 retval = poppler_document_save_a_copy (pdf_document->document,
255 uri, &poppler_error);
259 convert_error (poppler_error, error);
265 pdf_document_load (EvDocument *document,
269 GError *poppler_error = NULL;
270 PdfDocument *pdf_document = PDF_DOCUMENT (document);
272 pdf_document->document =
273 poppler_document_new_from_file (uri, pdf_document->password, &poppler_error);
275 if (pdf_document->document == NULL) {
276 convert_error (poppler_error, error);
284 pdf_document_get_n_pages (EvDocument *document)
286 return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document);
290 pdf_document_get_page (EvDocument *document,
293 PdfDocument *pdf_document = PDF_DOCUMENT (document);
294 PopplerPage *poppler_page;
297 poppler_page = poppler_document_get_page (pdf_document->document, index);
298 page = ev_page_new (index);
299 page->backend_page = (EvBackendPage)g_object_ref (poppler_page);
300 page->backend_destroy_func = (EvBackendPageDestroyFunc)g_object_unref;
301 g_object_unref (poppler_page);
307 pdf_document_get_page_size (EvDocument *document,
312 g_return_if_fail (POPPLER_IS_PAGE (page->backend_page));
314 poppler_page_get_size (POPPLER_PAGE (page->backend_page), width, height);
318 pdf_document_get_page_label (EvDocument *document,
323 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
325 g_object_get (G_OBJECT (page->backend_page),
331 static cairo_surface_t *
332 pdf_page_render (PopplerPage *page,
337 cairo_surface_t *surface;
340 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
342 cr = cairo_create (surface);
344 switch (rc->rotation) {
346 cairo_translate (cr, width, 0);
349 cairo_translate (cr, width, height);
352 cairo_translate (cr, 0, height);
355 cairo_translate (cr, 0, 0);
357 cairo_scale (cr, rc->scale, rc->scale);
358 cairo_rotate (cr, rc->rotation * G_PI / 180.0);
359 poppler_page_render (page, cr);
361 cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
362 cairo_set_source_rgb (cr, 1., 1., 1.);
370 static cairo_surface_t *
371 pdf_document_render (EvDocument *document,
374 PdfDocument *pdf_document;
375 PopplerPage *poppler_page;
376 double width_points, height_points;
379 poppler_page = POPPLER_PAGE (rc->page->backend_page);
381 poppler_page_get_size (poppler_page,
382 &width_points, &height_points);
384 if (rc->rotation == 90 || rc->rotation == 270) {
385 width = (int) ((height_points * rc->scale) + 0.5);
386 height = (int) ((width_points * rc->scale) + 0.5);
388 width = (int) ((width_points * rc->scale) + 0.5);
389 height = (int) ((height_points * rc->scale) + 0.5);
392 return pdf_page_render (poppler_page,
397 make_thumbnail_for_page (PopplerPage *poppler_page,
404 #ifdef POPPLER_WITH_GDK
405 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
407 gdk_pixbuf_fill (pixbuf, 0xffffffff);
409 ev_document_fc_mutex_lock ();
410 poppler_page_render_to_pixbuf (poppler_page, 0, 0,
412 rc->scale, rc->rotation, pixbuf);
413 ev_document_fc_mutex_unlock ();
415 cairo_surface_t *surface;
417 ev_document_fc_mutex_lock ();
418 surface = pdf_page_render (poppler_page, width, height, rc);
419 ev_document_fc_mutex_unlock ();
421 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
422 cairo_surface_destroy (surface);
423 #endif /* POPPLER_WITH_GDK */
429 pdf_document_get_thumbnail (EvDocument *document,
432 PdfDocument *pdf_document = PDF_DOCUMENT (document);
433 PopplerPage *poppler_page;
434 GdkPixbuf *pixbuf = NULL;
435 GdkPixbuf *border_pixbuf;
436 double page_width, page_height;
439 poppler_page = POPPLER_PAGE (rc->page->backend_page);
441 poppler_page_get_size (poppler_page,
442 &page_width, &page_height);
444 width = MAX ((gint)(page_width * rc->scale + 0.5), 1);
445 height = MAX ((gint)(page_height * rc->scale + 0.5), 1);
447 if (rc->rotation == 90 || rc->rotation == 270) {
455 #ifdef POPPLER_WITH_GDK
456 pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page);
458 cairo_surface_t *surface;
460 surface = poppler_page_get_thumbnail (poppler_page);
462 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
463 cairo_surface_destroy (surface);
465 #endif /* POPPLER_WITH_GDK */
467 if (pixbuf != NULL) {
468 int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ?
469 gdk_pixbuf_get_height (pixbuf) :
470 gdk_pixbuf_get_width (pixbuf);
472 if (thumb_width == width) {
473 GdkPixbuf *rotated_pixbuf;
475 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
476 (GdkPixbufRotation) (360 - rc->rotation));
477 g_object_unref (pixbuf);
478 pixbuf = rotated_pixbuf;
480 /* The provided thumbnail has a different size */
481 g_object_unref (pixbuf);
482 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
485 /* There is no provided thumbnail. We need to make one. */
486 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
493 http://www.pdfa.org/lib/exe/fetch.php?id=pdfa%3Aen%3Atechdoc&cache=cache&media=pdfa:techdoc:tn0001_pdfa-1_and_namespaces_2008-03-18.pdf */
495 pdf_document_get_format_from_metadata (xmlDocPtr doc,
496 xmlXPathContextPtr xpathCtx)
498 xmlXPathObjectPtr xpathObj;
499 xmlChar *part = NULL;
500 xmlChar *conf = NULL;
504 /* add pdf/a namespaces */
505 xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
506 xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
507 xmlXPathRegisterNs (xpathCtx, BAD_CAST "pdfaid", BAD_CAST "http://www.aiim.org/pdfa/ns/id/");
509 /* reads pdf/a part */
510 /* first syntax: child node */
511 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:part", xpathCtx);
512 if (xpathObj != NULL) {
513 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
514 part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
516 xmlXPathFreeObject (xpathObj);
519 /* second syntax: attribute */
520 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:part", xpathCtx);
521 if (xpathObj != NULL) {
522 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
523 part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
525 xmlXPathFreeObject (xpathObj);
529 /* reads pdf/a conformance */
530 /* first syntax: child node */
531 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:conformance", xpathCtx);
532 if (xpathObj != NULL) {
533 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
534 conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
536 xmlXPathFreeObject (xpathObj);
539 /* second syntax: attribute */
540 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:conformance", xpathCtx);
541 if (xpathObj != NULL) {
542 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
543 conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
545 xmlXPathFreeObject (xpathObj);
549 if (part != NULL && conf != NULL) {
550 /* makes conf lowercase */
551 for (i = 0; conf[i]; i++)
552 conf[i] = g_ascii_tolower (conf[i]);
555 result = g_strdup_printf ("PDF/A - %s%s", part, conf);
565 static EvDocumentLicense *
566 pdf_document_get_license_from_metadata (xmlDocPtr doc,
567 xmlXPathContextPtr xpathCtx)
569 xmlXPathObjectPtr xpathObj;
570 xmlChar *marked = NULL;
571 const char *language_string;
574 gchar *tag, *tag_aux;
576 EvDocumentLicense *license;
578 /* register namespaces */
579 xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
580 xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
581 xmlXPathRegisterNs (xpathCtx, BAD_CAST "dc", BAD_CAST "http://purl.org/dc/elements/1.1/");
582 /* XMP Rights Management Schema */
583 xmlXPathRegisterNs (xpathCtx, BAD_CAST "xmpRights", BAD_CAST "http://ns.adobe.com/xap/1.0/rights/");
584 /* Creative Commons Schema */
585 xmlXPathRegisterNs (xpathCtx, BAD_CAST "cc", BAD_CAST "http://creativecommons.org/ns#");
587 /* checking if the document has been marked as defined on the XMP Rights
588 * Management Schema */
589 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_MARKED, xpathCtx);
590 if (xpathObj != NULL) {
591 if (xpathObj->nodesetval != NULL &&
592 xpathObj->nodesetval->nodeNr != 0)
593 marked = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
594 xmlXPathFreeObject (xpathObj);
597 /* a) Not marked => No XMP Rights information */
603 license = ev_document_license_new ();
605 /* b) Marked False => Public Domain, no copyrighted material and no
607 if (g_strrstr ((char *) marked, "False") != NULL) {
608 license->text = g_strdup (_("This work is in the Public Domain"));
609 /* c) Marked True => Copyrighted material */
611 /* Checking usage terms as defined by the XMP Rights Management
612 * Schema. This field is recomended to be checked by Creative
614 /* 1) checking for a suitable localized string */
615 language_string = pango_language_to_string (gtk_get_default_language ());
616 tags = g_strsplit (language_string, "-", -1);
617 i = g_strv_length (tags);
618 while (i-- && !license->text) {
619 tag = g_strdup (tags[0]);
620 for (j = 1; j <= i; j++) {
621 tag_aux = g_strdup_printf ("%s-%s", tag, tags[j]);
625 aux = g_strdup_printf (LICENSE_TEXT, tag);
626 xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
627 if (xpathObj != NULL) {
628 if (xpathObj->nodesetval != NULL &&
629 xpathObj->nodesetval->nodeNr != 0)
630 license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
631 xmlXPathFreeObject (xpathObj);
638 /* 2) if not, use the default string */
639 if (!license->text) {
640 aux = g_strdup_printf (LICENSE_TEXT, "x-default");
641 xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
642 if (xpathObj != NULL) {
643 if (xpathObj->nodesetval != NULL &&
644 xpathObj->nodesetval->nodeNr != 0)
645 license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
646 xmlXPathFreeObject (xpathObj);
651 /* Checking the license URI as defined by the Creative Commons
652 * Schema. This field is recomended to be checked by Creative
654 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_URI, xpathCtx);
655 if (xpathObj != NULL) {
656 if (xpathObj->nodesetval != NULL &&
657 xpathObj->nodesetval->nodeNr != 0)
658 license->uri = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
659 xmlXPathFreeObject (xpathObj);
662 /* Checking the web statement as defined by the XMP Rights
663 * Management Schema. Checking it out is a sort of above-and-beyond
664 * the basic recommendations by Creative Commons. It can be
665 * considered as a "reinforcement" approach to add certainty. */
666 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_WEB_STATEMENT, xpathCtx);
667 if (xpathObj != NULL) {
668 if (xpathObj->nodesetval != NULL &&
669 xpathObj->nodesetval->nodeNr != 0)
670 license->web_statement = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
671 xmlXPathFreeObject (xpathObj);
676 if (!license->text && !license->uri && !license->web_statement) {
677 ev_document_license_free (license);
685 pdf_document_parse_metadata (const gchar *metadata,
686 EvDocumentInfo *info)
689 xmlXPathContextPtr xpathCtx;
692 doc = xmlParseMemory (metadata, strlen (metadata));
694 return; /* invalid xml metadata */
696 xpathCtx = xmlXPathNewContext (doc);
697 if (xpathCtx == NULL) {
699 return; /* invalid xpath context */
702 fmt = pdf_document_get_format_from_metadata (doc, xpathCtx);
704 g_free (info->format);
708 info->license = pdf_document_get_license_from_metadata (doc, xpathCtx);
710 xmlXPathFreeContext (xpathCtx);
715 static EvDocumentInfo *
716 pdf_document_get_info (EvDocument *document)
718 EvDocumentInfo *info;
719 PopplerPageLayout layout;
720 PopplerPageMode mode;
721 PopplerViewerPreferences view_prefs;
722 PopplerPermissions permissions;
726 info = g_new0 (EvDocumentInfo, 1);
728 info->fields_mask = EV_DOCUMENT_INFO_TITLE |
729 EV_DOCUMENT_INFO_FORMAT |
730 EV_DOCUMENT_INFO_AUTHOR |
731 EV_DOCUMENT_INFO_SUBJECT |
732 EV_DOCUMENT_INFO_KEYWORDS |
733 EV_DOCUMENT_INFO_LAYOUT |
734 EV_DOCUMENT_INFO_START_MODE |
735 EV_DOCUMENT_INFO_PERMISSIONS |
736 EV_DOCUMENT_INFO_UI_HINTS |
737 EV_DOCUMENT_INFO_CREATOR |
738 EV_DOCUMENT_INFO_PRODUCER |
739 EV_DOCUMENT_INFO_CREATION_DATE |
740 EV_DOCUMENT_INFO_MOD_DATE |
741 EV_DOCUMENT_INFO_LINEARIZED |
742 EV_DOCUMENT_INFO_N_PAGES |
743 EV_DOCUMENT_INFO_SECURITY |
744 EV_DOCUMENT_INFO_PAPER_SIZE |
745 EV_DOCUMENT_INFO_LICENSE;
747 g_object_get (PDF_DOCUMENT (document)->document,
748 "title", &(info->title),
749 "format", &(info->format),
750 "author", &(info->author),
751 "subject", &(info->subject),
752 "keywords", &(info->keywords),
754 "page-layout", &layout,
755 "viewer-preferences", &view_prefs,
756 "permissions", &permissions,
757 "creator", &(info->creator),
758 "producer", &(info->producer),
759 "creation-date", &(info->creation_date),
760 "mod-date", &(info->modified_date),
761 "linearized", &(info->linearized),
762 "metadata", &metadata,
765 if (metadata != NULL) {
766 pdf_document_parse_metadata (metadata, info);
770 info->n_pages = ev_document_get_n_pages (document);
772 if (info->n_pages > 0) {
773 ev_document_get_page_size (document, 0,
774 &(info->paper_width),
775 &(info->paper_height));
777 info->paper_width = info->paper_width / 72.0f * 25.4f;
778 info->paper_height = info->paper_height / 72.0f * 25.4f;
782 case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
783 info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
785 case POPPLER_PAGE_LAYOUT_ONE_COLUMN:
786 info->layout = EV_DOCUMENT_LAYOUT_ONE_COLUMN;
788 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_LEFT:
789 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_LEFT;
791 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
792 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
793 case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
794 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
796 case POPPLER_PAGE_LAYOUT_TWO_PAGE_RIGHT:
797 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_RIGHT;
804 case POPPLER_PAGE_MODE_NONE:
805 info->mode = EV_DOCUMENT_MODE_NONE;
807 case POPPLER_PAGE_MODE_USE_THUMBS:
808 info->mode = EV_DOCUMENT_MODE_USE_THUMBS;
810 case POPPLER_PAGE_MODE_USE_OC:
811 info->mode = EV_DOCUMENT_MODE_USE_OC;
813 case POPPLER_PAGE_MODE_FULL_SCREEN:
814 info->mode = EV_DOCUMENT_MODE_FULL_SCREEN;
816 case POPPLER_PAGE_MODE_USE_ATTACHMENTS:
817 info->mode = EV_DOCUMENT_MODE_USE_ATTACHMENTS;
823 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_TOOLBAR) {
824 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_TOOLBAR;
826 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_MENUBAR) {
827 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_MENUBAR;
829 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_WINDOWUI) {
830 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_WINDOWUI;
832 if (view_prefs & POPPLER_VIEWER_PREFERENCES_FIT_WINDOW) {
833 info->ui_hints |= EV_DOCUMENT_UI_HINT_FIT_WINDOW;
835 if (view_prefs & POPPLER_VIEWER_PREFERENCES_CENTER_WINDOW) {
836 info->ui_hints |= EV_DOCUMENT_UI_HINT_CENTER_WINDOW;
838 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DISPLAY_DOC_TITLE) {
839 info->ui_hints |= EV_DOCUMENT_UI_HINT_DISPLAY_DOC_TITLE;
841 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL) {
842 info->ui_hints |= EV_DOCUMENT_UI_HINT_DIRECTION_RTL;
845 info->permissions = 0;
846 if (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT) {
847 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT;
849 if (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY) {
850 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY;
852 if (permissions & POPPLER_PERMISSIONS_OK_TO_COPY) {
853 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_COPY;
855 if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) {
856 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES;
859 if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
860 /* translators: this is the document security state */
861 info->security = g_strdup (_("Yes"));
863 /* translators: this is the document security state */
864 info->security = g_strdup (_("No"));
871 pdf_document_get_backend_info (EvDocument *document, EvDocumentBackendInfo *info)
873 PopplerBackend backend;
875 backend = poppler_get_backend ();
877 case POPPLER_BACKEND_CAIRO:
878 info->name = "poppler/cairo";
880 case POPPLER_BACKEND_SPLASH:
881 info->name = "poppler/splash";
884 info->name = "poppler/unknown";
888 info->version = poppler_get_version ();
894 pdf_document_support_synctex (EvDocument *document)
900 pdf_document_class_init (PdfDocumentClass *klass)
902 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
903 EvDocumentClass *ev_document_class = EV_DOCUMENT_CLASS (klass);
905 g_object_class->dispose = pdf_document_dispose;
907 ev_document_class->save = pdf_document_save;
908 ev_document_class->load = pdf_document_load;
909 ev_document_class->get_n_pages = pdf_document_get_n_pages;
910 ev_document_class->get_page = pdf_document_get_page;
911 ev_document_class->get_page_size = pdf_document_get_page_size;
912 ev_document_class->get_page_label = pdf_document_get_page_label;
913 ev_document_class->render = pdf_document_render;
914 ev_document_class->get_thumbnail = pdf_document_get_thumbnail;
915 ev_document_class->get_info = pdf_document_get_info;
916 ev_document_class->get_backend_info = pdf_document_get_backend_info;
917 ev_document_class->support_synctex = pdf_document_support_synctex;
920 /* EvDocumentSecurity */
922 pdf_document_has_document_security (EvDocumentSecurity *document_security)
924 /* FIXME: do we really need to have this? */
929 pdf_document_set_password (EvDocumentSecurity *document_security,
930 const char *password)
932 PdfDocument *document = PDF_DOCUMENT (document_security);
934 if (document->password)
935 g_free (document->password);
937 document->password = g_strdup (password);
941 pdf_document_security_iface_init (EvDocumentSecurityInterface *iface)
943 iface->has_document_security = pdf_document_has_document_security;
944 iface->set_password = pdf_document_set_password;
948 pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts)
950 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
953 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
955 return (double)pdf_document->fonts_scanned_pages / (double)n_pages;
959 pdf_document_fonts_scan (EvDocumentFonts *document_fonts,
962 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
965 g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE);
967 if (pdf_document->font_info == NULL) {
968 pdf_document->font_info = poppler_font_info_new (pdf_document->document);
971 if (pdf_document->fonts_iter) {
972 poppler_fonts_iter_free (pdf_document->fonts_iter);
975 pdf_document->fonts_scanned_pages += n_pages;
977 result = poppler_font_info_scan (pdf_document->font_info, n_pages,
978 &pdf_document->fonts_iter);
980 pdf_document->fonts_scanned_pages = 0;
981 poppler_font_info_free (pdf_document->font_info);
982 pdf_document->font_info = NULL;
989 font_type_to_string (PopplerFontType type)
992 case POPPLER_FONT_TYPE_TYPE1:
994 case POPPLER_FONT_TYPE_TYPE1C:
996 case POPPLER_FONT_TYPE_TYPE3:
998 case POPPLER_FONT_TYPE_TRUETYPE:
999 return _("TrueType");
1000 case POPPLER_FONT_TYPE_CID_TYPE0:
1001 return _("Type 1 (CID)");
1002 case POPPLER_FONT_TYPE_CID_TYPE0C:
1003 return _("Type 1C (CID)");
1004 case POPPLER_FONT_TYPE_CID_TYPE2:
1005 return _("TrueType (CID)");
1007 return _("Unknown font type");
1012 pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
1013 GtkTreeModel *model)
1015 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
1016 PopplerFontsIter *iter = pdf_document->fonts_iter;
1018 g_return_if_fail (PDF_IS_DOCUMENT (document_fonts));
1024 GtkTreeIter list_iter;
1027 const char *embedded;
1030 name = poppler_fonts_iter_get_name (iter);
1033 name = _("No name");
1036 type = font_type_to_string (
1037 poppler_fonts_iter_get_font_type (iter));
1039 if (poppler_fonts_iter_is_embedded (iter)) {
1040 if (poppler_fonts_iter_is_subset (iter))
1041 embedded = _("Embedded subset");
1043 embedded = _("Embedded");
1045 embedded = _("Not embedded");
1048 details = g_markup_printf_escaped ("%s\n%s", type, embedded);
1050 gtk_list_store_append (GTK_LIST_STORE (model), &list_iter);
1051 gtk_list_store_set (GTK_LIST_STORE (model), &list_iter,
1052 EV_DOCUMENT_FONTS_COLUMN_NAME, name,
1053 EV_DOCUMENT_FONTS_COLUMN_DETAILS, details,
1057 } while (poppler_fonts_iter_next (iter));
1061 pdf_document_document_fonts_iface_init (EvDocumentFontsInterface *iface)
1063 iface->fill_model = pdf_document_fonts_fill_model;
1064 iface->scan = pdf_document_fonts_scan;
1065 iface->get_progress = pdf_document_fonts_get_progress;
1069 pdf_document_links_has_document_links (EvDocumentLinks *document_links)
1071 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1072 PopplerIndexIter *iter;
1074 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
1076 iter = poppler_index_iter_new (pdf_document->document);
1079 poppler_index_iter_free (iter);
1085 ev_link_dest_from_dest (PdfDocument *pdf_document,
1088 EvLinkDest *ev_dest = NULL;
1089 const char *unimplemented_dest = NULL;
1091 g_assert (dest != NULL);
1093 switch (dest->type) {
1094 case POPPLER_DEST_XYZ: {
1095 PopplerPage *poppler_page;
1098 poppler_page = poppler_document_get_page (pdf_document->document,
1099 MAX (0, dest->page_num - 1));
1100 poppler_page_get_size (poppler_page, NULL, &height);
1101 ev_dest = ev_link_dest_new_xyz (dest->page_num - 1,
1103 height - MIN (height, dest->top),
1108 g_object_unref (poppler_page);
1111 case POPPLER_DEST_FITB:
1112 case POPPLER_DEST_FIT:
1113 ev_dest = ev_link_dest_new_fit (dest->page_num - 1);
1115 case POPPLER_DEST_FITBH:
1116 case POPPLER_DEST_FITH: {
1117 PopplerPage *poppler_page;
1120 poppler_page = poppler_document_get_page (pdf_document->document,
1121 MAX (0, dest->page_num - 1));
1122 poppler_page_get_size (poppler_page, NULL, &height);
1123 ev_dest = ev_link_dest_new_fith (dest->page_num - 1,
1124 height - MIN (height, dest->top),
1126 g_object_unref (poppler_page);
1129 case POPPLER_DEST_FITBV:
1130 case POPPLER_DEST_FITV:
1131 ev_dest = ev_link_dest_new_fitv (dest->page_num - 1,
1135 case POPPLER_DEST_FITR: {
1136 PopplerPage *poppler_page;
1139 poppler_page = poppler_document_get_page (pdf_document->document,
1140 MAX (0, dest->page_num - 1));
1141 poppler_page_get_size (poppler_page, NULL, &height);
1142 ev_dest = ev_link_dest_new_fitr (dest->page_num - 1,
1144 height - MIN (height, dest->bottom),
1146 height - MIN (height, dest->top));
1147 g_object_unref (poppler_page);
1150 case POPPLER_DEST_NAMED:
1151 ev_dest = ev_link_dest_new_named (dest->named_dest);
1153 case POPPLER_DEST_UNKNOWN:
1154 unimplemented_dest = "POPPLER_DEST_UNKNOWN";
1158 if (unimplemented_dest) {
1159 g_warning ("Unimplemented destination: %s, please post a "
1160 "bug report in Evince bugzilla "
1161 "(http://bugzilla.gnome.org) with a testcase.",
1162 unimplemented_dest);
1166 ev_dest = ev_link_dest_new_page (dest->page_num - 1);
1172 ev_link_from_action (PdfDocument *pdf_document,
1173 PopplerAction *action)
1175 EvLink *link = NULL;
1176 EvLinkAction *ev_action = NULL;
1177 const char *unimplemented_action = NULL;
1179 switch (action->type) {
1180 case POPPLER_ACTION_NONE:
1182 case POPPLER_ACTION_GOTO_DEST: {
1185 dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest);
1186 ev_action = ev_link_action_new_dest (dest);
1189 case POPPLER_ACTION_GOTO_REMOTE: {
1192 dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest);
1193 ev_action = ev_link_action_new_remote (dest,
1194 action->goto_remote.file_name);
1198 case POPPLER_ACTION_LAUNCH:
1199 ev_action = ev_link_action_new_launch (action->launch.file_name,
1200 action->launch.params);
1202 case POPPLER_ACTION_URI:
1203 ev_action = ev_link_action_new_external_uri (action->uri.uri);
1205 case POPPLER_ACTION_NAMED:
1206 ev_action = ev_link_action_new_named (action->named.named_dest);
1208 case POPPLER_ACTION_MOVIE:
1209 unimplemented_action = "POPPLER_ACTION_MOVIE";
1211 #if POPPLER_CHECK_VERSION (0, 13, 2)
1212 case POPPLER_ACTION_RENDITION:
1213 unimplemented_action = "POPPLER_ACTION_RENDITION";
1215 case POPPLER_ACTION_OCG_STATE:
1216 unimplemented_action = "POPPLER_ACTION_OCG_STATE";
1219 case POPPLER_ACTION_UNKNOWN:
1220 unimplemented_action = "POPPLER_ACTION_UNKNOWN";
1223 if (unimplemented_action) {
1224 g_warning ("Unimplemented action: %s, please post a bug report "
1225 "in Evince bugzilla (http://bugzilla.gnome.org) "
1226 "with a testcase.", unimplemented_action);
1229 link = ev_link_new (action->any.title, ev_action);
1235 build_tree (PdfDocument *pdf_document,
1236 GtkTreeModel *model,
1237 GtkTreeIter *parent,
1238 PopplerIndexIter *iter)
1242 GtkTreeIter tree_iter;
1243 PopplerIndexIter *child;
1244 PopplerAction *action;
1245 EvLink *link = NULL;
1249 action = poppler_index_iter_get_action (iter);
1250 expand = poppler_index_iter_is_open (iter);
1255 link = ev_link_from_action (pdf_document, action);
1256 if (!link || strlen (ev_link_get_title (link)) <= 0) {
1257 poppler_action_free (action);
1259 g_object_unref (link);
1264 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
1265 title_markup = g_markup_escape_text (ev_link_get_title (link), -1);
1267 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
1268 EV_DOCUMENT_LINKS_COLUMN_MARKUP, title_markup,
1269 EV_DOCUMENT_LINKS_COLUMN_LINK, link,
1270 EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand,
1273 g_free (title_markup);
1274 g_object_unref (link);
1276 child = poppler_index_iter_get_child (iter);
1278 build_tree (pdf_document, model, &tree_iter, child);
1279 poppler_index_iter_free (child);
1280 poppler_action_free (action);
1282 } while (poppler_index_iter_next (iter));
1285 static GtkTreeModel *
1286 pdf_document_links_get_links_model (EvDocumentLinks *document_links)
1288 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1289 GtkTreeModel *model = NULL;
1290 PopplerIndexIter *iter;
1292 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
1294 iter = poppler_index_iter_new (pdf_document->document);
1295 /* Create the model if we have items*/
1297 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
1302 build_tree (pdf_document, model, NULL, iter);
1303 poppler_index_iter_free (iter);
1309 static EvMappingList *
1310 pdf_document_links_get_links (EvDocumentLinks *document_links,
1313 PdfDocument *pdf_document;
1314 PopplerPage *poppler_page;
1315 GList *retval = NULL;
1316 GList *mapping_list;
1320 pdf_document = PDF_DOCUMENT (document_links);
1321 poppler_page = POPPLER_PAGE (page->backend_page);
1322 mapping_list = poppler_page_get_link_mapping (poppler_page);
1323 poppler_page_get_size (poppler_page, NULL, &height);
1325 for (list = mapping_list; list; list = list->next) {
1326 PopplerLinkMapping *link_mapping;
1327 EvMapping *ev_link_mapping;
1329 link_mapping = (PopplerLinkMapping *)list->data;
1330 ev_link_mapping = g_new (EvMapping, 1);
1331 ev_link_mapping->data = ev_link_from_action (pdf_document,
1332 link_mapping->action);
1333 ev_link_mapping->area.x1 = link_mapping->area.x1;
1334 ev_link_mapping->area.x2 = link_mapping->area.x2;
1335 /* Invert this for X-style coordinates */
1336 ev_link_mapping->area.y1 = height - link_mapping->area.y2;
1337 ev_link_mapping->area.y2 = height - link_mapping->area.y1;
1339 retval = g_list_prepend (retval, ev_link_mapping);
1342 poppler_page_free_link_mapping (mapping_list);
1344 return ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
1348 pdf_document_links_find_link_dest (EvDocumentLinks *document_links,
1349 const gchar *link_name)
1351 PdfDocument *pdf_document;
1353 EvLinkDest *ev_dest = NULL;
1355 pdf_document = PDF_DOCUMENT (document_links);
1356 dest = poppler_document_find_dest (pdf_document->document,
1359 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1360 poppler_dest_free (dest);
1367 pdf_document_links_find_link_page (EvDocumentLinks *document_links,
1368 const gchar *link_name)
1370 PdfDocument *pdf_document;
1374 pdf_document = PDF_DOCUMENT (document_links);
1375 dest = poppler_document_find_dest (pdf_document->document,
1378 retval = dest->page_num - 1;
1379 poppler_dest_free (dest);
1386 pdf_document_document_links_iface_init (EvDocumentLinksInterface *iface)
1388 iface->has_document_links = pdf_document_links_has_document_links;
1389 iface->get_links_model = pdf_document_links_get_links_model;
1390 iface->get_links = pdf_document_links_get_links;
1391 iface->find_link_dest = pdf_document_links_find_link_dest;
1392 iface->find_link_page = pdf_document_links_find_link_page;
1395 static EvMappingList *
1396 pdf_document_images_get_image_mapping (EvDocumentImages *document_images,
1399 GList *retval = NULL;
1400 PdfDocument *pdf_document;
1401 PopplerPage *poppler_page;
1402 GList *mapping_list;
1405 pdf_document = PDF_DOCUMENT (document_images);
1406 poppler_page = POPPLER_PAGE (page->backend_page);
1407 mapping_list = poppler_page_get_image_mapping (poppler_page);
1409 for (list = mapping_list; list; list = list->next) {
1410 PopplerImageMapping *image_mapping;
1411 EvMapping *ev_image_mapping;
1413 image_mapping = (PopplerImageMapping *)list->data;
1415 ev_image_mapping = g_new (EvMapping, 1);
1417 ev_image_mapping->data = ev_image_new (page->index, image_mapping->image_id);
1418 ev_image_mapping->area.x1 = image_mapping->area.x1;
1419 ev_image_mapping->area.y1 = image_mapping->area.y1;
1420 ev_image_mapping->area.x2 = image_mapping->area.x2;
1421 ev_image_mapping->area.y2 = image_mapping->area.y2;
1423 retval = g_list_prepend (retval, ev_image_mapping);
1426 poppler_page_free_image_mapping (mapping_list);
1428 return ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
1432 pdf_document_images_get_image (EvDocumentImages *document_images,
1435 GdkPixbuf *retval = NULL;
1436 PdfDocument *pdf_document;
1437 PopplerPage *poppler_page;
1438 cairo_surface_t *surface;
1440 pdf_document = PDF_DOCUMENT (document_images);
1441 poppler_page = poppler_document_get_page (pdf_document->document,
1442 ev_image_get_page (image));
1444 surface = poppler_page_get_image (poppler_page, ev_image_get_id (image));
1446 retval = ev_document_misc_pixbuf_from_surface (surface);
1447 cairo_surface_destroy (surface);
1450 g_object_unref (poppler_page);
1456 pdf_document_document_images_iface_init (EvDocumentImagesInterface *iface)
1458 iface->get_image_mapping = pdf_document_images_get_image_mapping;
1459 iface->get_image = pdf_document_images_get_image;
1463 pdf_document_find_find_text (EvDocumentFind *document_find,
1466 gboolean case_sensitive)
1469 PopplerPage *poppler_page;
1471 GList *retval = NULL;
1473 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1474 g_return_val_if_fail (text != NULL, NULL);
1476 poppler_page = POPPLER_PAGE (page->backend_page);
1478 matches = poppler_page_find_text (poppler_page, text);
1482 poppler_page_get_size (poppler_page, NULL, &height);
1483 for (l = matches; l && l->data; l = g_list_next (l)) {
1484 PopplerRectangle *rect = (PopplerRectangle *)l->data;
1485 EvRectangle *ev_rect;
1487 ev_rect = ev_rectangle_new ();
1488 ev_rect->x1 = rect->x1;
1489 ev_rect->x2 = rect->x2;
1490 /* Invert this for X-style coordinates */
1491 ev_rect->y1 = height - rect->y2;
1492 ev_rect->y2 = height - rect->y1;
1494 retval = g_list_prepend (retval, ev_rect);
1497 g_list_foreach (matches, (GFunc)poppler_rectangle_free, NULL);
1498 g_list_free (matches);
1500 return g_list_reverse (retval);
1504 pdf_document_find_iface_init (EvDocumentFindInterface *iface)
1506 iface->find_text = pdf_document_find_find_text;
1510 pdf_print_context_free (PdfPrintContext *ctx)
1515 #ifdef HAVE_CAIRO_PRINT
1517 cairo_destroy (ctx->cr);
1522 poppler_ps_file_free (ctx->ps_file);
1523 ctx->ps_file = NULL;
1530 pdf_document_file_exporter_begin (EvFileExporter *exporter,
1531 EvFileExporterContext *fc)
1533 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1534 PdfPrintContext *ctx;
1535 #ifdef HAVE_CAIRO_PRINT
1536 gdouble width, height;
1537 cairo_surface_t *surface = NULL;
1540 if (pdf_document->print_ctx)
1541 pdf_print_context_free (pdf_document->print_ctx);
1542 pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
1543 ctx = pdf_document->print_ctx;
1544 ctx->format = fc->format;
1546 #ifdef HAVE_CAIRO_PRINT
1547 ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
1549 ctx->paper_width = fc->paper_width;
1550 ctx->paper_height = fc->paper_height;
1552 switch (fc->pages_per_sheet) {
1580 ctx->pages_printed = 0;
1582 switch (fc->format) {
1583 case EV_FILE_FORMAT_PS:
1584 #ifdef HAVE_CAIRO_PS
1585 surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1588 case EV_FILE_FORMAT_PDF:
1589 #ifdef HAVE_CAIRO_PDF
1590 surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1594 g_assert_not_reached ();
1597 ctx->cr = cairo_create (surface);
1598 cairo_surface_destroy (surface);
1600 #else /* HAVE_CAIRO_PRINT */
1601 if (ctx->format == EV_FILE_FORMAT_PS) {
1602 ctx->ps_file = poppler_ps_file_new (pdf_document->document,
1603 fc->filename, fc->first_page,
1604 fc->last_page - fc->first_page + 1);
1605 poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
1606 poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
1608 #endif /* HAVE_CAIRO_PRINT */
1612 pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
1614 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1615 PdfPrintContext *ctx = pdf_document->print_ctx;
1617 g_return_if_fail (pdf_document->print_ctx != NULL);
1619 ctx->pages_printed = 0;
1621 #ifdef HAVE_CAIRO_PRINT
1622 if (ctx->paper_width > ctx->paper_height) {
1623 if (ctx->format == EV_FILE_FORMAT_PS) {
1624 cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
1627 } else if (ctx->format == EV_FILE_FORMAT_PDF) {
1628 cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
1633 #endif /* HAVE_CAIRO_PRINT */
1637 pdf_document_file_exporter_do_page (EvFileExporter *exporter,
1638 EvRenderContext *rc)
1640 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1641 PdfPrintContext *ctx = pdf_document->print_ctx;
1642 PopplerPage *poppler_page;
1643 #ifdef HAVE_CAIRO_PRINT
1644 gdouble page_width, page_height;
1647 gdouble width, height;
1648 gdouble pwidth, pheight;
1649 gdouble xscale, yscale;
1652 g_return_if_fail (pdf_document->print_ctx != NULL);
1654 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1656 #ifdef HAVE_CAIRO_PRINT
1657 x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
1658 y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
1659 poppler_page_get_size (poppler_page, &page_width, &page_height);
1661 if (page_width > page_height && page_width > ctx->paper_width) {
1667 /* Use always portrait mode and rotate when necessary */
1668 if (ctx->paper_width > ctx->paper_height) {
1669 width = ctx->paper_height;
1670 height = ctx->paper_width;
1673 width = ctx->paper_width;
1674 height = ctx->paper_height;
1677 if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
1690 page_width = page_height;
1694 pwidth = width / ctx->pages_x;
1695 pheight = height / ctx->pages_y;
1697 if ((page_width > pwidth || page_height > pheight) ||
1698 (page_width < pwidth && page_height < pheight)) {
1699 xscale = pwidth / page_width;
1700 yscale = pheight / page_height;
1702 if (yscale < xscale) {
1709 xscale = yscale = 1;
1714 cairo_save (ctx->cr);
1716 cairo_matrix_t matrix;
1718 cairo_translate (ctx->cr, (2 * y + 1) * pwidth, 0);
1719 cairo_matrix_init (&matrix,
1723 cairo_transform (ctx->cr, &matrix);
1726 cairo_translate (ctx->cr,
1727 x * (rotate ? pheight : pwidth),
1728 y * (rotate ? pwidth : pheight));
1729 cairo_scale (ctx->cr, xscale, yscale);
1731 poppler_page_render_for_printing (poppler_page, ctx->cr);
1733 ctx->pages_printed++;
1735 cairo_restore (ctx->cr);
1736 #else /* HAVE_CAIRO_PRINT */
1737 if (ctx->format == EV_FILE_FORMAT_PS)
1738 poppler_page_render_to_ps (poppler_page, ctx->ps_file);
1739 #endif /* HAVE_CAIRO_PRINT */
1743 pdf_document_file_exporter_end_page (EvFileExporter *exporter)
1745 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1746 PdfPrintContext *ctx = pdf_document->print_ctx;
1748 g_return_if_fail (pdf_document->print_ctx != NULL);
1750 #ifdef HAVE_CAIRO_PRINT
1751 cairo_show_page (ctx->cr);
1756 pdf_document_file_exporter_end (EvFileExporter *exporter)
1758 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1760 pdf_print_context_free (pdf_document->print_ctx);
1761 pdf_document->print_ctx = NULL;
1764 static EvFileExporterCapabilities
1765 pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter)
1767 return (EvFileExporterCapabilities) (
1768 EV_FILE_EXPORTER_CAN_PAGE_SET |
1769 EV_FILE_EXPORTER_CAN_COPIES |
1770 EV_FILE_EXPORTER_CAN_COLLATE |
1771 EV_FILE_EXPORTER_CAN_REVERSE |
1772 EV_FILE_EXPORTER_CAN_SCALE |
1773 #ifdef HAVE_CAIRO_PRINT
1774 EV_FILE_EXPORTER_CAN_NUMBER_UP |
1777 #ifdef HAVE_CAIRO_PDF
1778 EV_FILE_EXPORTER_CAN_GENERATE_PDF |
1780 EV_FILE_EXPORTER_CAN_GENERATE_PS);
1784 pdf_document_file_exporter_iface_init (EvFileExporterInterface *iface)
1786 iface->begin = pdf_document_file_exporter_begin;
1787 iface->begin_page = pdf_document_file_exporter_begin_page;
1788 iface->do_page = pdf_document_file_exporter_do_page;
1789 iface->end_page = pdf_document_file_exporter_end_page;
1790 iface->end = pdf_document_file_exporter_end;
1791 iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
1794 /* EvDocumentPrint */
1796 pdf_document_print_print_page (EvDocumentPrint *document,
1800 PdfDocument *pdf_document = PDF_DOCUMENT (document);
1802 poppler_page_render_for_printing (POPPLER_PAGE (page->backend_page), cr);
1806 pdf_document_document_print_iface_init (EvDocumentPrintInterface *iface)
1808 iface->print_page = pdf_document_print_print_page;
1812 pdf_selection_render_selection (EvSelection *selection,
1813 EvRenderContext *rc,
1814 cairo_surface_t **surface,
1815 EvRectangle *points,
1816 EvRectangle *old_points,
1817 EvSelectionStyle style,
1821 PopplerPage *poppler_page;
1823 PopplerColor text_color, base_color;
1824 double width_points, height_points;
1827 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1829 poppler_page_get_size (poppler_page,
1830 &width_points, &height_points);
1831 width = (int) ((width_points * rc->scale) + 0.5);
1832 height = (int) ((height_points * rc->scale) + 0.5);
1834 text_color.red = text->red;
1835 text_color.green = text->green;
1836 text_color.blue = text->blue;
1838 base_color.red = base->red;
1839 base_color.green = base->green;
1840 base_color.blue = base->blue;
1842 if (*surface == NULL) {
1843 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1848 cr = cairo_create (*surface);
1849 cairo_scale (cr, rc->scale, rc->scale);
1850 cairo_surface_set_device_offset (*surface, 0, 0);
1851 memset (cairo_image_surface_get_data (*surface), 0x00,
1852 cairo_image_surface_get_height (*surface) *
1853 cairo_image_surface_get_stride (*surface));
1854 poppler_page_render_selection (poppler_page,
1856 (PopplerRectangle *)points,
1857 (PopplerRectangle *)old_points,
1858 (PopplerSelectionStyle)style,
1865 pdf_selection_get_selected_text (EvSelection *selection,
1867 EvSelectionStyle style,
1868 EvRectangle *points)
1870 PopplerPage *poppler_page;
1873 poppler_page = POPPLER_PAGE (page->backend_page);
1875 #ifdef HAVE_POPPLER_PAGE_GET_SELECTED_TEXT
1876 retval = poppler_page_get_selected_text (poppler_page,
1877 (PopplerSelectionStyle)style,
1878 (PopplerRectangle *)points);
1883 poppler_page_get_size (poppler_page, NULL, &height);
1885 r.y1 = height - points->y2;
1887 r.y2 = height - points->y1;
1889 retval = poppler_page_get_text (poppler_page,
1890 (PopplerSelectionStyle)style,
1892 #endif /* HAVE_POPPLER_PAGE_GET_SELECTED_TEXT */
1897 static cairo_region_t *
1898 create_region_from_poppler_region (GList *region, gdouble scale)
1901 cairo_region_t *retval;
1903 retval = cairo_region_create ();
1905 for (l = region; l; l = g_list_next (l)) {
1906 PopplerRectangle *rectangle;
1907 cairo_rectangle_int_t rect;
1909 rectangle = (PopplerRectangle *)l->data;
1911 rect.x = (gint) ((rectangle->x1 * scale) + 0.5);
1912 rect.y = (gint) ((rectangle->y1 * scale) + 0.5);
1913 rect.width = (gint) (((rectangle->x2 - rectangle->x1) * scale) + 0.5);
1914 rect.height = (gint) (((rectangle->y2 - rectangle->y1) * scale) + 0.5);
1915 cairo_region_union_rectangle (retval, &rect);
1917 poppler_rectangle_free (rectangle);
1923 static cairo_region_t *
1924 pdf_selection_get_selection_region (EvSelection *selection,
1925 EvRenderContext *rc,
1926 EvSelectionStyle style,
1927 EvRectangle *points)
1929 PopplerPage *poppler_page;
1930 cairo_region_t *retval;
1933 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1934 region = poppler_page_get_selection_region (poppler_page,
1936 (PopplerSelectionStyle)style,
1937 (PopplerRectangle *) points);
1938 retval = create_region_from_poppler_region (region, rc->scale);
1939 g_list_free (region);
1945 pdf_selection_iface_init (EvSelectionInterface *iface)
1947 iface->render_selection = pdf_selection_render_selection;
1948 iface->get_selected_text = pdf_selection_get_selected_text;
1949 iface->get_selection_region = pdf_selection_get_selection_region;
1953 /* EvDocumentText */
1954 static cairo_region_t *
1955 pdf_document_text_get_text_mapping (EvDocumentText *document_text,
1958 PopplerPage *poppler_page;
1959 PopplerRectangle points;
1961 cairo_region_t *retval;
1963 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1965 poppler_page = POPPLER_PAGE (page->backend_page);
1969 poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
1971 region = poppler_page_get_selection_region (poppler_page, 1.0,
1972 POPPLER_SELECTION_GLYPH,
1974 retval = create_region_from_poppler_region (region, 1.0);
1975 g_list_free (region);
1980 #ifdef HAVE_POPPLER_PAGE_GET_SELECTED_TEXT
1982 pdf_document_text_get_text (EvDocumentText *selection,
1985 PopplerPage *poppler_page;
1987 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1989 poppler_page = POPPLER_PAGE (page->backend_page);
1991 return poppler_page_get_text (poppler_page);
1995 pdf_document_text_get_text (EvDocumentText *selection,
1998 PopplerPage *poppler_page;
2001 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2003 poppler_page = POPPLER_PAGE (page->backend_page);
2007 poppler_page_get_size (poppler_page, &(r.x2), &(r.y2));
2009 return poppler_page_get_text (poppler_page,
2010 POPPLER_SELECTION_WORD,
2013 #endif /* HAVE_POPPLER_PAGE_GET_SELECTED_TEXT */
2015 #ifdef HAVE_POPPLER_PAGE_GET_TEXT_LAYOUT
2017 pdf_document_text_get_text_layout (EvDocumentText *selection,
2019 EvRectangle **areas,
2022 PopplerPage *poppler_page;
2024 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2026 poppler_page = POPPLER_PAGE (page->backend_page);
2028 return poppler_page_get_text_layout (poppler_page, (PopplerRectangle **)areas, n_areas);
2033 pdf_document_text_iface_init (EvDocumentTextInterface *iface)
2035 iface->get_text_mapping = pdf_document_text_get_text_mapping;
2036 iface->get_text = pdf_document_text_get_text;
2037 #ifdef HAVE_POPPLER_PAGE_GET_TEXT_LAYOUT
2038 iface->get_text_layout = pdf_document_text_get_text_layout;
2042 /* Page Transitions */
2044 pdf_document_get_page_duration (EvDocumentTransition *trans,
2047 PdfDocument *pdf_document;
2048 PopplerPage *poppler_page;
2049 gdouble duration = -1;
2051 pdf_document = PDF_DOCUMENT (trans);
2052 poppler_page = poppler_document_get_page (pdf_document->document, page);
2056 duration = poppler_page_get_duration (poppler_page);
2057 g_object_unref (poppler_page);
2062 static EvTransitionEffect *
2063 pdf_document_get_effect (EvDocumentTransition *trans,
2066 PdfDocument *pdf_document;
2067 PopplerPage *poppler_page;
2068 PopplerPageTransition *page_transition;
2069 EvTransitionEffect *effect;
2071 pdf_document = PDF_DOCUMENT (trans);
2072 poppler_page = poppler_document_get_page (pdf_document->document, page);
2077 page_transition = poppler_page_get_transition (poppler_page);
2079 if (!page_transition) {
2080 g_object_unref (poppler_page);
2084 /* enums in PopplerPageTransition match the EvTransitionEffect ones */
2085 effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
2086 "alignment", page_transition->alignment,
2087 "direction", page_transition->direction,
2088 "duration", page_transition->duration,
2089 "angle", page_transition->angle,
2090 "scale", page_transition->scale,
2091 "rectangular", page_transition->rectangular,
2094 poppler_page_transition_free (page_transition);
2095 g_object_unref (poppler_page);
2101 pdf_document_page_transition_iface_init (EvDocumentTransitionInterface *iface)
2103 iface->get_page_duration = pdf_document_get_page_duration;
2104 iface->get_effect = pdf_document_get_effect;
2109 pdf_document_get_crop_box (EvDocument *document,
2113 PdfDocument *pdf_document;
2114 PopplerPage *poppler_page;
2115 PopplerRectangle poppler_rect;
2117 pdf_document = PDF_DOCUMENT (document);
2118 poppler_page = poppler_document_get_page (pdf_document->document, page);
2119 poppler_page_get_crop_box (poppler_page, &poppler_rect);
2120 rect->x1 = poppler_rect.x1;
2121 rect->x2 = poppler_rect.x2;
2122 rect->y1 = poppler_rect.y1;
2123 rect->y2 = poppler_rect.y2;
2126 static EvFormField *
2127 ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
2129 EvFormField *ev_field = NULL;
2132 gboolean is_read_only;
2134 id = poppler_form_field_get_id (poppler_field);
2135 font_size = poppler_form_field_get_font_size (poppler_field);
2136 is_read_only = poppler_form_field_is_read_only (poppler_field);
2138 switch (poppler_form_field_get_field_type (poppler_field)) {
2139 case POPPLER_FORM_FIELD_TEXT: {
2140 EvFormFieldText *field_text;
2141 EvFormFieldTextType ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2143 switch (poppler_form_field_text_get_text_type (poppler_field)) {
2144 case POPPLER_FORM_TEXT_NORMAL:
2145 ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2147 case POPPLER_FORM_TEXT_MULTILINE:
2148 ev_text_type = EV_FORM_FIELD_TEXT_MULTILINE;
2150 case POPPLER_FORM_TEXT_FILE_SELECT:
2151 ev_text_type = EV_FORM_FIELD_TEXT_FILE_SELECT;
2155 ev_field = ev_form_field_text_new (id, ev_text_type);
2156 field_text = EV_FORM_FIELD_TEXT (ev_field);
2158 field_text->do_spell_check = poppler_form_field_text_do_spell_check (poppler_field);
2159 field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
2160 field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
2161 field_text->is_password = poppler_form_field_text_is_password (poppler_field);
2162 field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
2163 field_text->text = poppler_form_field_text_get_text (poppler_field);
2167 case POPPLER_FORM_FIELD_BUTTON: {
2168 EvFormFieldButton *field_button;
2169 EvFormFieldButtonType ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2171 switch (poppler_form_field_button_get_button_type (poppler_field)) {
2172 case POPPLER_FORM_BUTTON_PUSH:
2173 ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2175 case POPPLER_FORM_BUTTON_CHECK:
2176 ev_button_type = EV_FORM_FIELD_BUTTON_CHECK;
2178 case POPPLER_FORM_BUTTON_RADIO:
2179 ev_button_type = EV_FORM_FIELD_BUTTON_RADIO;
2183 ev_field = ev_form_field_button_new (id, ev_button_type);
2184 field_button = EV_FORM_FIELD_BUTTON (ev_field);
2186 field_button->state = poppler_form_field_button_get_state (poppler_field);
2189 case POPPLER_FORM_FIELD_CHOICE: {
2190 EvFormFieldChoice *field_choice;
2191 EvFormFieldChoiceType ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2193 switch (poppler_form_field_choice_get_choice_type (poppler_field)) {
2194 case POPPLER_FORM_CHOICE_COMBO:
2195 ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2197 case EV_FORM_FIELD_CHOICE_LIST:
2198 ev_choice_type = EV_FORM_FIELD_CHOICE_LIST;
2202 ev_field = ev_form_field_choice_new (id, ev_choice_type);
2203 field_choice = EV_FORM_FIELD_CHOICE (ev_field);
2205 field_choice->is_editable = poppler_form_field_choice_is_editable (poppler_field);
2206 field_choice->multi_select = poppler_form_field_choice_can_select_multiple (poppler_field);
2207 field_choice->do_spell_check = poppler_form_field_choice_do_spell_check (poppler_field);
2208 field_choice->commit_on_sel_change = poppler_form_field_choice_commit_on_change (poppler_field);
2210 /* TODO: we need poppler_form_field_choice_get_selected_items in poppler
2211 field_choice->selected_items = poppler_form_field_choice_get_selected_items (poppler_field);*/
2212 if (field_choice->is_editable)
2213 field_choice->text = poppler_form_field_choice_get_text (poppler_field);
2216 case POPPLER_FORM_FIELD_SIGNATURE:
2218 ev_field = ev_form_field_signature_new (id);
2220 case POPPLER_FORM_FIELD_UNKNOWN:
2224 ev_field->font_size = font_size;
2225 ev_field->is_read_only = is_read_only;
2230 static EvMappingList *
2231 pdf_document_forms_get_form_fields (EvDocumentForms *document,
2234 PopplerPage *poppler_page;
2235 GList *retval = NULL;
2240 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2242 poppler_page = POPPLER_PAGE (page->backend_page);
2243 fields = poppler_page_get_form_field_mapping (poppler_page);
2244 poppler_page_get_size (poppler_page, NULL, &height);
2246 for (list = fields; list; list = list->next) {
2247 PopplerFormFieldMapping *mapping;
2248 EvMapping *field_mapping;
2249 EvFormField *ev_field;
2251 mapping = (PopplerFormFieldMapping *)list->data;
2253 ev_field = ev_form_field_from_poppler_field (mapping->field);
2257 field_mapping = g_new0 (EvMapping, 1);
2258 field_mapping->area.x1 = mapping->area.x1;
2259 field_mapping->area.x2 = mapping->area.x2;
2260 field_mapping->area.y1 = height - mapping->area.y2;
2261 field_mapping->area.y2 = height - mapping->area.y1;
2262 field_mapping->data = ev_field;
2263 ev_field->page = EV_PAGE (g_object_ref (page));
2265 g_object_set_data_full (G_OBJECT (ev_field),
2267 g_object_ref (mapping->field),
2268 (GDestroyNotify) g_object_unref);
2270 retval = g_list_prepend (retval, field_mapping);
2273 poppler_page_free_form_field_mapping (fields);
2275 return retval ? ev_mapping_list_new (page->index,
2276 g_list_reverse (retval),
2277 (GDestroyNotify)g_object_unref) : NULL;
2281 pdf_document_forms_document_is_modified (EvDocumentForms *document)
2283 return PDF_DOCUMENT (document)->forms_modified;
2287 pdf_document_forms_form_field_text_get_text (EvDocumentForms *document,
2291 PopplerFormField *poppler_field;
2294 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2298 text = poppler_form_field_text_get_text (poppler_field);
2304 pdf_document_forms_form_field_text_set_text (EvDocumentForms *document,
2308 PopplerFormField *poppler_field;
2310 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2314 poppler_form_field_text_set_text (poppler_field, text);
2315 PDF_DOCUMENT (document)->forms_modified = TRUE;
2319 pdf_document_forms_form_field_button_set_state (EvDocumentForms *document,
2323 PopplerFormField *poppler_field;
2325 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2329 poppler_form_field_button_set_state (poppler_field, state);
2330 PDF_DOCUMENT (document)->forms_modified = TRUE;
2334 pdf_document_forms_form_field_button_get_state (EvDocumentForms *document,
2337 PopplerFormField *poppler_field;
2340 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2344 state = poppler_form_field_button_get_state (poppler_field);
2350 pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document,
2354 PopplerFormField *poppler_field;
2357 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2361 text = poppler_form_field_choice_get_item (poppler_field, index);
2367 pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document,
2370 PopplerFormField *poppler_field;
2373 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2377 n_items = poppler_form_field_choice_get_n_items (poppler_field);
2383 pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document,
2387 PopplerFormField *poppler_field;
2390 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2394 selected = poppler_form_field_choice_is_item_selected (poppler_field, index);
2400 pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document,
2404 PopplerFormField *poppler_field;
2406 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2410 poppler_form_field_choice_select_item (poppler_field, index);
2411 PDF_DOCUMENT (document)->forms_modified = TRUE;
2415 pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document,
2419 PopplerFormField *poppler_field;
2421 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2425 poppler_form_field_choice_toggle_item (poppler_field, index);
2426 PDF_DOCUMENT (document)->forms_modified = TRUE;
2430 pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document,
2433 PopplerFormField *poppler_field;
2435 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2439 poppler_form_field_choice_unselect_all (poppler_field);
2440 PDF_DOCUMENT (document)->forms_modified = TRUE;
2444 pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document,
2448 PopplerFormField *poppler_field;
2450 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2454 poppler_form_field_choice_set_text (poppler_field, text);
2455 PDF_DOCUMENT (document)->forms_modified = TRUE;
2459 pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document,
2462 PopplerFormField *poppler_field;
2465 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2469 text = poppler_form_field_choice_get_text (poppler_field);
2475 pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface)
2477 iface->get_form_fields = pdf_document_forms_get_form_fields;
2478 iface->document_is_modified = pdf_document_forms_document_is_modified;
2479 iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
2480 iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
2481 iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
2482 iface->form_field_button_get_state = pdf_document_forms_form_field_button_get_state;
2483 iface->form_field_choice_get_item = pdf_document_forms_form_field_choice_get_item;
2484 iface->form_field_choice_get_n_items = pdf_document_forms_form_field_choice_get_n_items;
2485 iface->form_field_choice_is_item_selected = pdf_document_forms_form_field_choice_is_item_selected;
2486 iface->form_field_choice_select_item = pdf_document_forms_form_field_choice_select_item;
2487 iface->form_field_choice_toggle_item = pdf_document_forms_form_field_choice_toggle_item;
2488 iface->form_field_choice_unselect_all = pdf_document_forms_form_field_choice_unselect_all;
2489 iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
2490 iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;
2495 poppler_annot_color_to_gdk_color (PopplerAnnot *poppler_annot,
2498 PopplerColor *poppler_color;
2500 poppler_color = poppler_annot_get_color (poppler_annot);
2501 if (poppler_color) {
2502 color->red = poppler_color->red;
2503 color->green = poppler_color->green;
2504 color->blue = poppler_color->blue;
2506 g_free (poppler_color);
2507 } /* TODO: else use a default color */
2510 static EvAnnotationTextIcon
2511 get_annot_text_icon (PopplerAnnotText *poppler_annot)
2513 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2514 gchar *icon = poppler_annot_text_get_icon (poppler_annot);
2515 EvAnnotationTextIcon retval;
2518 return EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2520 if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_NOTE) == 0)
2521 retval = EV_ANNOTATION_TEXT_ICON_NOTE;
2522 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_COMMENT) == 0)
2523 retval = EV_ANNOTATION_TEXT_ICON_COMMENT;
2524 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_KEY) == 0)
2525 retval = EV_ANNOTATION_TEXT_ICON_KEY;
2526 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_HELP) == 0)
2527 retval = EV_ANNOTATION_TEXT_ICON_HELP;
2528 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH) == 0)
2529 retval = EV_ANNOTATION_TEXT_ICON_NEW_PARAGRAPH;
2530 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_PARAGRAPH) == 0)
2531 retval = EV_ANNOTATION_TEXT_ICON_PARAGRAPH;
2532 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_INSERT) == 0)
2533 retval = EV_ANNOTATION_TEXT_ICON_INSERT;
2534 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_CROSS) == 0)
2535 retval = EV_ANNOTATION_TEXT_ICON_CROSS;
2536 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_CIRCLE) == 0)
2537 retval = EV_ANNOTATION_TEXT_ICON_CIRCLE;
2539 retval = EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2545 return EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2549 static const gchar *
2550 get_poppler_annot_text_icon (EvAnnotationTextIcon icon)
2552 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2554 case EV_ANNOTATION_TEXT_ICON_NOTE:
2555 return POPPLER_ANNOT_TEXT_ICON_NOTE;
2556 case EV_ANNOTATION_TEXT_ICON_COMMENT:
2557 return POPPLER_ANNOT_TEXT_ICON_COMMENT;
2558 case EV_ANNOTATION_TEXT_ICON_KEY:
2559 return POPPLER_ANNOT_TEXT_ICON_KEY;
2560 case EV_ANNOTATION_TEXT_ICON_HELP:
2561 return POPPLER_ANNOT_TEXT_ICON_HELP;
2562 case EV_ANNOTATION_TEXT_ICON_NEW_PARAGRAPH:
2563 return POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH;
2564 case EV_ANNOTATION_TEXT_ICON_PARAGRAPH:
2565 return POPPLER_ANNOT_TEXT_ICON_PARAGRAPH;
2566 case EV_ANNOTATION_TEXT_ICON_INSERT:
2567 return POPPLER_ANNOT_TEXT_ICON_INSERT;
2568 case EV_ANNOTATION_TEXT_ICON_CROSS:
2569 return POPPLER_ANNOT_TEXT_ICON_CROSS;
2570 case EV_ANNOTATION_TEXT_ICON_CIRCLE:
2571 return POPPLER_ANNOT_TEXT_ICON_CIRCLE;
2572 case EV_ANNOTATION_TEXT_ICON_UNKNOWN:
2574 return POPPLER_ANNOT_TEXT_ICON_NOTE;
2581 static EvAnnotation *
2582 ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
2585 EvAnnotation *ev_annot = NULL;
2586 const gchar *unimplemented_annot = NULL;
2588 switch (poppler_annot_get_annot_type (poppler_annot)) {
2589 case POPPLER_ANNOT_TEXT: {
2590 PopplerAnnotText *poppler_text;
2591 EvAnnotationText *ev_annot_text;
2593 poppler_text = POPPLER_ANNOT_TEXT (poppler_annot);
2595 ev_annot = ev_annotation_text_new (page);
2597 ev_annot_text = EV_ANNOTATION_TEXT (ev_annot);
2598 ev_annotation_text_set_is_open (ev_annot_text,
2599 poppler_annot_text_get_is_open (poppler_text));
2600 ev_annotation_text_set_icon (ev_annot_text, get_annot_text_icon (poppler_text));
2603 case POPPLER_ANNOT_FILE_ATTACHMENT: {
2604 PopplerAnnotFileAttachment *poppler_annot_attachment;
2605 EvAnnotationAttachment *ev_annot_attachment;
2606 PopplerAttachment *poppler_attachment;
2609 GError *error = NULL;
2611 poppler_annot_attachment = POPPLER_ANNOT_FILE_ATTACHMENT (poppler_annot);
2612 poppler_attachment = poppler_annot_file_attachment_get_attachment (poppler_annot_attachment);
2614 if (poppler_attachment &&
2615 attachment_save_to_buffer (poppler_attachment, &data, &size, &error)) {
2616 EvAttachment *ev_attachment;
2618 ev_attachment = ev_attachment_new (poppler_attachment->name,
2619 poppler_attachment->description,
2620 poppler_attachment->mtime,
2621 poppler_attachment->ctime,
2623 ev_annot = ev_annotation_attachment_new (page, ev_attachment);
2624 g_object_unref (ev_attachment);
2626 g_warning ("%s", error->message);
2627 g_error_free (error);
2630 if (poppler_attachment)
2631 g_object_unref (poppler_attachment);
2634 case POPPLER_ANNOT_LINK:
2635 case POPPLER_ANNOT_WIDGET:
2636 /* Ignore link and widgets annots since they are already handled */
2639 GEnumValue *enum_value;
2641 enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ANNOT_TYPE),
2642 poppler_annot_get_annot_type (poppler_annot));
2643 unimplemented_annot = enum_value ? enum_value->value_name : "Unknown annotation";
2647 if (unimplemented_annot) {
2648 g_warning ("Unimplemented annotation: %s, please post a "
2649 "bug report in Evince bugzilla "
2650 "(http://bugzilla.gnome.org) with a testcase.",
2651 unimplemented_annot);
2661 contents = poppler_annot_get_contents (poppler_annot);
2663 ev_annotation_set_contents (ev_annot, contents);
2667 name = poppler_annot_get_name (poppler_annot);
2669 ev_annotation_set_name (ev_annot, name);
2673 modified = poppler_annot_get_modified (poppler_annot);
2674 if (poppler_date_parse (modified, &utime)) {
2675 ev_annotation_set_modified_from_time (ev_annot, utime);
2677 ev_annotation_set_modified (ev_annot, modified);
2681 poppler_annot_color_to_gdk_color (poppler_annot, &color);
2682 ev_annotation_set_color (ev_annot, &color);
2684 if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
2685 PopplerAnnotMarkup *markup;
2688 PopplerRectangle poppler_rect;
2690 markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2692 if (poppler_annot_markup_get_popup_rectangle (markup, &poppler_rect)) {
2693 EvRectangle ev_rect;
2697 poppler_page_get_size (POPPLER_PAGE (page->backend_page),
2699 ev_rect.x1 = poppler_rect.x1;
2700 ev_rect.x2 = poppler_rect.x2;
2701 ev_rect.y1 = height - poppler_rect.y2;
2702 ev_rect.y2 = height - poppler_rect.y1;
2704 is_open = poppler_annot_markup_get_popup_is_open (markup);
2706 g_object_set (ev_annot,
2707 "rectangle", &ev_rect,
2708 "popup_is_open", is_open,
2712 g_object_set (ev_annot,
2717 label = poppler_annot_markup_get_label (markup);
2718 opacity = poppler_annot_markup_get_opacity (markup);
2720 g_object_set (ev_annot,
2732 static EvMappingList *
2733 pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annotations,
2736 GList *retval = NULL;
2737 PdfDocument *pdf_document;
2738 PopplerPage *poppler_page;
2739 EvMappingList *mapping_list;
2745 pdf_document = PDF_DOCUMENT (document_annotations);
2746 poppler_page = POPPLER_PAGE (page->backend_page);
2748 if (pdf_document->annots) {
2749 mapping_list = (EvMappingList *)g_hash_table_lookup (pdf_document->annots,
2750 GINT_TO_POINTER (page->index));
2752 return ev_mapping_list_ref (mapping_list);
2755 annots = poppler_page_get_annot_mapping (poppler_page);
2756 poppler_page_get_size (poppler_page, NULL, &height);
2758 for (list = annots; list; list = list->next) {
2759 PopplerAnnotMapping *mapping;
2760 EvMapping *annot_mapping;
2761 EvAnnotation *ev_annot;
2763 mapping = (PopplerAnnotMapping *)list->data;
2765 ev_annot = ev_annot_from_poppler_annot (mapping->annot, page);
2771 /* Make sure annot has a unique name */
2772 if (!ev_annotation_get_name (ev_annot)) {
2773 gchar *name = g_strdup_printf ("annot-%d-%d", page->index, i);
2775 ev_annotation_set_name (ev_annot, name);
2779 annot_mapping = g_new (EvMapping, 1);
2780 annot_mapping->area.x1 = mapping->area.x1;
2781 annot_mapping->area.x2 = mapping->area.x2;
2782 annot_mapping->area.y1 = height - mapping->area.y2;
2783 annot_mapping->area.y2 = height - mapping->area.y1;
2784 annot_mapping->data = ev_annot;
2786 g_object_set_data_full (G_OBJECT (ev_annot),
2788 g_object_ref (mapping->annot),
2789 (GDestroyNotify) g_object_unref);
2791 retval = g_list_prepend (retval, annot_mapping);
2794 poppler_page_free_annot_mapping (annots);
2799 if (!pdf_document->annots) {
2800 pdf_document->annots = g_hash_table_new_full (g_direct_hash,
2802 (GDestroyNotify)NULL,
2803 (GDestroyNotify)ev_mapping_list_unref);
2806 mapping_list = ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
2807 g_hash_table_insert (pdf_document->annots,
2808 GINT_TO_POINTER (page->index),
2809 ev_mapping_list_ref (mapping_list));
2811 return mapping_list;
2815 pdf_document_annotations_document_is_modified (EvDocumentAnnotations *document_annotations)
2817 return PDF_DOCUMENT (document_annotations)->annots_modified;
2820 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2822 pdf_document_annotations_add_annotation (EvDocumentAnnotations *document_annotations,
2823 EvAnnotation *annot,
2826 PopplerAnnot *poppler_annot;
2827 PdfDocument *pdf_document;
2829 PopplerPage *poppler_page;
2831 EvMappingList *mapping_list;
2832 EvMapping *annot_mapping;
2833 PopplerRectangle poppler_rect;
2835 PopplerColor poppler_color;
2841 pdf_document = PDF_DOCUMENT (document_annotations);
2842 page = ev_annotation_get_page (annot);
2843 poppler_page = POPPLER_PAGE (page->backend_page);
2845 poppler_page_get_size (poppler_page, NULL, &height);
2846 poppler_rect.x1 = rect->x1;
2847 poppler_rect.x2 = rect->x2;
2848 poppler_rect.y1 = height - rect->y2;
2849 poppler_rect.y2 = height - rect->y1;
2850 poppler_annot = poppler_annot_text_new (pdf_document->document, &poppler_rect);
2852 ev_annotation_get_color (annot, &color);
2853 poppler_color.red = color.red;
2854 poppler_color.green = color.green;
2855 poppler_color.blue = color.blue;
2856 poppler_annot_set_color (poppler_annot, &poppler_color);
2858 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2859 EvAnnotationMarkup *markup = EV_ANNOTATION_MARKUP (annot);
2862 if (ev_annotation_markup_has_popup (markup)) {
2863 EvRectangle popup_rect;
2865 ev_annotation_markup_get_rectangle (markup, &popup_rect);
2866 poppler_rect.x1 = popup_rect.x1;
2867 poppler_rect.x2 = popup_rect.x2;
2868 poppler_rect.y1 = height - popup_rect.y2;
2869 poppler_rect.y2 = height - popup_rect.y1;
2870 poppler_annot_markup_set_popup (POPPLER_ANNOT_MARKUP (poppler_annot), &poppler_rect);
2871 poppler_annot_markup_set_popup_is_open (POPPLER_ANNOT_MARKUP (poppler_annot),
2872 ev_annotation_markup_get_popup_is_open (markup));
2875 label = ev_annotation_markup_get_label (markup);
2877 poppler_annot_markup_set_label (POPPLER_ANNOT_MARKUP (poppler_annot), label);
2880 if (EV_IS_ANNOTATION_TEXT (annot)) {
2881 EvAnnotationText *text = EV_ANNOTATION_TEXT (annot);
2882 EvAnnotationTextIcon icon;
2884 icon = ev_annotation_text_get_icon (text);
2885 poppler_annot_text_set_icon (POPPLER_ANNOT_TEXT (poppler_annot),
2886 get_poppler_annot_text_icon (icon));
2888 poppler_page_add_annot (poppler_page, poppler_annot);
2890 annot_mapping = g_new (EvMapping, 1);
2891 annot_mapping->area = *rect;
2892 annot_mapping->data = annot;
2893 g_object_set_data_full (G_OBJECT (annot),
2895 g_object_ref (poppler_annot),
2896 (GDestroyNotify) g_object_unref);
2898 if (pdf_document->annots) {
2899 mapping_list = (EvMappingList *)g_hash_table_lookup (pdf_document->annots,
2900 GINT_TO_POINTER (page->index));
2901 list = ev_mapping_list_get_list (mapping_list);
2902 name = g_strdup_printf ("annot-%d-%d", page->index, g_list_length (list) + 1);
2903 ev_annotation_set_name (annot, name);
2905 list = g_list_append (list, annot_mapping);
2907 pdf_document->annots = g_hash_table_new_full (g_direct_hash,
2909 (GDestroyNotify)NULL,
2910 (GDestroyNotify)ev_mapping_list_unref);
2911 name = g_strdup_printf ("annot-%d-0", page->index);
2912 ev_annotation_set_name (annot, name);
2914 list = g_list_append (list, annot_mapping);
2915 mapping_list = ev_mapping_list_new (page->index, list, (GDestroyNotify)g_object_unref);
2916 g_hash_table_insert (pdf_document->annots,
2917 GINT_TO_POINTER (page->index),
2918 ev_mapping_list_ref (mapping_list));
2921 pdf_document->annots_modified = TRUE;
2923 #endif /* HAVE_POPPLER_PAGE_ADD_ANNOT */
2926 pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annotations,
2927 EvAnnotation *annot,
2928 EvAnnotationsSaveMask mask)
2930 PopplerAnnot *poppler_annot;
2932 poppler_annot = POPPLER_ANNOT (g_object_get_data (G_OBJECT (annot), "poppler-annot"));
2936 if (mask & EV_ANNOTATIONS_SAVE_CONTENTS)
2937 poppler_annot_set_contents (poppler_annot,
2938 ev_annotation_get_contents (annot));
2940 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2941 if (mask & EV_ANNOTATIONS_SAVE_COLOR) {
2945 ev_annotation_get_color (annot, &ev_color);
2946 color.red = ev_color.red;
2947 color.green = ev_color.green;
2948 color.blue = ev_color.blue;
2949 poppler_annot_set_color (poppler_annot, &color);
2952 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2953 EvAnnotationMarkup *ev_markup = EV_ANNOTATION_MARKUP (annot);
2954 PopplerAnnotMarkup *markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2956 if (mask & EV_ANNOTATIONS_SAVE_LABEL)
2957 poppler_annot_markup_set_label (markup, ev_annotation_markup_get_label (ev_markup));
2958 if (mask & EV_ANNOTATIONS_SAVE_OPACITY)
2959 poppler_annot_markup_set_opacity (markup, ev_annotation_markup_get_opacity (ev_markup));
2960 if (mask & EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN)
2961 poppler_annot_markup_set_popup_is_open (markup, ev_annotation_markup_get_popup_is_open (ev_markup));
2964 if (EV_IS_ANNOTATION_TEXT (annot)) {
2965 EvAnnotationText *ev_text = EV_ANNOTATION_TEXT (annot);
2966 PopplerAnnotText *text = POPPLER_ANNOT_TEXT (poppler_annot);
2968 if (mask & EV_ANNOTATIONS_SAVE_TEXT_IS_OPEN) {
2969 poppler_annot_text_set_is_open (text,
2970 ev_annotation_text_get_is_open (ev_text));
2972 if (mask & EV_ANNOTATIONS_SAVE_TEXT_ICON) {
2973 EvAnnotationTextIcon icon;
2975 icon = ev_annotation_text_get_icon (ev_text);
2976 poppler_annot_text_set_icon (text, get_poppler_annot_text_icon (icon));
2979 #endif /* HAVE_POPPLER_PAGE_ADD_ANNOT */
2980 PDF_DOCUMENT (document_annotations)->annots_modified = TRUE;
2984 pdf_document_document_annotations_iface_init (EvDocumentAnnotationsInterface *iface)
2986 iface->get_annotations = pdf_document_annotations_get_annotations;
2987 iface->document_is_modified = pdf_document_annotations_document_is_modified;
2988 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2989 iface->add_annotation = pdf_document_annotations_add_annotation;
2991 iface->save_annotation = pdf_document_annotations_save_annotation;
2995 struct SaveToBufferData {
3001 attachment_save_to_buffer_callback (const gchar *buf,
3006 struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
3010 if (sdata->len + count > sdata->max) {
3011 new_max = MAX (sdata->max * 2, sdata->len + count);
3012 new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
3014 sdata->buffer = new_buffer;
3015 sdata->max = new_max;
3018 memcpy (sdata->buffer + sdata->len, buf, count);
3019 sdata->len += count;
3025 attachment_save_to_buffer (PopplerAttachment *attachment,
3030 static const gint initial_max = 1024;
3031 struct SaveToBufferData sdata;
3036 sdata.buffer = (gchar *) g_malloc (initial_max);
3037 sdata.max = initial_max;
3040 if (! poppler_attachment_save_to_callback (attachment,
3041 attachment_save_to_buffer_callback,
3044 g_free (sdata.buffer);
3048 *buffer = sdata.buffer;
3049 *buffer_size = sdata.len;
3055 pdf_document_attachments_get_attachments (EvDocumentAttachments *document)
3057 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3060 GList *retval = NULL;
3062 attachments = poppler_document_get_attachments (pdf_document->document);
3064 for (list = attachments; list; list = list->next) {
3065 PopplerAttachment *attachment;
3066 EvAttachment *ev_attachment;
3069 GError *error = NULL;
3071 attachment = (PopplerAttachment *) list->data;
3073 if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
3074 ev_attachment = ev_attachment_new (attachment->name,
3075 attachment->description,
3080 retval = g_list_prepend (retval, ev_attachment);
3083 g_warning ("%s", error->message);
3084 g_error_free (error);
3090 g_object_unref (attachment);
3093 return g_list_reverse (retval);
3097 pdf_document_attachments_has_attachments (EvDocumentAttachments *document)
3099 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3101 return poppler_document_has_attachments (pdf_document->document);
3105 pdf_document_document_attachments_iface_init (EvDocumentAttachmentsInterface *iface)
3107 iface->has_attachments = pdf_document_attachments_has_attachments;
3108 iface->get_attachments = pdf_document_attachments_get_attachments;
3113 pdf_document_layers_has_layers (EvDocumentLayers *document)
3115 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3116 PopplerLayersIter *iter;
3118 iter = poppler_layers_iter_new (pdf_document->document);
3121 poppler_layers_iter_free (iter);
3127 build_layers_tree (PdfDocument *pdf_document,
3128 GtkTreeModel *model,
3129 GtkTreeIter *parent,
3130 PopplerLayersIter *iter)
3133 GtkTreeIter tree_iter;
3134 PopplerLayersIter *child;
3135 PopplerLayer *layer;
3136 EvLayer *ev_layer = NULL;
3141 layer = poppler_layers_iter_get_layer (iter);
3143 markup = g_markup_escape_text (poppler_layer_get_title (layer), -1);
3144 visible = poppler_layer_is_visible (layer);
3145 rb_group = poppler_layer_get_radio_button_group_id (layer);
3146 ev_layer = ev_layer_new (poppler_layer_is_parent (layer),
3148 g_object_set_data_full (G_OBJECT (ev_layer),
3150 g_object_ref (layer),
3151 (GDestroyNotify) g_object_unref);
3155 title = poppler_layers_iter_get_title (iter);
3156 markup = g_markup_escape_text (title, -1);
3163 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
3164 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
3165 EV_DOCUMENT_LAYERS_COLUMN_TITLE, markup,
3166 EV_DOCUMENT_LAYERS_COLUMN_VISIBLE, visible,
3167 EV_DOCUMENT_LAYERS_COLUMN_ENABLED, TRUE, /* FIXME */
3168 EV_DOCUMENT_LAYERS_COLUMN_SHOWTOGGLE, (layer != NULL),
3169 EV_DOCUMENT_LAYERS_COLUMN_RBGROUP, rb_group,
3170 EV_DOCUMENT_LAYERS_COLUMN_LAYER, ev_layer,
3173 g_object_unref (ev_layer);
3176 child = poppler_layers_iter_get_child (iter);
3178 build_layers_tree (pdf_document, model, &tree_iter, child);
3179 poppler_layers_iter_free (child);
3180 } while (poppler_layers_iter_next (iter));
3183 static GtkTreeModel *
3184 pdf_document_layers_get_layers (EvDocumentLayers *document)
3186 GtkTreeModel *model = NULL;
3187 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3188 PopplerLayersIter *iter;
3190 iter = poppler_layers_iter_new (pdf_document->document);
3192 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LAYERS_N_COLUMNS,
3193 G_TYPE_STRING, /* TITLE */
3194 G_TYPE_OBJECT, /* LAYER */
3195 G_TYPE_BOOLEAN, /* VISIBLE */
3196 G_TYPE_BOOLEAN, /* ENABLED */
3197 G_TYPE_BOOLEAN, /* SHOWTOGGLE */
3198 G_TYPE_INT); /* RBGROUP */
3199 build_layers_tree (pdf_document, model, NULL, iter);
3200 poppler_layers_iter_free (iter);
3206 pdf_document_layers_show_layer (EvDocumentLayers *document,
3209 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3210 PopplerLayer *poppler_layer;
3212 poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer"));
3213 poppler_layer_show (poppler_layer);
3217 pdf_document_layers_hide_layer (EvDocumentLayers *document,
3220 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3221 PopplerLayer *poppler_layer;
3223 poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer"));
3224 poppler_layer_hide (poppler_layer);
3228 pdf_document_layers_layer_is_visible (EvDocumentLayers *document,
3231 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3232 PopplerLayer *poppler_layer;
3234 poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer"));
3235 return poppler_layer_is_visible (poppler_layer);
3239 pdf_document_document_layers_iface_init (EvDocumentLayersInterface *iface)
3241 iface->has_layers = pdf_document_layers_has_layers;
3242 iface->get_layers = pdf_document_layers_get_layers;
3243 iface->show_layer = pdf_document_layers_show_layer;
3244 iface->hide_layer = pdf_document_layers_hide_layer;
3245 iface->layer_is_visible = pdf_document_layers_layer_is_visible;