Back to index

tetex-bin  3.0
pdfobj.h
Go to the documentation of this file.
00001 /*  $Header$
00002 
00003     This is dvipdfm, a DVI to PDF translator.
00004     Copyright (C) 1998, 1999 by Mark A. Wicks
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019     
00020     The author may be contacted via the e-mail address
00021 
00022        mwicks@kettering.edu
00023 */
00024 
00025        
00026 #ifndef PDFOBJ_H
00027 #define PDFOBJ_H
00028 #include <stdio.h>
00029 
00030 /* Here is the complete list of PDF object types */
00031 
00032 #define       PDF_BOOLEAN   1u
00033 #define       PDF_NUMBER    2u
00034 #define PDF_STRING   3u
00035 #define PDF_NAME     4u
00036 #define PDF_ARRAY    5u
00037 #define PDF_DICT     6u
00038 #define PDF_STREAM   7u
00039 #define PDF_NULL        8u
00040 #define PDF_INDIRECT 9u   
00041 
00042 typedef unsigned char pdf_obj_type;
00043 
00044 /* Any of these types can be represented as follows */
00045 
00046 struct pdf_obj 
00047 {
00048   pdf_obj_type type;
00049   void *data;
00050   unsigned long label;  /* Only used for indirect objects
00051                                all other "label" to zero */
00052   unsigned generation;  /* Only used if "label" is used */
00053   unsigned refcount;  /* Number of links to this object */
00054 };
00055 typedef struct pdf_obj pdf_obj;
00056 
00057 struct pdf_boolean
00058 {
00059   char value;
00060 };
00061 typedef struct pdf_boolean pdf_boolean;
00062 
00063 
00064 struct pdf_number
00065 {
00066   double value;
00067 };
00068 typedef struct pdf_number pdf_number;
00069 
00070 struct pdf_string
00071 {
00072   unsigned char *string;
00073   unsigned length;
00074 };
00075 typedef struct pdf_string pdf_string;
00076 
00077 
00078 struct pdf_name
00079 {
00080   char *name;
00081 };
00082 typedef struct pdf_name pdf_name;
00083 
00084 
00085 struct pdf_array
00086 {
00087   unsigned long max, size;
00088   pdf_obj **values;
00089 };
00090 typedef struct pdf_array pdf_array;
00091 
00092 struct pdf_dict
00093 {
00094   pdf_obj *key;
00095   pdf_obj *value;
00096   struct pdf_dict *next;
00097 };
00098 typedef struct pdf_dict pdf_dict;
00099 
00100 struct pdf_stream
00101 {
00102   struct pdf_obj *dict;
00103   char *stream;  /* Actual stream contents stored in "stream" */
00104   unsigned long stream_length;
00105   unsigned long max_length;
00106   unsigned char _flags;
00107 };
00108 typedef struct pdf_stream pdf_stream;
00109 
00110 struct pdf_indirect
00111 {
00112   unsigned label, generation;
00113   int dirty;  /* Dirty objects came from an input file and were not
00114                generated by this program.  They have a label in a
00115                different numbering sequence.  These are translated
00116                when the object is written out */
00117   FILE *dirty_file;
00118 };
00119 typedef struct pdf_indirect pdf_indirect;
00120 
00121 /* External interface to pdf routines */
00122 
00123 extern void pdf_obj_set_verbose(void);
00124 struct pdf_obj *pdf_new_obj (pdf_obj_type type);
00125 extern void pdf_out_init (const char *filename);
00126 extern void pdf_out_flush (void);
00127 extern pdf_obj *pdf_new_obj(pdf_obj_type type);
00128 extern pdf_obj *pdf_link_obj(pdf_obj *object);
00129 extern pdf_obj *pdf_new_null (void);
00130 extern pdf_obj *pdf_new_boolean (char value);
00131 extern void pdf_set_boolean (pdf_obj *object, char value);
00132 extern void pdf_set_info (pdf_obj *object);
00133 extern void pdf_set_root (pdf_obj *object);
00134 extern pdf_obj *pdf_new_number (double value);
00135 extern void pdf_set_number (pdf_obj *object, double value);
00136 extern double pdf_number_value (pdf_obj *number);
00137 extern char *pdf_name_value (pdf_obj *object);
00138 extern pdf_obj *pdf_new_string (const void *string, unsigned length);
00139 extern void pdf_set_string (pdf_obj *object, unsigned char *string, unsigned length);
00140 extern void *pdf_string_value (pdf_obj *object);
00141 extern unsigned int pdf_string_length (pdf_obj *object);
00142 #define pdf_obj_string_value(s) ((void *)(((pdf_string *)((s)->data)) -> string))
00143 #define pdf_obj_string_length(s) (((pdf_string *)((s)->data)) -> length)
00144 
00145 extern pdf_obj *pdf_new_name (const char *name);  /* Name does not include the / */
00146 extern int pdf_check_name (const char *name);  /* Tell whether name is a
00147                                       valid PDF name */
00148 
00149 extern pdf_obj *pdf_new_array (void);
00150 extern void pdf_add_array (pdf_obj *array, pdf_obj *object); /* Array is ended
00151                                                   by a node with NULL
00152                                                   this pointer */
00153 extern pdf_obj *pdf_get_array (pdf_obj *array, unsigned long index);
00154 extern pdf_obj *pdf_new_dict (void);
00155 extern void pdf_add_dict (pdf_obj *dict, pdf_obj *key, pdf_obj *value);  /* Array is ended
00156                                                              by a node with NULL
00157                                                              this pointer */
00158 extern void pdf_merge_dict (pdf_obj *dict1, pdf_obj *dict2);
00159 extern pdf_obj *pdf_lookup_dict (const pdf_obj *dict, const char *name);
00160 extern char *pdf_get_dict (const pdf_obj *dict, int index);
00161 
00162 extern pdf_obj *pdf_new_stream (int flags);
00163 #define STREAM_COMPRESS 1
00164 extern void pdf_obj_set_compression(int level);
00165 extern void pdf_add_stream (pdf_obj *stream, char *stream_data, unsigned
00166                    length);
00167 
00168 extern pdf_obj *pdf_stream_dict(pdf_obj *stream);
00169 
00170 extern void pdf_release_obj (pdf_obj *object);
00171 extern pdf_obj *pdf_deref_obj (pdf_obj *object);
00172 extern pdf_obj *pdf_ref_obj (pdf_obj *object);
00173 extern pdf_obj *pdf_new_ref (unsigned long label, int generation);
00174 extern pdf_obj *pdf_ref_file_obj (unsigned long obj_no);
00175 extern void pdf_write_obj (FILE *file, const pdf_obj *object);
00176 extern pdf_obj *pdf_open (FILE *file);
00177 extern void pdf_close (void);
00178 
00179 extern int pdfobj_escape_str (char *buffer, int size, unsigned char
00180                            *s, int len, int remap);
00181 extern int check_for_pdf (FILE *file);
00182 extern void pdf_set_version (unsigned version);
00183 extern pdf_obj *pdf_read_object (unsigned long obj_no);
00184 extern void pdf_error_cleanup(void);
00185 
00186 #endif  /* PDFOBJ_H */
00187