3 Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
4 Copyright 2006-2015 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/>. */
21 // this is the common header file for C++ sources pdftoepdf.cc and lepdflib.cc
27 #include <w2c/config.h>
35 # include <kpathsea/c-ctype.h>
36 # include <sys/stat.h>
38 # include <poppler-config.h>
39 # include <goo/GooString.h>
40 # include <goo/gmem.h>
41 # include <goo/gfile.h>
50 # include <StructTreeRoot.h>
55 # include <GlobalParams.h>
57 # include <FileSpec.h>
61 # include <kpathsea/c-auto.h>
63 extern char *xstrdup(const char *);
65 typedef enum { FE_FAIL
, FE_RETURN_NULL
} file_error_mode
;
67 /* the following code is extremly ugly but needed for including web2c/config.h */
69 typedef const char *const_string
; /* including kpathsea/types.h doesn't work on some systems */
71 # define KPATHSEA_CONFIG_H /* avoid including other kpathsea header files */
72 /* from web2c/config.h */
74 # ifdef CONFIG_H /* CONFIG_H has been defined by some xpdf */
75 # undef CONFIG_H /* header file */
78 # include <c-auto.h> /* define SIZEOF_LONG */
81 # include "utils/avlstuff.h"
82 # include "pdf/pdftypes.h"
88 extern int ten_pow
[10];
89 __attribute__ ((format(printf
, 2, 3)))
90 extern void pdf_printf(PDF
, const char *fmt
, ...);
91 extern void pdf_begin_obj(PDF
, int, int);
92 extern void pdf_end_obj(PDF
);
93 extern void pdf_begin_dict(PDF
);
94 extern void pdf_end_dict(PDF
);
95 extern void pdf_begin_array(PDF
);
96 extern void pdf_end_array(PDF
);
97 extern void pdf_add_null(PDF
);
98 extern void pdf_add_bool(PDF
, int i
);
99 extern void pdf_add_int(PDF
, int i
);
100 extern void pdf_add_ref(PDF
, int num
);
101 extern void pdf_add_name(PDF
, const char *name
);
102 extern void pdf_dict_add_streaminfo(PDF
);
103 extern void pdf_begin_stream(PDF
);
104 extern void pdf_end_stream(PDF
);
105 extern void pdf_room(PDF
, int);
106 extern void pdf_out_block(PDF pdf
, const char *s
, size_t n
);
108 extern void pdf_dict_add_int(PDF
, const char *key
, int i
);
109 extern void pdf_dict_add_ref(PDF
, const char *key
, int num
);
110 extern void pdf_dict_add_name(PDF
, const char *key
, const char *val
);
111 extern void pdf_dict_add_streaminfo(PDF
);
113 # define pdf_out(pdf, A) do { pdf_room(pdf, 1); *(pdf->buf->p++) = A; } while (0)
114 # define pdf_quick_out(pdf,A) *(pdf->buf->p++)=(unsigned char)(A)
115 # define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s))
118 extern void print_pdffloat(PDF pdf
, pdffloat f
);
121 extern int pdf_create_obj(PDF pdf
, int t
, int i
);
124 extern void read_pdf_info(image_dict
*);
125 extern void flush_pdf_info(image_dict
*);
126 extern void write_epdf(PDF
, image_dict
*);
127 extern void unrefPdfDocument(char *);
128 extern void unrefMemStreamPdfDocument(char *);
129 extern void epdf_free(void);
130 extern void copyReal(PDF pdf
, double d
);
133 extern void pdf_dict_add_img_filename(PDF pdf
, image_dict
* idict
);
136 extern char *convertStringToPDFString(char *in
, int len
);
139 int luaopen_epdf(lua_State
* L
);
141 # include "luatex-common.h"
145 /**********************************************************************/
147 // PdfObject encapsulates the xpdf Object type,
148 // and properly frees its resources on destruction.
149 // Use obj-> to access members of the Object,
150 // and &obj to get a pointer to the object.
151 // It is no longer necessary to call Object::free explicitely.
154 // PdfObject is replaced by xpdf's Object type, with manual obj.free()
159 PdfObject() { // nothing
164 Object
*operator->() {
167 Object
*operator&() {
170 private: // no copying or assigning
171 PdfObject(const PdfObject
&);
172 void operator=(const PdfObject
&);
179 /**********************************************************************/
182 Ref ref
; // ref in original PDF
183 int num
; // new object number in output PDF
184 InObj
*next
; // next entry in list of indirect objects
188 char *file_path
; // full file name including path
189 char *checksum
; // for reopening
191 InObj
*inObjList
; // temporary linked list
192 avl_table
*ObjMapTree
; // permanent over luatex run
193 unsigned int occurences
; // number of references to the PdfDocument; it can be deleted when occurences == 0
194 unsigned int pc
; // counter to track PDFDoc generation or deletion
197 PdfDocument
*refPdfDocument(const char *file_path
, file_error_mode fe
);
199 PdfDocument
*refMemStreamPdfDocument(char *docstream
, unsigned long long streamsize
, const char *file_id
);
201 #define STREAM_CHECKSUM_SIZE 16 // md5
202 #define STRSTREAM_CHECKSUM_SIZE 1+((unsigned int)(log((double)ULONG_MAX)/log(16.0))) // djb2 printable digest as hex stream
203 #define STREAM_FILE_ID_LEN 2048 // 2048 bytes are enough to make a strong almost-unique name
204 #define STREAM_URI "data:application/pdf,"
205 #define STREAM_URI_LEN 21 // length of "data:application/pdf," without final '\0'