[evince/wip/bug654832: 14/16] pdf: Implement EvDocument::load_{stream, gfile}_sync vfunc



commit b06327be68767d0a19cc8b781855e462aefe0e05
Author: Christian Persch <chpe gnome org>
Date:   Sun May 13 19:46:24 2012 +0200

    pdf: Implement EvDocument::load_{stream,gfile}_sync vfunc

 backend/pdf/ev-poppler.cc |   66 +++++++++++++++++++++++++++++++++++++++++++++
 configure.ac              |    4 +++
 2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 95c127e..8a9d40e 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -280,6 +280,66 @@ pdf_document_load (EvDocument   *document,
 	return TRUE;
 }
 
+#ifdef HAVE_POPPLER_DOCUMENT_NEW_FROM_STREAM
+
+static gboolean
+pdf_document_load_stream_sync (EvDocument          *document,
+                               GInputStream        *stream,
+                               EvDocumentLoadFlags  flags,
+                               GCancellable        *cancellable,
+                               GError             **error)
+{
+        GError *err = NULL;
+        PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+        pdf_document->document =
+                poppler_document_new_from_stream (stream, -1, 
+                                                  pdf_document->password,
+                                                  cancellable,
+                                                  &err);
+
+        if (pdf_document->document == NULL) {
+                convert_error (err, error);
+                return FALSE;
+        }
+
+        return TRUE;
+}
+
+#else
+#error foo
+#endif
+
+#ifdef HAVE_POPPLER_DOCUMENT_NEW_FROM_GFILE
+
+static gboolean
+pdf_document_load_gfile_sync (EvDocument          *document,
+                              GFile               *file,
+                              EvDocumentLoadFlags  flags,
+                              GCancellable        *cancellable,
+                              GError             **error)
+{
+        GError *err = NULL;
+        PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+        pdf_document->document =
+                poppler_document_new_from_gfile (file,
+                                                 pdf_document->password,
+                                                 cancellable,
+                                                 &err);
+
+        if (pdf_document->document == NULL) {
+                convert_error (err, error);
+                return FALSE;
+        }
+
+        return TRUE;
+}
+
+#else
+#error foobar
+#endif
+
 static int
 pdf_document_get_n_pages (EvDocument *document)
 {
@@ -887,6 +947,12 @@ pdf_document_class_init (PdfDocumentClass *klass)
 
 	ev_document_class->save = pdf_document_save;
 	ev_document_class->load = pdf_document_load;
+#ifdef HAVE_POPPLER_DOCUMENT_NEW_FROM_STREAM
+        ev_document_class->load_stream_sync = pdf_document_load_stream_sync;
+#endif
+#ifdef HAVE_POPPLER_DOCUMENT_NEW_FROM_GFILE
+        ev_document_class->load_gfile_sync = pdf_document_load_gfile_sync;
+#endif
 	ev_document_class->get_n_pages = pdf_document_get_n_pages;
 	ev_document_class->get_page = pdf_document_get_page;
 	ev_document_class->get_page_size = pdf_document_get_page_size;
diff --git a/configure.ac b/configure.ac
index 50abc0e..ed4f037 100644
--- a/configure.ac
+++ b/configure.ac
@@ -486,6 +486,10 @@ if test "x$enable_pdf" = "xyes"; then
     else
 	    AC_MSG_ERROR("PDF support is disabled since poppler-glib library version $POPPLER_REQUIRED or newer not found")
     fi 
+    evince_save_LIBS=$LIBS
+    LIBS="$LIBS $POPPLER_LIBS"
+    AC_CHECK_FUNCS(poppler_document_new_from_stream poppler_document_new_from_gfile)
+    LIBS=$evince_save_LIBS
 fi
 
 AM_CONDITIONAL(ENABLE_PDF, test x$enable_pdf = xyes)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]