Mon, 14 Dec 2009 16:18:21 +0000
remove erroneous 0.33-philpem1 tag
eric@62 | 1 | /* |
eric@125 | 2 | * tumble: build a PDF file from image files |
eric@62 | 3 | * |
eric@62 | 4 | * PDF routines |
eric@125 | 5 | * $Id: pdf_prim.h,v 1.10 2003/03/13 00:57:05 eric Exp $ |
eric@62 | 6 | * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> |
eric@62 | 7 | * |
eric@62 | 8 | * This program is free software; you can redistribute it and/or modify |
eric@62 | 9 | * it under the terms of the GNU General Public License version 2 as |
eric@62 | 10 | * published by the Free Software Foundation. Note that permission is |
eric@62 | 11 | * not granted to redistribute this program under the terms of any |
eric@62 | 12 | * other version of the General Public License. |
eric@62 | 13 | * |
eric@62 | 14 | * This program is distributed in the hope that it will be useful, |
eric@62 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
eric@62 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eric@62 | 17 | * GNU General Public License for more details. |
eric@62 | 18 | * |
eric@62 | 19 | * You should have received a copy of the GNU General Public License |
eric@62 | 20 | * along with this program; if not, write to the Free Software |
eric@62 | 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA |
eric@62 | 22 | */ |
eric@62 | 23 | |
eric@62 | 24 | |
eric@59 | 25 | typedef enum |
eric@59 | 26 | { |
eric@59 | 27 | PT_BAD, |
eric@59 | 28 | |
eric@59 | 29 | /* scalar */ |
eric@59 | 30 | PT_NULL, |
eric@59 | 31 | PT_BOOL, |
eric@59 | 32 | PT_NAME, |
eric@59 | 33 | PT_STRING, |
eric@59 | 34 | PT_INTEGER, |
eric@59 | 35 | PT_REAL, |
eric@59 | 36 | PT_IND_REF, |
eric@59 | 37 | |
eric@59 | 38 | /* composite */ |
eric@59 | 39 | PT_DICTIONARY, |
eric@59 | 40 | PT_ARRAY, |
eric@59 | 41 | PT_STREAM |
eric@59 | 42 | } pdf_obj_type; |
eric@59 | 43 | |
eric@59 | 44 | |
eric@59 | 45 | struct pdf_obj; |
eric@59 | 46 | |
eric@59 | 47 | |
eric@59 | 48 | typedef void (*pdf_stream_write_callback)(pdf_file_handle pdf_file, |
eric@59 | 49 | struct pdf_obj *stream, |
eric@59 | 50 | void *app_data); |
eric@59 | 51 | |
eric@59 | 52 | |
eric@118 | 53 | /* returns -1 if o1 < 02, 0 if o1 == o2, 1 if o1 > o2 */ |
eric@118 | 54 | /* only works for integer, real, string, and name objects */ |
eric@118 | 55 | int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2); |
eric@118 | 56 | |
eric@118 | 57 | |
eric@59 | 58 | void pdf_set_dict_entry (struct pdf_obj *dict_obj, char *key, struct pdf_obj *val); |
eric@59 | 59 | struct pdf_obj *pdf_get_dict_entry (struct pdf_obj *dict_obj, char *key); |
eric@59 | 60 | |
eric@59 | 61 | |
eric@59 | 62 | void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val); |
eric@59 | 63 | |
eric@59 | 64 | |
eric@118 | 65 | /* Following is intended for things like ProcSet in which an array object |
eric@118 | 66 | is used to represent a set. Only works if all objects in array, and |
eric@118 | 67 | the element to be added are of scalar types (types that are supported |
eric@118 | 68 | by pdf_compare_obj. Not efficient for large arrays as it does a |
eric@118 | 69 | comaprison to every element. */ |
eric@118 | 70 | void pdf_add_array_elem_unique (struct pdf_obj *array_obj, struct pdf_obj *val); |
eric@118 | 71 | |
eric@118 | 72 | |
eric@59 | 73 | /* Create a new object that will NOT be used indirectly */ |
eric@59 | 74 | struct pdf_obj *pdf_new_obj (pdf_obj_type type); |
eric@59 | 75 | |
eric@62 | 76 | struct pdf_obj *pdf_new_bool (bool val); |
eric@59 | 77 | |
eric@59 | 78 | struct pdf_obj *pdf_new_name (char *name); |
eric@59 | 79 | |
eric@59 | 80 | struct pdf_obj *pdf_new_string (char *str); |
eric@59 | 81 | |
philpem@166 | 82 | struct pdf_obj *pdf_new_string_n (char *str, int n); |
philpem@166 | 83 | |
eric@74 | 84 | struct pdf_obj *pdf_new_integer (long val); |
eric@59 | 85 | |
eric@59 | 86 | struct pdf_obj *pdf_new_real (double val); |
eric@59 | 87 | |
eric@59 | 88 | |
eric@59 | 89 | /* Create a new indirect object */ |
eric@59 | 90 | struct pdf_obj *pdf_new_ind_ref (pdf_file_handle pdf_file, struct pdf_obj *obj); |
eric@59 | 91 | |
eric@59 | 92 | /* get the object referenced by an indirect reference */ |
eric@59 | 93 | struct pdf_obj *pdf_deref_ind_obj (struct pdf_obj *ind_obj); |
eric@59 | 94 | |
eric@59 | 95 | |
eric@74 | 96 | long pdf_get_integer (struct pdf_obj *obj); |
eric@74 | 97 | void pdf_set_integer (struct pdf_obj *obj, long val); |
eric@59 | 98 | |
eric@59 | 99 | |
eric@59 | 100 | double pdf_get_real (struct pdf_obj *obj); |
eric@59 | 101 | void pdf_set_real (struct pdf_obj *obj, double val); |
eric@59 | 102 | |
eric@59 | 103 | |
eric@59 | 104 | /* The callback will be called when the stream data is to be written to the |
eric@59 | 105 | file. app_data will be passed as an argument to the callback. */ |
eric@59 | 106 | struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file, |
eric@59 | 107 | struct pdf_obj *stream_dict, |
eric@59 | 108 | pdf_stream_write_callback callback, |
eric@59 | 109 | void *app_data); |
eric@59 | 110 | |
eric@91 | 111 | /* The callback should call pdf_stream_write_data() or pdf_stream_printf() |
eric@91 | 112 | to write the actual stream data. */ |
eric@67 | 113 | |
eric@67 | 114 | void pdf_stream_flush_bits (pdf_file_handle pdf_file, |
eric@67 | 115 | struct pdf_obj *stream); |
eric@67 | 116 | |
eric@59 | 117 | void pdf_stream_write_data (pdf_file_handle pdf_file, |
eric@59 | 118 | struct pdf_obj *stream, |
eric@59 | 119 | char *data, |
eric@59 | 120 | unsigned long len); |
eric@59 | 121 | |
eric@66 | 122 | void pdf_stream_printf (pdf_file_handle pdf_file, |
eric@66 | 123 | struct pdf_obj *stream, |
eric@66 | 124 | char *fmt, ...); |
eric@66 | 125 | |
eric@66 | 126 | |
eric@59 | 127 | void pdf_stream_add_filter (struct pdf_obj *stream, |
eric@59 | 128 | char *filter_name, |
eric@59 | 129 | struct pdf_obj *decode_parms); |
eric@59 | 130 | |
eric@59 | 131 | |
eric@59 | 132 | /* Write the object to the file */ |
eric@59 | 133 | void pdf_write_obj (pdf_file_handle pdf_file, struct pdf_obj *obj); |
eric@59 | 134 | |
eric@59 | 135 | |
eric@59 | 136 | /* Write the indirect object to the file. For most objects this should |
eric@59 | 137 | be done by pdf_write_all_ind_obj() when the file is being closed, but for |
eric@59 | 138 | large objects such as streams, it's probably better to do it as soon as the |
eric@59 | 139 | object is complete. */ |
eric@59 | 140 | void pdf_write_ind_obj (pdf_file_handle pdf_file, struct pdf_obj *ind_obj); |
eric@59 | 141 | |
eric@59 | 142 | |
eric@59 | 143 | /* Write all indirect objects that haven't already been written to the file. */ |
eric@59 | 144 | void pdf_write_all_ind_obj (pdf_file_handle pdf_file); |
eric@59 | 145 | |
eric@59 | 146 | |
eric@59 | 147 | /* Write the cross reference table, and return the maximum object number */ |
eric@59 | 148 | unsigned long pdf_write_xref (pdf_file_handle pdf_file); |
eric@101 | 149 | |
eric@101 | 150 | |
eric@101 | 151 | /* this isn't really a PDF primitive data type */ |
eric@101 | 152 | char pdf_new_XObject (pdf_page_handle pdf_page, struct pdf_obj *ind_ref); |