| 1 |
/* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. |
| 2 |
|
| 3 |
Copyright (C) 2002-2020 by Jin-Hwan Cho and Shunsaku Hirata, |
| 4 |
the dvipdfmx project team. |
| 5 |
|
| 6 |
Copyright (C) 1998, 1999 by Mark A. Wicks <[email protected]> |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 2 of the License, or |
| 11 |
(at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program; if not, write to the Free Software |
| 20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef _PDFOBJ_H_ |
| 24 |
#define _PDFOBJ_H_ |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
|
| 28 |
typedef struct pdf_out pdf_out; |
| 29 |
|
| 30 |
/* Here is the complete list of PDF object types */ |
| 31 |
|
| 32 |
#define PDF_BOOLEAN 1 |
| 33 |
#define PDF_NUMBER 2 |
| 34 |
#define PDF_STRING 3 |
| 35 |
#define PDF_NAME 4 |
| 36 |
#define PDF_ARRAY 5 |
| 37 |
#define PDF_DICT 6 |
| 38 |
#define PDF_STREAM 7 |
| 39 |
#define PDF_NULL 8 |
| 40 |
#define PDF_INDIRECT 9 |
| 41 |
#define PDF_UNDEFINED 10 |
| 42 |
|
| 43 |
#define PDF_OBJ_INVALID 0 |
| 44 |
|
| 45 |
#define STREAM_COMPRESS (1 << 0) |
| 46 |
#define STREAM_USE_PREDICTOR (1 << 1) |
| 47 |
|
| 48 |
/* A deeper object hierarchy will be considered as (illegal) loop. */ |
| 49 |
#define PDF_OBJ_MAX_DEPTH 30 |
| 50 |
|
| 51 |
typedef struct pdf_obj pdf_obj; |
| 52 |
typedef struct pdf_file pdf_file; |
| 53 |
|
| 54 |
/* External interface to pdf routines */ |
| 55 |
extern void pdf_error_cleanup (void); |
| 56 |
|
| 57 |
extern FILE *pdf_get_output_file (void); |
| 58 |
extern pdf_out *pdf_out_init (const char *filename, |
| 59 |
const unsigned char *id1, const unsigned char *id2, |
| 60 |
int ver_major, int ver_minor, |
| 61 |
int compression_level, |
| 62 |
int enable_encrypt, |
| 63 |
int enable_objstm, |
| 64 |
int enable_predictor); |
| 65 |
extern void pdf_out_set_encrypt (int keybits, int32_t permission, |
| 66 |
const char *opasswd, const char *upasswd, |
| 67 |
int use_aes, int encrypt_metadata); |
| 68 |
extern void pdf_out_flush (void); |
| 69 |
|
| 70 |
extern int pdf_get_version (void); |
| 71 |
extern int pdf_get_version_major (void); |
| 72 |
extern int pdf_get_version_minor (void); |
| 73 |
|
| 74 |
extern void pdf_release_obj (pdf_obj *object); |
| 75 |
extern int pdf_obj_typeof (pdf_obj *object); |
| 76 |
|
| 77 |
#define PDF_OBJ_NUMBERTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_NUMBER) |
| 78 |
#define PDF_OBJ_BOOLEANTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_BOOLEAN) |
| 79 |
#define PDF_OBJ_STRINGTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_STRING) |
| 80 |
#define PDF_OBJ_NAMETYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_NAME) |
| 81 |
#define PDF_OBJ_ARRAYTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_ARRAY) |
| 82 |
#define PDF_OBJ_NULLTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_NULL) |
| 83 |
#define PDF_OBJ_DICTTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_DICT) |
| 84 |
#define PDF_OBJ_STREAMTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_STREAM) |
| 85 |
#define PDF_OBJ_INDIRECTTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_INDIRECT) |
| 86 |
#define PDF_OBJ_UNDEFINED(o) ((o) && pdf_obj_typeof((o)) == PDF_UNDEFINED) |
| 87 |
|
| 88 |
#define PDF_OBJ_TYPEOF(o) pdf_obj_typeof((o)) |
| 89 |
|
| 90 |
extern pdf_obj *pdf_ref_obj (pdf_obj *object); |
| 91 |
extern pdf_obj *pdf_link_obj (pdf_obj *object); |
| 92 |
|
| 93 |
extern void pdf_transfer_label (pdf_obj *dst, pdf_obj *src); |
| 94 |
extern pdf_obj *pdf_new_undefined (void); |
| 95 |
|
| 96 |
extern pdf_obj *pdf_new_null (void); |
| 97 |
|
| 98 |
extern pdf_obj *pdf_new_boolean (char value); |
| 99 |
extern char pdf_boolean_value (pdf_obj *object); |
| 100 |
|
| 101 |
extern pdf_obj *pdf_new_number (double value); |
| 102 |
extern void pdf_set_number (pdf_obj *object, double value); |
| 103 |
extern double pdf_number_value (pdf_obj *number); |
| 104 |
|
| 105 |
extern pdf_obj *pdf_new_string (const void *str, unsigned length); |
| 106 |
extern void pdf_set_string (pdf_obj *object, unsigned char *str, unsigned length); |
| 107 |
extern void *pdf_string_value (pdf_obj *object); |
| 108 |
extern unsigned pdf_string_length (pdf_obj *object); |
| 109 |
|
| 110 |
/* Name does not include the / */ |
| 111 |
extern pdf_obj *pdf_new_name (const char *name); |
| 112 |
extern char *pdf_name_value (pdf_obj *object); |
| 113 |
|
| 114 |
extern pdf_obj *pdf_new_array (void); |
| 115 |
/* pdf_add_dict requires key but pdf_add_array does not. |
| 116 |
* pdf_add_array always append elements to array. |
| 117 |
* They should be pdf_put_array(array, idx, element) and |
| 118 |
* pdf_put_dict(dict, key, value) |
| 119 |
*/ |
| 120 |
extern void pdf_add_array (pdf_obj *array, pdf_obj *object); |
| 121 |
#if 0 |
| 122 |
extern void pdf_put_array (pdf_obj *array, unsigned idx, pdf_obj *object); |
| 123 |
#endif |
| 124 |
extern pdf_obj *pdf_get_array (pdf_obj *array, int idx); |
| 125 |
extern unsigned pdf_array_length (pdf_obj *array); |
| 126 |
|
| 127 |
#if 0 |
| 128 |
extern pdf_obj *pdf_shift_array (pdf_obj *array); |
| 129 |
extern pdf_obj *pdf_pop_array (pdf_obj *array); |
| 130 |
#endif |
| 131 |
|
| 132 |
extern pdf_obj *pdf_new_dict (void); |
| 133 |
extern void pdf_remove_dict (pdf_obj *dict, const char *key); |
| 134 |
extern void pdf_merge_dict (pdf_obj *dict1, pdf_obj *dict2); |
| 135 |
extern pdf_obj *pdf_lookup_dict (pdf_obj *dict, const char *key); |
| 136 |
extern pdf_obj *pdf_dict_keys (pdf_obj *dict); |
| 137 |
|
| 138 |
/* pdf_add_dict() want pdf_obj as key, however, key must always be name |
| 139 |
* object and pdf_lookup_dict() and pdf_remove_dict() uses const char as |
| 140 |
* key. This strange difference seems come from pdfdoc that first allocate |
| 141 |
* name objects frequently used (maybe 1000 times) such as /Type and does |
| 142 |
* pdf_link_obj() it rather than allocate/free-ing them each time. But I |
| 143 |
* already removed that. |
| 144 |
*/ |
| 145 |
extern int pdf_add_dict (pdf_obj *dict, pdf_obj *key, pdf_obj *value); |
| 146 |
#if 0 |
| 147 |
extern void pdf_put_dict (pdf_obj *dict, const char *key, pdf_obj *value); |
| 148 |
#endif |
| 149 |
|
| 150 |
/* Apply proc(key, value, pdata) for each key-value pairs in dict, stop if proc() |
| 151 |
* returned non-zero value (and that value is returned). PDF object is passed for |
| 152 |
* key to allow modification (fix) of key. |
| 153 |
*/ |
| 154 |
extern int pdf_foreach_dict (pdf_obj *dict, |
| 155 |
int (*proc) (pdf_obj *, pdf_obj *, void *), |
| 156 |
void *pdata); |
| 157 |
|
| 158 |
extern pdf_obj *pdf_new_stream (int flags); |
| 159 |
extern void pdf_add_stream (pdf_obj *stream, |
| 160 |
const void *stream_data_ptr, |
| 161 |
int stream_data_len); |
| 162 |
|
| 163 |
extern int pdf_concat_stream (pdf_obj *dst, pdf_obj *src); |
| 164 |
extern pdf_obj *pdf_stream_dict (pdf_obj *stream); |
| 165 |
extern int pdf_stream_length (pdf_obj *stream); |
| 166 |
#if 0 |
| 167 |
extern void pdf_stream_set_flags (pdf_obj *stream, int flags); |
| 168 |
extern int pdf_stream_get_flags (pdf_obj *stream); |
| 169 |
#endif |
| 170 |
extern const void *pdf_stream_dataptr (pdf_obj *stream); |
| 171 |
extern void pdf_stream_set_predictor (pdf_obj *stream, |
| 172 |
int predictor, int32_t columns, |
| 173 |
int bpc, int colors); |
| 174 |
|
| 175 |
/* Compare label of two indirect reference object. */ |
| 176 |
extern int pdf_compare_reference (pdf_obj *ref1, pdf_obj *ref2); |
| 177 |
/* Compare objects. */ |
| 178 |
extern int pdf_compare_object (pdf_obj *obj1, pdf_obj *obj2); |
| 179 |
|
| 180 |
|
| 181 |
/* The following routines are not appropriate for pdfobj. |
| 182 |
*/ |
| 183 |
|
| 184 |
extern void pdf_set_info (pdf_obj *obj); |
| 185 |
extern void pdf_set_root (pdf_obj *obj); |
| 186 |
|
| 187 |
extern void pdf_files_init (void); |
| 188 |
extern void pdf_files_close (void); |
| 189 |
extern int check_for_pdf (FILE *file); |
| 190 |
extern pdf_file *pdf_open (const char *ident, FILE *file); |
| 191 |
extern void pdf_close (pdf_file *pf); |
| 192 |
extern pdf_obj *pdf_file_get_trailer (pdf_file *pf); |
| 193 |
extern pdf_obj *pdf_file_get_catalog (pdf_file *pf); |
| 194 |
extern int pdf_file_get_version (pdf_file *pf); |
| 195 |
|
| 196 |
extern pdf_obj *pdf_deref_obj (pdf_obj *object); |
| 197 |
extern pdf_obj *pdf_import_object (pdf_obj *object); |
| 198 |
|
| 199 |
extern int pdfobj_escape_str (char *buffer, int size, const unsigned char *s, int len); |
| 200 |
|
| 201 |
extern pdf_obj *pdf_new_indirect (pdf_file *pf, uint32_t label, uint16_t generation); |
| 202 |
|
| 203 |
extern int pdf_check_version (int major, int minor); |
| 204 |
|
| 205 |
#endif /* _PDFOBJ_H_ */ |