Back to index

texmacs  1.0.7.15
pdfobj.h
Go to the documentation of this file.
00001 /*  $Header: /home/cvsroot/dvipdfmx/src/pdfobj.h,v 1.35 2010/02/07 12:53:44 chofchof Exp $
00002 
00003     This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
00004 
00005     Copyright (C) 2007 by Jin-Hwan Cho and Shunsaku Hirata,
00006     the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
00007     
00008     Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014     
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019     
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00023 */
00024 
00025 #ifndef _PDFOBJ_H_
00026 #define _PDFOBJ_H_
00027 
00028 #include <stdio.h>
00029 
00030 /* Here is the complete list of PDF object types */
00031 
00032 #define       PDF_BOOLEAN   1
00033 #define       PDF_NUMBER    2
00034 #define PDF_STRING   3
00035 #define PDF_NAME     4
00036 #define PDF_ARRAY    5
00037 #define PDF_DICT     6
00038 #define PDF_STREAM   7
00039 #define PDF_NULL        8
00040 #define PDF_INDIRECT 9
00041 #define PDF_UNDEFINED   10
00042 
00043 #define PDF_OBJ_INVALID 0
00044 
00045 #define STREAM_COMPRESS (1 << 0)
00046 
00047 /* A deeper object hierarchy will be considered as (illegal) loop. */
00048 #define PDF_OBJ_MAX_DEPTH  30
00049 
00050 typedef struct pdf_obj  pdf_obj;
00051 typedef struct pdf_file pdf_file;
00052 
00053 /* External interface to pdf routines */
00054 
00055 extern int      pdf_obj_get_verbose (void);
00056 extern void     pdf_obj_set_verbose (void);
00057 extern void     pdf_error_cleanup   (void);
00058 
00059 extern void     pdf_out_init      (const char *filename, int do_encryption);
00060 extern void     pdf_out_flush     (void);
00061 extern void     pdf_set_version   (unsigned version);
00062 extern unsigned pdf_get_version   (void);
00063 
00064 extern void     pdf_release_obj (pdf_obj *object);
00065 extern int      pdf_obj_typeof  (pdf_obj *object);
00066 
00067 #define PDF_OBJ_NUMBERTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_NUMBER)
00068 #define PDF_OBJ_BOOLEANTYPE(o)  ((o) && pdf_obj_typeof((o)) == PDF_BOOLEAN)
00069 #define PDF_OBJ_STRINGTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_STRING)
00070 #define PDF_OBJ_NAMETYPE(o)     ((o) && pdf_obj_typeof((o)) == PDF_NAME)
00071 #define PDF_OBJ_ARRAYTYPE(o)    ((o) && pdf_obj_typeof((o)) == PDF_ARRAY)
00072 #define PDF_OBJ_NULLTYPE(o)     ((o) && pdf_obj_typeof((o)) == PDF_NULL)
00073 #define PDF_OBJ_DICTTYPE(o)     ((o) && pdf_obj_typeof((o)) == PDF_DICT)
00074 #define PDF_OBJ_STREAMTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_STREAM)
00075 #define PDF_OBJ_INDIRECTTYPE(o) ((o) && pdf_obj_typeof((o)) == PDF_INDIRECT)
00076 #define PDF_OBJ_UNDEFINED(o)    ((o) && pdf_obj_typeof((o)) == PDF_UNDEFINED)
00077 
00078 #define PDF_OBJ_TYPEOF(o)       pdf_obj_typeof((o))
00079 
00080 
00081 extern pdf_obj *pdf_ref_obj        (pdf_obj *object);
00082 extern pdf_obj *pdf_link_obj       (pdf_obj *object);
00083 extern void     pdf_transfer_label (pdf_obj *dst, pdf_obj *src);
00084 
00085 extern pdf_obj *pdf_new_undefined  (void);
00086 
00087 extern pdf_obj *pdf_new_null       (void);
00088 
00089 extern pdf_obj *pdf_new_boolean    (char value);
00090 #if 0
00091 extern void     pdf_set_boolean    (pdf_obj *object, char value);
00092 #endif
00093 extern char     pdf_boolean_value  (pdf_obj *object);
00094 
00095 extern pdf_obj *pdf_new_number     (double value);
00096 extern void     pdf_set_number     (pdf_obj *object, double value);
00097 extern double   pdf_number_value   (pdf_obj *number);
00098 
00099 extern pdf_obj  *pdf_new_string    (const void *str, unsigned length);
00100 extern void      pdf_set_string    (pdf_obj *object, unsigned char *str, unsigned length);
00101 extern void     *pdf_string_value  (pdf_obj *object);
00102 extern unsigned  pdf_string_length (pdf_obj *object);
00103 
00104 /* Name does not include the / */
00105 extern pdf_obj *pdf_new_name   (const char *name);
00106 #if 0
00107 extern void     pdf_set_name   (pdf_obj *object, const char *name);
00108 #endif
00109 extern char    *pdf_name_value (pdf_obj *object);
00110 
00111 extern pdf_obj *pdf_new_array     (void);
00112 /* pdf_add_dict requires key but pdf_add_array does not.
00113  * pdf_add_array always append elements to array.
00114  * They should be pdf_put_array(array, idx, element) and
00115  * pdf_put_dict(dict, key, value)
00116  */
00117 extern void     pdf_add_array     (pdf_obj *array, pdf_obj *object);
00118 #if 0
00119 extern void     pdf_put_array     (pdf_obj *array, unsigned idx, pdf_obj *object);
00120 #endif
00121 extern pdf_obj *pdf_get_array     (pdf_obj *array, long idx);
00122 extern unsigned pdf_array_length  (pdf_obj *array);
00123 
00124 extern void     pdf_unshift_array (pdf_obj *array, pdf_obj *object);
00125 #if 0
00126 extern pdf_obj *pdf_shift_array   (pdf_obj *array);
00127 extern pdf_obj *pdf_pop_array     (pdf_obj *array);
00128 #endif
00129 
00130 extern pdf_obj *pdf_new_dict    (void);
00131 extern void     pdf_remove_dict (pdf_obj *dict,  const char *key);
00132 extern void     pdf_merge_dict  (pdf_obj *dict1, pdf_obj *dict2);
00133 extern pdf_obj *pdf_lookup_dict (pdf_obj *dict,  const char *key);
00134 extern pdf_obj *pdf_dict_keys   (pdf_obj *dict);
00135 
00136 /* pdf_add_dict() want pdf_obj as key, however, key must always be name
00137  * object and pdf_lookup_dict() and pdf_remove_dict() uses const char as
00138  * key. This strange difference seems come from pdfdoc that first allocate
00139  * name objects frequently used (maybe 1000 times) such as /Type and does
00140  * pdf_link_obj() it rather than allocate/free-ing them each time. But I
00141  * already removed that.
00142  */
00143 extern int      pdf_add_dict     (pdf_obj *dict, pdf_obj *key,    pdf_obj *value); 
00144 #if 0
00145 extern void     pdf_put_dict     (pdf_obj *dict, const char *key, pdf_obj *value);
00146 #endif
00147 
00148 /* Apply proc(key, value, pdata) for each key-value pairs in dict, stop if proc()
00149  * returned non-zero value (and that value is returned). PDF object is passed for
00150  * key to allow modification (fix) of key.
00151  */
00152 extern int      pdf_foreach_dict (pdf_obj *dict,
00153                               int (*proc) (pdf_obj *, pdf_obj *, void *),
00154                               void *pdata);
00155 
00156 extern pdf_obj    *pdf_new_stream        (int flags);
00157 extern void        pdf_add_stream        (pdf_obj *stream,
00158                                      const void *stream_data_ptr,
00159                                      long stream_data_len);
00160 #if HAVE_ZLIB
00161 extern int         pdf_add_stream_flate  (pdf_obj *stream,
00162                                      const void *stream_data_ptr,
00163                                      long stream_data_len);
00164 #endif
00165 extern int         pdf_concat_stream     (pdf_obj *dst, pdf_obj *src);
00166 extern pdf_obj    *pdf_stream_dict       (pdf_obj *stream);
00167 extern long        pdf_stream_length     (pdf_obj *stream);
00168 #if 0
00169 extern void        pdf_stream_set_flags  (pdf_obj *stream, int flags);
00170 extern int         pdf_stream_get_flags  (pdf_obj *stream);
00171 #endif
00172 extern const void *pdf_stream_dataptr    (pdf_obj *stream);
00173 
00174 #if 0
00175 extern int         pdf_stream_pop_filter (pdf_obj *stream);
00176 #endif
00177 
00178 /* Compare label of two indirect reference object.
00179  */
00180 extern int         pdf_compare_reference (pdf_obj *ref1, pdf_obj *ref2);
00181 
00182 /* The following routines are not appropriate for pdfobj.
00183  */
00184 
00185 extern void      pdf_set_compression (int level);
00186 
00187 extern void      pdf_set_info     (pdf_obj *obj);
00188 extern void      pdf_set_id       (pdf_obj *id);
00189 extern void      pdf_set_root     (pdf_obj *obj);
00190 extern void      pdf_set_encrypt  (pdf_obj *encrypt);
00191 
00192 extern void      pdf_files_init    (void);
00193 extern void      pdf_files_close   (void);
00194 extern int      check_for_pdf     (FILE *file);
00195 extern pdf_file *pdf_open          (const char *ident, FILE *file);
00196 extern void      pdf_close         (pdf_file *pf);
00197 #if 0
00198 extern pdf_obj  *pdf_file_get_trailer (pdf_file *pf);
00199 #endif
00200 extern int       pdf_file_get_version (pdf_file *pf);
00201 extern pdf_obj  *pdf_file_get_catalog (pdf_file *pf);
00202 
00203 extern pdf_obj *pdf_deref_obj     (pdf_obj *object);
00204 extern pdf_obj *pdf_import_object (pdf_obj *object);
00205 
00206 extern int      pdfobj_escape_str (char *buffer, int size, const unsigned char *s, int len);
00207 
00208 extern pdf_obj *pdf_new_indirect  (pdf_file *pf, unsigned long label, unsigned short generation);
00209 
00210 #endif  /* _PDFOBJ_H_ */