[evince/wip/chpe/load-fd: 17/17] pdf: Implement loading from file descriptor




commit 687a2afe5830056d3f6a18cc37a8b4291c0fc40d
Author: Christian Persch <chpe src gnome org>
Date:   Wed Dec 1 21:25:02 2021 +0100

    pdf: Implement loading from file descriptor

 backend/pdf/ev-poppler.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
---
diff --git a/backend/pdf/ev-poppler.c b/backend/pdf/ev-poppler.c
index 1bba43a9a..8738f0052 100644
--- a/backend/pdf/ev-poppler.c
+++ b/backend/pdf/ev-poppler.c
@@ -30,6 +30,7 @@
 #include <poppler.h>
 #include <poppler-document.h>
 #include <poppler-page.h>
+#include <poppler-features.h>
 #ifdef HAVE_CAIRO_PDF
 #include <cairo-pdf.h>
 #endif
@@ -66,6 +67,10 @@
 #define HAVE_CAIRO_PRINT
 #endif
 
+#if POPPLER_CHECK_VERSION (21, 12, 0)
+#define HAVE_POPPLER_LOAD_FD
+#endif
+
 typedef struct {
        EvFileExporterFormat format;
 
@@ -314,6 +319,32 @@ pdf_document_load_gfile (EvDocument          *document,
         return TRUE;
 }
 
+#ifdef HAVE_POPPLER_LOAD_FD
+static gboolean
+pdf_document_load_fd (EvDocument          *document,
+                      int                  fd,
+                      EvDocumentLoadFlags  flags,
+                      GCancellable        *cancellable,
+                      GError             **error)
+{
+        GError *err = NULL;
+        PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+        /* Note: this consumes @fd */
+        pdf_document->document =
+                poppler_document_new_from_fd (fd,
+                                              pdf_document->password,
+                                              &err);
+
+        if (pdf_document->document == NULL) {
+                convert_error (err, error);
+                return FALSE;
+        }
+
+        return TRUE;
+}
+#endif
+
 static int
 pdf_document_get_n_pages (EvDocument *document)
 {
@@ -767,6 +798,9 @@ pdf_document_class_init (PdfDocumentClass *klass)
        ev_document_class->get_info = pdf_document_get_info;
        ev_document_class->get_backend_info = pdf_document_get_backend_info;
        ev_document_class->support_synctex = pdf_document_support_synctex;
+#ifdef HAVE_POPPLER_LOAD_FD
+        ev_document_class->load_fd = pdf_document_load_fd;
+#endif
 }
 
 /* EvDocumentSecurity */


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