[poppler] glib/poppler.cc

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Tue Jan 21 05:47:06 PST 2014


 glib/poppler.cc |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

New commits:
commit 92ea15642a6d3fe65d66d5c59fb6bed54e060e5d
Author: Christian Persch <chpe at gnome.org>
Date:   Fri Jan 3 23:31:56 2014 +0100

    glib: Install error callback
    
    Install an error callback so that poppler error messages can be redirected
    to the GLib logging API.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=73269

diff --git a/glib/poppler.cc b/glib/poppler.cc
index cc2ca4d..09ec9f4 100644
--- a/glib/poppler.cc
+++ b/glib/poppler.cc
@@ -19,6 +19,10 @@
 #include <config.h>
 #include "poppler.h"
 
+#ifndef __GI_SCANNER__
+#include <Error.h>
+#endif
+
 GQuark poppler_error_quark (void)
 {
   static GQuark q = 0;
@@ -56,3 +60,46 @@ poppler_get_version (void)
 {
   return poppler_version;
 }
+
+#if  __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+
+/* We want to install an error callback so that PDF syntax warnings etc
+ * can be redirected through the GLib logging API instead of always just
+ * going to stderr.
+ */
+
+static void
+error_cb (void *data G_GNUC_UNUSED,
+          ErrorCategory category,
+          Goffset pos,
+          char *message)
+{
+  static const char * const cat_str[] = {
+    "Syntax warning",
+    "Syntax error",
+    NULL,
+    NULL,
+    "IO error",
+    NULL,
+    "Unimplemented feature",
+    "Internal error"
+  };
+
+  /* The following will never occur in poppler-glib */
+  if (category == errConfig ||
+      category == errCommandLine ||
+      category == errNotAllowed)
+    return;
+
+  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO,
+         "%s at position %" G_GOFFSET_FORMAT ": %s",
+         cat_str[category], (goffset) pos, message);
+}
+
+static void __attribute__((__constructor__))
+poppler_constructor (void)
+{
+  setErrorCallback (error_cb, NULL);
+}
+
+#endif /* GNUC */


More information about the poppler mailing list