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




commit 87ed241ccc24903e784b763cfb0bd73c336a8281
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 | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/backend/pdf/ev-poppler.c b/backend/pdf/ev-poppler.c
index 27c9a2e8e..852ccdcf0 100644
--- a/backend/pdf/ev-poppler.c
+++ b/backend/pdf/ev-poppler.c
@@ -1,4 +1,3 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
 /* this file is part of evince, a gnome document viewer
  *
  * Copyright (C) 2018, Evangelos Rigas <erigas rnd2 org>
@@ -31,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
@@ -72,6 +72,10 @@
 #define HAVE_CAIRO_PRINT
 #endif
 
+#if POPPLER_CHECK_VERSION (21, 12, 0)
+#define HAVE_POPPLER_LOAD_FD
+#endif
+
 /* Fields for checking the license info suggested by Creative Commons 
  * Main reference: http://wiki.creativecommons.org/XMP */
 
@@ -354,6 +358,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)
 {
@@ -1223,6 +1253,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]