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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
// Copyright (C) 2013, 2014 Andreas Politz
// Author: Andreas Politz <politza@fh-trier.de>
// 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
#ifndef _EPDF_H_
#define _EPDF_H_ _EPDF_H_
#include "config.h"
#include <glib.h>
#include <poppler.h>
#include <png.h>
/* Some library functions print warnings to stdout, inhibit it. */
#define DISCARD_STDOUT(saved_fd) \
do { \
int __fd; \
fflush(stdout); \
saved_fd = dup(1); \
__fd = open("/dev/null", O_WRONLY); \
dup2(__fd, 1); \
close(__fd); \
} while (0)
#define UNDISCARD_STDOUT(saved_fd) \
do { \
fflush(stdout); \
dup2(saved_fd, 1); \
close(saved_fd); \
} while (0)
/* Writing responses */
#define OK_BEGIN() \
do { \
puts("OK"); \
} while (0)
#define OK_END() \
do { \
puts("."); \
fflush (stdout); \
} while (0)
#define OK() \
do { \
puts ("OK\n."); \
fflush (stdout); \
} while (0)
/* Dealing with image data. */
#ifdef WORDS_BIGENDIAN
#define ARGB_TO_RGB(rgb, argb) \
do { \
rgb[0] = argb[1]; \
rgb[1] = argb[2]; \
rgb[2] = argb[3]; \
} while (0)
#define ARGB_EQUAL(argb1, argb2) \
(argb1[1] == argb2[1] \
&& argb1[2] == argb2[2] \
&& argb1[3] == argb2[3])
#else
#define ARGB_TO_RGB(rgb, argb) \
do { \
rgb[0] = argb[2]; \
rgb[1] = argb[1]; \
rgb[2] = argb[0]; \
} while (0)
#define ARGB_EQUAL(argb1, argb2) \
(argb1[0] == argb2[0] \
&& argb1[1] == argb2[1] \
&& argb1[2] == argb2[2])
#endif
#define NORMALIZE_PAGE_ARG(doc, first, last) \
*first = MAX(1, *first); \
if (*last <= 0) \
*last = poppler_document_get_n_pages (doc); \
else \
*last = MIN(*last, poppler_document_get_n_pages (doc));
/* png_jmpbuf is supposed to be not available in older versions of
libpng. */
#ifndef png_jmpbuf
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
#endif
#ifndef HAVE_ERROR_H
# define error(status, errno, fmt, args...) \
do { \
int error = (errno); \
fflush (stdout); \
fprintf (stderr, "%s: " fmt, PACKAGE_NAME, ## args); \
if (error) \
fprintf (stderr, ": %s", strerror (error)); \
fprintf (stderr, "\n"); \
exit (status); \
} while (0)
#endif
#define internal_error(fmt, args...) \
error (2, 0, "internal error in %s: " fmt, __func__, ## args)
#define error_if_not(expr) \
if (! (expr)) goto error;
#define perror_if_not(expr, fmt, args...) \
do { \
if (! (expr)) \
{ \
printf_error_response ((fmt), ## args); \
goto error; \
} \
} while (0)
#define cerror_if_not(expr, error_msg, fmt, args...) \
do { \
if (! (expr)) \
{ \
if (error_msg) \
*(error_msg) = g_strdup_printf((fmt), ## args); \
goto error; \
} \
} while (0)
/* Declare commands */
#define DEC_CMD(name) \
{#name, cmd_ ## name, cmd_ ## name ## _spec, \
G_N_ELEMENTS (cmd_ ## name ## _spec)}
#define DEC_CMD2(command, name) \
{name, cmd_ ## command, cmd_ ## command ## _spec, \
G_N_ELEMENTS (cmd_ ## command ## _spec)}
/* Declare option */
#define DEC_DOPT(name, type, sname) \
{name, type, offsetof (document_options_t, sname)}
enum suffix_char { NONE, COLON, NEWLINE};
enum image_type { PPM, PNG };
typedef struct
{
PopplerAnnotMapping *amap;
gchar *key;
} annotation_t;
typedef enum
{
ARG_INVALID = 0,
ARG_DOC,
ARG_BOOL,
ARG_STRING,
ARG_NONEMPTY_STRING,
ARG_NATNUM,
ARG_EDGE,
ARG_EDGE_OR_NEGATIVE,
ARG_EDGES,
ARG_EDGES_OR_POSITION,
ARG_COLOR,
ARG_REST
} command_arg_type_t;
typedef struct
{
const char *name;
command_arg_type_t type;
size_t offset;
} document_option_t;
typedef struct
{
PopplerColor bg, fg;
gboolean usecolors;
gboolean printed;
} render_options_t;
typedef struct
{
render_options_t render;
} document_options_t;
typedef struct
{
PopplerDocument *pdf;
char *filename;
char *passwd;
struct
{
GHashTable *keys; /* key => page */
GList **pages; /* page array */
} annotations;
document_options_t options;
} document_t;
typedef struct
{
command_arg_type_t type;
union
{
gboolean flag;
const char *string;
long natnum;
document_t *doc;
gdouble edge;
PopplerColor color;
PopplerRectangle rectangle;
#ifdef HAVE_POPPLER_ANNOT_MARKUP
PopplerQuadrilateral quadrilateral;
#endif
struct
{
char * const *args;
int nargs;
} rest;
} value;
} command_arg_t;
typedef struct
{
GHashTable *documents;
} epdfinfo_t;
typedef struct
{
const char *name;
void (* execute) (const epdfinfo_t *ctxt, const command_arg_t *args);
const command_arg_type_t *args_spec;
int nargs;
} command_t;
/* Defined in poppler-hack.cc */
#ifdef HAVE_POPPLER_ANNOT_WRITE
extern void xpoppler_annot_set_rectangle (PopplerAnnot*, PopplerRectangle*);
#endif
extern gchar *xpoppler_annot_markup_get_created (PopplerAnnotMarkup*);
#endif /* _EPDF_H_ */
|