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-thumbnails.h"
47 #include "ev-document-transition.h"
48 #include "ev-document-forms.h"
49 #include "ev-document-layers.h"
50 #include "ev-document-print.h"
51 #include "ev-document-annotations.h"
52 #include "ev-document-attachments.h"
53 #include "ev-document-text.h"
54 #include "ev-selection.h"
55 #include "ev-transition-effect.h"
56 #include "ev-attachment.h"
59 #include <libxml/tree.h>
60 #include <libxml/parser.h>
61 #include <libxml/xpath.h>
62 #include <libxml/xpathInternals.h>
64 #if (defined (HAVE_CAIRO_PDF) || defined (HAVE_CAIRO_PS))
65 #define HAVE_CAIRO_PRINT
68 /* fields from the XMP Rights Management Schema, XMP Specification Sept 2005, pag. 45 */
69 #define LICENSE_MARKED "/x:xmpmeta/rdf:RDF/rdf:Description/xmpRights:Marked"
70 #define LICENSE_TEXT "/x:xmpmeta/rdf:RDF/rdf:Description/dc:rights/rdf:Alt/rdf:li[lang('%s')]"
71 #define LICENSE_WEB_STATEMENT "/x:xmpmeta/rdf:RDF/rdf:Description/xmpRights:WebStatement"
72 /* license field from Creative Commons schema, http://creativecommons.org/ns */
73 #define LICENSE_URI "/x:xmpmeta/rdf:RDF/rdf:Description/cc:license/@rdf:resource"
76 EvFileExporterFormat format;
86 #ifdef HAVE_CAIRO_PRINT
89 PopplerPSFile *ps_file;
93 struct _PdfDocumentClass
95 EvDocumentClass parent_class;
100 EvDocument parent_instance;
102 PopplerDocument *document;
104 gboolean forms_modified;
105 gboolean annots_modified;
107 PopplerFontInfo *font_info;
108 PopplerFontsIter *fonts_iter;
109 int fonts_scanned_pages;
111 PdfPrintContext *print_ctx;
117 static void pdf_document_security_iface_init (EvDocumentSecurityInterface *iface);
118 static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface);
119 static void pdf_document_document_links_iface_init (EvDocumentLinksInterface *iface);
120 static void pdf_document_document_images_iface_init (EvDocumentImagesInterface *iface);
121 static void pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface);
122 static void pdf_document_document_fonts_iface_init (EvDocumentFontsInterface *iface);
123 static void pdf_document_document_layers_iface_init (EvDocumentLayersInterface *iface);
124 static void pdf_document_document_print_iface_init (EvDocumentPrintInterface *iface);
125 static void pdf_document_document_annotations_iface_init (EvDocumentAnnotationsInterface *iface);
126 static void pdf_document_document_attachments_iface_init (EvDocumentAttachmentsInterface *iface);
127 static void pdf_document_find_iface_init (EvDocumentFindInterface *iface);
128 static void pdf_document_file_exporter_iface_init (EvFileExporterInterface *iface);
129 static void pdf_selection_iface_init (EvSelectionInterface *iface);
130 static void pdf_document_page_transition_iface_init (EvDocumentTransitionInterface *iface);
131 static void pdf_document_text_iface_init (EvDocumentTextInterface *iface);
132 static int pdf_document_get_n_pages (EvDocument *document);
134 static EvLinkDest *ev_link_dest_from_dest (PdfDocument *pdf_document,
136 static EvLink *ev_link_from_action (PdfDocument *pdf_document,
137 PopplerAction *action);
138 static void pdf_print_context_free (PdfPrintContext *ctx);
139 static gboolean attachment_save_to_buffer (PopplerAttachment *attachment,
144 EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
146 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
147 pdf_document_security_iface_init);
148 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
149 pdf_document_document_thumbnails_iface_init);
150 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
151 pdf_document_document_links_iface_init);
152 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES,
153 pdf_document_document_images_iface_init);
154 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FORMS,
155 pdf_document_document_forms_iface_init);
156 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS,
157 pdf_document_document_fonts_iface_init);
158 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LAYERS,
159 pdf_document_document_layers_iface_init);
160 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_PRINT,
161 pdf_document_document_print_iface_init);
162 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ANNOTATIONS,
163 pdf_document_document_annotations_iface_init);
164 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ATTACHMENTS,
165 pdf_document_document_attachments_iface_init);
166 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
167 pdf_document_find_iface_init);
168 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
169 pdf_document_file_exporter_iface_init);
170 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION,
171 pdf_selection_iface_init);
172 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
173 pdf_document_page_transition_iface_init);
174 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TEXT,
175 pdf_document_text_iface_init);
179 pdf_document_dispose (GObject *object)
181 PdfDocument *pdf_document = PDF_DOCUMENT(object);
183 if (pdf_document->print_ctx) {
184 pdf_print_context_free (pdf_document->print_ctx);
185 pdf_document->print_ctx = NULL;
188 if (pdf_document->annots) {
189 g_hash_table_destroy (pdf_document->annots);
190 pdf_document->annots = NULL;
193 if (pdf_document->document) {
194 g_object_unref (pdf_document->document);
197 if (pdf_document->font_info) {
198 poppler_font_info_free (pdf_document->font_info);
201 if (pdf_document->fonts_iter) {
202 poppler_fonts_iter_free (pdf_document->fonts_iter);
205 if (pdf_document->layers) {
206 g_list_foreach (pdf_document->layers, (GFunc)g_object_unref, NULL);
207 g_list_free (pdf_document->layers);
210 G_OBJECT_CLASS (pdf_document_parent_class)->dispose (object);
214 pdf_document_init (PdfDocument *pdf_document)
216 pdf_document->password = NULL;
220 convert_error (GError *poppler_error,
223 if (poppler_error == NULL)
226 if (poppler_error->domain == POPPLER_ERROR) {
227 /* convert poppler errors into EvDocument errors */
228 gint code = EV_DOCUMENT_ERROR_INVALID;
229 if (poppler_error->code == POPPLER_ERROR_INVALID)
230 code = EV_DOCUMENT_ERROR_INVALID;
231 else if (poppler_error->code == POPPLER_ERROR_ENCRYPTED)
232 code = EV_DOCUMENT_ERROR_ENCRYPTED;
234 g_set_error_literal (error,
237 poppler_error->message);
239 g_error_free (poppler_error);
241 g_propagate_error (error, poppler_error);
248 pdf_document_save (EvDocument *document,
252 PdfDocument *pdf_document = PDF_DOCUMENT (document);
254 GError *poppler_error = NULL;
256 if (pdf_document->forms_modified || pdf_document->annots_modified) {
257 retval = poppler_document_save (pdf_document->document,
258 uri, &poppler_error);
260 pdf_document->forms_modified = FALSE;
261 pdf_document->annots_modified = FALSE;
264 retval = poppler_document_save_a_copy (pdf_document->document,
265 uri, &poppler_error);
269 convert_error (poppler_error, error);
275 pdf_document_load (EvDocument *document,
279 GError *poppler_error = NULL;
280 PdfDocument *pdf_document = PDF_DOCUMENT (document);
282 pdf_document->document =
283 poppler_document_new_from_file (uri, pdf_document->password, &poppler_error);
285 if (pdf_document->document == NULL) {
286 convert_error (poppler_error, error);
294 pdf_document_get_n_pages (EvDocument *document)
296 return poppler_document_get_n_pages (PDF_DOCUMENT (document)->document);
300 pdf_document_get_page (EvDocument *document,
303 PdfDocument *pdf_document = PDF_DOCUMENT (document);
304 PopplerPage *poppler_page;
307 poppler_page = poppler_document_get_page (pdf_document->document, index);
308 page = ev_page_new (index);
309 page->backend_page = (EvBackendPage)g_object_ref (poppler_page);
310 page->backend_destroy_func = (EvBackendPageDestroyFunc)g_object_unref;
311 g_object_unref (poppler_page);
317 pdf_document_get_page_size (EvDocument *document,
322 g_return_if_fail (POPPLER_IS_PAGE (page->backend_page));
324 poppler_page_get_size (POPPLER_PAGE (page->backend_page), width, height);
328 pdf_document_get_page_label (EvDocument *document,
333 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
335 g_object_get (G_OBJECT (page->backend_page),
341 static cairo_surface_t *
342 pdf_page_render (PopplerPage *page,
347 cairo_surface_t *surface;
350 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
352 cr = cairo_create (surface);
354 switch (rc->rotation) {
356 cairo_translate (cr, width, 0);
359 cairo_translate (cr, width, height);
362 cairo_translate (cr, 0, height);
365 cairo_translate (cr, 0, 0);
367 cairo_scale (cr, rc->scale, rc->scale);
368 cairo_rotate (cr, rc->rotation * G_PI / 180.0);
369 poppler_page_render (page, cr);
371 cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
372 cairo_set_source_rgb (cr, 1., 1., 1.);
380 static cairo_surface_t *
381 pdf_document_render (EvDocument *document,
384 PdfDocument *pdf_document;
385 PopplerPage *poppler_page;
386 double width_points, height_points;
389 poppler_page = POPPLER_PAGE (rc->page->backend_page);
391 poppler_page_get_size (poppler_page,
392 &width_points, &height_points);
394 if (rc->rotation == 90 || rc->rotation == 270) {
395 width = (int) ((height_points * rc->scale) + 0.5);
396 height = (int) ((width_points * rc->scale) + 0.5);
398 width = (int) ((width_points * rc->scale) + 0.5);
399 height = (int) ((height_points * rc->scale) + 0.5);
402 return pdf_page_render (poppler_page,
407 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 */
409 pdf_document_get_format_from_metadata (xmlDocPtr doc,
410 xmlXPathContextPtr xpathCtx)
412 xmlXPathObjectPtr xpathObj;
413 xmlChar *part = NULL;
414 xmlChar *conf = NULL;
418 /* add pdf/a namespaces */
419 xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
420 xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
421 xmlXPathRegisterNs (xpathCtx, BAD_CAST "pdfaid", BAD_CAST "http://www.aiim.org/pdfa/ns/id/");
423 /* reads pdf/a part */
424 /* first syntax: child node */
425 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:part", xpathCtx);
426 if (xpathObj != NULL) {
427 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
428 part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
430 xmlXPathFreeObject (xpathObj);
433 /* second syntax: attribute */
434 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:part", xpathCtx);
435 if (xpathObj != NULL) {
436 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
437 part = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
439 xmlXPathFreeObject (xpathObj);
443 /* reads pdf/a conformance */
444 /* first syntax: child node */
445 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/pdfaid:conformance", xpathCtx);
446 if (xpathObj != NULL) {
447 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
448 conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
450 xmlXPathFreeObject (xpathObj);
453 /* second syntax: attribute */
454 xpathObj = xmlXPathEvalExpression (BAD_CAST "/x:xmpmeta/rdf:RDF/rdf:Description/@pdfaid:conformance", xpathCtx);
455 if (xpathObj != NULL) {
456 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
457 conf = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
459 xmlXPathFreeObject (xpathObj);
463 if (part != NULL && conf != NULL) {
464 /* makes conf lowercase */
465 for (i = 0; conf[i]; i++)
466 conf[i] = g_ascii_tolower (conf[i]);
469 result = g_strdup_printf ("PDF/A - %s%s", part, conf);
479 static EvDocumentLicense *
480 pdf_document_get_license_from_metadata (xmlDocPtr doc,
481 xmlXPathContextPtr xpathCtx)
483 xmlXPathObjectPtr xpathObj;
484 xmlChar *marked = NULL;
485 const char *language_string;
488 gchar *tag, *tag_aux;
490 EvDocumentLicense *license;
492 /* register namespaces */
493 xmlXPathRegisterNs (xpathCtx, BAD_CAST "x", BAD_CAST "adobe:ns:meta/");
494 xmlXPathRegisterNs (xpathCtx, BAD_CAST "rdf", BAD_CAST "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
495 xmlXPathRegisterNs (xpathCtx, BAD_CAST "dc", BAD_CAST "http://purl.org/dc/elements/1.1/");
496 /* XMP Rights Management Schema */
497 xmlXPathRegisterNs (xpathCtx, BAD_CAST "xmpRights", BAD_CAST "http://ns.adobe.com/xap/1.0/rights/");
498 /* Creative Commons Schema */
499 xmlXPathRegisterNs (xpathCtx, BAD_CAST "cc", BAD_CAST "http://creativecommons.org/ns#");
501 /* checking if the document has been marked as defined on the XMP Rights
502 * Management Schema */
503 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_MARKED, xpathCtx);
504 if (xpathObj != NULL) {
505 if (xpathObj->nodesetval != NULL &&
506 xpathObj->nodesetval->nodeNr != 0)
507 marked = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
508 xmlXPathFreeObject (xpathObj);
511 /* a) Not marked => No XMP Rights information */
517 license = ev_document_license_new ();
519 /* b) Marked False => Public Domain, no copyrighted material and no
521 if (g_strrstr ((char *) marked, "False") != NULL) {
522 license->text = g_strdup (_("This work is in the Public Domain"));
523 /* c) Marked True => Copyrighted material */
525 /* Checking usage terms as defined by the XMP Rights Management
526 * Schema. This field is recomended to be checked by Creative
528 /* 1) checking for a suitable localized string */
529 language_string = pango_language_to_string (gtk_get_default_language ());
530 tags = g_strsplit (language_string, "-", -1);
531 i = g_strv_length (tags);
532 while (i-- && !license->text) {
533 tag = g_strdup (tags[0]);
534 for (j = 1; j <= i; j++) {
535 tag_aux = g_strdup_printf ("%s-%s", tag, tags[j]);
539 aux = g_strdup_printf (LICENSE_TEXT, tag);
540 xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
541 if (xpathObj != NULL) {
542 if (xpathObj->nodesetval != NULL &&
543 xpathObj->nodesetval->nodeNr != 0)
544 license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
545 xmlXPathFreeObject (xpathObj);
552 /* 2) if not, use the default string */
553 if (!license->text) {
554 aux = g_strdup_printf (LICENSE_TEXT, "x-default");
555 xpathObj = xmlXPathEvalExpression (BAD_CAST aux, xpathCtx);
556 if (xpathObj != NULL) {
557 if (xpathObj->nodesetval != NULL &&
558 xpathObj->nodesetval->nodeNr != 0)
559 license->text = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
560 xmlXPathFreeObject (xpathObj);
565 /* Checking the license URI as defined by the Creative Commons
566 * Schema. This field is recomended to be checked by Creative
568 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_URI, xpathCtx);
569 if (xpathObj != NULL) {
570 if (xpathObj->nodesetval != NULL &&
571 xpathObj->nodesetval->nodeNr != 0)
572 license->uri = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
573 xmlXPathFreeObject (xpathObj);
576 /* Checking the web statement as defined by the XMP Rights
577 * Management Schema. Checking it out is a sort of above-and-beyond
578 * the basic recommendations by Creative Commons. It can be
579 * considered as a "reinforcement" approach to add certainty. */
580 xpathObj = xmlXPathEvalExpression (BAD_CAST LICENSE_WEB_STATEMENT, xpathCtx);
581 if (xpathObj != NULL) {
582 if (xpathObj->nodesetval != NULL &&
583 xpathObj->nodesetval->nodeNr != 0)
584 license->web_statement = (gchar *)xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
585 xmlXPathFreeObject (xpathObj);
590 if (!license->text && !license->uri && !license->web_statement) {
591 ev_document_license_free (license);
599 pdf_document_parse_metadata (const gchar *metadata,
600 EvDocumentInfo *info)
603 xmlXPathContextPtr xpathCtx;
606 doc = xmlParseMemory (metadata, strlen (metadata));
608 return; /* invalid xml metadata */
610 xpathCtx = xmlXPathNewContext (doc);
611 if (xpathCtx == NULL) {
613 return; /* invalid xpath context */
616 fmt = pdf_document_get_format_from_metadata (doc, xpathCtx);
618 g_free (info->format);
622 info->license = pdf_document_get_license_from_metadata (doc, xpathCtx);
624 xmlXPathFreeContext (xpathCtx);
629 static EvDocumentInfo *
630 pdf_document_get_info (EvDocument *document)
632 EvDocumentInfo *info;
633 PopplerPageLayout layout;
634 PopplerPageMode mode;
635 PopplerViewerPreferences view_prefs;
636 PopplerPermissions permissions;
640 info = g_new0 (EvDocumentInfo, 1);
642 info->fields_mask = EV_DOCUMENT_INFO_TITLE |
643 EV_DOCUMENT_INFO_FORMAT |
644 EV_DOCUMENT_INFO_AUTHOR |
645 EV_DOCUMENT_INFO_SUBJECT |
646 EV_DOCUMENT_INFO_KEYWORDS |
647 EV_DOCUMENT_INFO_LAYOUT |
648 EV_DOCUMENT_INFO_START_MODE |
649 EV_DOCUMENT_INFO_PERMISSIONS |
650 EV_DOCUMENT_INFO_UI_HINTS |
651 EV_DOCUMENT_INFO_CREATOR |
652 EV_DOCUMENT_INFO_PRODUCER |
653 EV_DOCUMENT_INFO_CREATION_DATE |
654 EV_DOCUMENT_INFO_MOD_DATE |
655 EV_DOCUMENT_INFO_LINEARIZED |
656 EV_DOCUMENT_INFO_N_PAGES |
657 EV_DOCUMENT_INFO_SECURITY |
658 EV_DOCUMENT_INFO_PAPER_SIZE |
659 EV_DOCUMENT_INFO_LICENSE;
661 g_object_get (PDF_DOCUMENT (document)->document,
662 "title", &(info->title),
663 "format", &(info->format),
664 "author", &(info->author),
665 "subject", &(info->subject),
666 "keywords", &(info->keywords),
668 "page-layout", &layout,
669 "viewer-preferences", &view_prefs,
670 "permissions", &permissions,
671 "creator", &(info->creator),
672 "producer", &(info->producer),
673 "creation-date", &(info->creation_date),
674 "mod-date", &(info->modified_date),
675 "linearized", &(info->linearized),
676 "metadata", &metadata,
679 if (metadata != NULL) {
680 pdf_document_parse_metadata (metadata, info);
684 info->n_pages = ev_document_get_n_pages (document);
686 if (info->n_pages > 0) {
687 ev_document_get_page_size (document, 0,
688 &(info->paper_width),
689 &(info->paper_height));
691 info->paper_width = info->paper_width / 72.0f * 25.4f;
692 info->paper_height = info->paper_height / 72.0f * 25.4f;
696 case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
697 info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
699 case POPPLER_PAGE_LAYOUT_ONE_COLUMN:
700 info->layout = EV_DOCUMENT_LAYOUT_ONE_COLUMN;
702 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_LEFT:
703 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_LEFT;
705 case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
706 info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
707 case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
708 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
710 case POPPLER_PAGE_LAYOUT_TWO_PAGE_RIGHT:
711 info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_RIGHT;
718 case POPPLER_PAGE_MODE_NONE:
719 info->mode = EV_DOCUMENT_MODE_NONE;
721 case POPPLER_PAGE_MODE_USE_THUMBS:
722 info->mode = EV_DOCUMENT_MODE_USE_THUMBS;
724 case POPPLER_PAGE_MODE_USE_OC:
725 info->mode = EV_DOCUMENT_MODE_USE_OC;
727 case POPPLER_PAGE_MODE_FULL_SCREEN:
728 info->mode = EV_DOCUMENT_MODE_FULL_SCREEN;
730 case POPPLER_PAGE_MODE_USE_ATTACHMENTS:
731 info->mode = EV_DOCUMENT_MODE_USE_ATTACHMENTS;
737 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_TOOLBAR) {
738 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_TOOLBAR;
740 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_MENUBAR) {
741 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_MENUBAR;
743 if (view_prefs & POPPLER_VIEWER_PREFERENCES_HIDE_WINDOWUI) {
744 info->ui_hints |= EV_DOCUMENT_UI_HINT_HIDE_WINDOWUI;
746 if (view_prefs & POPPLER_VIEWER_PREFERENCES_FIT_WINDOW) {
747 info->ui_hints |= EV_DOCUMENT_UI_HINT_FIT_WINDOW;
749 if (view_prefs & POPPLER_VIEWER_PREFERENCES_CENTER_WINDOW) {
750 info->ui_hints |= EV_DOCUMENT_UI_HINT_CENTER_WINDOW;
752 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DISPLAY_DOC_TITLE) {
753 info->ui_hints |= EV_DOCUMENT_UI_HINT_DISPLAY_DOC_TITLE;
755 if (view_prefs & POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL) {
756 info->ui_hints |= EV_DOCUMENT_UI_HINT_DIRECTION_RTL;
759 info->permissions = 0;
760 if (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT) {
761 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT;
763 if (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY) {
764 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY;
766 if (permissions & POPPLER_PERMISSIONS_OK_TO_COPY) {
767 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_COPY;
769 if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) {
770 info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES;
773 if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
774 /* translators: this is the document security state */
775 info->security = g_strdup (_("Yes"));
777 /* translators: this is the document security state */
778 info->security = g_strdup (_("No"));
785 pdf_document_get_backend_info (EvDocument *document, EvDocumentBackendInfo *info)
787 PopplerBackend backend;
789 backend = poppler_get_backend ();
791 case POPPLER_BACKEND_CAIRO:
792 info->name = "poppler/cairo";
794 case POPPLER_BACKEND_SPLASH:
795 info->name = "poppler/splash";
798 info->name = "poppler/unknown";
802 info->version = poppler_get_version ();
808 pdf_document_support_synctex (EvDocument *document)
814 pdf_document_class_init (PdfDocumentClass *klass)
816 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
817 EvDocumentClass *ev_document_class = EV_DOCUMENT_CLASS (klass);
819 g_object_class->dispose = pdf_document_dispose;
821 ev_document_class->save = pdf_document_save;
822 ev_document_class->load = pdf_document_load;
823 ev_document_class->get_n_pages = pdf_document_get_n_pages;
824 ev_document_class->get_page = pdf_document_get_page;
825 ev_document_class->get_page_size = pdf_document_get_page_size;
826 ev_document_class->get_page_label = pdf_document_get_page_label;
827 ev_document_class->render = pdf_document_render;
828 ev_document_class->get_info = pdf_document_get_info;
829 ev_document_class->get_backend_info = pdf_document_get_backend_info;
830 ev_document_class->support_synctex = pdf_document_support_synctex;
833 /* EvDocumentSecurity */
835 pdf_document_has_document_security (EvDocumentSecurity *document_security)
837 /* FIXME: do we really need to have this? */
842 pdf_document_set_password (EvDocumentSecurity *document_security,
843 const char *password)
845 PdfDocument *document = PDF_DOCUMENT (document_security);
847 if (document->password)
848 g_free (document->password);
850 document->password = g_strdup (password);
854 pdf_document_security_iface_init (EvDocumentSecurityInterface *iface)
856 iface->has_document_security = pdf_document_has_document_security;
857 iface->set_password = pdf_document_set_password;
861 pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts)
863 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
866 n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document));
868 return (double)pdf_document->fonts_scanned_pages / (double)n_pages;
872 pdf_document_fonts_scan (EvDocumentFonts *document_fonts,
875 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
878 g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE);
880 if (pdf_document->font_info == NULL) {
881 pdf_document->font_info = poppler_font_info_new (pdf_document->document);
884 if (pdf_document->fonts_iter) {
885 poppler_fonts_iter_free (pdf_document->fonts_iter);
888 pdf_document->fonts_scanned_pages += n_pages;
890 result = poppler_font_info_scan (pdf_document->font_info, n_pages,
891 &pdf_document->fonts_iter);
893 pdf_document->fonts_scanned_pages = 0;
894 poppler_font_info_free (pdf_document->font_info);
895 pdf_document->font_info = NULL;
902 font_type_to_string (PopplerFontType type)
905 case POPPLER_FONT_TYPE_TYPE1:
907 case POPPLER_FONT_TYPE_TYPE1C:
909 case POPPLER_FONT_TYPE_TYPE3:
911 case POPPLER_FONT_TYPE_TRUETYPE:
912 return _("TrueType");
913 case POPPLER_FONT_TYPE_CID_TYPE0:
914 return _("Type 1 (CID)");
915 case POPPLER_FONT_TYPE_CID_TYPE0C:
916 return _("Type 1C (CID)");
917 case POPPLER_FONT_TYPE_CID_TYPE2:
918 return _("TrueType (CID)");
920 return _("Unknown font type");
925 pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts,
928 PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts);
929 PopplerFontsIter *iter = pdf_document->fonts_iter;
931 g_return_if_fail (PDF_IS_DOCUMENT (document_fonts));
937 GtkTreeIter list_iter;
940 const char *embedded;
943 name = poppler_fonts_iter_get_name (iter);
949 type = font_type_to_string (
950 poppler_fonts_iter_get_font_type (iter));
952 if (poppler_fonts_iter_is_embedded (iter)) {
953 if (poppler_fonts_iter_is_subset (iter))
954 embedded = _("Embedded subset");
956 embedded = _("Embedded");
958 embedded = _("Not embedded");
961 details = g_markup_printf_escaped ("%s\n%s", type, embedded);
963 gtk_list_store_append (GTK_LIST_STORE (model), &list_iter);
964 gtk_list_store_set (GTK_LIST_STORE (model), &list_iter,
965 EV_DOCUMENT_FONTS_COLUMN_NAME, name,
966 EV_DOCUMENT_FONTS_COLUMN_DETAILS, details,
970 } while (poppler_fonts_iter_next (iter));
974 pdf_document_document_fonts_iface_init (EvDocumentFontsInterface *iface)
976 iface->fill_model = pdf_document_fonts_fill_model;
977 iface->scan = pdf_document_fonts_scan;
978 iface->get_progress = pdf_document_fonts_get_progress;
982 pdf_document_links_has_document_links (EvDocumentLinks *document_links)
984 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
985 PopplerIndexIter *iter;
987 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
989 iter = poppler_index_iter_new (pdf_document->document);
992 poppler_index_iter_free (iter);
998 ev_link_dest_from_dest (PdfDocument *pdf_document,
1001 EvLinkDest *ev_dest = NULL;
1002 const char *unimplemented_dest = NULL;
1004 g_assert (dest != NULL);
1006 switch (dest->type) {
1007 case POPPLER_DEST_XYZ: {
1008 PopplerPage *poppler_page;
1011 poppler_page = poppler_document_get_page (pdf_document->document,
1012 MAX (0, dest->page_num - 1));
1013 poppler_page_get_size (poppler_page, NULL, &height);
1014 ev_dest = ev_link_dest_new_xyz (dest->page_num - 1,
1016 height - MIN (height, dest->top),
1021 g_object_unref (poppler_page);
1024 case POPPLER_DEST_FITB:
1025 case POPPLER_DEST_FIT:
1026 ev_dest = ev_link_dest_new_fit (dest->page_num - 1);
1028 case POPPLER_DEST_FITBH:
1029 case POPPLER_DEST_FITH: {
1030 PopplerPage *poppler_page;
1033 poppler_page = poppler_document_get_page (pdf_document->document,
1034 MAX (0, dest->page_num - 1));
1035 poppler_page_get_size (poppler_page, NULL, &height);
1036 ev_dest = ev_link_dest_new_fith (dest->page_num - 1,
1037 height - MIN (height, dest->top),
1039 g_object_unref (poppler_page);
1042 case POPPLER_DEST_FITBV:
1043 case POPPLER_DEST_FITV:
1044 ev_dest = ev_link_dest_new_fitv (dest->page_num - 1,
1048 case POPPLER_DEST_FITR: {
1049 PopplerPage *poppler_page;
1052 poppler_page = poppler_document_get_page (pdf_document->document,
1053 MAX (0, dest->page_num - 1));
1054 poppler_page_get_size (poppler_page, NULL, &height);
1055 ev_dest = ev_link_dest_new_fitr (dest->page_num - 1,
1057 height - MIN (height, dest->bottom),
1059 height - MIN (height, dest->top));
1060 g_object_unref (poppler_page);
1063 case POPPLER_DEST_NAMED:
1064 ev_dest = ev_link_dest_new_named (dest->named_dest);
1066 case POPPLER_DEST_UNKNOWN:
1067 unimplemented_dest = "POPPLER_DEST_UNKNOWN";
1071 if (unimplemented_dest) {
1072 g_warning ("Unimplemented destination: %s, please post a "
1073 "bug report in Evince bugzilla "
1074 "(http://bugzilla.gnome.org) with a testcase.",
1075 unimplemented_dest);
1079 ev_dest = ev_link_dest_new_page (dest->page_num - 1);
1085 ev_link_from_action (PdfDocument *pdf_document,
1086 PopplerAction *action)
1088 EvLink *link = NULL;
1089 EvLinkAction *ev_action = NULL;
1090 const char *unimplemented_action = NULL;
1092 switch (action->type) {
1093 case POPPLER_ACTION_NONE:
1095 case POPPLER_ACTION_GOTO_DEST: {
1098 dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest);
1099 ev_action = ev_link_action_new_dest (dest);
1102 case POPPLER_ACTION_GOTO_REMOTE: {
1105 dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest);
1106 ev_action = ev_link_action_new_remote (dest,
1107 action->goto_remote.file_name);
1111 case POPPLER_ACTION_LAUNCH:
1112 ev_action = ev_link_action_new_launch (action->launch.file_name,
1113 action->launch.params);
1115 case POPPLER_ACTION_URI:
1116 ev_action = ev_link_action_new_external_uri (action->uri.uri);
1118 case POPPLER_ACTION_NAMED:
1119 ev_action = ev_link_action_new_named (action->named.named_dest);
1121 case POPPLER_ACTION_MOVIE:
1122 unimplemented_action = "POPPLER_ACTION_MOVIE";
1124 #if POPPLER_CHECK_VERSION (0, 13, 2)
1125 case POPPLER_ACTION_RENDITION:
1126 unimplemented_action = "POPPLER_ACTION_RENDITION";
1128 case POPPLER_ACTION_OCG_STATE:
1129 unimplemented_action = "POPPLER_ACTION_OCG_STATE";
1132 case POPPLER_ACTION_UNKNOWN:
1133 unimplemented_action = "POPPLER_ACTION_UNKNOWN";
1136 if (unimplemented_action) {
1137 g_warning ("Unimplemented action: %s, please post a bug report "
1138 "in Evince bugzilla (http://bugzilla.gnome.org) "
1139 "with a testcase.", unimplemented_action);
1142 link = ev_link_new (action->any.title, ev_action);
1148 build_tree (PdfDocument *pdf_document,
1149 GtkTreeModel *model,
1150 GtkTreeIter *parent,
1151 PopplerIndexIter *iter)
1155 GtkTreeIter tree_iter;
1156 PopplerIndexIter *child;
1157 PopplerAction *action;
1158 EvLink *link = NULL;
1162 action = poppler_index_iter_get_action (iter);
1163 expand = poppler_index_iter_is_open (iter);
1168 switch (action->type) {
1169 case POPPLER_ACTION_GOTO_DEST: {
1170 /* For bookmarks, solve named destinations */
1171 if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
1173 EvLinkDest *ev_dest = NULL;
1174 EvLinkAction *ev_action;
1176 dest = poppler_document_find_dest (pdf_document->document,
1177 action->goto_dest.dest->named_dest);
1179 link = ev_link_from_action (pdf_document, action);
1183 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1184 poppler_dest_free (dest);
1186 ev_action = ev_link_action_new_dest (ev_dest);
1187 link = ev_link_new (action->any.title, ev_action);
1189 link = ev_link_from_action (pdf_document, action);
1194 link = ev_link_from_action (pdf_document, action);
1198 if (!link || strlen (ev_link_get_title (link)) <= 0) {
1199 poppler_action_free (action);
1201 g_object_unref (link);
1206 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
1207 title_markup = g_markup_escape_text (ev_link_get_title (link), -1);
1209 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
1210 EV_DOCUMENT_LINKS_COLUMN_MARKUP, title_markup,
1211 EV_DOCUMENT_LINKS_COLUMN_LINK, link,
1212 EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand,
1215 g_free (title_markup);
1216 g_object_unref (link);
1218 child = poppler_index_iter_get_child (iter);
1220 build_tree (pdf_document, model, &tree_iter, child);
1221 poppler_index_iter_free (child);
1222 poppler_action_free (action);
1224 } while (poppler_index_iter_next (iter));
1227 static GtkTreeModel *
1228 pdf_document_links_get_links_model (EvDocumentLinks *document_links)
1230 PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
1231 GtkTreeModel *model = NULL;
1232 PopplerIndexIter *iter;
1234 g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
1236 iter = poppler_index_iter_new (pdf_document->document);
1237 /* Create the model if we have items*/
1239 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
1244 build_tree (pdf_document, model, NULL, iter);
1245 poppler_index_iter_free (iter);
1251 static EvMappingList *
1252 pdf_document_links_get_links (EvDocumentLinks *document_links,
1255 PdfDocument *pdf_document;
1256 PopplerPage *poppler_page;
1257 GList *retval = NULL;
1258 GList *mapping_list;
1262 pdf_document = PDF_DOCUMENT (document_links);
1263 poppler_page = POPPLER_PAGE (page->backend_page);
1264 mapping_list = poppler_page_get_link_mapping (poppler_page);
1265 poppler_page_get_size (poppler_page, NULL, &height);
1267 for (list = mapping_list; list; list = list->next) {
1268 PopplerLinkMapping *link_mapping;
1269 EvMapping *ev_link_mapping;
1271 link_mapping = (PopplerLinkMapping *)list->data;
1272 ev_link_mapping = g_new (EvMapping, 1);
1273 ev_link_mapping->data = ev_link_from_action (pdf_document,
1274 link_mapping->action);
1275 ev_link_mapping->area.x1 = link_mapping->area.x1;
1276 ev_link_mapping->area.x2 = link_mapping->area.x2;
1277 /* Invert this for X-style coordinates */
1278 ev_link_mapping->area.y1 = height - link_mapping->area.y2;
1279 ev_link_mapping->area.y2 = height - link_mapping->area.y1;
1281 retval = g_list_prepend (retval, ev_link_mapping);
1284 poppler_page_free_link_mapping (mapping_list);
1286 return ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
1290 pdf_document_links_find_link_dest (EvDocumentLinks *document_links,
1291 const gchar *link_name)
1293 PdfDocument *pdf_document;
1295 EvLinkDest *ev_dest = NULL;
1297 pdf_document = PDF_DOCUMENT (document_links);
1298 dest = poppler_document_find_dest (pdf_document->document,
1301 ev_dest = ev_link_dest_from_dest (pdf_document, dest);
1302 poppler_dest_free (dest);
1309 pdf_document_document_links_iface_init (EvDocumentLinksInterface *iface)
1311 iface->has_document_links = pdf_document_links_has_document_links;
1312 iface->get_links_model = pdf_document_links_get_links_model;
1313 iface->get_links = pdf_document_links_get_links;
1314 iface->find_link_dest = pdf_document_links_find_link_dest;
1317 static EvMappingList *
1318 pdf_document_images_get_image_mapping (EvDocumentImages *document_images,
1321 GList *retval = NULL;
1322 PdfDocument *pdf_document;
1323 PopplerPage *poppler_page;
1324 GList *mapping_list;
1327 pdf_document = PDF_DOCUMENT (document_images);
1328 poppler_page = POPPLER_PAGE (page->backend_page);
1329 mapping_list = poppler_page_get_image_mapping (poppler_page);
1331 for (list = mapping_list; list; list = list->next) {
1332 PopplerImageMapping *image_mapping;
1333 EvMapping *ev_image_mapping;
1335 image_mapping = (PopplerImageMapping *)list->data;
1337 ev_image_mapping = g_new (EvMapping, 1);
1339 ev_image_mapping->data = ev_image_new (page->index, image_mapping->image_id);
1340 ev_image_mapping->area.x1 = image_mapping->area.x1;
1341 ev_image_mapping->area.y1 = image_mapping->area.y1;
1342 ev_image_mapping->area.x2 = image_mapping->area.x2;
1343 ev_image_mapping->area.y2 = image_mapping->area.y2;
1345 retval = g_list_prepend (retval, ev_image_mapping);
1348 poppler_page_free_image_mapping (mapping_list);
1350 return ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
1354 pdf_document_images_get_image (EvDocumentImages *document_images,
1357 GdkPixbuf *retval = NULL;
1358 PdfDocument *pdf_document;
1359 PopplerPage *poppler_page;
1360 cairo_surface_t *surface;
1362 pdf_document = PDF_DOCUMENT (document_images);
1363 poppler_page = poppler_document_get_page (pdf_document->document,
1364 ev_image_get_page (image));
1366 surface = poppler_page_get_image (poppler_page, ev_image_get_id (image));
1368 retval = ev_document_misc_pixbuf_from_surface (surface);
1369 cairo_surface_destroy (surface);
1372 g_object_unref (poppler_page);
1378 pdf_document_document_images_iface_init (EvDocumentImagesInterface *iface)
1380 iface->get_image_mapping = pdf_document_images_get_image_mapping;
1381 iface->get_image = pdf_document_images_get_image;
1385 make_thumbnail_for_page (PopplerPage *poppler_page,
1386 EvRenderContext *rc,
1392 #ifdef POPPLER_WITH_GDK
1393 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
1395 gdk_pixbuf_fill (pixbuf, 0xffffffff);
1397 ev_document_fc_mutex_lock ();
1398 poppler_page_render_to_pixbuf (poppler_page, 0, 0,
1400 rc->scale, rc->rotation, pixbuf);
1401 ev_document_fc_mutex_unlock ();
1403 cairo_surface_t *surface;
1405 ev_document_fc_mutex_lock ();
1406 surface = pdf_page_render (poppler_page, width, height, rc);
1407 ev_document_fc_mutex_unlock ();
1409 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1410 cairo_surface_destroy (surface);
1411 #endif /* POPPLER_WITH_GDK */
1417 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
1418 EvRenderContext *rc,
1421 PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
1422 PopplerPage *poppler_page;
1423 GdkPixbuf *pixbuf = NULL;
1424 GdkPixbuf *border_pixbuf;
1425 double page_width, page_height;
1428 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1430 poppler_page_get_size (poppler_page,
1431 &page_width, &page_height);
1433 width = MAX ((gint)(page_width * rc->scale + 0.5), 1);
1434 height = MAX ((gint)(page_height * rc->scale + 0.5), 1);
1436 if (rc->rotation == 90 || rc->rotation == 270) {
1444 #ifdef POPPLER_WITH_GDK
1445 pixbuf = poppler_page_get_thumbnail_pixbuf (poppler_page);
1447 cairo_surface_t *surface;
1449 surface = poppler_page_get_thumbnail (poppler_page);
1451 pixbuf = ev_document_misc_pixbuf_from_surface (surface);
1452 cairo_surface_destroy (surface);
1454 #endif /* POPPLER_WITH_GDK */
1456 if (pixbuf != NULL) {
1457 int thumb_width = (rc->rotation == 90 || rc->rotation == 270) ?
1458 gdk_pixbuf_get_height (pixbuf) :
1459 gdk_pixbuf_get_width (pixbuf);
1461 if (thumb_width == width) {
1462 GdkPixbuf *rotated_pixbuf;
1464 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf,
1465 (GdkPixbufRotation) (360 - rc->rotation));
1466 g_object_unref (pixbuf);
1467 pixbuf = rotated_pixbuf;
1469 /* The provided thumbnail has a different size */
1470 g_object_unref (pixbuf);
1471 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1474 /* There is no provided thumbnail. We need to make one. */
1475 pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
1478 if (border && pixbuf) {
1479 border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
1480 g_object_unref (pixbuf);
1481 pixbuf = border_pixbuf;
1488 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface)
1490 iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
1495 pdf_document_find_find_text (EvDocumentFind *document_find,
1498 gboolean case_sensitive)
1501 PopplerPage *poppler_page;
1503 GList *retval = NULL;
1505 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1506 g_return_val_if_fail (text != NULL, NULL);
1508 poppler_page = POPPLER_PAGE (page->backend_page);
1510 matches = poppler_page_find_text (poppler_page, text);
1514 poppler_page_get_size (poppler_page, NULL, &height);
1515 for (l = matches; l && l->data; l = g_list_next (l)) {
1516 PopplerRectangle *rect = (PopplerRectangle *)l->data;
1517 EvRectangle *ev_rect;
1519 ev_rect = ev_rectangle_new ();
1520 ev_rect->x1 = rect->x1;
1521 ev_rect->x2 = rect->x2;
1522 /* Invert this for X-style coordinates */
1523 ev_rect->y1 = height - rect->y2;
1524 ev_rect->y2 = height - rect->y1;
1526 retval = g_list_prepend (retval, ev_rect);
1529 g_list_foreach (matches, (GFunc)poppler_rectangle_free, NULL);
1530 g_list_free (matches);
1532 return g_list_reverse (retval);
1536 pdf_document_find_iface_init (EvDocumentFindInterface *iface)
1538 iface->find_text = pdf_document_find_find_text;
1542 pdf_print_context_free (PdfPrintContext *ctx)
1547 #ifdef HAVE_CAIRO_PRINT
1549 cairo_destroy (ctx->cr);
1554 poppler_ps_file_free (ctx->ps_file);
1555 ctx->ps_file = NULL;
1562 pdf_document_file_exporter_begin (EvFileExporter *exporter,
1563 EvFileExporterContext *fc)
1565 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1566 PdfPrintContext *ctx;
1567 #ifdef HAVE_CAIRO_PRINT
1568 gdouble width, height;
1569 cairo_surface_t *surface = NULL;
1572 if (pdf_document->print_ctx)
1573 pdf_print_context_free (pdf_document->print_ctx);
1574 pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
1575 ctx = pdf_document->print_ctx;
1576 ctx->format = fc->format;
1578 #ifdef HAVE_CAIRO_PRINT
1579 ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
1581 ctx->paper_width = fc->paper_width;
1582 ctx->paper_height = fc->paper_height;
1584 switch (fc->pages_per_sheet) {
1612 ctx->pages_printed = 0;
1614 switch (fc->format) {
1615 case EV_FILE_FORMAT_PS:
1616 #ifdef HAVE_CAIRO_PS
1617 surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1620 case EV_FILE_FORMAT_PDF:
1621 #ifdef HAVE_CAIRO_PDF
1622 surface = cairo_pdf_surface_create (fc->filename, fc->paper_width, fc->paper_height);
1626 g_assert_not_reached ();
1629 ctx->cr = cairo_create (surface);
1630 cairo_surface_destroy (surface);
1632 #else /* HAVE_CAIRO_PRINT */
1633 if (ctx->format == EV_FILE_FORMAT_PS) {
1634 ctx->ps_file = poppler_ps_file_new (pdf_document->document,
1635 fc->filename, fc->first_page,
1636 fc->last_page - fc->first_page + 1);
1637 poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
1638 poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
1640 #endif /* HAVE_CAIRO_PRINT */
1644 pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
1646 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1647 PdfPrintContext *ctx = pdf_document->print_ctx;
1649 g_return_if_fail (pdf_document->print_ctx != NULL);
1651 ctx->pages_printed = 0;
1653 #ifdef HAVE_CAIRO_PRINT
1654 if (ctx->paper_width > ctx->paper_height) {
1655 if (ctx->format == EV_FILE_FORMAT_PS) {
1656 cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
1659 } else if (ctx->format == EV_FILE_FORMAT_PDF) {
1660 cairo_pdf_surface_set_size (cairo_get_target (ctx->cr),
1665 #endif /* HAVE_CAIRO_PRINT */
1669 pdf_document_file_exporter_do_page (EvFileExporter *exporter,
1670 EvRenderContext *rc)
1672 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1673 PdfPrintContext *ctx = pdf_document->print_ctx;
1674 PopplerPage *poppler_page;
1675 #ifdef HAVE_CAIRO_PRINT
1676 gdouble page_width, page_height;
1679 gdouble width, height;
1680 gdouble pwidth, pheight;
1681 gdouble xscale, yscale;
1684 g_return_if_fail (pdf_document->print_ctx != NULL);
1686 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1688 #ifdef HAVE_CAIRO_PRINT
1689 x = (ctx->pages_printed % ctx->pages_per_sheet) % ctx->pages_x;
1690 y = (ctx->pages_printed % ctx->pages_per_sheet) / ctx->pages_x;
1691 poppler_page_get_size (poppler_page, &page_width, &page_height);
1693 if (page_width > page_height && page_width > ctx->paper_width) {
1699 /* Use always portrait mode and rotate when necessary */
1700 if (ctx->paper_width > ctx->paper_height) {
1701 width = ctx->paper_height;
1702 height = ctx->paper_width;
1705 width = ctx->paper_width;
1706 height = ctx->paper_height;
1709 if (ctx->pages_per_sheet == 2 || ctx->pages_per_sheet == 6) {
1722 page_width = page_height;
1726 pwidth = width / ctx->pages_x;
1727 pheight = height / ctx->pages_y;
1729 if ((page_width > pwidth || page_height > pheight) ||
1730 (page_width < pwidth && page_height < pheight)) {
1731 xscale = pwidth / page_width;
1732 yscale = pheight / page_height;
1734 if (yscale < xscale) {
1741 xscale = yscale = 1;
1746 cairo_save (ctx->cr);
1748 cairo_matrix_t matrix;
1750 cairo_translate (ctx->cr, (2 * y + 1) * pwidth, 0);
1751 cairo_matrix_init (&matrix,
1755 cairo_transform (ctx->cr, &matrix);
1758 cairo_translate (ctx->cr,
1759 x * (rotate ? pheight : pwidth),
1760 y * (rotate ? pwidth : pheight));
1761 cairo_scale (ctx->cr, xscale, yscale);
1763 poppler_page_render_for_printing (poppler_page, ctx->cr);
1765 ctx->pages_printed++;
1767 cairo_restore (ctx->cr);
1768 #else /* HAVE_CAIRO_PRINT */
1769 if (ctx->format == EV_FILE_FORMAT_PS)
1770 poppler_page_render_to_ps (poppler_page, ctx->ps_file);
1771 #endif /* HAVE_CAIRO_PRINT */
1775 pdf_document_file_exporter_end_page (EvFileExporter *exporter)
1777 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1778 PdfPrintContext *ctx = pdf_document->print_ctx;
1780 g_return_if_fail (pdf_document->print_ctx != NULL);
1782 #ifdef HAVE_CAIRO_PRINT
1783 cairo_show_page (ctx->cr);
1788 pdf_document_file_exporter_end (EvFileExporter *exporter)
1790 PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
1792 pdf_print_context_free (pdf_document->print_ctx);
1793 pdf_document->print_ctx = NULL;
1796 static EvFileExporterCapabilities
1797 pdf_document_file_exporter_get_capabilities (EvFileExporter *exporter)
1799 return (EvFileExporterCapabilities) (
1800 EV_FILE_EXPORTER_CAN_PAGE_SET |
1801 EV_FILE_EXPORTER_CAN_COPIES |
1802 EV_FILE_EXPORTER_CAN_COLLATE |
1803 EV_FILE_EXPORTER_CAN_REVERSE |
1804 EV_FILE_EXPORTER_CAN_SCALE |
1805 #ifdef HAVE_CAIRO_PRINT
1806 EV_FILE_EXPORTER_CAN_NUMBER_UP |
1809 #ifdef HAVE_CAIRO_PDF
1810 EV_FILE_EXPORTER_CAN_GENERATE_PDF |
1812 EV_FILE_EXPORTER_CAN_GENERATE_PS);
1816 pdf_document_file_exporter_iface_init (EvFileExporterInterface *iface)
1818 iface->begin = pdf_document_file_exporter_begin;
1819 iface->begin_page = pdf_document_file_exporter_begin_page;
1820 iface->do_page = pdf_document_file_exporter_do_page;
1821 iface->end_page = pdf_document_file_exporter_end_page;
1822 iface->end = pdf_document_file_exporter_end;
1823 iface->get_capabilities = pdf_document_file_exporter_get_capabilities;
1826 /* EvDocumentPrint */
1828 pdf_document_print_print_page (EvDocumentPrint *document,
1832 PdfDocument *pdf_document = PDF_DOCUMENT (document);
1834 poppler_page_render_for_printing (POPPLER_PAGE (page->backend_page), cr);
1838 pdf_document_document_print_iface_init (EvDocumentPrintInterface *iface)
1840 iface->print_page = pdf_document_print_print_page;
1844 pdf_selection_render_selection (EvSelection *selection,
1845 EvRenderContext *rc,
1846 cairo_surface_t **surface,
1847 EvRectangle *points,
1848 EvRectangle *old_points,
1849 EvSelectionStyle style,
1853 PopplerPage *poppler_page;
1855 PopplerColor text_color, base_color;
1856 double width_points, height_points;
1859 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1861 poppler_page_get_size (poppler_page,
1862 &width_points, &height_points);
1863 width = (int) ((width_points * rc->scale) + 0.5);
1864 height = (int) ((height_points * rc->scale) + 0.5);
1866 text_color.red = text->red;
1867 text_color.green = text->green;
1868 text_color.blue = text->blue;
1870 base_color.red = base->red;
1871 base_color.green = base->green;
1872 base_color.blue = base->blue;
1874 if (*surface == NULL) {
1875 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1880 cr = cairo_create (*surface);
1881 cairo_scale (cr, rc->scale, rc->scale);
1882 cairo_surface_set_device_offset (*surface, 0, 0);
1883 memset (cairo_image_surface_get_data (*surface), 0x00,
1884 cairo_image_surface_get_height (*surface) *
1885 cairo_image_surface_get_stride (*surface));
1886 poppler_page_render_selection (poppler_page,
1888 (PopplerRectangle *)points,
1889 (PopplerRectangle *)old_points,
1890 (PopplerSelectionStyle)style,
1897 pdf_selection_get_selected_text (EvSelection *selection,
1899 EvSelectionStyle style,
1900 EvRectangle *points)
1902 PopplerPage *poppler_page;
1905 poppler_page = POPPLER_PAGE (page->backend_page);
1907 #ifdef HAVE_POPPLER_PAGE_GET_SELECTED_TEXT
1908 retval = poppler_page_get_selected_text (poppler_page,
1909 (PopplerSelectionStyle)style,
1910 (PopplerRectangle *)points);
1915 poppler_page_get_size (poppler_page, NULL, &height);
1917 r.y1 = height - points->y2;
1919 r.y2 = height - points->y1;
1921 retval = poppler_page_get_text (poppler_page,
1922 (PopplerSelectionStyle)style,
1924 #endif /* HAVE_POPPLER_PAGE_GET_SELECTED_TEXT */
1929 static cairo_region_t *
1930 create_region_from_poppler_region (GList *region, gdouble scale)
1933 cairo_region_t *retval;
1935 retval = cairo_region_create ();
1937 for (l = region; l; l = g_list_next (l)) {
1938 PopplerRectangle *rectangle;
1939 cairo_rectangle_int_t rect;
1941 rectangle = (PopplerRectangle *)l->data;
1943 rect.x = (gint) ((rectangle->x1 * scale) + 0.5);
1944 rect.y = (gint) ((rectangle->y1 * scale) + 0.5);
1945 rect.width = (gint) (((rectangle->x2 - rectangle->x1) * scale) + 0.5);
1946 rect.height = (gint) (((rectangle->y2 - rectangle->y1) * scale) + 0.5);
1947 cairo_region_union_rectangle (retval, &rect);
1949 poppler_rectangle_free (rectangle);
1955 static cairo_region_t *
1956 pdf_selection_get_selection_region (EvSelection *selection,
1957 EvRenderContext *rc,
1958 EvSelectionStyle style,
1959 EvRectangle *points)
1961 PopplerPage *poppler_page;
1962 cairo_region_t *retval;
1965 poppler_page = POPPLER_PAGE (rc->page->backend_page);
1966 region = poppler_page_get_selection_region (poppler_page,
1968 (PopplerSelectionStyle)style,
1969 (PopplerRectangle *) points);
1970 retval = create_region_from_poppler_region (region, rc->scale);
1971 g_list_free (region);
1977 pdf_selection_iface_init (EvSelectionInterface *iface)
1979 iface->render_selection = pdf_selection_render_selection;
1980 iface->get_selected_text = pdf_selection_get_selected_text;
1981 iface->get_selection_region = pdf_selection_get_selection_region;
1985 /* EvDocumentText */
1986 static cairo_region_t *
1987 pdf_document_text_get_text_mapping (EvDocumentText *document_text,
1990 PopplerPage *poppler_page;
1991 PopplerRectangle points;
1993 cairo_region_t *retval;
1995 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
1997 poppler_page = POPPLER_PAGE (page->backend_page);
2001 poppler_page_get_size (poppler_page, &(points.x2), &(points.y2));
2003 region = poppler_page_get_selection_region (poppler_page, 1.0,
2004 POPPLER_SELECTION_GLYPH,
2006 retval = create_region_from_poppler_region (region, 1.0);
2007 g_list_free (region);
2012 #ifdef HAVE_POPPLER_PAGE_GET_SELECTED_TEXT
2014 pdf_document_text_get_text (EvDocumentText *selection,
2017 PopplerPage *poppler_page;
2019 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2021 poppler_page = POPPLER_PAGE (page->backend_page);
2023 return poppler_page_get_text (poppler_page);
2027 pdf_document_text_get_text (EvDocumentText *selection,
2030 PopplerPage *poppler_page;
2033 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2035 poppler_page = POPPLER_PAGE (page->backend_page);
2039 poppler_page_get_size (poppler_page, &(r.x2), &(r.y2));
2041 return poppler_page_get_text (poppler_page,
2042 POPPLER_SELECTION_WORD,
2045 #endif /* HAVE_POPPLER_PAGE_GET_SELECTED_TEXT */
2047 #ifdef HAVE_POPPLER_PAGE_GET_TEXT_LAYOUT
2049 pdf_document_text_get_text_layout (EvDocumentText *selection,
2051 EvRectangle **areas,
2054 PopplerPage *poppler_page;
2056 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2058 poppler_page = POPPLER_PAGE (page->backend_page);
2060 return poppler_page_get_text_layout (poppler_page, (PopplerRectangle **)areas, n_areas);
2065 pdf_document_text_iface_init (EvDocumentTextInterface *iface)
2067 iface->get_text_mapping = pdf_document_text_get_text_mapping;
2068 iface->get_text = pdf_document_text_get_text;
2069 #ifdef HAVE_POPPLER_PAGE_GET_TEXT_LAYOUT
2070 iface->get_text_layout = pdf_document_text_get_text_layout;
2074 /* Page Transitions */
2076 pdf_document_get_page_duration (EvDocumentTransition *trans,
2079 PdfDocument *pdf_document;
2080 PopplerPage *poppler_page;
2081 gdouble duration = -1;
2083 pdf_document = PDF_DOCUMENT (trans);
2084 poppler_page = poppler_document_get_page (pdf_document->document, page);
2088 duration = poppler_page_get_duration (poppler_page);
2089 g_object_unref (poppler_page);
2094 static EvTransitionEffect *
2095 pdf_document_get_effect (EvDocumentTransition *trans,
2098 PdfDocument *pdf_document;
2099 PopplerPage *poppler_page;
2100 PopplerPageTransition *page_transition;
2101 EvTransitionEffect *effect;
2103 pdf_document = PDF_DOCUMENT (trans);
2104 poppler_page = poppler_document_get_page (pdf_document->document, page);
2109 page_transition = poppler_page_get_transition (poppler_page);
2111 if (!page_transition) {
2112 g_object_unref (poppler_page);
2116 /* enums in PopplerPageTransition match the EvTransitionEffect ones */
2117 effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
2118 "alignment", page_transition->alignment,
2119 "direction", page_transition->direction,
2120 "duration", page_transition->duration,
2121 "angle", page_transition->angle,
2122 "scale", page_transition->scale,
2123 "rectangular", page_transition->rectangular,
2126 poppler_page_transition_free (page_transition);
2127 g_object_unref (poppler_page);
2133 pdf_document_page_transition_iface_init (EvDocumentTransitionInterface *iface)
2135 iface->get_page_duration = pdf_document_get_page_duration;
2136 iface->get_effect = pdf_document_get_effect;
2141 pdf_document_get_crop_box (EvDocument *document,
2145 PdfDocument *pdf_document;
2146 PopplerPage *poppler_page;
2147 PopplerRectangle poppler_rect;
2149 pdf_document = PDF_DOCUMENT (document);
2150 poppler_page = poppler_document_get_page (pdf_document->document, page);
2151 poppler_page_get_crop_box (poppler_page, &poppler_rect);
2152 rect->x1 = poppler_rect.x1;
2153 rect->x2 = poppler_rect.x2;
2154 rect->y1 = poppler_rect.y1;
2155 rect->y2 = poppler_rect.y2;
2158 static EvFormField *
2159 ev_form_field_from_poppler_field (PopplerFormField *poppler_field)
2161 EvFormField *ev_field = NULL;
2164 gboolean is_read_only;
2166 id = poppler_form_field_get_id (poppler_field);
2167 font_size = poppler_form_field_get_font_size (poppler_field);
2168 is_read_only = poppler_form_field_is_read_only (poppler_field);
2170 switch (poppler_form_field_get_field_type (poppler_field)) {
2171 case POPPLER_FORM_FIELD_TEXT: {
2172 EvFormFieldText *field_text;
2173 EvFormFieldTextType ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2175 switch (poppler_form_field_text_get_text_type (poppler_field)) {
2176 case POPPLER_FORM_TEXT_NORMAL:
2177 ev_text_type = EV_FORM_FIELD_TEXT_NORMAL;
2179 case POPPLER_FORM_TEXT_MULTILINE:
2180 ev_text_type = EV_FORM_FIELD_TEXT_MULTILINE;
2182 case POPPLER_FORM_TEXT_FILE_SELECT:
2183 ev_text_type = EV_FORM_FIELD_TEXT_FILE_SELECT;
2187 ev_field = ev_form_field_text_new (id, ev_text_type);
2188 field_text = EV_FORM_FIELD_TEXT (ev_field);
2190 field_text->do_spell_check = poppler_form_field_text_do_spell_check (poppler_field);
2191 field_text->do_scroll = poppler_form_field_text_do_scroll (poppler_field);
2192 field_text->is_rich_text = poppler_form_field_text_is_rich_text (poppler_field);
2193 field_text->is_password = poppler_form_field_text_is_password (poppler_field);
2194 field_text->max_len = poppler_form_field_text_get_max_len (poppler_field);
2195 field_text->text = poppler_form_field_text_get_text (poppler_field);
2199 case POPPLER_FORM_FIELD_BUTTON: {
2200 EvFormFieldButton *field_button;
2201 EvFormFieldButtonType ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2203 switch (poppler_form_field_button_get_button_type (poppler_field)) {
2204 case POPPLER_FORM_BUTTON_PUSH:
2205 ev_button_type = EV_FORM_FIELD_BUTTON_PUSH;
2207 case POPPLER_FORM_BUTTON_CHECK:
2208 ev_button_type = EV_FORM_FIELD_BUTTON_CHECK;
2210 case POPPLER_FORM_BUTTON_RADIO:
2211 ev_button_type = EV_FORM_FIELD_BUTTON_RADIO;
2215 ev_field = ev_form_field_button_new (id, ev_button_type);
2216 field_button = EV_FORM_FIELD_BUTTON (ev_field);
2218 field_button->state = poppler_form_field_button_get_state (poppler_field);
2221 case POPPLER_FORM_FIELD_CHOICE: {
2222 EvFormFieldChoice *field_choice;
2223 EvFormFieldChoiceType ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2225 switch (poppler_form_field_choice_get_choice_type (poppler_field)) {
2226 case POPPLER_FORM_CHOICE_COMBO:
2227 ev_choice_type = EV_FORM_FIELD_CHOICE_COMBO;
2229 case EV_FORM_FIELD_CHOICE_LIST:
2230 ev_choice_type = EV_FORM_FIELD_CHOICE_LIST;
2234 ev_field = ev_form_field_choice_new (id, ev_choice_type);
2235 field_choice = EV_FORM_FIELD_CHOICE (ev_field);
2237 field_choice->is_editable = poppler_form_field_choice_is_editable (poppler_field);
2238 field_choice->multi_select = poppler_form_field_choice_can_select_multiple (poppler_field);
2239 field_choice->do_spell_check = poppler_form_field_choice_do_spell_check (poppler_field);
2240 field_choice->commit_on_sel_change = poppler_form_field_choice_commit_on_change (poppler_field);
2242 /* TODO: we need poppler_form_field_choice_get_selected_items in poppler
2243 field_choice->selected_items = poppler_form_field_choice_get_selected_items (poppler_field);*/
2244 if (field_choice->is_editable)
2245 field_choice->text = poppler_form_field_choice_get_text (poppler_field);
2248 case POPPLER_FORM_FIELD_SIGNATURE:
2250 ev_field = ev_form_field_signature_new (id);
2252 case POPPLER_FORM_FIELD_UNKNOWN:
2256 ev_field->font_size = font_size;
2257 ev_field->is_read_only = is_read_only;
2262 static EvMappingList *
2263 pdf_document_forms_get_form_fields (EvDocumentForms *document,
2266 PopplerPage *poppler_page;
2267 GList *retval = NULL;
2272 g_return_val_if_fail (POPPLER_IS_PAGE (page->backend_page), NULL);
2274 poppler_page = POPPLER_PAGE (page->backend_page);
2275 fields = poppler_page_get_form_field_mapping (poppler_page);
2276 poppler_page_get_size (poppler_page, NULL, &height);
2278 for (list = fields; list; list = list->next) {
2279 PopplerFormFieldMapping *mapping;
2280 EvMapping *field_mapping;
2281 EvFormField *ev_field;
2283 mapping = (PopplerFormFieldMapping *)list->data;
2285 ev_field = ev_form_field_from_poppler_field (mapping->field);
2289 field_mapping = g_new0 (EvMapping, 1);
2290 field_mapping->area.x1 = mapping->area.x1;
2291 field_mapping->area.x2 = mapping->area.x2;
2292 field_mapping->area.y1 = height - mapping->area.y2;
2293 field_mapping->area.y2 = height - mapping->area.y1;
2294 field_mapping->data = ev_field;
2295 ev_field->page = EV_PAGE (g_object_ref (page));
2297 g_object_set_data_full (G_OBJECT (ev_field),
2299 g_object_ref (mapping->field),
2300 (GDestroyNotify) g_object_unref);
2302 retval = g_list_prepend (retval, field_mapping);
2305 poppler_page_free_form_field_mapping (fields);
2307 return retval ? ev_mapping_list_new (page->index,
2308 g_list_reverse (retval),
2309 (GDestroyNotify)g_object_unref) : NULL;
2313 pdf_document_forms_document_is_modified (EvDocumentForms *document)
2315 return PDF_DOCUMENT (document)->forms_modified;
2319 pdf_document_forms_form_field_text_get_text (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_text_get_text (poppler_field);
2336 pdf_document_forms_form_field_text_set_text (EvDocumentForms *document,
2340 PopplerFormField *poppler_field;
2342 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2346 poppler_form_field_text_set_text (poppler_field, text);
2347 PDF_DOCUMENT (document)->forms_modified = TRUE;
2351 pdf_document_forms_form_field_button_set_state (EvDocumentForms *document,
2355 PopplerFormField *poppler_field;
2357 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2361 poppler_form_field_button_set_state (poppler_field, state);
2362 PDF_DOCUMENT (document)->forms_modified = TRUE;
2366 pdf_document_forms_form_field_button_get_state (EvDocumentForms *document,
2369 PopplerFormField *poppler_field;
2372 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2376 state = poppler_form_field_button_get_state (poppler_field);
2382 pdf_document_forms_form_field_choice_get_item (EvDocumentForms *document,
2386 PopplerFormField *poppler_field;
2389 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2393 text = poppler_form_field_choice_get_item (poppler_field, index);
2399 pdf_document_forms_form_field_choice_get_n_items (EvDocumentForms *document,
2402 PopplerFormField *poppler_field;
2405 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2409 n_items = poppler_form_field_choice_get_n_items (poppler_field);
2415 pdf_document_forms_form_field_choice_is_item_selected (EvDocumentForms *document,
2419 PopplerFormField *poppler_field;
2422 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2426 selected = poppler_form_field_choice_is_item_selected (poppler_field, index);
2432 pdf_document_forms_form_field_choice_select_item (EvDocumentForms *document,
2436 PopplerFormField *poppler_field;
2438 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2442 poppler_form_field_choice_select_item (poppler_field, index);
2443 PDF_DOCUMENT (document)->forms_modified = TRUE;
2447 pdf_document_forms_form_field_choice_toggle_item (EvDocumentForms *document,
2451 PopplerFormField *poppler_field;
2453 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2457 poppler_form_field_choice_toggle_item (poppler_field, index);
2458 PDF_DOCUMENT (document)->forms_modified = TRUE;
2462 pdf_document_forms_form_field_choice_unselect_all (EvDocumentForms *document,
2465 PopplerFormField *poppler_field;
2467 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2471 poppler_form_field_choice_unselect_all (poppler_field);
2472 PDF_DOCUMENT (document)->forms_modified = TRUE;
2476 pdf_document_forms_form_field_choice_set_text (EvDocumentForms *document,
2480 PopplerFormField *poppler_field;
2482 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2486 poppler_form_field_choice_set_text (poppler_field, text);
2487 PDF_DOCUMENT (document)->forms_modified = TRUE;
2491 pdf_document_forms_form_field_choice_get_text (EvDocumentForms *document,
2494 PopplerFormField *poppler_field;
2497 poppler_field = POPPLER_FORM_FIELD (g_object_get_data (G_OBJECT (field), "poppler-field"));
2501 text = poppler_form_field_choice_get_text (poppler_field);
2507 pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface)
2509 iface->get_form_fields = pdf_document_forms_get_form_fields;
2510 iface->document_is_modified = pdf_document_forms_document_is_modified;
2511 iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
2512 iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
2513 iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
2514 iface->form_field_button_get_state = pdf_document_forms_form_field_button_get_state;
2515 iface->form_field_choice_get_item = pdf_document_forms_form_field_choice_get_item;
2516 iface->form_field_choice_get_n_items = pdf_document_forms_form_field_choice_get_n_items;
2517 iface->form_field_choice_is_item_selected = pdf_document_forms_form_field_choice_is_item_selected;
2518 iface->form_field_choice_select_item = pdf_document_forms_form_field_choice_select_item;
2519 iface->form_field_choice_toggle_item = pdf_document_forms_form_field_choice_toggle_item;
2520 iface->form_field_choice_unselect_all = pdf_document_forms_form_field_choice_unselect_all;
2521 iface->form_field_choice_set_text = pdf_document_forms_form_field_choice_set_text;
2522 iface->form_field_choice_get_text = pdf_document_forms_form_field_choice_get_text;
2527 poppler_annot_color_to_gdk_color (PopplerAnnot *poppler_annot,
2530 PopplerColor *poppler_color;
2532 poppler_color = poppler_annot_get_color (poppler_annot);
2533 if (poppler_color) {
2534 color->red = poppler_color->red;
2535 color->green = poppler_color->green;
2536 color->blue = poppler_color->blue;
2538 g_free (poppler_color);
2539 } /* TODO: else use a default color */
2542 static EvAnnotationTextIcon
2543 get_annot_text_icon (PopplerAnnotText *poppler_annot)
2545 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2546 gchar *icon = poppler_annot_text_get_icon (poppler_annot);
2547 EvAnnotationTextIcon retval;
2550 return EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2552 if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_NOTE) == 0)
2553 retval = EV_ANNOTATION_TEXT_ICON_NOTE;
2554 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_COMMENT) == 0)
2555 retval = EV_ANNOTATION_TEXT_ICON_COMMENT;
2556 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_KEY) == 0)
2557 retval = EV_ANNOTATION_TEXT_ICON_KEY;
2558 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_HELP) == 0)
2559 retval = EV_ANNOTATION_TEXT_ICON_HELP;
2560 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH) == 0)
2561 retval = EV_ANNOTATION_TEXT_ICON_NEW_PARAGRAPH;
2562 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_PARAGRAPH) == 0)
2563 retval = EV_ANNOTATION_TEXT_ICON_PARAGRAPH;
2564 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_INSERT) == 0)
2565 retval = EV_ANNOTATION_TEXT_ICON_INSERT;
2566 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_CROSS) == 0)
2567 retval = EV_ANNOTATION_TEXT_ICON_CROSS;
2568 else if (strcmp (icon, POPPLER_ANNOT_TEXT_ICON_CIRCLE) == 0)
2569 retval = EV_ANNOTATION_TEXT_ICON_CIRCLE;
2571 retval = EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2577 return EV_ANNOTATION_TEXT_ICON_UNKNOWN;
2581 static const gchar *
2582 get_poppler_annot_text_icon (EvAnnotationTextIcon icon)
2584 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2586 case EV_ANNOTATION_TEXT_ICON_NOTE:
2587 return POPPLER_ANNOT_TEXT_ICON_NOTE;
2588 case EV_ANNOTATION_TEXT_ICON_COMMENT:
2589 return POPPLER_ANNOT_TEXT_ICON_COMMENT;
2590 case EV_ANNOTATION_TEXT_ICON_KEY:
2591 return POPPLER_ANNOT_TEXT_ICON_KEY;
2592 case EV_ANNOTATION_TEXT_ICON_HELP:
2593 return POPPLER_ANNOT_TEXT_ICON_HELP;
2594 case EV_ANNOTATION_TEXT_ICON_NEW_PARAGRAPH:
2595 return POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH;
2596 case EV_ANNOTATION_TEXT_ICON_PARAGRAPH:
2597 return POPPLER_ANNOT_TEXT_ICON_PARAGRAPH;
2598 case EV_ANNOTATION_TEXT_ICON_INSERT:
2599 return POPPLER_ANNOT_TEXT_ICON_INSERT;
2600 case EV_ANNOTATION_TEXT_ICON_CROSS:
2601 return POPPLER_ANNOT_TEXT_ICON_CROSS;
2602 case EV_ANNOTATION_TEXT_ICON_CIRCLE:
2603 return POPPLER_ANNOT_TEXT_ICON_CIRCLE;
2604 case EV_ANNOTATION_TEXT_ICON_UNKNOWN:
2606 return POPPLER_ANNOT_TEXT_ICON_NOTE;
2613 static EvAnnotation *
2614 ev_annot_from_poppler_annot (PopplerAnnot *poppler_annot,
2617 EvAnnotation *ev_annot = NULL;
2618 const gchar *unimplemented_annot = NULL;
2620 switch (poppler_annot_get_annot_type (poppler_annot)) {
2621 case POPPLER_ANNOT_TEXT: {
2622 PopplerAnnotText *poppler_text;
2623 EvAnnotationText *ev_annot_text;
2625 poppler_text = POPPLER_ANNOT_TEXT (poppler_annot);
2627 ev_annot = ev_annotation_text_new (page);
2629 ev_annot_text = EV_ANNOTATION_TEXT (ev_annot);
2630 ev_annotation_text_set_is_open (ev_annot_text,
2631 poppler_annot_text_get_is_open (poppler_text));
2632 ev_annotation_text_set_icon (ev_annot_text, get_annot_text_icon (poppler_text));
2635 case POPPLER_ANNOT_FILE_ATTACHMENT: {
2636 PopplerAnnotFileAttachment *poppler_annot_attachment;
2637 EvAnnotationAttachment *ev_annot_attachment;
2638 PopplerAttachment *poppler_attachment;
2641 GError *error = NULL;
2643 poppler_annot_attachment = POPPLER_ANNOT_FILE_ATTACHMENT (poppler_annot);
2644 poppler_attachment = poppler_annot_file_attachment_get_attachment (poppler_annot_attachment);
2646 if (poppler_attachment &&
2647 attachment_save_to_buffer (poppler_attachment, &data, &size, &error)) {
2648 EvAttachment *ev_attachment;
2650 ev_attachment = ev_attachment_new (poppler_attachment->name,
2651 poppler_attachment->description,
2652 poppler_attachment->mtime,
2653 poppler_attachment->ctime,
2655 ev_annot = ev_annotation_attachment_new (page, ev_attachment);
2656 g_object_unref (ev_attachment);
2658 g_warning ("%s", error->message);
2659 g_error_free (error);
2662 if (poppler_attachment)
2663 g_object_unref (poppler_attachment);
2666 case POPPLER_ANNOT_LINK:
2667 case POPPLER_ANNOT_WIDGET:
2668 /* Ignore link and widgets annots since they are already handled */
2671 GEnumValue *enum_value;
2673 enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ANNOT_TYPE),
2674 poppler_annot_get_annot_type (poppler_annot));
2675 unimplemented_annot = enum_value ? enum_value->value_name : "Unknown annotation";
2679 if (unimplemented_annot) {
2680 g_warning ("Unimplemented annotation: %s, please post a "
2681 "bug report in Evince bugzilla "
2682 "(http://bugzilla.gnome.org) with a testcase.",
2683 unimplemented_annot);
2693 contents = poppler_annot_get_contents (poppler_annot);
2695 ev_annotation_set_contents (ev_annot, contents);
2699 name = poppler_annot_get_name (poppler_annot);
2701 ev_annotation_set_name (ev_annot, name);
2705 modified = poppler_annot_get_modified (poppler_annot);
2706 if (poppler_date_parse (modified, &utime)) {
2707 ev_annotation_set_modified_from_time (ev_annot, utime);
2709 ev_annotation_set_modified (ev_annot, modified);
2713 poppler_annot_color_to_gdk_color (poppler_annot, &color);
2714 ev_annotation_set_color (ev_annot, &color);
2716 if (POPPLER_IS_ANNOT_MARKUP (poppler_annot)) {
2717 PopplerAnnotMarkup *markup;
2720 PopplerRectangle poppler_rect;
2722 markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2724 if (poppler_annot_markup_get_popup_rectangle (markup, &poppler_rect)) {
2725 EvRectangle ev_rect;
2729 poppler_page_get_size (POPPLER_PAGE (page->backend_page),
2731 ev_rect.x1 = poppler_rect.x1;
2732 ev_rect.x2 = poppler_rect.x2;
2733 ev_rect.y1 = height - poppler_rect.y2;
2734 ev_rect.y2 = height - poppler_rect.y1;
2736 is_open = poppler_annot_markup_get_popup_is_open (markup);
2738 g_object_set (ev_annot,
2739 "rectangle", &ev_rect,
2740 "popup_is_open", is_open,
2744 g_object_set (ev_annot,
2749 label = poppler_annot_markup_get_label (markup);
2750 opacity = poppler_annot_markup_get_opacity (markup);
2752 g_object_set (ev_annot,
2764 static EvMappingList *
2765 pdf_document_annotations_get_annotations (EvDocumentAnnotations *document_annotations,
2768 GList *retval = NULL;
2769 PdfDocument *pdf_document;
2770 PopplerPage *poppler_page;
2771 EvMappingList *mapping_list;
2777 pdf_document = PDF_DOCUMENT (document_annotations);
2778 poppler_page = POPPLER_PAGE (page->backend_page);
2780 if (pdf_document->annots) {
2781 mapping_list = (EvMappingList *)g_hash_table_lookup (pdf_document->annots,
2782 GINT_TO_POINTER (page->index));
2784 return ev_mapping_list_ref (mapping_list);
2787 annots = poppler_page_get_annot_mapping (poppler_page);
2788 poppler_page_get_size (poppler_page, NULL, &height);
2790 for (list = annots; list; list = list->next) {
2791 PopplerAnnotMapping *mapping;
2792 EvMapping *annot_mapping;
2793 EvAnnotation *ev_annot;
2795 mapping = (PopplerAnnotMapping *)list->data;
2797 ev_annot = ev_annot_from_poppler_annot (mapping->annot, page);
2803 /* Make sure annot has a unique name */
2804 if (!ev_annotation_get_name (ev_annot)) {
2805 gchar *name = g_strdup_printf ("annot-%d-%d", page->index, i);
2807 ev_annotation_set_name (ev_annot, name);
2811 annot_mapping = g_new (EvMapping, 1);
2812 annot_mapping->area.x1 = mapping->area.x1;
2813 annot_mapping->area.x2 = mapping->area.x2;
2814 annot_mapping->area.y1 = height - mapping->area.y2;
2815 annot_mapping->area.y2 = height - mapping->area.y1;
2816 annot_mapping->data = ev_annot;
2818 g_object_set_data_full (G_OBJECT (ev_annot),
2820 g_object_ref (mapping->annot),
2821 (GDestroyNotify) g_object_unref);
2823 retval = g_list_prepend (retval, annot_mapping);
2826 poppler_page_free_annot_mapping (annots);
2831 if (!pdf_document->annots) {
2832 pdf_document->annots = g_hash_table_new_full (g_direct_hash,
2834 (GDestroyNotify)NULL,
2835 (GDestroyNotify)ev_mapping_list_unref);
2838 mapping_list = ev_mapping_list_new (page->index, g_list_reverse (retval), (GDestroyNotify)g_object_unref);
2839 g_hash_table_insert (pdf_document->annots,
2840 GINT_TO_POINTER (page->index),
2841 ev_mapping_list_ref (mapping_list));
2843 return mapping_list;
2847 pdf_document_annotations_document_is_modified (EvDocumentAnnotations *document_annotations)
2849 return PDF_DOCUMENT (document_annotations)->annots_modified;
2852 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2854 pdf_document_annotations_add_annotation (EvDocumentAnnotations *document_annotations,
2855 EvAnnotation *annot,
2858 PopplerAnnot *poppler_annot;
2859 PdfDocument *pdf_document;
2861 PopplerPage *poppler_page;
2863 EvMappingList *mapping_list;
2864 EvMapping *annot_mapping;
2865 PopplerRectangle poppler_rect;
2867 PopplerColor poppler_color;
2873 pdf_document = PDF_DOCUMENT (document_annotations);
2874 page = ev_annotation_get_page (annot);
2875 poppler_page = POPPLER_PAGE (page->backend_page);
2877 poppler_page_get_size (poppler_page, NULL, &height);
2878 poppler_rect.x1 = rect->x1;
2879 poppler_rect.x2 = rect->x2;
2880 poppler_rect.y1 = height - rect->y2;
2881 poppler_rect.y2 = height - rect->y1;
2882 poppler_annot = poppler_annot_text_new (pdf_document->document, &poppler_rect);
2884 ev_annotation_get_color (annot, &color);
2885 poppler_color.red = color.red;
2886 poppler_color.green = color.green;
2887 poppler_color.blue = color.blue;
2888 poppler_annot_set_color (poppler_annot, &poppler_color);
2890 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2891 EvAnnotationMarkup *markup = EV_ANNOTATION_MARKUP (annot);
2894 if (ev_annotation_markup_has_popup (markup)) {
2895 EvRectangle popup_rect;
2897 ev_annotation_markup_get_rectangle (markup, &popup_rect);
2898 poppler_rect.x1 = popup_rect.x1;
2899 poppler_rect.x2 = popup_rect.x2;
2900 poppler_rect.y1 = height - popup_rect.y2;
2901 poppler_rect.y2 = height - popup_rect.y1;
2902 poppler_annot_markup_set_popup (POPPLER_ANNOT_MARKUP (poppler_annot), &poppler_rect);
2903 poppler_annot_markup_set_popup_is_open (POPPLER_ANNOT_MARKUP (poppler_annot),
2904 ev_annotation_markup_get_popup_is_open (markup));
2907 label = ev_annotation_markup_get_label (markup);
2909 poppler_annot_markup_set_label (POPPLER_ANNOT_MARKUP (poppler_annot), label);
2912 if (EV_IS_ANNOTATION_TEXT (annot)) {
2913 EvAnnotationText *text = EV_ANNOTATION_TEXT (annot);
2914 EvAnnotationTextIcon icon;
2916 icon = ev_annotation_text_get_icon (text);
2917 poppler_annot_text_set_icon (POPPLER_ANNOT_TEXT (poppler_annot),
2918 get_poppler_annot_text_icon (icon));
2920 poppler_page_add_annot (poppler_page, poppler_annot);
2922 annot_mapping = g_new (EvMapping, 1);
2923 annot_mapping->area = *rect;
2924 annot_mapping->data = annot;
2925 g_object_set_data_full (G_OBJECT (annot),
2927 g_object_ref (poppler_annot),
2928 (GDestroyNotify) g_object_unref);
2930 if (pdf_document->annots) {
2931 mapping_list = (EvMappingList *)g_hash_table_lookup (pdf_document->annots,
2932 GINT_TO_POINTER (page->index));
2933 list = ev_mapping_list_get_list (mapping_list);
2934 name = g_strdup_printf ("annot-%d-%d", page->index, g_list_length (list) + 1);
2935 ev_annotation_set_name (annot, name);
2937 list = g_list_append (list, annot_mapping);
2939 pdf_document->annots = g_hash_table_new_full (g_direct_hash,
2941 (GDestroyNotify)NULL,
2942 (GDestroyNotify)ev_mapping_list_unref);
2943 name = g_strdup_printf ("annot-%d-0", page->index);
2944 ev_annotation_set_name (annot, name);
2946 list = g_list_append (list, annot_mapping);
2947 mapping_list = ev_mapping_list_new (page->index, list, (GDestroyNotify)g_object_unref);
2948 g_hash_table_insert (pdf_document->annots,
2949 GINT_TO_POINTER (page->index),
2950 ev_mapping_list_ref (mapping_list));
2953 pdf_document->annots_modified = TRUE;
2955 #endif /* HAVE_POPPLER_PAGE_ADD_ANNOT */
2958 pdf_document_annotations_save_annotation (EvDocumentAnnotations *document_annotations,
2959 EvAnnotation *annot,
2960 EvAnnotationsSaveMask mask)
2962 PopplerAnnot *poppler_annot;
2964 poppler_annot = POPPLER_ANNOT (g_object_get_data (G_OBJECT (annot), "poppler-annot"));
2968 if (mask & EV_ANNOTATIONS_SAVE_CONTENTS)
2969 poppler_annot_set_contents (poppler_annot,
2970 ev_annotation_get_contents (annot));
2972 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
2973 if (mask & EV_ANNOTATIONS_SAVE_COLOR) {
2977 ev_annotation_get_color (annot, &ev_color);
2978 color.red = ev_color.red;
2979 color.green = ev_color.green;
2980 color.blue = ev_color.blue;
2981 poppler_annot_set_color (poppler_annot, &color);
2984 if (EV_IS_ANNOTATION_MARKUP (annot)) {
2985 EvAnnotationMarkup *ev_markup = EV_ANNOTATION_MARKUP (annot);
2986 PopplerAnnotMarkup *markup = POPPLER_ANNOT_MARKUP (poppler_annot);
2988 if (mask & EV_ANNOTATIONS_SAVE_LABEL)
2989 poppler_annot_markup_set_label (markup, ev_annotation_markup_get_label (ev_markup));
2990 if (mask & EV_ANNOTATIONS_SAVE_OPACITY)
2991 poppler_annot_markup_set_opacity (markup, ev_annotation_markup_get_opacity (ev_markup));
2992 if (mask & EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN)
2993 poppler_annot_markup_set_popup_is_open (markup, ev_annotation_markup_get_popup_is_open (ev_markup));
2996 if (EV_IS_ANNOTATION_TEXT (annot)) {
2997 EvAnnotationText *ev_text = EV_ANNOTATION_TEXT (annot);
2998 PopplerAnnotText *text = POPPLER_ANNOT_TEXT (poppler_annot);
3000 if (mask & EV_ANNOTATIONS_SAVE_TEXT_IS_OPEN) {
3001 poppler_annot_text_set_is_open (text,
3002 ev_annotation_text_get_is_open (ev_text));
3004 if (mask & EV_ANNOTATIONS_SAVE_TEXT_ICON) {
3005 EvAnnotationTextIcon icon;
3007 icon = ev_annotation_text_get_icon (ev_text);
3008 poppler_annot_text_set_icon (text, get_poppler_annot_text_icon (icon));
3011 #endif /* HAVE_POPPLER_PAGE_ADD_ANNOT */
3012 PDF_DOCUMENT (document_annotations)->annots_modified = TRUE;
3016 pdf_document_document_annotations_iface_init (EvDocumentAnnotationsInterface *iface)
3018 iface->get_annotations = pdf_document_annotations_get_annotations;
3019 iface->document_is_modified = pdf_document_annotations_document_is_modified;
3020 #ifdef HAVE_POPPLER_PAGE_ADD_ANNOT
3021 iface->add_annotation = pdf_document_annotations_add_annotation;
3023 iface->save_annotation = pdf_document_annotations_save_annotation;
3027 struct SaveToBufferData {
3033 attachment_save_to_buffer_callback (const gchar *buf,
3038 struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
3042 if (sdata->len + count > sdata->max) {
3043 new_max = MAX (sdata->max * 2, sdata->len + count);
3044 new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
3046 sdata->buffer = new_buffer;
3047 sdata->max = new_max;
3050 memcpy (sdata->buffer + sdata->len, buf, count);
3051 sdata->len += count;
3057 attachment_save_to_buffer (PopplerAttachment *attachment,
3062 static const gint initial_max = 1024;
3063 struct SaveToBufferData sdata;
3068 sdata.buffer = (gchar *) g_malloc (initial_max);
3069 sdata.max = initial_max;
3072 if (! poppler_attachment_save_to_callback (attachment,
3073 attachment_save_to_buffer_callback,
3076 g_free (sdata.buffer);
3080 *buffer = sdata.buffer;
3081 *buffer_size = sdata.len;
3087 pdf_document_attachments_get_attachments (EvDocumentAttachments *document)
3089 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3092 GList *retval = NULL;
3094 attachments = poppler_document_get_attachments (pdf_document->document);
3096 for (list = attachments; list; list = list->next) {
3097 PopplerAttachment *attachment;
3098 EvAttachment *ev_attachment;
3101 GError *error = NULL;
3103 attachment = (PopplerAttachment *) list->data;
3105 if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
3106 ev_attachment = ev_attachment_new (attachment->name,
3107 attachment->description,
3112 retval = g_list_prepend (retval, ev_attachment);
3115 g_warning ("%s", error->message);
3116 g_error_free (error);
3122 g_object_unref (attachment);
3125 return g_list_reverse (retval);
3129 pdf_document_attachments_has_attachments (EvDocumentAttachments *document)
3131 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3133 return poppler_document_has_attachments (pdf_document->document);
3137 pdf_document_document_attachments_iface_init (EvDocumentAttachmentsInterface *iface)
3139 iface->has_attachments = pdf_document_attachments_has_attachments;
3140 iface->get_attachments = pdf_document_attachments_get_attachments;
3145 pdf_document_layers_has_layers (EvDocumentLayers *document)
3147 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3148 PopplerLayersIter *iter;
3150 iter = poppler_layers_iter_new (pdf_document->document);
3153 poppler_layers_iter_free (iter);
3159 build_layers_tree (PdfDocument *pdf_document,
3160 GtkTreeModel *model,
3161 GtkTreeIter *parent,
3162 PopplerLayersIter *iter)
3165 GtkTreeIter tree_iter;
3166 PopplerLayersIter *child;
3167 PopplerLayer *layer;
3168 EvLayer *ev_layer = NULL;
3173 layer = poppler_layers_iter_get_layer (iter);
3175 markup = g_markup_escape_text (poppler_layer_get_title (layer), -1);
3176 visible = poppler_layer_is_visible (layer);
3177 rb_group = poppler_layer_get_radio_button_group_id (layer);
3178 pdf_document->layers = g_list_append (pdf_document->layers,
3179 g_object_ref (layer));
3180 ev_layer = ev_layer_new (g_list_length (pdf_document->layers) - 1,
3181 poppler_layer_is_parent (layer),
3186 title = poppler_layers_iter_get_title (iter);
3187 markup = g_markup_escape_text (title, -1);
3194 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
3195 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
3196 EV_DOCUMENT_LAYERS_COLUMN_TITLE, markup,
3197 EV_DOCUMENT_LAYERS_COLUMN_VISIBLE, visible,
3198 EV_DOCUMENT_LAYERS_COLUMN_ENABLED, TRUE, /* FIXME */
3199 EV_DOCUMENT_LAYERS_COLUMN_SHOWTOGGLE, (layer != NULL),
3200 EV_DOCUMENT_LAYERS_COLUMN_RBGROUP, rb_group,
3201 EV_DOCUMENT_LAYERS_COLUMN_LAYER, ev_layer,
3204 g_object_unref (ev_layer);
3207 child = poppler_layers_iter_get_child (iter);
3209 build_layers_tree (pdf_document, model, &tree_iter, child);
3210 poppler_layers_iter_free (child);
3211 } while (poppler_layers_iter_next (iter));
3214 static GtkTreeModel *
3215 pdf_document_layers_get_layers (EvDocumentLayers *document)
3217 GtkTreeModel *model = NULL;
3218 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3219 PopplerLayersIter *iter;
3221 iter = poppler_layers_iter_new (pdf_document->document);
3223 model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LAYERS_N_COLUMNS,
3224 G_TYPE_STRING, /* TITLE */
3225 G_TYPE_OBJECT, /* LAYER */
3226 G_TYPE_BOOLEAN, /* VISIBLE */
3227 G_TYPE_BOOLEAN, /* ENABLED */
3228 G_TYPE_BOOLEAN, /* SHOWTOGGLE */
3229 G_TYPE_INT); /* RBGROUP */
3230 build_layers_tree (pdf_document, model, NULL, iter);
3231 poppler_layers_iter_free (iter);
3237 pdf_document_layers_show_layer (EvDocumentLayers *document,
3240 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3241 guint layer_id = ev_layer_get_id (layer);
3243 poppler_layer_show (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
3247 pdf_document_layers_hide_layer (EvDocumentLayers *document,
3250 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3251 guint layer_id = ev_layer_get_id (layer);
3253 poppler_layer_hide (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
3257 pdf_document_layers_layer_is_visible (EvDocumentLayers *document,
3260 PdfDocument *pdf_document = PDF_DOCUMENT (document);
3261 guint layer_id = ev_layer_get_id (layer);
3263 return poppler_layer_is_visible (POPPLER_LAYER (g_list_nth_data (pdf_document->layers, layer_id)));
3267 pdf_document_document_layers_iface_init (EvDocumentLayersInterface *iface)
3269 iface->has_layers = pdf_document_layers_has_layers;
3270 iface->get_layers = pdf_document_layers_get_layers;
3271 iface->show_layer = pdf_document_layers_show_layer;
3272 iface->hide_layer = pdf_document_layers_hide_layer;
3273 iface->layer_is_visible = pdf_document_layers_layer_is_visible;