summaryrefslogtreecommitdiff
path: root/glib/poppler.cc
blob: abb634ffd17aead3376c8ecd43b634d750c47378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* poppler.cc: glib wrapper for poppler
 * Copyright (C) 2005, Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <config.h>
#include "poppler.h"

#ifndef __GI_SCANNER__
#include <Error.h>
#endif

/**
 * SECTION: poppler-errors
 * @title: Error handling
 * @short_description: Error domain and codes
 *
 */

/**
 * POPPLER_ERROR:
 *
 * Error domain for poppler operations. Errors in this domain will
 * be from the #PopplerError enumeration. See #GError for information
 * on error domains.
 */

GQuark poppler_error_quark (void)
{
  static GQuark q = 0;

  if (q == 0)
    q = g_quark_from_static_string ("poppler-quark");

  return q;
}

/**
 * poppler_get_backend:
 * 
 * Returns the backend compiled into the poppler library.
 * 
 * Return value: The backend used by poppler
 **/
PopplerBackend
poppler_get_backend (void)
{
  return POPPLER_BACKEND_CAIRO;
}

static const char poppler_version[] = PACKAGE_VERSION;

/**
 * poppler_get_version:
 * 
 * Returns the version of poppler in use.  This result is not to be freed.
 * 
 * Return value: the version of poppler.
 **/
const char *
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 */