beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / image / epdf.h
blob3d4751c45871457af519c4994eb5ec72363d2d79
1 /* epdf.h
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
23 #ifndef EPDF_H
24 # define EPDF_H
25 extern "C" {
26 #ifdef HAVE_CONFIG_H
27 #include <w2c/config.h>
28 #endif
30 # include <stdlib.h>
31 # include <math.h>
32 # include <stddef.h>
33 # include <stdio.h>
34 # include <string.h>
35 # include <kpathsea/c-ctype.h>
36 # include <sys/stat.h>
37 # include <dirent.h>
38 # include <poppler-config.h>
39 # include <goo/GooString.h>
40 # include <goo/gmem.h>
41 # include <goo/gfile.h>
42 # include <Object.h>
43 # include <Stream.h>
44 # include <Gfx.h>
45 # include <Annot.h>
46 # include <Array.h>
47 # include <Dict.h>
48 # include <XRef.h>
49 # include <Catalog.h>
50 # include <StructTreeRoot.h>
51 # include <Link.h>
52 # include <Page.h>
53 # include <GfxFont.h>
54 # include <PDFDoc.h>
55 # include <GlobalParams.h>
56 # include <Error.h>
57 # include <FileSpec.h>
59 extern "C" {
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 */
76 # endif
78 # include <c-auto.h> /* define SIZEOF_LONG */
80 # include "image.h"
81 # include "utils/avlstuff.h"
82 # include "pdf/pdftypes.h"
84 # include "lua.h"
85 # include "lauxlib.h"
87 /* pdfgen.w */
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))
117 /* pdfpage.w */
118 extern void print_pdffloat(PDF pdf, pdffloat f);
120 /* pdftables.w */
121 extern int pdf_create_obj(PDF pdf, int t, int i);
123 /* pdftoepdf.cc */
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);
132 /* writeimg.w */
133 extern void pdf_dict_add_img_filename(PDF pdf, image_dict * idict);
135 /* utils.w */
136 extern char *convertStringToPDFString(char *in, int len);
138 /* lepdflib.w */
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.
153 # if 0
154 // PdfObject is replaced by xpdf's Object type, with manual obj.free()
156 // *INDENT-OFF*
157 class PdfObject {
158 public:
159 PdfObject() { // nothing
161 ~PdfObject() {
162 iObject.free();
164 Object *operator->() {
165 return &iObject;
167 Object *operator&() {
168 return &iObject;
170 private: // no copying or assigning
171 PdfObject(const PdfObject &);
172 void operator=(const PdfObject &);
173 public:
174 Object iObject;
176 // *INDENT-ON*
177 # endif
179 /**********************************************************************/
181 struct InObj {
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
187 struct PdfDocument {
188 char *file_path; // full file name including path
189 char *checksum; // for reopening
190 PDFDoc *doc;
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'
207 #endif /* EPDF_H */