1 /* epdf.h 2 3 Copyright 1996-2006 Han The Thanh <thanh@pdftex.org> 4 Copyright 2006-2012 Taco Hoekwater <taco@luatex.org> 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 // this is the common header file for C++ sources pdftoepdf.cc and lepdflib.cc 22 23 #ifndef EPDF_H 24 # define EPDF_H 25 extern "C" { 26 #ifdef HAVE_CONFIG_H 27 #include <w2c/config.h> 28 #endif 29 } 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 # ifdef HAVE_STRUCTTREEROOT_H 51 # include <StructTreeRoot.h> 52 # endif 53 # include <Link.h> 54 # include <Page.h> 55 # include <GfxFont.h> 56 # include <PDFDoc.h> 57 # include <GlobalParams.h> 58 # include <Error.h> 59 # include <FileSpec.h> 60 61 extern "C" { 62 63 # include <kpathsea/c-auto.h> 64 65 extern char *xstrdup(const char *); 66 67 typedef enum { FE_FAIL, FE_RETURN_NULL } file_error_mode; 68 69 /* the following code is extremly ugly but needed for including web2c/config.h */ 70 71 typedef const char *const_string; /* including kpathsea/types.h doesn't work on some systems */ 72 73 # define KPATHSEA_CONFIG_H /* avoid including other kpathsea header files */ 74 /* from web2c/config.h */ 75 76 # ifdef CONFIG_H /* CONFIG_H has been defined by some xpdf */ 77 # undef CONFIG_H /* header file */ 78 # endif 79 80 # include <c-auto.h> /* define SIZEOF_LONG */ 81 82 # include "image.h" 83 # include "utils/avlstuff.h" 84 # include "pdf/pdftypes.h" 85 86 # include "lua.h" 87 # include "lauxlib.h" 88 89 /* pdfgen.w */ 90 extern int ten_pow[10]; 91 __attribute__ ((format(printf, 2, 3))) 92 extern void pdf_printf(PDF, const char *fmt, ...); 93 extern void pdf_begin_obj(PDF, int, int); 94 extern void pdf_end_obj(PDF); 95 extern void pdf_begin_dict(PDF); 96 extern void pdf_end_dict(PDF); 97 extern void pdf_begin_array(PDF); 98 extern void pdf_end_array(PDF); 99 extern void pdf_add_null(PDF); 100 extern void pdf_add_bool(PDF, int i); 101 extern void pdf_add_int(PDF, int i); 102 extern void pdf_add_ref(PDF, int num); 103 extern void pdf_add_name(PDF, const char *name); 104 extern void pdf_dict_add_streaminfo(PDF); 105 extern void pdf_begin_stream(PDF); 106 extern void pdf_end_stream(PDF); 107 extern void pdf_room(PDF, int); 108 extern void pdf_out_block(PDF pdf, const char *s, size_t n); 109 110 extern void pdf_dict_add_int(PDF, const char *key, int i); 111 extern void pdf_dict_add_ref(PDF, const char *key, int num); 112 extern void pdf_dict_add_name(PDF, const char *key, const char *val); 113 extern void pdf_dict_add_streaminfo(PDF); 114 115 # define pdf_out(pdf, A) do { pdf_room(pdf, 1); *(pdf->buf->p++) = A; } while (0) 116 # define pdf_quick_out(pdf,A) *(pdf->buf->p++)=(unsigned char)(A) 117 # define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s)) 118 119 /* pdfpage.w */ 120 extern void print_pdffloat(PDF pdf, pdffloat f); 121 122 /* pdftables.w */ 123 extern int pdf_create_obj(PDF pdf, int t, int i); 124 125 /* pdftoepdf.cc */ 126 extern void read_pdf_info(image_dict *, int, int, img_readtype_e); 127 extern void write_epdf(PDF, image_dict *); 128 extern void unrefPdfDocument(char *); 129 extern void epdf_free(void); 130 extern void copyReal(PDF pdf, double d); 131 132 /* writeimg.w */ 133 extern void pdf_dict_add_img_filename(PDF pdf, image_dict * idict); 134 135 /* utils.w */ 136 extern char *convertStringToPDFString(char *in, int len); 137 138 /* lepdflib.w */ 139 int luaopen_epdf(lua_State * L); 140 141 # include "luatex-common.h" 142 143 }; 144 145 /**********************************************************************/ 146 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. 152 153 # if 0 154 // PdfObject is replaced by xpdf's Object type, with manual obj.free() 155 156 // *INDENT-OFF* 157 class PdfObject { 158 public: 159 PdfObject() { // nothing 160 } 161 ~PdfObject() { 162 iObject.free(); 163 } 164 Object *operator->() { 165 return &iObject; 166 } 167 Object *operator&() { 168 return &iObject; 169 } 170 private: // no copying or assigning 171 PdfObject(const PdfObject &); 172 void operator=(const PdfObject &); 173 public: 174 Object iObject; 175 }; 176 // *INDENT-ON* 177 # endif 178 179 /**********************************************************************/ 180 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 185 }; 186 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 195 }; 196 197 PdfDocument *refPdfDocument(char *file_path, file_error_mode fe); 198 199 #endif /* EPDF_H */ 200