diff options
author | Christian Persch <chpe@gnome.org> | 2014-01-03 23:31:56 +0100 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2014-01-21 14:45:25 +0100 |
commit | 92ea15642a6d3fe65d66d5c59fb6bed54e060e5d (patch) | |
tree | 3b00752e09bb28672bd9a91c758f949e4a9d274e /glib/poppler.cc | |
parent | f99128e38bbff43623d5cd1c1bc27fd789d0bc0c (diff) |
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
Diffstat (limited to 'glib/poppler.cc')
-rw-r--r-- | glib/poppler.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/glib/poppler.cc b/glib/poppler.cc index cc2ca4de..09ec9f45 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 */ |