3 Copyright 2009-2013 Taco Hoekwater <taco@luatex.org>
5 This file is part of LuaTeX.
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.
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.
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/>.
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)
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 */
33 extern PDF static_pdf
;
35 extern int pdf_get_mem(PDF pdf
, int s
);
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.
46 # define inf_pdfout_buf_size 16384 /* initial value of |pdf->buf| size */
47 # define sup_pdfout_buf_size 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 */
51 # define PDF_OS_MAX_OBJS 100 /* maximum number of objects in object stream */
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 */
56 /* The following macros are similar as for \.{DVI} buffer handling */
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))
61 # define set_ff(A) do { \
62 if (pdf_font_num(A) < 0) \
63 ff = -pdf_font_num(A); \
68 typedef enum { /* needs pdf_prefix */
74 extern scaled one_hundred_inch
;
75 extern scaled one_inch
;
76 extern scaled one_true_inch
;
77 extern scaled one_hundred_bp
;
79 extern int ten_pow
[10];
81 extern void pdf_flush(PDF
);
82 extern void pdf_room(PDF
, int);
84 extern void fix_pdf_minorversion(PDF
);
86 /* output a byte to PDF buffer without checking of overflow */
88 # define pdf_quick_out(pdf,A) * (pdf->buf->p++) = (unsigned char) (A)
90 /* do the same as |pdf_quick_out| and flush the PDF buffer if necessary */
92 # define pdf_out(pdf,A) do { \
94 pdf_quick_out(pdf, A); \
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.
105 # define pdf_print_ln(pdf,A) do { \
107 pdf_out(pdf, '\n'); \
110 /* print out an integer to PDF buffer followed by a new-line character */
112 # define pdf_print_int_ln(pdf,A) do { \
113 pdf_print_int(pdf,A); \
114 pdf_out(pdf, '\n'); \
117 extern __attribute__ ((format(printf
, 2, 3)))
118 void pdf_printf(PDF
, const char *, ...);
120 extern void pdf_print(PDF
, str_number
);
121 extern void pdf_print_int(PDF
, longinteger
);
122 extern void print_pdffloat(PDF pdf
, pdffloat f
);
123 extern void pdf_print_str(PDF
, const char *);
125 extern void pdf_add_null(PDF
);
126 extern void pdf_add_bool(PDF
, int i
);
127 extern void pdf_add_int(PDF
, int i
);
128 extern void pdf_add_longint(PDF
, longinteger n
);
129 extern void pdf_add_ref(PDF
, int num
);
130 extern void pdf_add_string(PDF
, const char *s
);
131 extern void pdf_add_name(PDF
, const char *name
);
133 extern void pdf_dict_add_bool(PDF
, const char *key
, int i
);
134 extern void pdf_dict_add_int(PDF
, const char *key
, int i
);
135 extern void pdf_dict_add_ref(PDF
, const char *key
, int num
);
136 extern void pdf_dict_add_name(PDF
, const char *key
, const char *val
);
137 extern void pdf_dict_add_string(PDF pdf
, const char *key
, const char *val
);
138 extern void pdf_dict_add_streaminfo(PDF
);
140 extern void pdf_begin_stream(PDF
);
141 extern void pdf_end_stream(PDF
);
143 extern void pdf_add_bp(PDF
, scaled
);
145 extern strbuf_s
*new_strbuf(size_t size
, size_t limit
);
146 extern void strbuf_seek(strbuf_s
* b
, off_t offset
);
147 extern size_t strbuf_offset(strbuf_s
* b
);
148 extern void strbuf_putchar(strbuf_s
* b
, unsigned char c
);
149 extern void strbuf_flush(PDF pdf
, strbuf_s
* b
);
150 extern void strbuf_free(strbuf_s
* b
);
152 /* This is for the resource lists */
154 extern void addto_page_resources(PDF pdf
, pdf_obj_type t
, int k
);
155 extern pdf_object_list
*get_page_resources_list(PDF pdf
, pdf_obj_type t
);
157 extern void pdf_out_block(PDF pdf
, const char *s
, size_t n
);
159 # define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s))
161 # define pdf_print_resname_prefix(pdf) do { \
162 if (pdf->resname_prefix != NULL) \
163 pdf_puts(pdf, pdf->resname_prefix); \
166 extern void pdf_print_str_ln(PDF
, const char *);
168 extern void pdf_print_toks(PDF
, halfword
);
170 extern void pdf_add_rect_spec(PDF
, halfword
);
171 extern void pdf_rectangle(PDF
, halfword
);
173 extern void pdf_begin_obj(PDF
, int, int);
174 extern void pdf_end_obj(PDF
);
176 extern void pdf_begin_dict(PDF
);
177 extern void pdf_end_dict(PDF
);
178 extern void pdf_begin_array(PDF
);
179 extern void pdf_end_array(PDF
);
181 extern void remove_pdffile(PDF
);
183 extern void zip_free(PDF
);
185 /* functions that do not output stuff */
187 extern scaled
round_xn_over_d(scaled x
, int n
, unsigned int d
);
189 extern char *convertStringToPDFString(const char *in
, int len
);
191 extern void init_start_time(PDF
);
192 extern char *getcreationdate(PDF
);
194 extern void check_o_mode(PDF pdf
, const char *s
, int o_mode
, boolean errorflag
);
196 extern void set_job_id(PDF
, int, int, int, int);
197 extern char *get_resname_prefix(PDF
);
198 extern void pdf_begin_page(PDF pdf
);
199 extern void pdf_end_page(PDF pdf
);
200 extern void print_pdf_table_string(PDF pdf
, const char *s
);
201 extern const char *get_pdf_table_string(const char *s
);
202 extern int get_pdf_table_bool(PDF
, const char *, int);
204 extern void ensure_output_state(PDF pdf
, output_state s
);
205 extern PDF
init_pdf_struct(PDF pdf
);
207 extern halfword pdf_info_toks
; /* additional keys of Info dictionary */
208 extern halfword pdf_catalog_toks
; /* additional keys of Catalog dictionary */
209 extern halfword pdf_catalog_openaction
;
210 extern halfword pdf_names_toks
; /* additional keys of Names dictionary */
211 extern halfword pdf_trailer_toks
; /* additional keys of Trailer dictionary */
212 extern void scan_pdfcatalog(PDF pdf
);
213 extern void finish_pdf_file(PDF pdf
, int luatex_version
, str_number luatex_revision
);
215 extern shipping_mode_e global_shipping_mode
;