Debian Codegraph @

texk/web2c/luatexdir/pdf/pdfgen.h

raw
1 /* pdfgen.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 #ifndef PDFGEN_H
22 # define PDFGEN_H
23
24 # define PROCSET_PDF (1 << 0)
25 # define PROCSET_TEXT (1 << 1)
26 # define PROCSET_IMAGE_B (1 << 2)
27 # define PROCSET_IMAGE_C (1 << 3)
28 # define PROCSET_IMAGE_I (1 << 4)
29
30 # define inf_pdf_mem_size 10000 /* min size of the |mem| array */
31 # define sup_pdf_mem_size 100000000 /* max size of the |mem| array */
32
33 extern PDF static_pdf;
34
35 extern int pdf_get_mem(PDF pdf, int s);
36
37 /*
38
39 We use the similiar subroutines to handle the output buffer for PDF output. When
40 compress is used, the state of writing to buffer is held in |zip_write_state|. We
41 must write the header of PDF output file in initialization to ensure that it will
42 be the first written bytes.
43
44 */
45
46 # define inf_pdfout_buf_size 16384 /* initial value of |pdf->buf| size */
47 # define sup_pdfout_buf_size 8*16384 /* arbitrary upper hard limit of |pdf->buf| size */
48 # define inf_objstm_buf_size 1 /* initial value of |os->buf[OBJSTM_BUF]| size */
49 # define sup_objstm_buf_size 5000000 /* arbitrary upper hard limit of |os->buf[OBJSTM_BUF]| size */
50
51 # define PDF_OS_MAX_OBJS 100 /* maximum number of objects in object stream */
52
53 # define inf_obj_tab_size 1000 /* min size of the cross-reference table for PDF output */
54 # define sup_obj_tab_size 8388607 /* max size of the cross-reference table for PDF output */
55
56 /* The following macros are similar as for \.{DVI} buffer handling */
57
58 # define pdf_offset(pdf) (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data))
59 # define pdf_save_offset(pdf) pdf->save_offset = (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data))
60
61 # define set_ff(A) do { \
62 if (pdf_font_num(A) < 0) \
63 ff = -pdf_font_num(A); \
64 else \
65 ff = A; \
66 } while (0)
67
68 typedef enum { /* needs pdf_prefix */
69 NOT_SHIPPING,
70 SHIPPING_PAGE,
71 SHIPPING_FORM
72 } shipping_mode_e;
73
74 extern scaled one_hundred_inch;
75 extern scaled one_inch;
76 extern scaled one_true_inch;
77 extern scaled one_hundred_bp;
78 extern scaled one_bp;
79 extern int ten_pow[10];
80
81 extern void pdf_flush(PDF);
82 extern void pdf_room(PDF, int);
83
84 extern void fix_pdf_version(PDF);
85
86 /* output a byte to PDF buffer without checking of overflow */
87
88 # define pdf_quick_out(pdf,A) * (pdf->buf->p++) = (unsigned char) (A)
89
90 /* do the same as |pdf_quick_out| and flush the PDF buffer if necessary */
91
92 # define pdf_out(pdf,A) do { \
93 pdf_room(pdf, 1); \
94 pdf_quick_out(pdf, A); \
95 } while (0)
96
97 /*
98
99 Basic printing procedures for PDF output are very similiar to \TeX\ basic
100 printing ones but the output is going to PDF buffer. Subroutines with suffix
101 |_ln| append a new-line character to the PDF output.
102
103 */
104
105 # define pdf_print_ln(pdf,A) do { \
106 pdf_print(pdf,A); \
107 pdf_out(pdf, '\n'); \
108 } while (0)
109
110 /* print out an integer to PDF buffer followed by a new-line character */
111
112 # define pdf_print_int_ln(pdf,A) do { \
113 pdf_print_int(pdf,A); \
114 pdf_out(pdf, '\n'); \
115 } while (0)
116
117 #define pdf_check_space(pdf) do { \
118 if (pdf->cave > 0) { \
119 pdf_out(pdf, ' '); \
120 pdf->cave = 0; \
121 } \
122 } while (0)
123
124 #define pdf_set_space(pdf) \
125 pdf->cave = 1;
126
127 #define pdf_reset_space(pdf) \
128 pdf->cave = 0;
129
130 extern __attribute__ ((format(printf, 2, 3)))
131 void pdf_printf(PDF, const char *, ...);
132
133 extern void pdf_print(PDF, str_number);
134 extern void pdf_print_int(PDF, longinteger);
135 extern void print_pdffloat(PDF pdf, pdffloat f);
136 extern void pdf_print_str(PDF, const char *);
137
138 extern void pdf_add_null(PDF);
139 extern void pdf_add_bool(PDF, int i);
140 extern void pdf_add_int(PDF, int i);
141 extern void pdf_add_real(PDF, double d);
142 extern void pdf_add_longint(PDF, longinteger n);
143 extern void pdf_add_ref(PDF, int num);
144 extern void pdf_add_string(PDF, const char *s);
145 extern void pdf_add_name(PDF, const char *name);
146
147 extern void pdf_dict_add_bool(PDF, const char *key, int i);
148 extern void pdf_dict_add_int(PDF, const char *key, int i);
149 extern void pdf_dict_add_ref(PDF, const char *key, int num);
150 extern void pdf_dict_add_name(PDF, const char *key, const char *val);
151 extern void pdf_dict_add_string(PDF pdf, const char *key, const char *val);
152 extern void pdf_dict_add_streaminfo(PDF);
153
154 extern void pdf_begin_stream(PDF);
155 extern void pdf_end_stream(PDF);
156
157 typedef unsigned char BYTE;
158 typedef unsigned long ULONG;
159
160 typedef struct {
161 ULONG length;
162 BYTE *data;
163 } pdf_obj;
164
165 extern pdf_obj *pdf_new_stream(void);
166 extern void pdf_add_stream(pdf_obj * stream, unsigned char *buf, long len);
167 extern void pdf_release_obj(pdf_obj * stream);
168
169 extern void pdf_add_bp(PDF, scaled);
170
171 extern strbuf_s *new_strbuf(size_t size, size_t limit);
172 extern void strbuf_seek(strbuf_s * b, off_t offset);
173 extern size_t strbuf_offset(strbuf_s * b);
174 extern void strbuf_putchar(strbuf_s * b, unsigned char c);
175 extern void strbuf_flush(PDF pdf, strbuf_s * b);
176 extern void strbuf_free(strbuf_s * b);
177
178 /* This is for the resource lists */
179
180 extern void addto_page_resources(PDF pdf, pdf_obj_type t, int k);
181 extern pdf_object_list *get_page_resources_list(PDF pdf, pdf_obj_type t);
182
183 extern void pdf_out_block(PDF pdf, const char *s, size_t n);
184
185 # define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s))
186
187 # define pdf_print_resname_prefix(pdf) do { \
188 if (pdf->resname_prefix != NULL) \
189 pdf_puts(pdf, pdf->resname_prefix); \
190 } while (0)
191
192 extern void pdf_print_str_ln(PDF, const char *);
193
194 extern void pdf_print_toks(PDF, halfword);
195
196 extern void pdf_add_rect_spec(PDF, halfword);
197 extern void pdf_rectangle(PDF, halfword);
198
199 extern void pdf_begin_obj(PDF, int, int);
200 extern void pdf_end_obj(PDF);
201
202 extern void pdf_begin_dict(PDF);
203 extern void pdf_end_dict(PDF);
204 extern void pdf_begin_array(PDF);
205 extern void pdf_end_array(PDF);
206
207 extern void remove_pdffile(PDF);
208
209 extern void zip_free(PDF);
210
211 /* functions that do not output stuff */
212
213 extern scaled round_xn_over_d(scaled x, int n, unsigned int d);
214
215 extern char *convertStringToPDFString(const char *in, int len);
216
217 extern void initialize_start_time(PDF);
218 extern char *getcreationdate(PDF);
219
220 extern void set_job_id(PDF, int, int, int, int);
221 extern char *get_resname_prefix(PDF);
222 extern void pdf_begin_page(PDF pdf);
223 extern void pdf_end_page(PDF pdf);
224 extern void print_pdf_table_string(PDF pdf, const char *s);
225 extern const char *get_pdf_table_string(const char *s);
226 extern int get_pdf_table_bool(PDF, const char *, int);
227
228 extern void pdf_open_file(PDF pdf);
229 extern void pdf_write_header(PDF pdf);
230 extern void pdf_finish_file(PDF pdf, int fatal_error);
231
232 extern void ensure_output_state(PDF pdf, output_state s);
233 extern PDF init_pdf_struct(PDF pdf);
234
235 extern halfword pdf_info_toks; /* additional keys of Info dictionary */
236 extern halfword pdf_catalog_toks; /* additional keys of Catalog dictionary */
237 extern halfword pdf_catalog_openaction;
238 extern halfword pdf_names_toks; /* additional keys of Names dictionary */
239 extern halfword pdf_trailer_toks; /* additional keys of Trailer dictionary */
240 extern void scan_pdfcatalog(PDF pdf);
241
242 extern shipping_mode_e global_shipping_mode;
243
244 extern void pdf_push_list(PDF pdf, scaledpos *saved_pos, int *saved_loc);
245 extern void pdf_pop_list(PDF pdf, scaledpos *saved_pos, int *saved_loc);
246
247 extern void pdf_set_reference_point(PDF pdf, posstructure *refpoint);
248
249 /* not pdf specific */
250
251 extern void check_o_mode(PDF pdf, const char *s, int o_mode, boolean errorflag);
252 extern void ensure_output_file_open(PDF pdf, const char *ext);
253
254 /* PTEX prefix */
255 extern const char *pdf_pdf_prefix_str(const char *a, const char *b);
256
257
258 #endif