summaryrefslogtreecommitdiff
path: root/src/pdflib/pdcore/pc_core.h
blob: c75878935e478330cd6d3a867f10cca0babc5868 (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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*---------------------------------------------------------------------------*
 |              PDFlib - A library for generating PDF on the fly             |
 +---------------------------------------------------------------------------+
 | Copyright (c) 1997-2006 Thomas Merz and PDFlib GmbH. All rights reserved. |
 +---------------------------------------------------------------------------+
 |                                                                           |
 |    This software is subject to the PDFlib license. It is NOT in the       |
 |    public domain. Extended versions and commercial licenses are           |
 |    available, please check http://www.pdflib.com.                         |
 |                                                                           |
 *---------------------------------------------------------------------------*/

/* $Id: pc_core.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
 *
 * PDFlib core services:
 * - memory management
 * - exception handling
 * - internal try/catch
 */

#ifndef PC_CORE_H
#define PC_CORE_H

/* Built-in metric support */
#define PDF_BUILTINMETRIC_SUPPORTED

/* Built-in encoding support */
#define PDF_BUILTINENCODING_SUPPORTED

/* TrueType font support */
#define PDF_TRUETYPE_SUPPORTED

/* Proportional widths for the standard CJK fonts support */
#define PDF_CJKFONTWIDTHS_SUPPORTED


#define PDF_FEATURE_NOT_PUBLIC


/* ------------------------- general  ------------------------- */

typedef struct pdc_core_priv_s pdc_core_priv;
typedef struct pdc_core_s pdc_core;

typedef int            pdc_bool;
typedef long           pdc_id;
typedef char           pdc_char;
typedef unsigned char  pdc_byte;
typedef unsigned char  pdc_uchar;
typedef short          pdc_short;
typedef unsigned short pdc_ushort;
typedef long           pdc_long;
typedef unsigned long  pdc_ulong;
typedef unsigned int   pdc_uint;

typedef unsigned short pdc_ucval;		/* unicode value	*/

typedef short          pdc_sint16;
typedef unsigned short pdc_uint16;
typedef int            pdc_sint32;
typedef unsigned int   pdc_uint32;

/* TODO2GB:	this is the signed 64-bit integer type for >2GB files.
**		 must be platform & compiler specific.
*/
#if	defined(_LARGEFILE_SOURCE)
    #if defined(WIN32)
	typedef __int64	pdc_off_t;
    #else
#include <sys/types.h>
	typedef off_t	pdc_off_t;
    #endif
#else
	typedef long	pdc_off_t;
#endif

/* use this one for casts from "off_t" to "long" - so we can "grep"
** for critical places.
*/
typedef long pdc_off_t1;


#define pdc_undef      -1
#define pdc_false       0
#define pdc_true	1

#define	PDC_1_1			11		/* PDF 1.1 = Acrobat 2 */
#define	PDC_1_2			12		/* PDF 1.2 = Acrobat 3 */
#define	PDC_1_3			13		/* PDF 1.3 = Acrobat 4 */
#define	PDC_1_4			14		/* PDF 1.4 = Acrobat 5 */
#define	PDC_1_5			15		/* PDF 1.5 = Acrobat 6 */
#define	PDC_1_6			16		/* PDF 1.6 = Acrobat 7 */
#define	PDC_1_7			17		/* PDF 1.7 = Acrobat 8 */
#define PDC_X_X_LAST		17

/* Acrobat limit for page dimensions */
#define PDF_ACRO_MINPAGE       (3.0)           /* 1/24 inch = 0.106 cm */
#define PDF_ACRO_MAXPAGE       (14400.0)       /* 200  inch = 508 cm   */



typedef void  (*pdc_error_fp)(void *opaque, int type, const char *msg);
typedef void* (*pdc_alloc_fp)(void *opaque, size_t size, const char *caller);
typedef void* (*pdc_realloc_fp)(void *opaque, void *mem, size_t size,
						const char *caller);
typedef void  (*pdc_free_fp)(void *opaque, void *mem);

pdc_core *pdc_new_core(pdc_error_fp errorhandler, pdc_alloc_fp allocproc,
    pdc_realloc_fp reallocproc, pdc_free_fp freeproc, void *opaque,
    const char *appname, const char *version);

void pdc_delete_core(pdc_core *pdc);

typedef enum
{
    pdc_pbox_none,
    pdc_pbox_art,
    pdc_pbox_bleed,
    pdc_pbox_crop,
    pdc_pbox_media,
    pdc_pbox_trim
} pdc_pagebox;

/* ------------------------- memory management  ------------------------- */

void	*pdc_malloc(pdc_core *pdc, size_t size, const char *caller);
void	*pdc_realloc(pdc_core *pdc, void *mem, size_t size, const char *caller);
void	*pdc_calloc(pdc_core *pdc, size_t size, const char *caller);
void	pdc_free(pdc_core *pdc, void *mem);

#define PDC_TMPMEM	1

typedef void (*pdc_destructor)(void *opaque, void *mem);

void    pdc_insert_mem_tmp(pdc_core *pdc, void *memory, void *opaque,
            pdc_destructor destr);
void	*pdc_malloc_tmp(pdc_core *pdc, size_t size, const char *caller,
	    void *opaque, pdc_destructor destr);
void	*pdc_realloc_tmp(pdc_core *pdc, void *mem, size_t size,
	    const char *caller);
void	*pdc_calloc_tmp(pdc_core *pdc, size_t size, const char *caller,
	    void *opaque, pdc_destructor destr);
void	pdc_free_tmp(pdc_core *pdc, void *mem);

void    pdc_tmlist_init(pdc_core *pdc);
void    pdc_tmlist_cleanup(pdc_core *pdc);


/* --------------------------- exception handling --------------------------- */

#define PDC_ASSERT(pdc, expr)						\
	((expr) ? (void) 0 : pdc_error((pdc), PDC_E_INT_ASSERT,		\
	    __FILE__, pdc_errprintf((pdc), "%d", __LINE__), 0, 0))

/* maximal length of strings for %.*s in pdc_errprintf format
*/
#define PDC_ERR_MAXSTRLEN 256

/* per-library error table base numbers.
*/
#define PDC_ET_CORE	1000
#define PDC_ET_PDFLIB	2000
#define PDC_ET_PDI	4000
#define PDC_ET_PLOP	5000
#define PDC_ET_PDPAGE   6000
#define PDC_ET_FONT     7000
#define PDC_ET_TET	8000
#define PDC_ET_PCOS	9000

#define PDC_ET_LAST	9000

/* core error numbers.
*/
enum
{
#define		pdc_genNames	1
#include	"pc_generr.h"

    PDC_E_dummy
};

typedef struct
{
    int		nparms;		/* number of error parameters	*/
    int		errnum;		/* error number			*/
    const char *errmsg;		/* default error message	*/
    const char *ce_msg;		/* custom error message		*/
} pdc_error_info;

void		pdc_register_errtab(pdc_core *pdc, int et,
		    const pdc_error_info *ei, int n_entries);

pdc_bool        pdc_enter_api(pdc_core *pdc, const char *apiname);
pdc_bool	pdc_in_error(pdc_core *pdc);

const char *	pdc_errprintf(pdc_core *pdc, const char *format, ...);

void            pdc_pop_errmsg(pdc_core *pdc);

void            pdc_push_errmsg(pdc_core *pdc, int errnum, const char *parm1,
                    const char *parm2, const char *parm3, const char *parm4);

void            pdc_set_errmsg(pdc_core *pdc, int errnum, const char *parm1,
                    const char *parm2, const char *parm3, const char *parm4);

void            pdc_set_warnmsg(pdc_core *pdc, int errnum, const char *parm1,
                    const char *parm2, const char *parm3, const char *parm4);

void		pdc_error(pdc_core *pdc, int errnum, const char *parm1,
		    const char *parm2, const char *parm3, const char *parm4);

int		pdc_get_errnum(pdc_core *pdc);
const char *	pdc_get_errmsg(pdc_core *pdc);
const char *	pdc_get_apiname(pdc_core *pdc);
const char *    pdc_get_errpref(pdc_core *pdc);

/* ----------------------------- try/catch ---------------------------- */

#include <setjmp.h>

typedef struct
{
    jmp_buf	jbuf;
} pdc_jmpbuf;

pdc_jmpbuf *	pdc_jbuf(pdc_core *pdc);
void		pdc_exit_try(pdc_core *pdc);
int		pdc_catch_intern(pdc_core *pdc);
int		pdc_catch_extern(pdc_core *pdc);
void		pdc_check_rethrow(pdc_core *pdc);
void		pdc_rethrow(pdc_core *pdc);

#define PDC_TRY(pdc)		if (setjmp(pdc_jbuf(pdc)->jbuf) == 0)

#define PDC_EXIT_TRY(pdc)	pdc_exit_try(pdc)

#define PDC_CATCH(pdc)		if (pdc_catch_intern(pdc))

#define PDC_RETHROW(pdc)	pdc_rethrow(pdc)


/* ----------- service function to get PDF version string  -------------- */

const char *pdc_get_pdfversion(pdc_core *pdc, int compatibility);


/* --------------------------- debug hexdump  --------------------------- */

#ifdef  PDC_DEBUG
void    pdc_enable_hexdump(pdc_core *pdc);
void    pdc_disable_hexdump(pdc_core *pdc);
void    pdc_hexdump(pdc_core *pdc, const char *msg, const char *text, int tlen);
#endif /* PDC_DEBUG */

/* --------------------------- scope  --------------------------- */

/*
 * An arbitrary number used for sanity checks.
 * Actually, we use the hex representation of pi in order to avoid
 * the more common patterns.
 */

#define PDC_MAGIC	((unsigned long) 0x126960A1)

/* environment variable name for license file
*/
#define PDC_LICFILE_ENV "PDFLIBLICENSEFILE"


#endif	/* PC_CORE_H */