[gimp] Issue #2611: Cannot open certain .pdf files in GIMP.



commit a89e50305468f498f27d0b98948cb22b1495f5f6
Author: Jehan <jehan girinstud io>
Date:   Wed Jan 2 22:51:31 2019 +0100

    Issue #2611: Cannot open certain .pdf files in GIMP.
    
    I am unsure of the problem, but it is fixed by using
    poppler_document_new_from_gfile() instead of giving the contents of a
    GMappedFile to poppler_document_new_from_data().
    Using GFile is anyway usually prefered so I don't dig up more and just
    make this change.

 plug-ins/common/file-pdf-load.c | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)
---
diff --git a/plug-ins/common/file-pdf-load.c b/plug-ins/common/file-pdf-load.c
index 1d878da4db..86c2cc9094 100644
--- a/plug-ins/common/file-pdf-load.c
+++ b/plug-ins/common/file-pdf-load.c
@@ -668,24 +668,11 @@ open_document (const gchar  *filename,
                GError      **load_error)
 {
   PopplerDocument *doc;
-  GMappedFile     *mapped_file;
+  GFile           *file;
   GError          *error = NULL;
 
-  mapped_file = g_mapped_file_new (filename, FALSE, &error);
-
-  if (! mapped_file)
-    {
-      g_set_error (load_error, GIMP_PLUGIN_PDF_LOAD_ERROR, 0,
-                   _("Could not load '%s': %s"),
-                   gimp_filename_to_utf8 (filename), error->message);
-      g_error_free (error);
-      return NULL;
-    }
-
-  doc = poppler_document_new_from_data (g_mapped_file_get_contents (mapped_file),
-                                        g_mapped_file_get_length (mapped_file),
-                                        PDF_password,
-                                        &error);
+  file = g_file_new_for_path (filename);
+  doc = poppler_document_new_from_gfile (file, PDF_password, NULL, &error);
 
   if (run_mode == GIMP_RUN_INTERACTIVE)
     {
@@ -724,10 +711,9 @@ open_document (const gchar  *filename,
           if (run == GTK_RESPONSE_OK)
             {
               g_clear_error (&error);
-              doc = poppler_document_new_from_data (g_mapped_file_get_contents (mapped_file),
-                                                    g_mapped_file_get_length (mapped_file),
-                                                    gtk_entry_get_text (GTK_ENTRY (entry)),
-                                                    &error);
+              doc = poppler_document_new_from_gfile (file,
+                                                     gtk_entry_get_text (GTK_ENTRY (entry)),
+                                                     NULL, &error);
             }
           label = gtk_label_new (_("Wrong password! Please input the right one:"));
           gtk_widget_destroy (dialog);
@@ -738,6 +724,7 @@ open_document (const gchar  *filename,
         }
       gtk_widget_destroy (label);
     }
+  g_object_unref (file);
 
   /* We can't g_mapped_file_unref(mapped_file) as apparently doc has
    * references to data in there. No big deal, this is just a


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