From f5ae890ba055fd90a4ac289ff83eacec01bf49e3 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Fri, 3 Jan 2014 23:31:56 +0100 Subject: [PATCH] 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 --- glib/poppler.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/glib/poppler.cc b/glib/poppler.cc index cc2ca4d..c6bc6d1 100644 --- a/glib/poppler.cc +++ b/glib/poppler.cc @@ -19,6 +19,10 @@ #include #include "poppler.h" +#ifndef __GI_SCANNER__ +#include +#endif + GQuark poppler_error_quark (void) { static GQuark q = 0; @@ -56,3 +60,48 @@ 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", + "", + "", + "IO error", + "", + "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 poppler_constructor (void) __attribute__((__constructor__)); + +static void +poppler_constructor (void) +{ + setErrorCallback (error_cb, NULL); +} + +#endif /* GNUC */ -- 1.8.3.1