Debian Codegraph @

texk/web2c/luatexdir/pdf/pdftypes.h

raw
1 /* pdftypes.h
2
3 Copyright 2009-2013 Taco Hoekwater <[email protected]>
4
5 This file is part of LuaTeX.
6
7 LuaTeX is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
11
12 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
19
20 */
21
22 #ifndef PDFTYPES_H
23 # define PDFTYPES_H
24
25 #ifdef HAVE_CONFIG_H
26 #include <w2c/config.h>
27 #endif
28 # include <zlib.h>
29 # include "lua/luatex-api.h"
30
31 /*
32 The prefix "PTEX" for the PDF keys is special to pdfTeX and has been registered with
33 Adobe by Hans Hagen.
34 */
35
36 # define pdfkeyprefix "PTEX"
37
38 # define i32round(a) (int) floor((a) + 0.5)
39 /*# define i64round(a) (int64_t) floor((a) + 0.5)*/
40 /*# define i64round(a) (int64_t) ( (double)(a+0.5) - ((int64_t)(a+0.5))%1 ) */
41 #ifdef _WIN32
42 # define i64round(a) (int64_t) win32_floor((a) + 0.5)
43 #else
44 # define i64round(a) (int64_t) llround((a))
45 #endif
46
47
48 # define MAX_OBJ_COMPRESS_LEVEL 3 /* maximum/clipping value for \pdfobjcompresslevel */
49 # define OBJSTM_UNSET -1 /* initial value */
50 # define OBJSTM_ALWAYS 1 /* \pdfobjcompresslevel >= OBJSTM_ALWAYS: put object into object stream */
51 # define OBJSTM_NEVER (MAX_OBJ_COMPRESS_LEVEL + 1) /* above maximum/clipping value for \pdfobjcompresslevel */
52
53 typedef int internal_font_number; /* |font| in a |char_node| */
54
55 typedef enum {
56 NO_ZIP, /* no \.{ZIP} compression */
57 ZIP_WRITING, /* \.{ZIP} compression being used */
58 ZIP_FINISH /* finish \.{ZIP} compression */
59 } zip_write_state_e;
60
61 typedef enum {
62 PDFOUT_BUF,
63 OBJSTM_BUF,
64 } buffer_e;
65
66 /*
67 This stucture holds everything that is needed for the actual pdf generation.
68
69 Because this structure interfaces with C++, it is not wise to use |boolean|
70 here (C++ has a boolean type built-in that is not compatible). Also, I have
71 plans to convert the backend code into a C library for use with e.g. standalone
72 lua. Together, this means that it is best only to use the standard C types and
73 the types explicitly defined in this header, and stay away from types like
74 |integer| and |eight_bits| that are used elsewhere in the \LUATEX\ sources.
75
76 */
77
78 typedef struct {
79 int64_t m; /* mantissa (significand) */
80 int e; /* exponent * -1 */
81 } pdffloat;
82
83 typedef struct {
84 pdffloat h;
85 pdffloat v;
86 } pdfpos;
87
88 # define scaled int
89
90 typedef struct scaledpos_ {
91 int64_t h;
92 int64_t v;
93 } scaledpos;
94
95 typedef struct scaled_whd_ {
96 scaled wd; /* TeX width */
97 scaled ht; /* TeX height */
98 scaled dp; /* TeX depth */
99 } scaled_whd;
100
101 typedef struct posstructure_ {
102 scaledpos pos; /* position on the page */
103 int dir; /* direction of stuff to be put onto the page */
104 } posstructure;
105
106 /* typedef struct { */
107 /* scaledpos curpos; */ /* \pdflastpos position */
108 /* posstructure boxpos; */ /* box dir and position of the box origin on the page */
109 /* scaled_whd boxdim; */ /* box dimensions (in hlist/vlist coordinate system) */
110 /* } pos_info_structure; */
111
112 typedef enum {
113 PMODE_NONE,
114 PMODE_PAGE,
115 PMODE_TEXT,
116 PMODE_CHARARRAY,
117 PMODE_CHAR
118 } pos_mode;
119
120 typedef enum {
121 ST_INITIAL,
122 ST_OMODE_FIX,
123 ST_FILE_OPEN,
124 ST_HEADER_WRITTEN,
125 ST_FILE_CLOSED
126 } output_state;
127
128 typedef struct pdf_object_list_ {
129 int info;
130 struct pdf_object_list_ *link;
131 } pdf_object_list;
132
133 typedef enum { /* []TJ runs horizontal or vertical */
134 WMODE_H,
135 WMODE_V
136 } writing_mode;
137
138 typedef struct {
139 pdfpos pdf; /* pos. on page (PDF page raster) */
140 pdfpos pdf_bt_pos; /* pos. at begin of BT-ET group (PDF page raster) */
141 pdfpos pdf_tj_pos; /* pos. at begin of TJ array (PDF page raster) */
142 pdffloat cw; /* pos. within [(..)..]TJ array (glyph raster); cw.e = fractional digits in /Widths array */
143 pdffloat tj_delta; /* rel. movement in [(..)..]TJ array (glyph raster) */
144 pdffloat fs; /* font size in PDF units */
145 pdffloat fs_cur; /* to check if fs.m has changed and Tf needed */
146 pdffloat tm0_cur; /* to check if tm[0] has changed and Tm needed */
147 pdffloat cm[6]; /* cm array */
148 pdffloat tm[6]; /* Tm array */
149 double k1; /* conv. factor from TeX sp to PDF page raster */
150 double k2; /* conv. factor from PDF page raster to TJ array raster */
151 int f_pdf; /* /F* font number, of unexpanded base font! */
152 int f_pdf_cur; /* to check if f_pdf has changed and Tf needed */
153 writing_mode wmode; /* PDF writing mode WMode (horizontal/vertical) */
154 pos_mode mode; /* current positioning mode */
155 int ishex; /* Whether the current char string is <> or () */
156 int need_tf; /* flag whether Tf needs to be set */
157 int need_tm; /* flag whether Tm needs to be set */
158 int cur_ex; /* the current glyph ex factor */
159 int need_width;
160 int need_mode;
161 int done_width;
162 int done_mode;
163 } pdfstructure;
164
165 typedef struct obj_entry_ {
166 union {
167 int int0;
168 char *str0;
169 } u;
170 int int1;
171 off_t int2;
172 int int3;
173 union {
174 int int4;
175 char *str4;
176 } v;
177 int objtype; /* integer int5 */
178 } obj_entry;
179
180 typedef struct dest_name_entry_ {
181 char *objname; /* destination name */
182 int objnum; /* destination object number */
183 } dest_name_entry;
184
185 # define pdf_max_link_level 10 /* maximum depth of link nesting */
186
187 typedef struct pdf_link_stack_record {
188 int nesting_level;
189 int link_node; /* holds a copy of the corresponding |pdf_start_link_node| */
190 int ref_link_node; /* points to original |pdf_start_link_node|, or a
191 copy of |link_node| created by |append_link| in
192 case of multi-line link */
193 int direction;
194 int count;
195 } pdf_link_stack_record;
196
197 /* types of objects */
198
199 /*
200 NB: |obj_type_thread| is the highest entry in |head_tab|, but there are a few
201 more linked lists that are handy.
202 */
203
204 typedef enum {
205 obj_type_font = 0, /* index of linked list of Fonts objects */
206 obj_type_outline = 1, /* index of linked list of outline objects */
207 obj_type_dest = 2, /* index of linked list of destination objects */
208 obj_type_struct_dest = 3, /* index of linked list of structure destination objects */
209 obj_type_obj = 4, /* index of linked list of raw objects */
210 obj_type_xform = 5, /* index of linked list of XObject forms */
211 obj_type_ximage = 6, /* index of linked list of XObject images */
212 obj_type_thread = 7, /* index of linked list of num article threads */
213 obj_type_pagestream = 8, /* Page stream objects */
214 obj_type_page = 9, /* /Page objects */
215 obj_type_pages = 10, /* /Pages objects */
216 obj_type_catalog = 11, /* /Catalog object */
217 obj_type_info = 12, /* /Info object */
218 obj_type_link = 13, /* link objects */
219 obj_type_annot = 14, /* annotation objects */
220 obj_type_annots = 15, /* /Annots objects */
221 obj_type_bead = 16, /* thread bead objects */
222 obj_type_beads = 17, /* /B objects (array of bead objects) */
223 obj_type_objstm = 18, /* /ObjStm objects */
224 obj_type_others = 19 /* any other objects (also not linked in any list) */
225 } pdf_obj_type;
226
227 # define HEAD_TAB_MAX 7 /* obj_type_thread */
228 # define PDF_OBJ_TYPE_MAX 19 /* obj_type_others */
229
230 typedef struct pdf_resource_struct_ {
231 struct avl_table *resources_tree;
232 int last_resources; /* halfword to most recently generated Resources object. */
233 } pdf_resource_struct;
234
235
236 typedef struct os_obj_data_ {
237 int num;
238 int off;
239 } os_obj_data;
240
241 typedef struct strbuf_s_ {
242 unsigned char *data; /* a PDF stream buffer */
243 unsigned char *p; /* pointer to the next character in the PDF stream buffer */
244 size_t size; /* currently allocated size of the PDF stream buffer, grows dynamically */
245 size_t limit; /* maximum allowed PDF stream buffer size */
246 } strbuf_s;
247
248 typedef struct os_struct_ {
249 os_obj_data *obj; /* array of object stream objects */
250 strbuf_s *buf[3];
251 buffer_e curbuf; /* select into which buffer to output */
252 unsigned int cur_objstm; /* number of current object stream object */
253 unsigned int idx; /* index of object within object stream [1...PDF_OS_MAX_OBJS - 1] */
254 unsigned int ostm_ctr; /* statistics: counter for object stream objects */
255 unsigned int o_ctr; /* statistics: counter for objects within object streams */
256 } os_struct;
257
258
259 # define packet_max_recursion 100 /* see |packet_cur_s| */
260 # define packet_stack_size 100
261
262 typedef struct packet_stack_record_ {
263 float c0;
264 float c1;
265 float c2;
266 float c3;
267 scaledpos pos; /* c4, c5 */
268 } packet_stack_record;
269
270 typedef struct vf_struct_ {
271 packet_stack_record *packet_stack; /* for "push" and "pop" */
272 int packet_stack_level;
273 int packet_stack_minlevel; /* to check stack underflow */
274 internal_font_number lf; /* local font number, resolved */
275 int fs_f; /* local font size */
276 int ex_glyph; /* expansion value; ex_glyph = 0 means unexpanded */
277 int packet_cur_s; /* do_vf_packet() nesting level */
278 posstructure *refpos;
279 int vflua; /* flag, whether vf.*() functions are allowed */
280 } vf_struct;
281
282 typedef struct pdf_output_file_ {
283 FILE *file; /* the PDF output file handle */
284 char *file_name; /* the PDF output file name */
285 char *job_name;
286 output_mode o_mode; /* output mode (DVI/PDF/...) */
287 output_state o_state;
288 /* generation parameters */
289 int gamma;
290 int image_gamma;
291 int image_hicolor; /* boolean */
292 int image_apply_gamma;
293 int draftmode;
294 int pk_resolution;
295 int pk_fixed_dpi;
296 int decimal_digits;
297 int gen_tounicode;
298 int omit_cidset;
299 int omit_charset;
300 int omit_infodict;
301 int omit_mediabox;
302 int inclusion_copy_font;
303 int major_version; /* fixed major part of the PDF version */
304 int minor_version; /* fixed minor part of the PDF version */
305 int recompress;
306 int compress_level; /* level for zlib object stream compression */
307 int objcompresslevel; /* fixed level for activating PDF object streams */
308 char *job_id_string; /* the full job string */
309
310 int os_enable; /* true if object streams are globally enabled */
311 os_struct *os; /* object stream structure pointer */
312
313 strbuf_s *buf; /* pointer to the current stream buffer (PDF stream, ObjStm, or Lua) */
314
315 off_t save_offset; /* to save |pdf_offset| */
316 off_t gone; /* number of bytes that were flushed to output */
317
318 char *printf_buf; /* a scratch buffer for |pdf_printf| */
319
320 time_t start_time; /* when this job started */
321 char *start_time_str; /* minimum size for time_str is 24: "D:YYYYmmddHHMMSS+HH'MM'" */
322
323 strbuf_s *fb; /* pointer to auxiliary buffer for font stuff */
324
325 char *zipbuf;
326 z_stream *c_stream; /* compression stream pointer */
327 zip_write_state_e zip_write_state; /* which state of compression we are in */
328 int stream_deflate; /* true, if stream dict has /Filter/FlateDecode */
329 int stream_writing; /* true while writing stream */
330
331 int pk_scale_factor; /* this is just a preprocessed value that depends on |pk_resolution| and |decimal_digits| */
332
333 int img_page_group_val; /* page group information pointer from included pdf or png images */
334 char *resname_prefix; /* global prefix of resources name */
335
336 int mem_size; /* allocated size of |mem| array */
337 int *mem;
338 int mem_ptr;
339
340 pdfstructure *pstruct; /* utity structure keeping position status in PDF page stream */
341 posstructure *posstruct; /* structure for positioning within page */
342
343 int obj_tab_size; /* allocated size of |obj_tab| array */
344 obj_entry *obj_tab;
345 int head_tab[HEAD_TAB_MAX + 1]; /* heads of the object lists in |obj_tab| */
346 struct avl_table *obj_tree[PDF_OBJ_TYPE_MAX + 1]; /* this is useful for finding the objects back */
347
348 int pages_tail;
349 int obj_ptr; /* objects counter */
350 int last_pages; /* pointer to most recently generated pages object */
351 int last_page; /* pointer to most recently generated page object */
352 int last_stream; /* pointer to most recently generated stream */
353 off_t stream_length; /* length of most recently generated stream */
354 off_t stream_length_offset; /* file offset of the last stream length */
355 int seek_write_length; /* flag whether to seek back and write \.{/Length} */
356 int last_byte; /* byte most recently written to PDF file; for \.{endstream} in new line */
357
358 int obj_count;
359 int xform_count;
360 int ximage_count;
361
362 int force_file;
363
364 pdf_resource_struct *page_resources;
365
366 scaledpos page_size; /* width and height of page being shipped */
367
368 /* the variables from pdfdest */
369 int dest_names_size;
370 int dest_names_ptr;
371 dest_name_entry *dest_names;
372 /* the (static) variables from pdfoutline */
373 int first_outline;
374 int last_outline;
375 int parent_outline;
376 /* the pdf link stack */
377 pdf_link_stack_record link_stack[(pdf_max_link_level + 1)];
378 int link_stack_ptr;
379 int link_state;
380 /* the thread data */
381 int last_thread; /* pointer to the last thread */
382 scaled_whd thread;
383 int last_thread_id; /* identifier of the last thread */
384 int last_thread_named_id; /* is identifier of the last thread named */
385 int thread_level; /* depth of nesting of box containing the last thread */
386
387 int f_cur; /* TeX font number */
388 int cave; /* stay away from previous PDF object */
389
390 vf_struct *vfstruct;
391 } pdf_output_file;
392
393 typedef pdf_output_file *PDF;
394
395 #endif