| 1 |
/* epdf.h |
| 2 |
|
| 3 |
Copyright 1996-2006 Han The Thanh <[email protected]> |
| 4 |
Copyright 2006-2015 Taco Hoekwater <[email protected]> |
| 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.c and lepdflib.c */ |
| 22 |
|
| 23 |
#ifndef EPDF_H |
| 24 |
# define EPDF_H |
| 25 |
|
| 26 |
/*extern "C" {*/ |
| 27 |
|
| 28 |
#ifdef HAVE_CONFIG_H |
| 29 |
#include <w2c/config.h> |
| 30 |
#endif |
| 31 |
|
| 32 |
/*}*/ |
| 33 |
|
| 34 |
# include <stdlib.h> |
| 35 |
# include <math.h> |
| 36 |
# include <stddef.h> |
| 37 |
# include <stdio.h> |
| 38 |
# include <string.h> |
| 39 |
# include <kpathsea/c-ctype.h> |
| 40 |
# include <kpathsea/simpletypes.h> |
| 41 |
# include <sys/stat.h> |
| 42 |
# include <dirent.h> |
| 43 |
|
| 44 |
/*extern "C" { */ |
| 45 |
|
| 46 |
# include <kpathsea/c-auto.h> |
| 47 |
|
| 48 |
extern char *xstrdup(const char *); |
| 49 |
|
| 50 |
typedef enum { FE_FAIL, FE_RETURN_NULL } file_error_mode; |
| 51 |
|
| 52 |
/* the following code is extremly ugly but needed for including web2c/config.h */ |
| 53 |
|
| 54 |
/*typedef const char *const_string;*/ /* including kpathsea/types.h doesn't work on some systems */ |
| 55 |
|
| 56 |
# define KPATHSEA_CONFIG_H /* avoid including other kpathsea header files */ |
| 57 |
|
| 58 |
/* from web2c/config.h */ |
| 59 |
|
| 60 |
# ifdef CONFIG_H /* CONFIG_H has been defined by some xpdf */ |
| 61 |
# undef CONFIG_H /* header file */ |
| 62 |
# endif |
| 63 |
|
| 64 |
# include <c-auto.h> /* define SIZEOF_LONG */ |
| 65 |
|
| 66 |
# include "image.h" |
| 67 |
# include "utils/avlstuff.h" |
| 68 |
# include "pdf/pdftypes.h" |
| 69 |
|
| 70 |
# include "lua.h" |
| 71 |
# include "lauxlib.h" |
| 72 |
|
| 73 |
# include "pplib.h" |
| 74 |
|
| 75 |
|
| 76 |
/* pdfgen.w */ |
| 77 |
|
| 78 |
extern int ten_pow[10]; |
| 79 |
__attribute__ ((format(printf, 2, 3))) |
| 80 |
extern void pdf_printf(PDF, const char *fmt, ...); |
| 81 |
extern void pdf_begin_obj(PDF, int, int); |
| 82 |
extern void pdf_end_obj(PDF); |
| 83 |
extern void pdf_begin_dict(PDF); |
| 84 |
extern void pdf_end_dict(PDF); |
| 85 |
extern void pdf_begin_array(PDF); |
| 86 |
extern void pdf_end_array(PDF); |
| 87 |
extern void pdf_add_null(PDF); |
| 88 |
extern void pdf_add_bool(PDF, int i); |
| 89 |
extern void pdf_add_int(PDF, int i); |
| 90 |
extern void pdf_add_real(PDF, double d); |
| 91 |
extern void pdf_add_ref(PDF, int num); |
| 92 |
extern void pdf_add_name(PDF, const char *name); |
| 93 |
extern void pdf_dict_add_streaminfo(PDF); |
| 94 |
extern void pdf_begin_stream(PDF); |
| 95 |
extern void pdf_end_stream(PDF); |
| 96 |
extern void pdf_room(PDF, int); |
| 97 |
extern void pdf_out_block(PDF pdf, const char *s, size_t n); |
| 98 |
|
| 99 |
extern void pdf_dict_add_int(PDF, const char *key, int i); |
| 100 |
extern void pdf_dict_add_ref(PDF, const char *key, int num); |
| 101 |
extern void pdf_dict_add_name(PDF, const char *key, const char *val); |
| 102 |
extern void pdf_dict_add_streaminfo(PDF); |
| 103 |
|
| 104 |
extern const char *pdf_pdf_prefix_str(const char *a, const char *b); |
| 105 |
|
| 106 |
/* Conflict with pdfgen.h */ |
| 107 |
/*# define pdf_out(pdf, A) do { pdf_room(pdf, 1); *(pdf->buf->p++) = A; } while (0)*/ |
| 108 |
/*# define pdf_quick_out(pdf,A) *(pdf->buf->p++)=(unsigned char)(A) */ |
| 109 |
|
| 110 |
# define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s)) |
| 111 |
|
| 112 |
/* pdfpage.w */ |
| 113 |
|
| 114 |
extern void print_pdffloat(PDF pdf, pdffloat f); |
| 115 |
|
| 116 |
/* pdftables.w */ |
| 117 |
|
| 118 |
extern int pdf_create_obj(PDF pdf, int t, int i); |
| 119 |
|
| 120 |
/* pdftoepdf.c */ |
| 121 |
|
| 122 |
extern void read_pdf_info(image_dict *); |
| 123 |
extern void flush_pdf_info(image_dict *); |
| 124 |
|
| 125 |
extern void write_epdf(PDF, image_dict *, int suppress_optional_info); |
| 126 |
extern int write_epdf_object(PDF, image_dict *, int n); |
| 127 |
|
| 128 |
extern void unrefPdfDocument(char *); |
| 129 |
extern void unrefMemStreamPdfDocument(char *); |
| 130 |
|
| 131 |
extern void epdf_free(void); |
| 132 |
|
| 133 |
/* writeimg.w */ |
| 134 |
|
| 135 |
extern void pdf_dict_add_img_filename(PDF pdf, image_dict * idict); |
| 136 |
|
| 137 |
/* utils.w */ |
| 138 |
|
| 139 |
/*extern char *convertStringToPDFString(const char *in, int len);*/ |
| 140 |
|
| 141 |
/* lepdflib.w */ |
| 142 |
|
| 143 |
int luaopen_epdf(lua_State * L); |
| 144 |
|
| 145 |
# include "luatex-common.h" |
| 146 |
|
| 147 |
/*}*/ |
| 148 |
|
| 149 |
typedef struct InObj InObj; |
| 150 |
|
| 151 |
struct InObj { |
| 152 |
/* int version; */ /* old object number in included PDF */ |
| 153 |
int objnum; /* old version number in included PDF, we can do without */ |
| 154 |
int num; /* new object number in output PDF */ |
| 155 |
InObj *next; /* next entry in list of indirect objects */ |
| 156 |
} ; |
| 157 |
|
| 158 |
|
| 159 |
typedef struct avl_table avl_table; |
| 160 |
|
| 161 |
struct PdfDocument { |
| 162 |
char *file_path; /* full file name including path */ |
| 163 |
char *checksum; /* for reopening */ |
| 164 |
ppdoc *pdfe; |
| 165 |
InObj *inObjList; /* temporary linked list */ |
| 166 |
avl_table *ObjMapTree; /* permanent over luatex run */ |
| 167 |
int is_mem; |
| 168 |
char *memstream; |
| 169 |
unsigned int occurences; /* number of references to the PdfDocument; it can be deleted when occurences == 0 */ |
| 170 |
unsigned int pc; /* counter to track PDFDoc generation or deletion */ |
| 171 |
}; |
| 172 |
|
| 173 |
typedef struct PdfDocument PdfDocument; |
| 174 |
|
| 175 |
PdfDocument *refPdfDocument(const char *file_path, file_error_mode fe, const char *userpassword, const char *ownerpassword); |
| 176 |
|
| 177 |
PdfDocument *refMemStreamPdfDocument(char *docstream, unsigned long long streamsize, const char *file_id); |
| 178 |
|
| 179 |
#define STREAM_CHECKSUM_SIZE 16 // md5 |
| 180 |
#define STRSTREAM_CHECKSUM_SIZE 1+((unsigned int)(log((double)ULONG_MAX)/log(16.0))) // djb2 printable digest as hex stream |
| 181 |
#define STREAM_FILE_ID_LEN 2048 // 2048 bytes are enough to make a strong almost-unique name |
| 182 |
#define STREAM_URI "data:application/pdf," |
| 183 |
#define STREAM_URI_LEN 21 // length of "data:application/pdf," without final '\0' |
| 184 |
|
| 185 |
#endif /* EPDF_H */ |