[evince: 11/13] pdf: Implement EvDocument::load_{stream, gfile}_sync vfunc



commit de8535e04e73a855ec160aacef5244ca17d2949b
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 |   58 +++++++++++++++++++++++++++++++++++++++++++++
 configure.ac              |    4 +++
 2 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 95c127e..77550ac 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -280,6 +280,58 @@ pdf_document_load (EvDocument   *document,
 	return TRUE;
 }
 
+#ifdef HAVE_POPPLER_DOCUMENT_NEW_FROM_STREAM
+static gboolean
+pdf_document_load_stream (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;
+}
+#endif
+
+#ifdef HAVE_POPPLER_DOCUMENT_NEW_FROM_GFILE
+static gboolean
+pdf_document_load_gfile (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;
+}
+#endif
+
 static int
 pdf_document_get_n_pages (EvDocument *document)
 {
@@ -887,6 +939,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 = pdf_document_load_stream;
+#endif
+#ifdef HAVE_POPPLER_DOCUMENT_NEW_FROM_GFILE
+        ev_document_class->load_gfile = pdf_document_load_gfile;
+#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]