]> www.fi.muni.cz Git - evince.git/blobdiff - backend/pdf/ev-poppler.cc
Make gnome-keyring optional. Fixes bug #509676.
[evince.git] / backend / pdf / ev-poppler.cc
index c7f4eeed29652f875519fc4beeccdeec060edb09..7c3a594df50e1fd15be9485140fa961a322aac7f 100644 (file)
 #include "ev-document-transition.h"
 #include "ev-document-forms.h"
 #include "ev-selection.h"
+#include "ev-transition-effect.h"
 #include "ev-attachment.h"
 #include "ev-image.h"
 
-#if defined (HAVE_CAIRO_PDF) || defined (HAVE_CAIRO_PS)
+#if (defined (HAVE_POPPLER_PAGE_RENDER) || defined (HAVE_POPPLER_PAGE_RENDER_FOR_PRINTING)) && (defined (HAVE_CAIRO_PDF) || defined (HAVE_CAIRO_PS))
 #define HAVE_CAIRO_PRINT
 #endif
 
@@ -123,10 +124,8 @@ static EvLink     *ev_link_from_action      (PdfDocument       *pdf_document,
 static void        pdf_document_search_free (PdfDocumentSearch *search);
 static void        pdf_print_context_free   (PdfPrintContext   *ctx);
 
-G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
-                         {
-                                G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
-                                                       pdf_document_document_iface_init);
+EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
+                        {
                                 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
                                                        pdf_document_security_iface_init);
                                 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
@@ -859,7 +858,10 @@ ev_link_dest_from_dest (PdfDocument *pdf_document,
                        ev_dest = ev_link_dest_new_xyz (dest->page_num - 1,
                                                        dest->left,
                                                        height - dest->top,
-                                                       dest->zoom);
+                                                       dest->zoom,
+                                                       dest->change_left,
+                                                       dest->change_top,
+                                                       dest->change_zoom);
                        g_object_unref (poppler_page);
                }
                        break;
@@ -874,13 +876,15 @@ ev_link_dest_from_dest (PdfDocument *pdf_document,
                                                                  MAX (0, dest->page_num - 1));
                        poppler_page_get_size (poppler_page, NULL, &height);
                        ev_dest = ev_link_dest_new_fith (dest->page_num - 1,
-                                                        height - dest->top);
+                                                        height - dest->top,
+                                                        dest->change_top);
                        g_object_unref (poppler_page);
                }
                        break;
                case POPPLER_DEST_FITV:
                        ev_dest = ev_link_dest_new_fitv (dest->page_num - 1,
-                                                        dest->left);
+                                                        dest->left,
+                                                        dest->change_left);
                        break;
                case POPPLER_DEST_FITR: {
                        PopplerPage *poppler_page;
@@ -1520,8 +1524,8 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
 {
        PdfDocument *pdf_document = PDF_DOCUMENT (exporter);
        PdfPrintContext *ctx;
-       gdouble width, height;
 #ifdef HAVE_CAIRO_PRINT
+       gdouble width, height;
        cairo_surface_t *surface = NULL;
 #endif
        
@@ -1530,6 +1534,8 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
        pdf_document->print_ctx = g_new0 (PdfPrintContext, 1);
        ctx = pdf_document->print_ctx;
        ctx->format = fc->format;
+       
+#ifdef HAVE_CAIRO_PRINT
        ctx->pages_per_sheet = CLAMP (fc->pages_per_sheet, 1, 16);
 
        ctx->paper_width = fc->paper_width;
@@ -1564,18 +1570,12 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
        }
 
        ctx->pages_printed = 0;
-
+       
        switch (fc->format) {
                case EV_FILE_FORMAT_PS:
 #ifdef HAVE_CAIRO_PS
                        surface = cairo_ps_surface_create (fc->filename, fc->paper_width, fc->paper_height);
-#else
-                       ctx->ps_file = poppler_ps_file_new (pdf_document->document,
-                                                           fc->filename, fc->first_page,
-                                                           fc->last_page - fc->first_page + 1);
-                       poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
-                       poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
-#endif /* HAVE_CAIRO_PS */
+#endif
                        break;
                case EV_FILE_FORMAT_PDF:
 #ifdef HAVE_CAIRO_PDF
@@ -1586,10 +1586,18 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
                        g_assert_not_reached ();
        }
 
-#ifdef HAVE_CAIRO_PRINT
        ctx->cr = cairo_create (surface);
        cairo_surface_destroy (surface);
-#endif
+
+#else /* HAVE_CAIRO_PRINT */
+       if (ctx->format == EV_FILE_FORMAT_PS) {
+               ctx->ps_file = poppler_ps_file_new (pdf_document->document,
+                                                   fc->filename, fc->first_page,
+                                                   fc->last_page - fc->first_page + 1);
+               poppler_ps_file_set_paper_size (ctx->ps_file, fc->paper_width, fc->paper_height);
+               poppler_ps_file_set_duplex (ctx->ps_file, fc->duplex);
+       }
+#endif /* HAVE_CAIRO_PRINT */
 }
 
 static void
@@ -1601,7 +1609,8 @@ pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
        g_return_if_fail (pdf_document->print_ctx != NULL);
 
        ctx->pages_printed = 0;
-
+       
+#ifdef HAVE_CAIRO_PRINT
        if (ctx->paper_width > ctx->paper_height) {
                if (ctx->format == EV_FILE_FORMAT_PS) {
                        cairo_ps_surface_set_size (cairo_get_target (ctx->cr),
@@ -1613,6 +1622,7 @@ pdf_document_file_exporter_begin_page (EvFileExporter *exporter)
                                                    ctx->paper_width);
                }
        }
+#endif /* HAVE_CAIRO_PRINT */
 }
 
 static void
@@ -1739,7 +1749,9 @@ pdf_document_file_exporter_end_page (EvFileExporter *exporter)
        
        g_return_if_fail (pdf_document->print_ctx != NULL);
 
+#ifdef HAVE_CAIRO_PRINT
        cairo_show_page (ctx->cr);
+#endif
 }
 
 static void
@@ -1956,16 +1968,49 @@ pdf_document_get_page_duration (EvDocumentTransition *trans,
        return duration;
 }
 
-static void
-pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
+static EvTransitionEffect *
+pdf_document_get_effect (EvDocumentTransition *trans,
+                        gint                  page)
 {
-       iface->get_page_duration = pdf_document_get_page_duration;
+       PdfDocument            *pdf_document;
+       PopplerPage            *poppler_page;
+       PopplerPageTransition  *page_transition;
+       EvTransitionEffect     *effect;
+
+       pdf_document = PDF_DOCUMENT (trans);
+       poppler_page = poppler_document_get_page (pdf_document->document, page);
+
+       if (!poppler_page)
+               return NULL;
+
+       page_transition = poppler_page_get_transition (poppler_page);
+
+       if (!page_transition) {
+               g_object_unref (poppler_page);
+               return NULL;
+       }
+
+       /* enums in PopplerPageTransition match the EvTransitionEffect ones */
+       effect = ev_transition_effect_new ((EvTransitionEffectType) page_transition->type,
+                                          "alignment", page_transition->alignment,
+                                          "direction", page_transition->direction,
+                                          "duration", page_transition->duration,
+                                          "angle", page_transition->angle,
+                                          "scale", page_transition->scale,
+                                          "rectangular", page_transition->rectangular,
+                                          NULL);
+
+       poppler_page_transition_free (page_transition);
+       g_object_unref (poppler_page);
+
+       return effect;
 }
 
-PdfDocument *
-pdf_document_new (void)
+static void
+pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
 {
-       return PDF_DOCUMENT (g_object_new (PDF_TYPE_DOCUMENT, NULL));
+       iface->get_page_duration = pdf_document_get_page_duration;
+       iface->get_effect = pdf_document_get_effect;
 }
 
 /* Forms */