1 /* poppler.cc: glib wrapper for poppler
2  * Copyright (C) 2005, Red Hat, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include <config.h>
20 #include "poppler.h"
21 
22 #ifndef __GI_SCANNER__
23 #    include <Error.h>
24 #endif
25 
26 #include "poppler-private.h"
27 
28 /**
29  * SECTION: poppler-errors
30  * @title: Error handling
31  * @short_description: Error domain and codes
32  *
33  */
34 
35 /**
36  * POPPLER_ERROR:
37  *
38  * Error domain for poppler operations. Errors in this domain will
39  * be from the #PopplerError enumeration. See #GError for information
40  * on error domains.
41  */
42 
poppler_error_quark(void)43 GQuark poppler_error_quark(void)
44 {
45     static GQuark q = 0;
46 
47     if (q == 0)
48         q = g_quark_from_static_string("poppler-quark");
49 
50     return q;
51 }
52 
53 /**
54  * poppler_get_backend:
55  *
56  * Returns the backend compiled into the poppler library.
57  *
58  * Return value: The backend used by poppler
59  **/
poppler_get_backend(void)60 PopplerBackend poppler_get_backend(void)
61 {
62     return POPPLER_BACKEND_CAIRO;
63 }
64 
65 static const char poppler_version[] = PACKAGE_VERSION;
66 
67 /**
68  * poppler_get_version:
69  *
70  * Returns the version of poppler in use.  This result is not to be freed.
71  *
72  * Return value: the version of poppler.
73  **/
poppler_get_version(void)74 const char *poppler_get_version(void)
75 {
76     return poppler_version;
77 }
78 
79 /* We want to install an error callback so that PDF syntax warnings etc
80  * can be redirected through the GLib logging API instead of always just
81  * going to stderr.
82  */
83 
_poppler_error_cb(ErrorCategory category,Goffset pos,const char * message)84 void _poppler_error_cb(ErrorCategory category, Goffset pos, const char *message)
85 {
86     static const char *const cat_str[] = { "Syntax warning", "Syntax error", nullptr, nullptr, "IO error", nullptr, "Unimplemented feature", "Internal error" };
87 
88     /* The following will never occur in poppler-glib */
89     if (category == errConfig || category == errCommandLine || category == errNotAllowed)
90         return;
91 
92     g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s at position %" G_GOFFSET_FORMAT ": %s", cat_str[category], (goffset)pos, message);
93 }
94