1 /* pdfgen.h
2 
3    Copyright 2009-2013 Taco Hoekwater <taco@luatex.org>
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 10000000     /* 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 We use the similiar subroutines to handle the output buffer for
39 PDF output. When compress is used, the state of writing to buffer
40 is held in |zip_write_state|. We must write the header of PDF
41 output file in initialization to ensure that it will be the first
42 written bytes.
43 */
44 
45 #  define inf_pdfout_buf_size 16384 /* initial value of |pdf->buf| size */
46 #  define sup_pdfout_buf_size 16384     /* arbitrary upper hard limit of |pdf->buf| size */
47 #  define inf_objstm_buf_size 1 /* initial value of |os->buf[OBJSTM_BUF]| size */
48 #  define sup_objstm_buf_size 5000000   /* arbitrary upper hard limit of |os->buf[OBJSTM_BUF]| size */
49 
50 #  define PDF_OS_MAX_OBJS 100   /* maximum number of objects in object stream */
51 
52 #  define inf_obj_tab_size 1000 /* min size of the cross-reference table for PDF output */
53 #  define sup_obj_tab_size 8388607      /* max size of the cross-reference table for PDF output */
54 
55 /* The following macros are similar as for \.{DVI} buffer handling */
56 
57 #  define pdf_offset(pdf) (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data))
58                                         /* the file offset of last byte in PDF
59                                            buffer that |pdf_ptr| points to */
60 #  define pdf_save_offset(pdf) pdf->save_offset = (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data))
61 
62 #  define set_ff(A)  do {                       \
63         if (pdf_font_num(A) < 0)                \
64             ff = -pdf_font_num(A);              \
65         else                                    \
66             ff = A;                             \
67     } while (0)
68 
69 typedef enum { NOT_SHIPPING, SHIPPING_PAGE, SHIPPING_FORM } shipping_mode_e;
70 
71 extern int pdf_output_option;
72 extern int pdf_output_value;
73 extern int pdf_draftmode_option;
74 extern int pdf_draftmode_value;
75 
76 extern scaled one_hundred_inch;
77 extern scaled one_inch;
78 extern scaled one_true_inch;
79 extern scaled one_hundred_bp;
80 extern scaled one_bp;
81 extern int ten_pow[10];
82 
83 extern void pdf_flush(PDF);
84 extern void pdf_room(PDF, int);
85 
86 extern void fix_pdf_minorversion(PDF);
87 
88  /* output a byte to PDF buffer without checking of overflow */
89 #  define pdf_quick_out(pdf,A) * (pdf->buf->p++) = (unsigned char) (A)
90 
91 /* do the same as |pdf_quick_out| and flush the PDF buffer if necessary */
92 #  define pdf_out(pdf,A) do { pdf_room(pdf, 1); pdf_quick_out(pdf, A); } while (0)
93 
94 /*
95 Basic printing procedures for PDF output are very similiar to \TeX\ basic
96 printing ones but the output is going to PDF buffer. Subroutines with
97 suffix |_ln| append a new-line character to the PDF output.
98 */
99 
100 /* print out a string to PDF buffer followed by a new-line character */
101 #  define pdf_print_ln(pdf,A) do {                 \
102         pdf_print(pdf,A);                          \
103         pdf_out(pdf, '\n');                        \
104     } while (0)
105 
106 /* print out an integer to PDF buffer followed by a new-line character */
107 #  define pdf_print_int_ln(pdf,A) do {             \
108         pdf_print_int(pdf,A);                      \
109         pdf_out(pdf, '\n');                        \
110     } while (0)
111 
112 extern __attribute__ ((format(printf, 2, 3)))
113 void pdf_printf(PDF, const char *, ...);
114 
115 extern void pdf_print(PDF, str_number);
116 extern void pdf_print_int(PDF, longinteger);
117 extern void print_pdffloat(PDF pdf, pdffloat f);
118 extern void pdf_print_str(PDF, const char *);
119 
120 extern void pdf_add_null(PDF);
121 extern void pdf_add_bool(PDF, int i);
122 extern void pdf_add_int(PDF, int i);
123 extern void pdf_add_longint(PDF, longinteger n);
124 extern void pdf_add_ref(PDF, int num);
125 extern void pdf_add_string(PDF, const char *s);
126 extern void pdf_add_name(PDF, const char *name);
127 
128 extern void pdf_dict_add_bool(PDF, const char *key, int i);
129 extern void pdf_dict_add_int(PDF, const char *key, int i);
130 extern void pdf_dict_add_ref(PDF, const char *key, int num);
131 extern void pdf_dict_add_name(PDF, const char *key, const char *val);
132 extern void pdf_dict_add_string(PDF pdf, const char *key, const char *val);
133 extern void pdf_dict_add_streaminfo(PDF);
134 
135 extern void pdf_begin_stream(PDF);
136 extern void pdf_end_stream(PDF);
137 
138 extern void pdf_add_bp(PDF, scaled);
139 extern void pdf_add_mag_bp(PDF, scaled);
140 
141 extern strbuf_s *new_strbuf(size_t size, size_t limit);
142 extern void strbuf_seek(strbuf_s * b, off_t offset);
143 extern size_t strbuf_offset(strbuf_s * b);
144 extern void strbuf_putchar(strbuf_s * b, unsigned char c);
145 extern void strbuf_flush(PDF pdf, strbuf_s * b);
146 extern void strbuf_free(strbuf_s * b);
147 
148 /* This is for the resource lists */
149 
150 extern void addto_page_resources(PDF pdf, pdf_obj_type t, int k);
151 extern pdf_object_list *get_page_resources_list(PDF pdf, pdf_obj_type t);
152 
153 extern void pdf_out_block(PDF pdf, const char *s, size_t n);
154 
155 #  define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s))
156 
157 #  define pdf_print_resname_prefix(pdf) do {        \
158         if (pdf->resname_prefix != NULL)            \
159             pdf_puts(pdf, pdf->resname_prefix);     \
160     } while (0)
161 
162 extern void pdf_print_str_ln(PDF, const char *);
163 
164 extern void pdf_print_toks(PDF, halfword);
165 
166 extern void pdf_add_rect_spec(PDF, halfword);
167 extern void pdf_rectangle(PDF, halfword);
168 
169 extern void pdf_begin_obj(PDF, int, int);
170 extern void pdf_end_obj(PDF);
171 
172 extern void pdf_begin_dict(PDF);
173 extern void pdf_end_dict(PDF);
174 extern void pdf_begin_array(PDF);
175 extern void pdf_end_array(PDF);
176 
177 extern void remove_pdffile(PDF);
178 
179 extern void zip_free(PDF);
180 
181 /* functions that do not output stuff */
182 
183 extern scaled round_xn_over_d(scaled x, int n, unsigned int d);
184 
185 extern char *convertStringToPDFString(const char *in, int len);
186 
187 extern void init_start_time(PDF);
188 extern char *getcreationdate(PDF);
189 
190 extern void pdf_error(const char *t, const char *p);
191 extern void pdf_warning(const char *t, const char *p, boolean pr, boolean ap);
192 extern void check_o_mode(PDF pdf, const char *s, int o_mode, boolean errorflag);
193 
194 extern void set_job_id(PDF, int, int, int, int);
195 extern char *get_resname_prefix(PDF);
196 extern void pdf_begin_page(PDF pdf);
197 extern void pdf_end_page(PDF pdf);
198 extern void print_pdf_table_string(PDF pdf, const char *s);
199 extern const char *get_pdf_table_string(const char *s);
200 extern int get_pdf_table_bool(PDF, const char *, int);
201 
202 extern void fix_o_mode(PDF pdf);
203 extern void ensure_output_state(PDF pdf, output_state s);
204 extern PDF init_pdf_struct(PDF pdf);
205 
206 extern halfword pdf_info_toks;  /* additional keys of Info dictionary */
207 extern halfword pdf_catalog_toks;       /* additional keys of Catalog dictionary */
208 extern halfword pdf_catalog_openaction;
209 extern halfword pdf_names_toks; /* additional keys of Names dictionary */
210 extern halfword pdf_trailer_toks;       /* additional keys of Trailer dictionary */
211 extern void scan_pdfcatalog(PDF pdf);
212 extern void finish_pdf_file(PDF pdf, int luatex_version,
213                             str_number luatex_revision);
214 
215 extern shipping_mode_e global_shipping_mode;
216 
217 #endif                          /* PDFGEN_H */
218