[gimp] Bug 544560 - Loading PDF file fails if its path contains non-ascii characters



commit df24468fde963d158d57d8926c4459f718403335
Author: Tor Lillqvist <tml iki fi>
Date:   Sun May 16 11:00:53 2010 +0200

    Bug 544560 - Loading PDF file fails if its path contains non-ascii characters
    
    Use poppler_document_new_from_data() instead of
    poppler_document_new_from_file() to work around filename encoding
    issues.

 plug-ins/common/file-pdf.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/plug-ins/common/file-pdf.c b/plug-ins/common/file-pdf.c
index 2bd8fe8..43c9c8a 100644
--- a/plug-ins/common/file-pdf.c
+++ b/plug-ins/common/file-pdf.c
@@ -526,28 +526,34 @@ open_document (const gchar  *filename,
                GError      **load_error)
 {
   PopplerDocument *doc;
-  gchar           *uri;
+  GMappedFile     *mapped_file;
   GError          *error = NULL;
 
-  uri = g_filename_to_uri (filename, NULL, &error);
+  mapped_file = g_mapped_file_new (filename, FALSE, &error);
 
-  if (! uri)
+  if (! mapped_file)
     {
       g_set_error (load_error, 0, 0,
-                   "Could not convert '%s' to an URI: %s",
+                   "Could not load '%s' %s",
                    gimp_filename_to_utf8 (filename), error->message);
       g_error_free (error);
       return NULL;
     }
 
-  doc = poppler_document_new_from_file (uri, NULL, &error);
+  doc = poppler_document_new_from_data (g_mapped_file_get_contents (mapped_file),
+                                        g_mapped_file_get_length (mapped_file),
+                                        NULL,
+                                        &error);
 
-  g_free (uri);
+  /* 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
+   * short-lived plug-in.
+   */
 
   if (! doc)
     {
       g_set_error (load_error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
-                   _("Could not open '%s' for reading: %s"),
+                   _("Could not load '%s': %s"),
                    gimp_filename_to_utf8 (filename),
                    error->message);
       g_error_free (error);



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