]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/ev-poppler.cc
Add page transition support in presentation mode. At the moment only page
[evince.git] / pdf / ev-poppler.cc
index d49579e24e983094ed9fec305753df1f5d5129f2..479a741bb887e4bffb3de39df86f1151d75e3235 100644 (file)
@@ -25,7 +25,9 @@
 #include <poppler.h>
 #include <poppler-document.h>
 #include <poppler-page.h>
+#ifdef HAVE_CAIRO_PDF
 #include <cairo-pdf.h>
+#endif
 #include <glib/gi18n.h>
 
 #include "ev-poppler.h"
@@ -36,6 +38,7 @@
 #include "ev-document-fonts.h"
 #include "ev-document-security.h"
 #include "ev-document-thumbnails.h"
+#include "ev-document-transition.h"
 #include "ev-selection.h"
 #include "ev-attachment.h"
 
@@ -51,7 +54,9 @@ typedef struct {
 typedef struct {
        EvFileExporterFormat format;
        PopplerPSFile *ps_file;
+#ifdef HAVE_CAIRO_PDF
        cairo_t *pdf_cairo;
+#endif
 } PdfPrintContext;
 
 struct _PdfDocumentClass
@@ -82,6 +87,7 @@ static void pdf_document_document_fonts_iface_init      (EvDocumentFontsIface
 static void pdf_document_find_iface_init                (EvDocumentFindIface       *iface);
 static void pdf_document_file_exporter_iface_init       (EvFileExporterIface       *iface);
 static void pdf_selection_iface_init                    (EvSelectionIface          *iface);
+static void pdf_document_page_transition_iface_init     (EvDocumentTransitionIface *iface);
 static void pdf_document_thumbnails_get_dimensions      (EvDocumentThumbnails      *document_thumbnails,
                                                         gint                       page,
                                                         gint                       size,
@@ -115,6 +121,8 @@ G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
                                                        pdf_document_file_exporter_iface_init);
                                 G_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION,
                                                        pdf_selection_iface_init);
+                                G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION,
+                                                       pdf_document_page_transition_iface_init);
                         });
 
 
@@ -1147,9 +1155,11 @@ make_thumbnail_for_size (PdfDocument   *pdf_document,
                                 width, height);
        gdk_pixbuf_fill (pixbuf, 0xffffffff);
 
+       ev_document_fc_mutex_lock ();
        poppler_page_render_to_pixbuf (poppler_page, 0, 0,
                                       width, height,
                                       scale, rotation, pixbuf);
+       ev_document_fc_mutex_unlock ();
        
 
        g_object_unref (poppler_page);
@@ -1423,11 +1433,13 @@ pdf_document_find_iface_init (EvDocumentFindIface *iface)
 
 static const gboolean supported_formats[] = {
        TRUE, /* EV_FILE_FORMAT_PS */
+#ifdef HAVE_CAIRO_PDF
 #ifdef HAVE_POPPLER_PAGE_RENDER
        TRUE, /* EV_FILE_FORMAT_PDF */
 #else
        FALSE, /* EV_FILE_FORMAT_PDF */
 #endif
+#endif
 };
 
 static void
@@ -1440,12 +1452,12 @@ pdf_print_context_free (PdfPrintContext *ctx)
                poppler_ps_file_free (ctx->ps_file);
                ctx->ps_file = NULL;
        }
-
+#ifdef HAVE_CAIRO_PDF
        if (ctx->pdf_cairo) {
                cairo_destroy (ctx->pdf_cairo);
                ctx->pdf_cairo = NULL;
        }
-
+#endif
        g_free (ctx);
 }
 
@@ -1485,11 +1497,13 @@ pdf_document_file_exporter_begin (EvFileExporter      *exporter,
 
                        break;
                case EV_FILE_FORMAT_PDF: {
+#ifdef HAVE_CAIRO_PDF
                        cairo_surface_t *surface;
                        
                        surface = cairo_pdf_surface_create (filename, width, height);
                        ctx->pdf_cairo = cairo_create (surface);
                        cairo_surface_destroy (surface);
+#endif
                }
                        break;
                default:
@@ -1516,7 +1530,9 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *r
 #ifdef HAVE_POPPLER_PAGE_RENDER
                        poppler_page_render (poppler_page, ctx->pdf_cairo);
 #endif
+#ifdef HAVE_CAIRO_PDF
                        cairo_show_page (ctx->pdf_cairo);
+#endif
                        break;
                default:
                        g_assert_not_reached ();
@@ -1625,6 +1641,36 @@ pdf_selection_iface_init (EvSelectionIface *iface)
         iface->get_selection_map = pdf_selection_get_selection_map;
 }
 
+/* Page Transitions */
+static gdouble
+pdf_document_get_page_duration (EvDocumentTransition *trans,
+                               gint                  page)
+{
+#ifdef HAVE_POPPLER_PAGE_GET_DURATION  
+       PdfDocument *pdf_document;
+       PopplerPage *poppler_page;
+       gdouble      duration = -1;
+
+       pdf_document = PDF_DOCUMENT (trans);
+       poppler_page = poppler_document_get_page (pdf_document->document, page);
+       if (!poppler_page)
+               return -1;
+
+       duration = poppler_page_get_duration (poppler_page);
+       g_object_unref (poppler_page);
+
+       return duration;
+#else
+       return -1;
+#endif /* HAVE_POPPLER_PAGE_GET_DURATION */
+}
+
+static void
+pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface)
+{
+       iface->get_page_duration = pdf_document_get_page_duration;
+}
+
 PdfDocument *
 pdf_document_new (void)
 {