[poppler] glib/poppler-document.cc glib/poppler.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Tue Mar 18 12:08:40 PDT 2008


 glib/poppler-document.cc |   40 ++++++++++++++++++++++++++++------------
 glib/poppler.h           |    5 ++++-
 2 files changed, 32 insertions(+), 13 deletions(-)

New commits:
commit 185d5818fd546f85934b041d5b0cdcdf1849b1dc
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Mar 18 20:08:21 2008 +0100

    Improve error handling when creating a document

diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index ef71db4..0348718 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -70,19 +70,35 @@ _poppler_document_new_from_pdfdoc (PDFDoc  *newDoc,
   document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL, NULL);
 
   if (!newDoc->isOk()) {
-    err = newDoc->getErrorCode();
-    delete newDoc;
-    if (err == errEncrypted) {
-      g_set_error (error, POPPLER_ERROR,
-		   POPPLER_ERROR_ENCRYPTED,
-		   "Document is encrypted.");
-    } else {
-      g_set_error (error, G_FILE_ERROR,
-		   G_FILE_ERROR_FAILED,
-		   "Failed to load document from data (error %d)'\n",
-		   err);
+    switch (newDoc->getErrorCode())
+      {
+      case errOpenFile:
+        g_set_error (error, POPPLER_ERROR,
+		     POPPLER_ERROR_OPEN_FILE,
+		     "Failed to open the PDF file");
+	break;
+      case errBadCatalog:
+        g_set_error (error, POPPLER_ERROR,
+		     POPPLER_ERROR_BAD_CATALOG,
+		     "Failed to read the document catalog");
+	break;
+      case errDamaged:
+        g_set_error (error, POPPLER_ERROR,
+		     POPPLER_ERROR_DAMAGED,
+		     "PDF document is damaged");
+	break;
+      case errEncrypted:
+        g_set_error (error, POPPLER_ERROR,
+		     POPPLER_ERROR_ENCRYPTED,
+		     "Document is encrypted");
+	break;
+      default:
+        g_set_error (error, POPPLER_ERROR,
+		     POPPLER_ERROR_INVALID,
+		     "Failed to load document");
     }
-
+    
+    delete newDoc;
     return NULL;
   }
 
diff --git a/glib/poppler.h b/glib/poppler.h
index 5f3eaa8..88a330c 100644
--- a/glib/poppler.h
+++ b/glib/poppler.h
@@ -30,7 +30,10 @@ GQuark poppler_error_quark (void);
 typedef enum
 {
   POPPLER_ERROR_INVALID,
-  POPPLER_ERROR_ENCRYPTED
+  POPPLER_ERROR_ENCRYPTED,
+  POPPLER_ERROR_OPEN_FILE,
+  POPPLER_ERROR_BAD_CATALOG,
+  POPPLER_ERROR_DAMAGED
 } PopplerError;
 
 typedef enum


More information about the poppler mailing list