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,
403 cairo_surface_t *surface;
405 ev_document_fc_mutex_lock ();
406 surface = pdf_page_render (poppler_page, width, height, rc);
407 ev_document_fc_mutex_unlock ();
409 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
410 cairo_surface_destroy (surface);
416 pdf_document_get_thumbnail (EvDocument *document,
419 PdfDocument *pdf_document = PDF_DOCUMENT (document);
420 PopplerPage *poppler_page;
421 cairo_surface_t *surface;
422 GdkPixbuf *pixbuf = NULL;
423 GdkPixbuf *border_pixbuf;
424 double page_width, page_height;
427 poppler_page = POPPLER_PAGE (rc->page->backend_page);
429 poppler_page_get_size (poppler_page,
430 &page_width, &page_height);
432 width = MAX ((gint)(page_width * rc->scale + 0.5), 1);
433 height = MAX ((gint)(page_height * rc->scale + 0.5), 1);
435 if (rc->rotation == 90 || rc->rotation == 270) {
443 surface = poppler_page_get_thumbnail (poppler_page);
445 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
446 cairo_surface_destroy (surface);
449 if (pixbuf != NULL) {
450 int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ?
451 gdk_pixbuf_get_height (pixbuf) :
452 gdk_pixbuf_get_width (pixbuf);
454 if (thumb_width == width) {
455 GdkPixbuf *rotated_pixbuf;
457 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
458 (GdkPixbufRotation) (360 - rc->rotation));
459 g_object_unref (pixbuf);
460 pixbuf = rotated_pixbuf;
462 /* The provided thumbnail has a different size */
463 g_object_unref (pixbuf);
464 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
467 /* There is no provided thumbnail. We need to make one. */
468 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
475 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 */
477 pdf_document_get_format_from_metadata (xmlDocPtr doc,
478 xmlXPathContextPtr xpathCtx)
480 xmlXPathObjectPtr xpathObj;
481 xmlChar *part = NULL;
482 xmlChar *conf = NULL;
486 /* add pdf/a namespaces */
487 xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
488 xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
489 xmlXPathRegisterNs (xpathCtx, BAD_CAST "pdfaid", BAD_CAST "http://www.aiim.org/pdfa/ns/id/");
491 /* reads pdf/a part */
492 /* first syntax: child node */
493 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:part", xpathCtx);
494 if (xpathObj != NULL) {
495 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
496 part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
498 xmlXPathFreeObject (xpathObj);
501 /* second syntax: attribute */
502 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:part", xpathCtx);
503 if (xpathObj != NULL) {
504 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
505 part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
507 xmlXPathFreeObject (xpathObj);
511 /* reads pdf/a conformance */
512 /* first syntax: child node */
513 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:conformance", xpathCtx);
514 if (xpathObj != NULL) {
515 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
516 conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
518 xmlXPathFreeObject (xpathObj);
521 /* second syntax: attribute */
522 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:conformance", xpathCtx);
523 if (xpathObj != NULL) {
524 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
525 conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
527 xmlXPathFreeObject (xpathObj);
531 if (part != NULL && conf != NULL) {
532 /* makes conf lowercase */
533 for (i = 0; conf[i]; i++)
534 conf[i] = g_ascii_tolower (conf[i]);
537 result = g_strdup_printf ("PDF/A - %s%s", part, conf);
547 static EvDocumentLicense *
548 pdf_document_get_license_from_metadata (xmlDocPtr doc,
549 xmlXPathContextPtr xpathCtx)
551 xmlXPathObjectPtr xpathObj;
552 xmlChar *marked = NULL;
553 const char *language_string;
556 gchar *tag, *tag_aux;
558 EvDocumentLicense *license;
560 /* register namespaces */
561 xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
562 xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
563 xmlXPathRegisterNs (xpathCtx, BAD_CAST "dc", BAD_CAST "http://purl.org/dc/elements/1.1/");
564 /* XMP Rights Management Schema */
565 xmlXPathRegisterNs (xpathCtx, BAD_CAST "xmpRights", BAD_CAST "http://ns.adobe.com/xap/1.0/rights/");
566 /* Creative Commons Schema */
567 xmlXPathRegisterNs (xpathCtx, BAD_CAST "cc", BAD_CAST "http://creativecommons.org/ns#");
569 /* checking if the document has been marked as defined on the XMP Rights
570 * Management Schema */
571 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_MARKED, xpathCtx);
572 if (xpathObj != NULL) {
573 if (xpathObj->nodesetval != NULL &&
574 xpathObj->nodesetval->nodeNr != 0)
575 marked = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
576 xmlXPathFreeObject (xpathObj);
579 /* a) Not marked => No XMP Rights information */
585 license = ev_document_license_new ();
587 /* b) Marked False => Public Domain, no copyrighted material and no
589 if (g_strrstr ((char *) marked, "False") != NULL) {
590 license->text = g_strdup (_("This work is in the Public Domain"));
591 /* c) Marked True => Copyrighted material */
593 /* Checking usage terms as defined by the XMP Rights Management
594 * Schema. This field is recomended to be checked by Creative
596 /* 1) checking for a suitable localized string */
597 language_string = pango_language_to_string (gtk_get_default_language ());
598 tags = g_strsplit (language_string, "-", -1);
599 i = g_strv_length (tags);
600 while (i-- && !license->text) {
601 tag = g_strdup (tags[0]);
602 for (j = 1; j <= i; j++) {
603 tag_aux = g_strdup_printf ("%s-%s", tag, tags[j]);
607 aux = g_strdup_printf (LICENSE_TEXT, tag);
608 xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
609 if (xpathObj != NULL) {
610 if (xpathObj->nodesetval != NULL &&
611 xpathObj->nodesetval->nodeNr != 0)
612 license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
613 xmlXPathFreeObject (xpathObj);
620 /* 2) if not, use the default string */
621 if (!license->text) {
622 aux = g_strdup_printf (LICENSE_TEXT, "x-default");
623 xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
624 if (xpathObj != NULL) {
625 if (xpathObj->nodesetval != NULL &&
626 xpathObj->nodesetval->nodeNr != 0)
627 license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
628 xmlXPathFreeObject (xpathObj);
633 /* Checking the license URI as defined by the Creative Commons
634 * Schema. This field is recomended to be checked by Creative
636 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_URI, xpathCtx);
637 if (xpathObj != NULL) {
638 if (xpathObj->nodesetval != NULL &&
639 xpathObj->nodesetval->nodeNr != 0)
640 license->uri = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
641 xmlXPathFreeObject (xpathObj);
644 /* Checking the web statement as defined by the XMP Rights
645 * Management Schema. Checking it out is a sort of above-and-beyond
646 * the basic recommendations by Creative Commons. It can be
647 * considered as a "reinforcement" approach to add certainty. */
648 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_WEB_STATEMENT, xpathCtx);
649 if (xpathObj != NULL) {
650 if (xpathObj->nodesetval != NULL &&
651 xpathObj->nodesetval->nodeNr != 0)
652 license->web_statement = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
653 xmlXPathFreeObject (xpathObj);
658 if (!license->text && !license->uri && !license->web_statement) {
659 ev_document_license_free (license);
667 pdf_document_parse_metadata (const gchar *metadata,
668 EvDocumentInfo *info)
671 xmlXPathContextPtr xpathCtx;
674 doc = xmlParseMemory (metadata, strlen (metadata));
676 return; /* invalid xml metadata */
678 xpathCtx = xmlXPathNewContext (doc);
679 if (xpathCtx == NULL) {
681 return; /* invalid xpath context */
684 fmt = pdf_document_get_format_from_metadata (doc, xpathCtx);
686 g_free (info->format);
690 info->license = pdf_document_get_license_from_metadata (doc, xpathCtx);
692 xmlXPathFreeContext (xpathCtx);
697 static EvDocumentInfo *
698 pdf_document_get_info (EvDocument *document)
700 EvDocumentInfo *info;
701 PopplerPageLayout layout;
702 PopplerPageMode mode;
703 PopplerViewerPreferences view_prefs;
704 PopplerPermissions permissions;
709 info = g_new0 (EvDocumentInfo, 1);
711 info->fields_mask = EV_DOCUMENT_INFO_TITLE |
712 EV_DOCUMENT_INFO_FORMAT |
713 EV_DOCUMENT_INFO_AUTHOR |
714 EV_DOCUMENT_INFO_SUBJECT |
715 EV_DOCUMENT_INFO_KEYWORDS |
716 EV_DOCUMENT_INFO_LAYOUT |
717 EV_DOCUMENT_INFO_START_MODE |
718 EV_DOCUMENT_INFO_PERMISSIONS |
719 EV_DOCUMENT_INFO_UI_HINTS |
720 EV_DOCUMENT_INFO_CREATOR |
721 EV_DOCUMENT_INFO_PRODUCER |
722 EV_DOCUMENT_INFO_CREATION_DATE |
723 EV_DOCUMENT_INFO_MOD_DATE |
724 EV_DOCUMENT_INFO_LINEARIZED |
725 EV_DOCUMENT_INFO_N_PAGES |
726 EV_DOCUMENT_INFO_SECURITY |
727 EV_DOCUMENT_INFO_PAPER_SIZE |
728 EV_DOCUMENT_INFO_LICENSE;
730 g_object_get (PDF_DOCUMENT (document)->document,
731 "title", &(info->title),
732 "format", &(info->format),
733 "author", &(info->author),
734 "subject", &(info->subject),
735 "keywords", &(info->keywords),
737 "page-layout", &layout,
738 "viewer-preferences", &view_prefs,
739 "permissions", &permissions,
740 "creator", &(info->creator),
741 "producer", &(info->producer),
742 "creation-date", &(info->creation_date),
743 "mod-date", &(info->modified_date),
744 "linearized", &linearized,
745 "metadata", &metadata,
748 if (metadata != NULL) {
749 pdf_document_parse_metadata (metadata, info);
753 info->n_pages = ev_document_get_n_pages (document);
755 if (info->n_pages > 0) {
756 ev_document_get_page_size (document, 0,
757 &(info->paper_width),
758 &(info->paper_height));
760 info->paper_width = info->paper_width / 72.0f * 25.4f;
761 info->paper_height = info->paper_height / 72.0f * 25.4f;
765 case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
766 info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
768 case POPPLER_PAGE_LAYOUT_ONE_COLUMN:
769 info->layout = EV_DOCUMENT_LAYOUT_ONE_COLUMN;
771 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_LEFT:
772 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_LEFT;
774 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
775 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
776 case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
777 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
779 case POPPLER_PAGE_LAYOUT_TWO_PAGE_RIGHT:
780 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_RIGHT;
787 case POPPLER_PAGE_MODE_NONE:
788 info->mode = EV_DOCUMENT_MODE_NONE;
790 case POPPLER_PAGE_MODE_USE_THUMBS:
791 info->mode = EV_DOCUMENT_MODE_USE_THUMBS;
793 case POPPLER_PAGE_MODE_USE_OC:
794 info->mode = EV_DOCUMENT_MODE_USE_OC;
796 case POPPLER_PAGE_MODE_FULL_SCREEN:
797 info->mode = EV_DOCUMENT_MODE_FULL_SCREEN;
799 case POPPLER_PAGE_MODE_USE_ATTACHMENTS:
800 info->mode = EV_DOCUMENT_MODE_USE_ATTACHMENTS;
806 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_TOOLBAR) {
807 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_TOOLBAR;
809 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_MENUBAR) {
810 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_MENUBAR;
812 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_WINDOWUI) {
813 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_WINDOWUI;
815 if (view_prefs & POPPLER_VIEWER_PREFERENCES_FIT_WINDOW) {
816 info->ui_hints |= EV_DOCUMENT_UI_HINT_FIT_WINDOW;
818 if (view_prefs & POPPLER_VIEWER_PREFERENCES_CENTER_WINDOW) {
819 info->ui_hints |= EV_DOCUMENT_UI_HINT_CENTER_WINDOW;
821 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DISPLAY_DOC_TITLE) {
822 info->ui_hints |= EV_DOCUMENT_UI_HINT_DISPLAY_DOC_TITLE;
824 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL) {
825 info->ui_hints |= EV_DOCUMENT_UI_HINT_DIRECTION_RTL;
828 info->permissions = 0;
829 if (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT) {
830 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT;
832 if (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY) {
833 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY;
835 if (permissions & POPPLER_PERMISSIONS_OK_TO_COPY) {
836 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_COPY;
838 if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) {
839 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES;
842 if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
843 /* translators: this is the document security state */
844 info->security = g_strdup (_("Yes"));
846 /* translators: this is the document security state */
847 info->security = g_strdup (_("No"));
850 info->linearized = linearized ? g_strdup (_("Yes")) : g_strdup (_("No"));
856 pdf_document_get_backend_info (EvDocument *document, EvDocumentBackendInfo *info)
858 PopplerBackend backend;
860 backend = poppler_get_backend ();
862 case POPPLER_BACKEND_CAIRO:
863 info->name = "poppler/cairo";
865 case POPPLER_BACKEND_SPLASH:
866 info->name = "poppler/splash";
869 info->name = "poppler/unknown";
873 info->version = poppler_get_version ();
879 pdf_document_support_synctex (EvDocument *document)
885 pdf_document_class_init (PdfDocumentClass *klass)
887 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
888 EvDocumentClass *ev_document_class = EV_DOCUMENT_CLASS (klass);
890 g_object_class->dispose = pdf_document_dispose;
892 ev_document_class->save = pdf_document_save;
893 ev_document_class->load = pdf_document_load;
894 ev_document_class->get_n_pages = pdf_document_get_n_pages;
895 ev_document_class->get_page = pdf_document_get_page;
896 ev_document_class->get_page_size = pdf_document_get_page_size;
897 ev_document_class->get_page_label = pdf_document_get_page_label;
898 ev_document_class->render = pdf_document_render;
899 ev_document_class->get_thumbnail = pdf_document_get_thumbnail;
900 ev_document_class->get_info = pdf_document_get_info;
901 ev_document_class->get_backend_info = pdf_document_get_backend_info;
902 ev_document_class->support_synctex = pdf_document_support_synctex;
905 /* EvDocumentSecurity */
907 pdf_document_has_document_security (EvDocumentSecurity *document_security)
909 /* FIXME: do we really need to have this? */
914 pdf_document_set_password (EvDocumentSecurity *document_security,
915 const char *password)
917 PdfDocument *document = PDF_DOCUMENT (document_security);
919 if (document->password)
920 g_free (document->password);
922 document->password = g_strdup (password);
926 pdf_document_security_iface_init (EvDocumentSecurityInterface *iface)
928 iface->has_document_security = pdf_document_has_document_security;
929 iface->set_password = pdf_document_set_password;
933 pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts)
935 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
938 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
940 return (double)pdf_document->fonts_scanned_pages / (double)n_pages;
944 pdf_document_fonts_scan (EvDocumentFonts *document_fonts,
947 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
950 g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE);
952 if (pdf_document->font_info == NULL) {
953 pdf_document->font_info = poppler_font_info_new (pdf_document->document);
956 if (pdf_document->fonts_iter) {
957 poppler_fonts_iter_free (pdf_document->fonts_iter);
960 pdf_document->fonts_scanned_pages += n_pages;
962 result = poppler_font_info_scan (pdf_document->font_info, n_pages,
963 &pdf_document->fonts_iter);
965 pdf_document->fonts_scanned_pages = 0;
966 poppler_font_info_free (pdf_document->font_info);
967 pdf_document->font_info = NULL;
974 font_type_to_string (PopplerFontType type)
977 case POPPLER_FONT_TYPE_TYPE1:
979 case POPPLER_FONT_TYPE_TYPE1C:
981 case POPPLER_FONT_TYPE_TYPE3:
983 case POPPLER_FONT_TYPE_TRUETYPE:
984 return _("TrueType");
985 case POPPLER_FONT_TYPE_CID_TYPE0:
986 return _("Type 1 (CID)");
987 case POPPLER_FONT_TYPE_CID_TYPE0C:
988 return _("Type 1C (CID)");
989 case POPPLER_FONT_TYPE_CID_TYPE2:
990 return _("TrueType (CID)");
992 return _("Unknown font type");
997 pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
1000 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
1001 PopplerFontsIter *iter = pdf_document->fonts_iter;
1003 g_return_if_fail (PDF_IS_DOCUMENT (document_fonts));
1009 GtkTreeIter list_iter;
1012 const char *embedded;
1015 name = poppler_fonts_iter_get_name (iter);
1018 name = _("No name");
1021 type = font_type_to_string (
1022 poppler_fonts_iter_get_font_type (iter));
1024 if (poppler_fonts_iter_is_embedded (iter)) {
1025 if (poppler_fonts_iter_is_subset (iter))
1026 embedded = _("Embedded subset");
1028 embedded = _("Embedded");
1030 embedded = _("Not embedded");
1033 details = g_markup_printf_escaped ("%s\n%s", type, embedded);
1035 gtk_list_store_append (GTK_LIST_STORE (model), &list_iter);
1036 gtk_list_store_set (GTK_LIST_STORE (model), &list_iter,
1037 EV_DOCUMENT_FONTS_COLUMN_NAME, name,
1038 EV_DOCUMENT_FONTS_COLUMN_DETAILS, details,
1042 } while (poppler_fonts_iter_next (iter));
1046 pdf_document_document_fonts_iface_init (EvDocumentFontsInterface *iface)
1048 iface->fill_model = pdf_document_fonts_fill_model;
1049 iface->scan = pdf_document_fonts_scan;
1050 iface->get_progress = pdf_document_fonts_get_progress;
1054 pdf_document_links_has_document_links (EvDocumentLinks *document_links)
1056 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1057 PopplerIndexIter *iter;
1059 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
1061 iter = poppler_index_iter_new (pdf_document->document);
1064 poppler_index_iter_free (iter);
1070 ev_link_dest_from_dest (PdfDocument *pdf_document,
1073 EvLinkDest *ev_dest = NULL;
1074 const char *unimplemented_dest = NULL;
1076 g_assert (dest != NULL);
1078 switch (dest->type) {
1079 case POPPLER_DEST_XYZ: {
1080 PopplerPage *poppler_page;
1083 poppler_page = poppler_document_get_page (pdf_document->document,
1084 MAX (0, dest->page_num - 1));
1085 poppler_page_get_size (poppler_page, NULL, &height);
1086 ev_dest = ev_link_dest_new_xyz (dest->page_num - 1,
1088 height - MIN (height, dest->top),
1093 g_object_unref (poppler_page);
1096 case POPPLER_DEST_FITB:
1097 case POPPLER_DEST_FIT:
1098 ev_dest = ev_link_dest_new_fit (dest->page_num - 1);
1100 case POPPLER_DEST_FITBH:
1101 case POPPLER_DEST_FITH: {
1102 PopplerPage *poppler_page;
1105 poppler_page = poppler_document_get_page (pdf_document->document,
1106 MAX (0, dest->page_num - 1));
1107 poppler_page_get_size (poppler_page, NULL, &height);
1108 ev_dest = ev_link_dest_new_fith (dest->page_num - 1,
1109 height - MIN (height, dest->top),
1111 g_object_unref (poppler_page);
1114 case POPPLER_DEST_FITBV:
1115 case POPPLER_DEST_FITV:
1116 ev_dest = ev_link_dest_new_fitv (dest->page_num - 1,
1120 case POPPLER_DEST_FITR: {
1121 PopplerPage *poppler_page;
1124 poppler_page = poppler_document_get_page (pdf_document->document,
1125 MAX (0, dest->page_num - 1));
1126 poppler_page_get_size (poppler_page, NULL, &height);
1127 ev_dest = ev_link_dest_new_fitr (dest->page_num - 1,
1129 height - MIN (height, dest->bottom),
1131 height - MIN (height, dest->top));
1132 g_object_unref (poppler_page);
1135 case POPPLER_DEST_NAMED:
1136 ev_dest = ev_link_dest_new_named (dest->named_dest);
1138 case POPPLER_DEST_UNKNOWN:
1139 unimplemented_dest = "POPPLER_DEST_UNKNOWN";
1143 if (unimplemented_dest) {
1144 g_warning ("Unimplemented destination: %s, please post a "
1145 "bug report in Evince bugzilla "
1146 "(http://bugzilla.gnome.org) with a testcase.",
1147 unimplemented_dest);
1151 ev_dest = ev_link_dest_new_page (dest->page_num - 1);
1157 ev_link_from_action (PdfDocument *pdf_document,
1158 PopplerAction *action)
1160 EvLink *link = NULL;
1161 EvLinkAction *ev_action = NULL;
1162 const char *unimplemented_action = NULL;
1164 switch (action->type) {
1165 case POPPLER_ACTION_NONE:
1167 case POPPLER_ACTION_GOTO_DEST: {
1170 dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest);
1171 ev_action = ev_link_action_new_dest (dest);
1174 case POPPLER_ACTION_GOTO_REMOTE: {
1177 dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest);
1178 ev_action = ev_link_action_new_remote (dest,
1179 action->goto_remote.file_name);
1183 case POPPLER_ACTION_LAUNCH:
1184 ev_action = ev_link_action_new_launch (action->launch.file_name,
1185 action->launch.params);
1187 case POPPLER_ACTION_URI:
1188 ev_action = ev_link_action_new_external_uri (action->uri.uri);
1190 case POPPLER_ACTION_NAMED:
1191 ev_action = ev_link_action_new_named (action->named.named_dest);
1193 case POPPLER_ACTION_MOVIE:
1194 unimplemented_action = "POPPLER_ACTION_MOVIE";
1196 case POPPLER_ACTION_RENDITION:
1197 unimplemented_action = "POPPLER_ACTION_RENDITION";
1199 case POPPLER_ACTION_OCG_STATE: {
1200 GList *on_list = NULL;
1201 GList *off_list = NULL;
1202 GList *toggle_list = NULL;
1205 for (l = action->ocg_state.state_list; l; l = g_list_next (l)) {
1206 PopplerActionLayer *action_layer = (PopplerActionLayer *)l->data;
1208 for (m = action_layer->layers; m; m = g_list_next (m)) {
1209 PopplerLayer *layer = (PopplerLayer *)m->data;
1212 ev_layer = ev_layer_new (poppler_layer_is_parent (layer),
1213 poppler_layer_get_radio_button_group_id (layer));
1214 g_object_set_data_full (G_OBJECT (ev_layer),
1216 g_object_ref (layer),
1217 (GDestroyNotify)g_object_unref);
1219 switch (action_layer->action) {
1220 case POPPLER_ACTION_LAYER_ON:
1221 on_list = g_list_prepend (on_list, ev_layer);
1223 case POPPLER_ACTION_LAYER_OFF:
1224 off_list = g_list_prepend (off_list, ev_layer);
1226 case POPPLER_ACTION_LAYER_TOGGLE:
1227 toggle_list = g_list_prepend (toggle_list, ev_layer);
1233 /* The action takes the ownership of the lists */
1234 ev_action = ev_link_action_new_layers_state (g_list_reverse (on_list),
1235 g_list_reverse (off_list),
1236 g_list_reverse (toggle_list));
1241 case POPPLER_ACTION_UNKNOWN:
1242 unimplemented_action = "POPPLER_ACTION_UNKNOWN";
1245 if (unimplemented_action) {
1246 g_warning ("Unimplemented action: %s, please post a bug report "
1247 "in Evince bugzilla (http://bugzilla.gnome.org) "
1248 "with a testcase.", unimplemented_action);
1251 link = ev_link_new (action->any.title, ev_action);
1257 build_tree (PdfDocument *pdf_document,
1258 GtkTreeModel *model,
1259 GtkTreeIter *parent,
1260 PopplerIndexIter *iter)
1264 GtkTreeIter tree_iter;
1265 PopplerIndexIter *child;
1266 PopplerAction *action;
1267 EvLink *link = NULL;
1271 action = poppler_index_iter_get_action (iter);
1272 expand = poppler_index_iter_is_open (iter);
1277 link = ev_link_from_action (pdf_document, action);
1278 if (!link || strlen (ev_link_get_title (link)) <= 0) {
1279 poppler_action_free (action);
1281 g_object_unref (link);
1286 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
1287 title_markup = g_markup_escape_text (ev_link_get_title (link), -1);
1289 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
1290 EV_DOCUMENT_LINKS_COLUMN_MARKUP, title_markup,
1291 EV_DOCUMENT_LINKS_COLUMN_LINK, link,
1292 EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand,
1295 g_free (title_markup);
1296 g_object_unref (link);
1298 child = poppler_index_iter_get_child (iter);
1300 build_tree (pdf_document, model, &tree_iter, child);
1301 poppler_index_iter_free (child);
1302 poppler_action_free (action);
1304 } while (poppler_index_iter_next (iter));
1307 static GtkTreeModel *
1308 pdf_document_links_get_links_model (EvDocumentLinks *document_links)
1310 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1311 GtkTreeModel *model = NULL;
1312 PopplerIndexIter *iter;
1314 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
1316 iter = poppler_index_iter_new (pdf_document->document);
1317 /* Create the model if we have items*/
1319 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
1324 build_tree (pdf_document, model, NULL, iter);
1325 poppler_index_iter_free (iter);
1331 static EvMappingList *
1332 pdf_document_links_get_links (EvDocumentLinks *document_links,
1335 PdfDocument *pdf_document;
1336 PopplerPage *poppler_page;
1337 GList *retval = NULL;
1338 GList *mapping_list;
1342 pdf_document = PDF_DOCUMENT (document_links);
1343 poppler_page = POPPLER_PAGE (page->backend_page);
1344 mapping_list = poppler_page_get_link_mapping (poppler_page);
1345 poppler_page_get_size (poppler_page, NULL, &height);
1347 for (list = mapping_list; list; list = list->next) {
1348 PopplerLinkMapping *link_mapping;
1349 EvMapping *ev_link_mapping;
1351 link_mapping = (PopplerLinkMapping *)list->data;
1352 ev_link_mapping = g_new (EvMapping, 1);
1353 ev_link_mapping->data = ev_link_from_action (pdf_document,
1354 link_mapping->action);
1355 ev_link_mapping->area.x1 = link_mapping->area.x1;
1356 ev_link_mapping->area.x2 = link_mapping->area.x2;
1357 /* Invert this for X-style coordinates */
1358 ev_link_mapping->area.y1 = height - link_mapping->area.y2;
1359 ev_link_mapping->area.y2 = height - link_mapping->area.y1;
1361 retval = g_list_prepend (retval, ev_link_mapping);
1364 poppler_page_free_link_mapping (mapping_list);
1366 return ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
1370 pdf_document_links_find_link_dest (EvDocumentLinks *document_links,
1371 const gchar *link_name)
1373 PdfDocument *pdf_document;
1375 EvLinkDest *ev_dest = NULL;
1377 pdf_document = PDF_DOCUMENT (document_links);
1378 dest = poppler_document_find_dest (pdf_document->document,
1381 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1382 poppler_dest_free (dest);
1389 pdf_document_links_find_link_page (EvDocumentLinks *document_links,
1390 const gchar *link_name)
1392 PdfDocument *pdf_document;
1396 pdf_document = PDF_DOCUMENT (document_links);
1397 dest = poppler_document_find_dest (pdf_document->document,
1400 retval = dest->page_num - 1;
1401 poppler_dest_free (dest);
1408 pdf_document_document_links_iface_init (EvDocumentLinksInterface *iface)
1410 iface->has_document_links = pdf_document_links_has_document_links;
1411 iface->get_links_model = pdf_document_links_get_links_model;
1412 iface->get_links = pdf_document_links_get_links;
1413 iface->find_link_dest = pdf_document_links_find_link_dest;
1414 iface->find_link_page = pdf_document_links_find_link_page;
1417 static EvMappingList *
1418 pdf_document_images_get_image_mapping (EvDocumentImages *document_images,
1421 GList *retval = NULL;
1422 PdfDocument *pdf_document;
1423 PopplerPage *poppler_page;
1424 GList *mapping_list;
1427 pdf_document = PDF_DOCUMENT (document_images);
1428 poppler_page = POPPLER_PAGE (page->backend_page);
1429 mapping_list = poppler_page_get_image_mapping (poppler_page);
1431 for (list = mapping_list; list; list = list->next) {
1432 PopplerImageMapping *image_mapping;
1433 EvMapping *ev_image_mapping;
1435 image_mapping = (PopplerImageMapping *)list->data;
1437 ev_image_mapping = g_new (EvMapping, 1);
1439 ev_image_mapping->data = ev_image_new (page->index, image_mapping->image_id);
1440 ev_image_mapping->area.x1 = image_mapping->area.x1;
1441 ev_image_mapping->area.y1 = image_mapping->area.y1;
1442 ev_image_mapping->area.x2 = image_mapping->area.x2;
1443 ev_image_mapping->area.y2 = image_mapping->area.y2;
1445 retval = g_list_prepend (retval, ev_image_mapping);
1448 poppler_page_free_image_mapping (mapping_list);
1450 return ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
1454 pdf_document_images_get_image (EvDocumentImages *document_images,
1457 GdkPixbuf *retval = NULL;
1458 PdfDocument *pdf_document;
1459 PopplerPage *poppler_page;
1460 cairo_surface_t *surface;
1462 pdf_document = PDF_DOCUMENT (document_images);
1463 poppler_page = poppler_document_get_page (pdf_document->document,
1464 ev_image_get_page (image));
1466 surface = poppler_page_get_image (poppler_page, ev_image_get_id (image));
1468 retval = ev_document_misc_pixbuf_from_surface (surface);
1469 cairo_surface_destroy (surface);
1472 g_object_unref (poppler_page);
1478 pdf_document_document_images_iface_init (EvDocumentImagesInterface *iface)
1480 iface->get_image_mapping = pdf_document_images_get_image_mapping;
1481 iface->get_image = pdf_document_images_get_image;
1485 pdf_document_find_find_text (EvDocumentFind *document_find,
1488 gboolean case_sensitive)
1491 PopplerPage *poppler_page;
1493 GList *retval = NULL;
1495 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1496 g_return_val_if_fail (text != NULL, NULL);
1498 poppler_page = POPPLER_PAGE (page->backend_page);
1500 matches = poppler_page_find_text (poppler_page, text);
1504 poppler_page_get_size (poppler_page, NULL, &height);
1505 for (l = matches; l && l->data; l = g_list_next (l)) {
1506 PopplerRectangle *rect = (PopplerRectangle *)l->data;
1507 EvRectangle *ev_rect;
1509 ev_rect = ev_rectangle_new ();
1510 ev_rect->x1 = rect->x1;
1511 ev_rect->x2 = rect->x2;
1512 /* Invert this for X-style coordinates */
1513 ev_rect->y1 = height - rect->y2;
1514 ev_rect->y2 = height - rect->y1;
1516 retval = g_list_prepend (retval, ev_rect);
1519 g_list_foreach (matches, (GFunc)poppler_rectangle_free, NULL);
1520 g_list_free (matches);
1522 return g_list_reverse (retval);
1526 pdf_document_find_iface_init (EvDocumentFindInterface *iface)
1528 iface->find_text = pdf_document_find_find_text;
1532 pdf_print_context_free (PdfPrintContext *ctx)
1537 #ifdef HAVE_CAIRO_PRINT
1539 cairo_destroy (ctx->cr);
1544 poppler_ps_file_free (ctx->ps_file);
1545 ctx->ps_file = NULL;
1552 pdf_document_file_exporter_begin (EvFileExporter *exporter,
1553 EvFileExporterContext *fc)
1555 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1556 PdfPrintContext *ctx;
1557 #ifdef HAVE_CAIRO_PRINT
1558 gdouble width, height;
1559 cairo_surface_t *surface = NULL;
1562 if (pdf_document->print_ctx)
1563 pdf_print_context_free (pdf_document->print_ctx);
1564 pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
1565 ctx = pdf_document->print_ctx;
1566 ctx->format = fc->format;
1568 #ifdef HAVE_CAIRO_PRINT
1569 ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
1571 ctx->paper_width = fc->paper_width;
1572 ctx->paper_height = fc->paper_height;
1574 switch (fc->pages_per_sheet) {
1602 ctx->pages_printed = 0;
1604 switch (fc->format) {
1605 case EV_FILE_FORMAT_PS:
1606 #ifdef HAVE_CAIRO_PS
1607 surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1610 case EV_FILE_FORMAT_PDF:
1611 #ifdef HAVE_CAIRO_PDF
1612 surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1616 g_assert_not_reached ();
1619 ctx->cr = cairo_create (surface);
1620 cairo_surface_destroy (surface);
1622 #else /* HAVE_CAIRO_PRINT */
1623 if (ctx->format == EV_FILE_FORMAT_PS) {
1624 ctx->ps_file = poppler_ps_file_new (pdf_document->document,
1625 fc->filename, fc->first_page,
1626 fc->last_page - fc->first_page + 1);
1627 poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
1628 poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
1630 #endif /* HAVE_CAIRO_PRINT */
1634 pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
1636 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1637 PdfPrintContext *ctx = pdf_document->print_ctx;
1639 g_return_if_fail (pdf_document->print_ctx != NULL);
1641 ctx->pages_printed = 0;
1643 #ifdef HAVE_CAIRO_PRINT
1644 if (ctx->paper_width > ctx->paper_height) {
1645 if (ctx->format == EV_FILE_FORMAT_PS) {
1646 cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
1649 } else if (ctx->format == EV_FILE_FORMAT_PDF) {
1650 cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
1655 #endif /* HAVE_CAIRO_PRINT */
1659 pdf_document_file_exporter_do_page (EvFileExporter *exporter,
1660 EvRenderContext *rc)
1662 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1663 PdfPrintContext *ctx = pdf_document->print_ctx;
1664 PopplerPage *poppler_page;
1665 #ifdef HAVE_CAIRO_PRINT
1666 gdouble page_width, page_height;
1669 gdouble width, height;
1670 gdouble pwidth, pheight;
1671 gdouble xscale, yscale;
1674 g_return_if_fail (pdf_document->print_ctx != NULL);
1676 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1678 #ifdef HAVE_CAIRO_PRINT
1679 x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
1680 y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
1681 poppler_page_get_size (poppler_page, &page_width, &page_height);
1683 if (page_width > page_height && page_width > ctx->paper_width) {
1689 /* Use always portrait mode and rotate when necessary */
1690 if (ctx->paper_width > ctx->paper_height) {
1691 width = ctx->paper_height;
1692 height = ctx->paper_width;
1695 width = ctx->paper_width;
1696 height = ctx->paper_height;
1699 if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
1712 page_width = page_height;
1716 pwidth = width / ctx->pages_x;
1717 pheight = height / ctx->pages_y;
1719 if ((page_width > pwidth || page_height > pheight) ||
1720 (page_width < pwidth && page_height < pheight)) {
1721 xscale = pwidth / page_width;
1722 yscale = pheight / page_height;
1724 if (yscale < xscale) {
1731 xscale = yscale = 1;
1736 cairo_save (ctx->cr);
1738 cairo_matrix_t matrix;
1740 cairo_translate (ctx->cr, (2 * y + 1) * pwidth, 0);
1741 cairo_matrix_init (&matrix,
1745 cairo_transform (ctx->cr, &matrix);
1748 cairo_translate (ctx->cr,
1749 x * (rotate ? pheight : pwidth),
1750 y * (rotate ? pwidth : pheight));
1751 cairo_scale (ctx->cr, xscale, yscale);
1753 poppler_page_render_for_printing (poppler_page, ctx->cr);
1755 ctx->pages_printed++;
1757 cairo_restore (ctx->cr);
1758 #else /* HAVE_CAIRO_PRINT */
1759 if (ctx->format == EV_FILE_FORMAT_PS)
1760 poppler_page_render_to_ps (poppler_page, ctx->ps_file);
1761 #endif /* HAVE_CAIRO_PRINT */
1765 pdf_document_file_exporter_end_page (EvFileExporter *exporter)
1767 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1768 PdfPrintContext *ctx = pdf_document->print_ctx;
1770 g_return_if_fail (pdf_document->print_ctx != NULL);
1772 #ifdef HAVE_CAIRO_PRINT
1773 cairo_show_page (ctx->cr);
1778 pdf_document_file_exporter_end (EvFileExporter *exporter)
1780 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1782 pdf_print_context_free (pdf_document->print_ctx);
1783 pdf_document->print_ctx = NULL;
1786 static EvFileExporterCapabilities
1787 pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter)
1789 return (EvFileExporterCapabilities) (
1790 EV_FILE_EXPORTER_CAN_PAGE_SET |
1791 EV_FILE_EXPORTER_CAN_COPIES |
1792 EV_FILE_EXPORTER_CAN_COLLATE |
1793 EV_FILE_EXPORTER_CAN_REVERSE |
1794 EV_FILE_EXPORTER_CAN_SCALE |
1795 #ifdef HAVE_CAIRO_PRINT
1796 EV_FILE_EXPORTER_CAN_NUMBER_UP |
1799 #ifdef HAVE_CAIRO_PDF
1800 EV_FILE_EXPORTER_CAN_GENERATE_PDF |
1802 EV_FILE_EXPORTER_CAN_GENERATE_PS);
1806 pdf_document_file_exporter_iface_init (EvFileExporterInterface *iface)
1808 iface->begin = pdf_document_file_exporter_begin;
1809 iface->begin_page = pdf_document_file_exporter_begin_page;
1810 iface->do_page = pdf_document_file_exporter_do_page;
1811 iface->end_page = pdf_document_file_exporter_end_page;
1812 iface->end = pdf_document_file_exporter_end;
1813 iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
1816 /* EvDocumentPrint */
1818 pdf_document_print_print_page (EvDocumentPrint *document,
1822 PdfDocument *pdf_document = PDF_DOCUMENT (document);
1824 poppler_page_render_for_printing (POPPLER_PAGE (page->backend_page), cr);
1828 pdf_document_document_print_iface_init (EvDocumentPrintInterface *iface)
1830 iface->print_page = pdf_document_print_print_page;
1834 pdf_selection_render_selection (EvSelection *selection,
1835 EvRenderContext *rc,
1836 cairo_surface_t **surface,
1837 EvRectangle *points,
1838 EvRectangle *old_points,
1839 EvSelectionStyle style,
1843 PopplerPage *poppler_page;
1845 PopplerColor text_color, base_color;
1846 double width_points, height_points;
1849 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1851 poppler_page_get_size (poppler_page,
1852 &width_points, &height_points);
1853 width = (int) ((width_points * rc->scale) + 0.5);
1854 height = (int) ((height_points * rc->scale) + 0.5);
1856 text_color.red = text->red;
1857 text_color.green = text->green;
1858 text_color.blue = text->blue;
1860 base_color.red = base->red;
1861 base_color.green = base->green;
1862 base_color.blue = base->blue;
1864 if (*surface == NULL) {
1865 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1870 cr = cairo_create (*surface);
1871 cairo_scale (cr, rc->scale, rc->scale);
1872 cairo_surface_set_device_offset (*surface, 0, 0);
1873 memset (cairo_image_surface_get_data (*surface), 0x00,
1874 cairo_image_surface_get_height (*surface) *
1875 cairo_image_surface_get_stride (*surface));
1876 poppler_page_render_selection (poppler_page,
1878 (PopplerRectangle *)points,
1879 (PopplerRectangle *)old_points,
1880 (PopplerSelectionStyle)style,
1887 pdf_selection_get_selected_text (EvSelection *selection,
1889 EvSelectionStyle style,
1890 EvRectangle *points)
1892 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1894 return poppler_page_get_selected_text (POPPLER_PAGE (page->backend_page),
1895 (PopplerSelectionStyle)style,
1896 (PopplerRectangle *)points);
1899 static cairo_region_t *
1900 create_region_from_poppler_region (GList *region, gdouble scale)
1903 cairo_region_t *retval;
1905 retval = cairo_region_create ();
1907 for (l = region; l; l = g_list_next (l)) {
1908 PopplerRectangle *rectangle;
1909 cairo_rectangle_int_t rect;
1911 rectangle = (PopplerRectangle *)l->data;
1913 rect.x = (gint) ((rectangle->x1 * scale) + 0.5);
1914 rect.y = (gint) ((rectangle->y1 * scale) + 0.5);
1915 rect.width = (gint) (((rectangle->x2 - rectangle->x1) * scale) + 0.5);
1916 rect.height = (gint) (((rectangle->y2 - rectangle->y1) * scale) + 0.5);
1917 cairo_region_union_rectangle (retval, &rect);
1919 poppler_rectangle_free (rectangle);
1925 static cairo_region_t *
1926 pdf_selection_get_selection_region (EvSelection *selection,
1927 EvRenderContext *rc,
1928 EvSelectionStyle style,
1929 EvRectangle *points)
1931 PopplerPage *poppler_page;
1932 cairo_region_t *retval;
1935 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1936 region = poppler_page_get_selection_region (poppler_page,
1938 (PopplerSelectionStyle)style,
1939 (PopplerRectangle *) points);
1940 retval = create_region_from_poppler_region (region, rc->scale);
1941 g_list_free (region);
1947 pdf_selection_iface_init (EvSelectionInterface *iface)
1949 iface->render_selection = pdf_selection_render_selection;
1950 iface->get_selected_text = pdf_selection_get_selected_text;
1951 iface->get_selection_region = pdf_selection_get_selection_region;
1955 /* EvDocumentText */
1956 static cairo_region_t *
1957 pdf_document_text_get_text_mapping (EvDocumentText *document_text,
1960 PopplerPage *poppler_page;
1961 PopplerRectangle points;
1963 cairo_region_t *retval;
1965 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1967 poppler_page = POPPLER_PAGE (page->backend_page);
1971 poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
1973 region = poppler_page_get_selection_region (poppler_page, 1.0,
1974 POPPLER_SELECTION_GLYPH,
1976 retval = create_region_from_poppler_region (region, 1.0);
1977 g_list_free (region);
1983 pdf_document_text_get_text (EvDocumentText *selection,
1986 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1988 return poppler_page_get_text (POPPLER_PAGE (page->backend_page));
1992 pdf_document_text_get_text_layout (EvDocumentText *selection,
1994 EvRectangle **areas,
1997 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), FALSE);
1999 return poppler_page_get_text_layout (POPPLER_PAGE (page->backend_page),
2000 (PopplerRectangle **)areas, n_areas);
2004 pdf_document_text_iface_init (EvDocumentTextInterface *iface)
2006 iface->get_text_mapping = pdf_document_text_get_text_mapping;
2007 iface->get_text = pdf_document_text_get_text;
2008 iface->get_text_layout = pdf_document_text_get_text_layout;
2011 /* Page Transitions */
2013 pdf_document_get_page_duration (EvDocumentTransition *trans,
2016 PdfDocument *pdf_document;
2017 PopplerPage *poppler_page;
2018 gdouble duration = -1;
2020 pdf_document = PDF_DOCUMENT (trans);
2021 poppler_page = poppler_document_get_page (pdf_document->document, page);
2025 duration = poppler_page_get_duration (poppler_page);
2026 g_object_unref (poppler_page);
2031 static EvTransitionEffect *
2032 pdf_document_get_effect (EvDocumentTransition *trans,
2035 PdfDocument *pdf_document;
2036 PopplerPage *poppler_page;
2037 PopplerPageTransition *page_transition;
2038 EvTransitionEffect *effect;
2040 pdf_document = PDF_DOCUMENT (trans);
2041 poppler_page = poppler_document_get_page (pdf_document->document, page);
2046 page_transition = poppler_page_get_transition (poppler_page);
2048 if (!page_transition) {
2049 g_object_unref (poppler_page);
2053 /* enums in PopplerPageTransition match the EvTransitionEffect ones */
2054 effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
2055 "alignment", page_transition->alignment,
2056 "direction", page_transition->direction,
2057 "duration", page_transition->duration,
2058 "angle", page_transition->angle,
2059 "scale", page_transition->scale,
2060 "rectangular", page_transition->rectangular,
2063 poppler_page_transition_free (page_transition);
2064 g_object_unref (poppler_page);
2070 pdf_document_page_transition_iface_init (EvDocumentTransitionInterface *iface)
2072 iface->get_page_duration = pdf_document_get_page_duration;
2073 iface->get_effect = pdf_document_get_effect;
2078 pdf_document_get_crop_box (EvDocument *document,
2082 PdfDocument *pdf_document;
2083 PopplerPage *poppler_page;
2084 PopplerRectangle poppler_rect;
2086 pdf_document = PDF_DOCUMENT (document);
2087 poppler_page = poppler_document_get_page (pdf_document->document, page);
2088 poppler_page_get_crop_box (poppler_page, &poppler_rect);
2089 rect->x1 = poppler_rect.x1;
2090 rect->x2 = poppler_rect.x2;
2091 rect->y1 = poppler_rect.y1;
2092 rect->y2 = poppler_rect.y2;
2095 static EvFormField *
2096 ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
2098 EvFormField *ev_field = NULL;
2101 gboolean is_read_only;
2103 id = poppler_form_field_get_id (poppler_field);
2104 font_size = poppler_form_field_get_font_size (poppler_field);
2105 is_read_only = poppler_form_field_is_read_only (poppler_field);
2107 switch (poppler_form_field_get_field_type (poppler_field)) {
2108 case POPPLER_FORM_FIELD_TEXT: {
2109 EvFormFieldText *field_text;
2110 EvFormFieldTextType ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2112 switch (poppler_form_field_text_get_text_type (poppler_field)) {
2113 case POPPLER_FORM_TEXT_NORMAL:
2114 ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2116 case POPPLER_FORM_TEXT_MULTILINE:
2117 ev_text_type = EV_FORM_FIELD_TEXT_MULTILINE;
2119 case POPPLER_FORM_TEXT_FILE_SELECT:
2120 ev_text_type = EV_FORM_FIELD_TEXT_FILE_SELECT;
2124 ev_field = ev_form_field_text_new (id, ev_text_type);
2125 field_text = EV_FORM_FIELD_TEXT (ev_field);
2127 field_text->do_spell_check = poppler_form_field_text_do_spell_check (poppler_field);
2128 field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
2129 field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
2130 field_text->is_password = poppler_form_field_text_is_password (poppler_field);
2131 field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
2132 field_text->text = poppler_form_field_text_get_text (poppler_field);
2136 case POPPLER_FORM_FIELD_BUTTON: {
2137 EvFormFieldButton *field_button;
2138 EvFormFieldButtonType ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2140 switch (poppler_form_field_button_get_button_type (poppler_field)) {
2141 case POPPLER_FORM_BUTTON_PUSH:
2142 ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2144 case POPPLER_FORM_BUTTON_CHECK:
2145 ev_button_type = EV_FORM_FIELD_BUTTON_CHECK;
2147 case POPPLER_FORM_BUTTON_RADIO:
2148 ev_button_type = EV_FORM_FIELD_BUTTON_RADIO;
2152 ev_field = ev_form_field_button_new (id, ev_button_type);
2153 field_button = EV_FORM_FIELD_BUTTON (ev_field);
2155 field_button->state = poppler_form_field_button_get_state (poppler_field);
2158 case POPPLER_FORM_FIELD_CHOICE: {
2159 EvFormFieldChoice *field_choice;
2160 EvFormFieldChoiceType ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2162 switch (poppler_form_field_choice_get_choice_type (poppler_field)) {
2163 case POPPLER_FORM_CHOICE_COMBO:
2164 ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2166 case EV_FORM_FIELD_CHOICE_LIST:
2167 ev_choice_type = EV_FORM_FIELD_CHOICE_LIST;
2171 ev_field = ev_form_field_choice_new (id, ev_choice_type);
2172 field_choice = EV_FORM_FIELD_CHOICE (ev_field);
2174 field_choice->is_editable = poppler_form_field_choice_is_editable (poppler_field);
2175 field_choice->multi_select = poppler_form_field_choice_can_select_multiple (poppler_field);
2176 field_choice->do_spell_check = poppler_form_field_choice_do_spell_check (poppler_field);
2177 field_choice->commit_on_sel_change = poppler_form_field_choice_commit_on_change (poppler_field);
2179 /* TODO: we need poppler_form_field_choice_get_selected_items in poppler
2180 field_choice->selected_items = poppler_form_field_choice_get_selected_items (poppler_field);*/
2181 if (field_choice->is_editable)
2182 field_choice->text = poppler_form_field_choice_get_text (poppler_field);
2185 case POPPLER_FORM_FIELD_SIGNATURE:
2187 ev_field = ev_form_field_signature_new (id);
2189 case POPPLER_FORM_FIELD_UNKNOWN:
2193 ev_field->font_size = font_size;
2194 ev_field->is_read_only = is_read_only;
2199 static EvMappingList *
2200 pdf_document_forms_get_form_fields (EvDocumentForms *document,
2203 PopplerPage *poppler_page;
2204 GList *retval = NULL;
2209 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2211 poppler_page = POPPLER_PAGE (page->backend_page);
2212 fields = poppler_page_get_form_field_mapping (poppler_page);
2213 poppler_page_get_size (poppler_page, NULL, &height);
2215 for (list = fields; list; list = list->next) {
2216 PopplerFormFieldMapping *mapping;
2217 EvMapping *field_mapping;
2218 EvFormField *ev_field;
2220 mapping = (PopplerFormFieldMapping *)list->data;
2222 ev_field = ev_form_field_from_poppler_field (mapping->field);
2226 field_mapping = g_new0 (EvMapping, 1);
2227 field_mapping->area.x1 = mapping->area.x1;
2228 field_mapping->area.x2 = mapping->area.x2;
2229 field_mapping->area.y1 = height - mapping->area.y2;
2230 field_mapping->area.y2 = height - mapping->area.y1;
2231 field_mapping->data = ev_field;
2232 ev_field->page = EV_PAGE (g_object_ref (page));
2234 g_object_set_data_full (G_OBJECT (ev_field),
2236 g_object_ref (mapping->field),
2237 (GDestroyNotify) g_object_unref);
2239 retval = g_list_prepend (retval, field_mapping);
2242 poppler_page_free_form_field_mapping (fields);
2244 return retval ? ev_mapping_list_new (page->index,
2245 g_list_reverse (retval),
2246 (GDestroyNotify)g_object_unref) : NULL;
2250 pdf_document_forms_document_is_modified (EvDocumentForms *document)
2252 return PDF_DOCUMENT (document)->forms_modified;
2256 pdf_document_forms_form_field_text_get_text (EvDocumentForms *document,
2260 PopplerFormField *poppler_field;
2263 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2267 text = poppler_form_field_text_get_text (poppler_field);
2273 pdf_document_forms_form_field_text_set_text (EvDocumentForms *document,
2277 PopplerFormField *poppler_field;
2279 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2283 poppler_form_field_text_set_text (poppler_field, text);
2284 PDF_DOCUMENT (document)->forms_modified = TRUE;
2288 pdf_document_forms_form_field_button_set_state (EvDocumentForms *document,
2292 PopplerFormField *poppler_field;
2294 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2298 poppler_form_field_button_set_state (poppler_field, state);
2299 PDF_DOCUMENT (document)->forms_modified = TRUE;
2303 pdf_document_forms_form_field_button_get_state (EvDocumentForms *document,
2306 PopplerFormField *poppler_field;
2309 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2313 state = poppler_form_field_button_get_state (poppler_field);
2319 pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document,
2323 PopplerFormField *poppler_field;
2326 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2330 text = poppler_form_field_choice_get_item (poppler_field, index);
2336 pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document,
2339 PopplerFormField *poppler_field;
2342 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2346 n_items = poppler_form_field_choice_get_n_items (poppler_field);
2352 pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document,
2356 PopplerFormField *poppler_field;
2359 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2363 selected = poppler_form_field_choice_is_item_selected (poppler_field, index);
2369 pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document,
2373 PopplerFormField *poppler_field;
2375 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2379 poppler_form_field_choice_select_item (poppler_field, index);
2380 PDF_DOCUMENT (document)->forms_modified = TRUE;
2384 pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document,
2388 PopplerFormField *poppler_field;
2390 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2394 poppler_form_field_choice_toggle_item (poppler_field, index);
2395 PDF_DOCUMENT (document)->forms_modified = TRUE;
2399 pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document,
2402 PopplerFormField *poppler_field;
2404 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2408 poppler_form_field_choice_unselect_all (poppler_field);
2409 PDF_DOCUMENT (document)->forms_modified = TRUE;
2413 pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document,
2417 PopplerFormField *poppler_field;
2419 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2423 poppler_form_field_choice_set_text (poppler_field, text);
2424 PDF_DOCUMENT (document)->forms_modified = TRUE;
2428 pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document,
2431 PopplerFormField *poppler_field;
2434 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2438 text = poppler_form_field_choice_get_text (poppler_field);
2444 pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface)
2446 iface->get_form_fields = pdf_document_forms_get_form_fields;
2447 iface->document_is_modified = pdf_document_forms_document_is_modified;
2448 iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
2449 iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
2450 iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
2451 iface->form_field_button_get_state = pdf_document_forms_form_field_button_get_state;
2452 iface->form_field_choice_get_item = pdf_document_forms_form_field_choice_get_item;
2453 iface->form_field_choice_get_n_items = pdf_document_forms_form_field_choice_get_n_items;
2454 iface->form_field_choice_is_item_selected = pdf_document_forms_form_field_choice_is_item_selected;
2455 iface->form_field_choice_select_item = pdf_document_forms_form_field_choice_select_item;
2456 iface->form_field_choice_toggle_item = pdf_document_forms_form_field_choice_toggle_item;
2457 iface->form_field_choice_unselect_all = pdf_document_forms_form_field_choice_unselect_all;
2458 iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
2459 iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;
2464 poppler_annot_color_to_gdk_color (PopplerAnnot *poppler_annot,
2467 PopplerColor *poppler_color;
2469 poppler_color = poppler_annot_get_color (poppler_annot);
2470 if (poppler_color) {
2471 color->red = poppler_color->red;
2472 color->green = poppler_color->green;
2473 color->blue = poppler_color->blue;
2475 g_free (poppler_color);
2476 } /* TODO: else use a default color */
2479 static EvAnnotationTextIcon
2480 get_annot_text_icon (PopplerAnnotText *poppler_annot)
2482 gchar *icon = poppler_annot_text_get_icon (poppler_annot);
2483 EvAnnotationTextIcon retval;
2486 return EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2488 if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_NOTE) == 0)
2489 retval = EV_ANNOTATION_TEXT_ICON_NOTE;
2490 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_COMMENT) == 0)
2491 retval = EV_ANNOTATION_TEXT_ICON_COMMENT;
2492 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_KEY) == 0)
2493 retval = EV_ANNOTATION_TEXT_ICON_KEY;
2494 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_HELP) == 0)
2495 retval = EV_ANNOTATION_TEXT_ICON_HELP;
2496 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH) == 0)
2497 retval = EV_ANNOTATION_TEXT_ICON_NEW_PARAGRAPH;
2498 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_PARAGRAPH) == 0)
2499 retval = EV_ANNOTATION_TEXT_ICON_PARAGRAPH;
2500 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_INSERT) == 0)
2501 retval = EV_ANNOTATION_TEXT_ICON_INSERT;
2502 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_CROSS) == 0)
2503 retval = EV_ANNOTATION_TEXT_ICON_CROSS;
2504 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_CIRCLE) == 0)
2505 retval = EV_ANNOTATION_TEXT_ICON_CIRCLE;
2507 retval = EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2514 static const gchar *
2515 get_poppler_annot_text_icon (EvAnnotationTextIcon icon)
2518 case EV_ANNOTATION_TEXT_ICON_NOTE:
2519 return POPPLER_ANNOT_TEXT_ICON_NOTE;
2520 case EV_ANNOTATION_TEXT_ICON_COMMENT:
2521 return POPPLER_ANNOT_TEXT_ICON_COMMENT;
2522 case EV_ANNOTATION_TEXT_ICON_KEY:
2523 return POPPLER_ANNOT_TEXT_ICON_KEY;
2524 case EV_ANNOTATION_TEXT_ICON_HELP:
2525 return POPPLER_ANNOT_TEXT_ICON_HELP;
2526 case EV_ANNOTATION_TEXT_ICON_NEW_PARAGRAPH:
2527 return POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH;
2528 case EV_ANNOTATION_TEXT_ICON_PARAGRAPH:
2529 return POPPLER_ANNOT_TEXT_ICON_PARAGRAPH;
2530 case EV_ANNOTATION_TEXT_ICON_INSERT:
2531 return POPPLER_ANNOT_TEXT_ICON_INSERT;
2532 case EV_ANNOTATION_TEXT_ICON_CROSS:
2533 return POPPLER_ANNOT_TEXT_ICON_CROSS;
2534 case EV_ANNOTATION_TEXT_ICON_CIRCLE:
2535 return POPPLER_ANNOT_TEXT_ICON_CIRCLE;
2536 case EV_ANNOTATION_TEXT_ICON_UNKNOWN:
2538 return POPPLER_ANNOT_TEXT_ICON_NOTE;
2542 static EvAnnotation *
2543 ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
2546 EvAnnotation *ev_annot = NULL;
2547 const gchar *unimplemented_annot = NULL;
2549 switch (poppler_annot_get_annot_type (poppler_annot)) {
2550 case POPPLER_ANNOT_TEXT: {
2551 PopplerAnnotText *poppler_text;
2552 EvAnnotationText *ev_annot_text;
2554 poppler_text = POPPLER_ANNOT_TEXT (poppler_annot);
2556 ev_annot = ev_annotation_text_new (page);
2558 ev_annot_text = EV_ANNOTATION_TEXT (ev_annot);
2559 ev_annotation_text_set_is_open (ev_annot_text,
2560 poppler_annot_text_get_is_open (poppler_text));
2561 ev_annotation_text_set_icon (ev_annot_text, get_annot_text_icon (poppler_text));
2564 case POPPLER_ANNOT_FILE_ATTACHMENT: {
2565 PopplerAnnotFileAttachment *poppler_annot_attachment;
2566 EvAnnotationAttachment *ev_annot_attachment;
2567 PopplerAttachment *poppler_attachment;
2570 GError *error = NULL;
2572 poppler_annot_attachment = POPPLER_ANNOT_FILE_ATTACHMENT (poppler_annot);
2573 poppler_attachment = poppler_annot_file_attachment_get_attachment (poppler_annot_attachment);
2575 if (poppler_attachment &&
2576 attachment_save_to_buffer (poppler_attachment, &data, &size, &error)) {
2577 EvAttachment *ev_attachment;
2579 ev_attachment = ev_attachment_new (poppler_attachment->name,
2580 poppler_attachment->description,
2581 poppler_attachment->mtime,
2582 poppler_attachment->ctime,
2584 ev_annot = ev_annotation_attachment_new (page, ev_attachment);
2585 g_object_unref (ev_attachment);
2587 g_warning ("%s", error->message);
2588 g_error_free (error);
2591 if (poppler_attachment)
2592 g_object_unref (poppler_attachment);
2595 case POPPLER_ANNOT_LINK:
2596 case POPPLER_ANNOT_WIDGET:
2597 /* Ignore link and widgets annots since they are already handled */
2600 GEnumValue *enum_value;
2602 enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ANNOT_TYPE),
2603 poppler_annot_get_annot_type (poppler_annot));
2604 unimplemented_annot = enum_value ? enum_value->value_name : "Unknown annotation";
2608 if (unimplemented_annot) {
2609 g_warning ("Unimplemented annotation: %s, please post a "
2610 "bug report in Evince bugzilla "
2611 "(http://bugzilla.gnome.org) with a testcase.",
2612 unimplemented_annot);
2622 contents = poppler_annot_get_contents (poppler_annot);
2624 ev_annotation_set_contents (ev_annot, contents);
2628 name = poppler_annot_get_name (poppler_annot);
2630 ev_annotation_set_name (ev_annot, name);
2634 modified = poppler_annot_get_modified (poppler_annot);
2635 if (poppler_date_parse (modified, &utime)) {
2636 ev_annotation_set_modified_from_time (ev_annot, utime);
2638 ev_annotation_set_modified (ev_annot, modified);
2642 poppler_annot_color_to_gdk_color (poppler_annot, &color);
2643 ev_annotation_set_color (ev_annot, &color);
2645 if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
2646 PopplerAnnotMarkup *markup;
2649 PopplerRectangle poppler_rect;
2651 markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2653 if (poppler_annot_markup_get_popup_rectangle (markup, &poppler_rect)) {
2654 EvRectangle ev_rect;
2658 poppler_page_get_size (POPPLER_PAGE (page->backend_page),
2660 ev_rect.x1 = poppler_rect.x1;
2661 ev_rect.x2 = poppler_rect.x2;
2662 ev_rect.y1 = height - poppler_rect.y2;
2663 ev_rect.y2 = height - poppler_rect.y1;
2665 is_open = poppler_annot_markup_get_popup_is_open (markup);
2667 g_object_set (ev_annot,
2668 "rectangle", &ev_rect,
2669 "popup_is_open", is_open,
2673 g_object_set (ev_annot,
2678 label = poppler_annot_markup_get_label (markup);
2679 opacity = poppler_annot_markup_get_opacity (markup);
2681 g_object_set (ev_annot,
2693 static EvMappingList *
2694 pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annotations,
2697 GList *retval = NULL;
2698 PdfDocument *pdf_document;
2699 PopplerPage *poppler_page;
2700 EvMappingList *mapping_list;
2706 pdf_document = PDF_DOCUMENT (document_annotations);
2707 poppler_page = POPPLER_PAGE (page->backend_page);
2709 if (pdf_document->annots) {
2710 mapping_list = (EvMappingList *)g_hash_table_lookup (pdf_document->annots,
2711 GINT_TO_POINTER (page->index));
2713 return ev_mapping_list_ref (mapping_list);
2716 annots = poppler_page_get_annot_mapping (poppler_page);
2717 poppler_page_get_size (poppler_page, NULL, &height);
2719 for (list = annots; list; list = list->next) {
2720 PopplerAnnotMapping *mapping;
2721 EvMapping *annot_mapping;
2722 EvAnnotation *ev_annot;
2724 mapping = (PopplerAnnotMapping *)list->data;
2726 ev_annot = ev_annot_from_poppler_annot (mapping->annot, page);
2732 /* Make sure annot has a unique name */
2733 if (!ev_annotation_get_name (ev_annot)) {
2734 gchar *name = g_strdup_printf ("annot-%d-%d", page->index, i);
2736 ev_annotation_set_name (ev_annot, name);
2740 annot_mapping = g_new (EvMapping, 1);
2741 annot_mapping->area.x1 = mapping->area.x1;
2742 annot_mapping->area.x2 = mapping->area.x2;
2743 annot_mapping->area.y1 = height - mapping->area.y2;
2744 annot_mapping->area.y2 = height - mapping->area.y1;
2745 annot_mapping->data = ev_annot;
2747 g_object_set_data_full (G_OBJECT (ev_annot),
2749 g_object_ref (mapping->annot),
2750 (GDestroyNotify) g_object_unref);
2752 retval = g_list_prepend (retval, annot_mapping);
2755 poppler_page_free_annot_mapping (annots);
2760 if (!pdf_document->annots) {
2761 pdf_document->annots = g_hash_table_new_full (g_direct_hash,
2763 (GDestroyNotify)NULL,
2764 (GDestroyNotify)ev_mapping_list_unref);
2767 mapping_list = ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
2768 g_hash_table_insert (pdf_document->annots,
2769 GINT_TO_POINTER (page->index),
2770 ev_mapping_list_ref (mapping_list));
2772 return mapping_list;
2776 pdf_document_annotations_document_is_modified (EvDocumentAnnotations *document_annotations)
2778 return PDF_DOCUMENT (document_annotations)->annots_modified;
2782 pdf_document_annotations_add_annotation (EvDocumentAnnotations *document_annotations,
2783 EvAnnotation *annot,
2786 PopplerAnnot *poppler_annot;
2787 PdfDocument *pdf_document;
2789 PopplerPage *poppler_page;
2791 EvMappingList *mapping_list;
2792 EvMapping *annot_mapping;
2793 PopplerRectangle poppler_rect;
2795 PopplerColor poppler_color;
2801 pdf_document = PDF_DOCUMENT (document_annotations);
2802 page = ev_annotation_get_page (annot);
2803 poppler_page = POPPLER_PAGE (page->backend_page);
2805 poppler_page_get_size (poppler_page, NULL, &height);
2806 poppler_rect.x1 = rect->x1;
2807 poppler_rect.x2 = rect->x2;
2808 poppler_rect.y1 = height - rect->y2;
2809 poppler_rect.y2 = height - rect->y1;
2810 poppler_annot = poppler_annot_text_new (pdf_document->document, &poppler_rect);
2812 ev_annotation_get_color (annot, &color);
2813 poppler_color.red = color.red;
2814 poppler_color.green = color.green;
2815 poppler_color.blue = color.blue;
2816 poppler_annot_set_color (poppler_annot, &poppler_color);
2818 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2819 EvAnnotationMarkup *markup = EV_ANNOTATION_MARKUP (annot);
2822 if (ev_annotation_markup_has_popup (markup)) {
2823 EvRectangle popup_rect;
2825 ev_annotation_markup_get_rectangle (markup, &popup_rect);
2826 poppler_rect.x1 = popup_rect.x1;
2827 poppler_rect.x2 = popup_rect.x2;
2828 poppler_rect.y1 = height - popup_rect.y2;
2829 poppler_rect.y2 = height - popup_rect.y1;
2830 poppler_annot_markup_set_popup (POPPLER_ANNOT_MARKUP (poppler_annot), &poppler_rect);
2831 poppler_annot_markup_set_popup_is_open (POPPLER_ANNOT_MARKUP (poppler_annot),
2832 ev_annotation_markup_get_popup_is_open (markup));
2835 label = ev_annotation_markup_get_label (markup);
2837 poppler_annot_markup_set_label (POPPLER_ANNOT_MARKUP (poppler_annot), label);
2840 if (EV_IS_ANNOTATION_TEXT (annot)) {
2841 EvAnnotationText *text = EV_ANNOTATION_TEXT (annot);
2842 EvAnnotationTextIcon icon;
2844 icon = ev_annotation_text_get_icon (text);
2845 poppler_annot_text_set_icon (POPPLER_ANNOT_TEXT (poppler_annot),
2846 get_poppler_annot_text_icon (icon));
2848 poppler_page_add_annot (poppler_page, poppler_annot);
2850 annot_mapping = g_new (EvMapping, 1);
2851 annot_mapping->area = *rect;
2852 annot_mapping->data = annot;
2853 g_object_set_data_full (G_OBJECT (annot),
2855 g_object_ref (poppler_annot),
2856 (GDestroyNotify) g_object_unref);
2858 if (pdf_document->annots) {
2859 mapping_list = (EvMappingList *)g_hash_table_lookup (pdf_document->annots,
2860 GINT_TO_POINTER (page->index));
2861 list = ev_mapping_list_get_list (mapping_list);
2862 name = g_strdup_printf ("annot-%d-%d", page->index, g_list_length (list) + 1);
2863 ev_annotation_set_name (annot, name);
2865 list = g_list_append (list, annot_mapping);
2867 pdf_document->annots = g_hash_table_new_full (g_direct_hash,
2869 (GDestroyNotify)NULL,
2870 (GDestroyNotify)ev_mapping_list_unref);
2871 name = g_strdup_printf ("annot-%d-0", page->index);
2872 ev_annotation_set_name (annot, name);
2874 list = g_list_append (list, annot_mapping);
2875 mapping_list = ev_mapping_list_new (page->index, list, (GDestroyNotify)g_object_unref);
2876 g_hash_table_insert (pdf_document->annots,
2877 GINT_TO_POINTER (page->index),
2878 ev_mapping_list_ref (mapping_list));
2881 pdf_document->annots_modified = TRUE;
2885 pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annotations,
2886 EvAnnotation *annot,
2887 EvAnnotationsSaveMask mask)
2889 PopplerAnnot *poppler_annot;
2891 poppler_annot = POPPLER_ANNOT (g_object_get_data (G_OBJECT (annot), "poppler-annot"));
2895 if (mask & EV_ANNOTATIONS_SAVE_CONTENTS)
2896 poppler_annot_set_contents (poppler_annot,
2897 ev_annotation_get_contents (annot));
2899 if (mask & EV_ANNOTATIONS_SAVE_COLOR) {
2903 ev_annotation_get_color (annot, &ev_color);
2904 color.red = ev_color.red;
2905 color.green = ev_color.green;
2906 color.blue = ev_color.blue;
2907 poppler_annot_set_color (poppler_annot, &color);
2910 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2911 EvAnnotationMarkup *ev_markup = EV_ANNOTATION_MARKUP (annot);
2912 PopplerAnnotMarkup *markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2914 if (mask & EV_ANNOTATIONS_SAVE_LABEL)
2915 poppler_annot_markup_set_label (markup, ev_annotation_markup_get_label (ev_markup));
2916 if (mask & EV_ANNOTATIONS_SAVE_OPACITY)
2917 poppler_annot_markup_set_opacity (markup, ev_annotation_markup_get_opacity (ev_markup));
2918 if (mask & EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN)
2919 poppler_annot_markup_set_popup_is_open (markup, ev_annotation_markup_get_popup_is_open (ev_markup));
2922 if (EV_IS_ANNOTATION_TEXT (annot)) {
2923 EvAnnotationText *ev_text = EV_ANNOTATION_TEXT (annot);
2924 PopplerAnnotText *text = POPPLER_ANNOT_TEXT (poppler_annot);
2926 if (mask & EV_ANNOTATIONS_SAVE_TEXT_IS_OPEN) {
2927 poppler_annot_text_set_is_open (text,
2928 ev_annotation_text_get_is_open (ev_text));
2930 if (mask & EV_ANNOTATIONS_SAVE_TEXT_ICON) {
2931 EvAnnotationTextIcon icon;
2933 icon = ev_annotation_text_get_icon (ev_text);
2934 poppler_annot_text_set_icon (text, get_poppler_annot_text_icon (icon));
2938 PDF_DOCUMENT (document_annotations)->annots_modified = TRUE;
2942 pdf_document_document_annotations_iface_init (EvDocumentAnnotationsInterface *iface)
2944 iface->get_annotations = pdf_document_annotations_get_annotations;
2945 iface->document_is_modified = pdf_document_annotations_document_is_modified;
2946 iface->add_annotation = pdf_document_annotations_add_annotation;
2947 iface->save_annotation = pdf_document_annotations_save_annotation;
2951 struct SaveToBufferData {
2957 attachment_save_to_buffer_callback (const gchar *buf,
2962 struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
2966 if (sdata->len + count > sdata->max) {
2967 new_max = MAX (sdata->max * 2, sdata->len + count);
2968 new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
2970 sdata->buffer = new_buffer;
2971 sdata->max = new_max;
2974 memcpy (sdata->buffer + sdata->len, buf, count);
2975 sdata->len += count;
2981 attachment_save_to_buffer (PopplerAttachment *attachment,
2986 static const gint initial_max = 1024;
2987 struct SaveToBufferData sdata;
2992 sdata.buffer = (gchar *) g_malloc (initial_max);
2993 sdata.max = initial_max;
2996 if (! poppler_attachment_save_to_callback (attachment,
2997 attachment_save_to_buffer_callback,
3000 g_free (sdata.buffer);
3004 *buffer = sdata.buffer;
3005 *buffer_size = sdata.len;
3011 pdf_document_attachments_get_attachments (EvDocumentAttachments *document)
3013 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3016 GList *retval = NULL;
3018 attachments = poppler_document_get_attachments (pdf_document->document);
3020 for (list = attachments; list; list = list->next) {
3021 PopplerAttachment *attachment;
3022 EvAttachment *ev_attachment;
3025 GError *error = NULL;
3027 attachment = (PopplerAttachment *) list->data;
3029 if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
3030 ev_attachment = ev_attachment_new (attachment->name,
3031 attachment->description,
3036 retval = g_list_prepend (retval, ev_attachment);
3039 g_warning ("%s", error->message);
3040 g_error_free (error);
3046 g_object_unref (attachment);
3049 return g_list_reverse (retval);
3053 pdf_document_attachments_has_attachments (EvDocumentAttachments *document)
3055 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3057 return poppler_document_has_attachments (pdf_document->document);
3061 pdf_document_document_attachments_iface_init (EvDocumentAttachmentsInterface *iface)
3063 iface->has_attachments = pdf_document_attachments_has_attachments;
3064 iface->get_attachments = pdf_document_attachments_get_attachments;
3069 pdf_document_layers_has_layers (EvDocumentLayers *document)
3071 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3072 PopplerLayersIter *iter;
3074 iter = poppler_layers_iter_new (pdf_document->document);
3077 poppler_layers_iter_free (iter);
3083 build_layers_tree (PdfDocument *pdf_document,
3084 GtkTreeModel *model,
3085 GtkTreeIter *parent,
3086 PopplerLayersIter *iter)
3089 GtkTreeIter tree_iter;
3090 PopplerLayersIter *child;
3091 PopplerLayer *layer;
3092 EvLayer *ev_layer = NULL;
3097 layer = poppler_layers_iter_get_layer (iter);
3099 markup = g_markup_escape_text (poppler_layer_get_title (layer), -1);
3100 visible = poppler_layer_is_visible (layer);
3101 rb_group = poppler_layer_get_radio_button_group_id (layer);
3102 ev_layer = ev_layer_new (poppler_layer_is_parent (layer),
3104 g_object_set_data_full (G_OBJECT (ev_layer),
3106 g_object_ref (layer),
3107 (GDestroyNotify) g_object_unref);
3111 title = poppler_layers_iter_get_title (iter);
3112 markup = g_markup_escape_text (title, -1);
3119 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
3120 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
3121 EV_DOCUMENT_LAYERS_COLUMN_TITLE, markup,
3122 EV_DOCUMENT_LAYERS_COLUMN_VISIBLE, visible,
3123 EV_DOCUMENT_LAYERS_COLUMN_ENABLED, TRUE, /* FIXME */
3124 EV_DOCUMENT_LAYERS_COLUMN_SHOWTOGGLE, (layer != NULL),
3125 EV_DOCUMENT_LAYERS_COLUMN_RBGROUP, rb_group,
3126 EV_DOCUMENT_LAYERS_COLUMN_LAYER, ev_layer,
3129 g_object_unref (ev_layer);
3132 child = poppler_layers_iter_get_child (iter);
3134 build_layers_tree (pdf_document, model, &tree_iter, child);
3135 poppler_layers_iter_free (child);
3136 } while (poppler_layers_iter_next (iter));
3139 static GtkTreeModel *
3140 pdf_document_layers_get_layers (EvDocumentLayers *document)
3142 GtkTreeModel *model = NULL;
3143 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3144 PopplerLayersIter *iter;
3146 iter = poppler_layers_iter_new (pdf_document->document);
3148 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LAYERS_N_COLUMNS,
3149 G_TYPE_STRING, /* TITLE */
3150 G_TYPE_OBJECT, /* LAYER */
3151 G_TYPE_BOOLEAN, /* VISIBLE */
3152 G_TYPE_BOOLEAN, /* ENABLED */
3153 G_TYPE_BOOLEAN, /* SHOWTOGGLE */
3154 G_TYPE_INT); /* RBGROUP */
3155 build_layers_tree (pdf_document, model, NULL, iter);
3156 poppler_layers_iter_free (iter);
3162 pdf_document_layers_show_layer (EvDocumentLayers *document,
3165 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3166 PopplerLayer *poppler_layer;
3168 poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer"));
3169 poppler_layer_show (poppler_layer);
3173 pdf_document_layers_hide_layer (EvDocumentLayers *document,
3176 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3177 PopplerLayer *poppler_layer;
3179 poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer"));
3180 poppler_layer_hide (poppler_layer);
3184 pdf_document_layers_layer_is_visible (EvDocumentLayers *document,
3187 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3188 PopplerLayer *poppler_layer;
3190 poppler_layer = POPPLER_LAYER (g_object_get_data (G_OBJECT (layer), "poppler-layer"));
3191 return poppler_layer_is_visible (poppler_layer);
3195 pdf_document_document_layers_iface_init (EvDocumentLayersInterface *iface)
3197 iface->has_layers = pdf_document_layers_has_layers;
3198 iface->get_layers = pdf_document_layers_get_layers;
3199 iface->show_layer = pdf_document_layers_show_layer;
3200 iface->hide_layer = pdf_document_layers_hide_layer;
3201 iface->layer_is_visible = pdf_document_layers_layer_is_visible;