| 1 |
/* lpdflib.c |
| 2 |
|
| 3 |
Copyright 2006-2011 Taco Hoekwater <[email protected]> |
| 4 |
|
| 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 |
#include "ptexlib.h" |
| 21 |
#include "lua/luatex-api.h" |
| 22 |
#include "pdf/pdftables.h" |
| 23 |
|
| 24 |
int luapdfprint(lua_State * L) |
| 25 |
{ |
| 26 |
int n; |
| 27 |
const_lstring st; |
| 28 |
const char *modestr_s; |
| 29 |
ctm_transform_modes literal_mode; |
| 30 |
st.s = modestr_s = NULL; |
| 31 |
n = lua_gettop(L); |
| 32 |
if (!lua_isstring(L, -1)) { /* or number */ |
| 33 |
luaL_error(L, "no string to print"); |
| 34 |
} |
| 35 |
literal_mode = set_origin; |
| 36 |
if (n == 2) { |
| 37 |
if (lua_type(L,-2) != LUA_TSTRING) { |
| 38 |
luaL_error(L, "invalid first argument for print literal mode"); |
| 39 |
} else { |
| 40 |
modestr_s = lua_tostring(L, -2); |
| 41 |
if (lua_key_eq(modestr_s,direct)) |
| 42 |
literal_mode = direct_always; |
| 43 |
else if (lua_key_eq(modestr_s,page)) |
| 44 |
literal_mode = direct_page; |
| 45 |
else if (lua_key_eq(modestr_s,text)) |
| 46 |
literal_mode = direct_text; |
| 47 |
else if (lua_key_eq(modestr_s,raw)) |
| 48 |
literal_mode = direct_raw; |
| 49 |
else if (lua_key_eq(modestr_s,origin)) |
| 50 |
literal_mode = set_origin; |
| 51 |
else { |
| 52 |
luaL_error(L, "invalid first argument for print literal mode"); |
| 53 |
} |
| 54 |
} |
| 55 |
} else if (n != 1) { |
| 56 |
luaL_error(L, "invalid number of arguments"); |
| 57 |
} |
| 58 |
check_o_mode(static_pdf, "pdf.print()", 1 << OMODE_PDF, true); |
| 59 |
switch (literal_mode) { |
| 60 |
case (set_origin): |
| 61 |
pdf_goto_pagemode(static_pdf); |
| 62 |
pdf_set_pos(static_pdf, static_pdf->posstruct->pos); |
| 63 |
(void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); |
| 64 |
break; |
| 65 |
case (direct_page): |
| 66 |
pdf_goto_pagemode(static_pdf); |
| 67 |
(void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); |
| 68 |
break; |
| 69 |
case (direct_text): |
| 70 |
pdf_goto_textmode(static_pdf); |
| 71 |
(void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); |
| 72 |
break; |
| 73 |
case (direct_always): |
| 74 |
pdf_end_string_nl(static_pdf); |
| 75 |
break; |
| 76 |
case (direct_raw): |
| 77 |
pdf_end_string_nl(static_pdf); |
| 78 |
break; |
| 79 |
default: |
| 80 |
assert(0); |
| 81 |
} |
| 82 |
st.s = lua_tolstring(L, n, &st.l); |
| 83 |
pdf_out_block(static_pdf, st.s, st.l); |
| 84 |
/* pdf_out(pdf, '\n'); */ |
| 85 |
return 0; |
| 86 |
} |
| 87 |
|
| 88 |
static unsigned char *fread_to_buf(lua_State * L, const char *filename, size_t * len) |
| 89 |
{ |
| 90 |
int ilen = 0; |
| 91 |
FILE *f; |
| 92 |
unsigned char *buf = NULL; |
| 93 |
if ((f = fopen(filename, "rb")) == NULL) |
| 94 |
luaL_error(L, "pdf.immediateobj() cannot open input file"); |
| 95 |
if (readbinfile(f, &buf, &ilen) == 0) |
| 96 |
luaL_error(L, "pdf.immediateobj() cannot read input file"); |
| 97 |
fclose(f); |
| 98 |
*len = (size_t) ilen; |
| 99 |
return buf; |
| 100 |
} |
| 101 |
|
| 102 |
static int l_immediateobj(lua_State * L) |
| 103 |
{ |
| 104 |
int n, first_arg = 1; |
| 105 |
int k; |
| 106 |
lstring buf; |
| 107 |
const_lstring st1,st2, st3; |
| 108 |
const char *st1_s = NULL; |
| 109 |
st1.s = st2.s = st3.s = NULL; |
| 110 |
check_o_mode(static_pdf, "immediateobj()", 1 << OMODE_PDF, true); |
| 111 |
if (global_shipping_mode != NOT_SHIPPING) |
| 112 |
luaL_error(L, "pdf.immediateobj() can not be used with \\latelua"); |
| 113 |
n = lua_gettop(L); |
| 114 |
if ((n > 0) && (lua_type(L, 1) == LUA_TNUMBER)) { |
| 115 |
first_arg++; |
| 116 |
k = (int) lua_tointeger(L, 1); |
| 117 |
check_obj_type(static_pdf, obj_type_obj, k); |
| 118 |
if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0) |
| 119 |
luaL_error(L, "pdf.immediateobj() object in use"); |
| 120 |
} else { |
| 121 |
static_pdf->obj_count++; |
| 122 |
k = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); |
| 123 |
} |
| 124 |
pdf_last_obj = k; |
| 125 |
switch (n - first_arg + 1) { |
| 126 |
case 0: |
| 127 |
luaL_error(L, "pdf.immediateobj() needs at least one argument"); |
| 128 |
break; |
| 129 |
case 1: |
| 130 |
if (!lua_isstring(L, first_arg)) /* or number */ |
| 131 |
luaL_error(L, "pdf.immediateobj() 1st argument must be string"); |
| 132 |
pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS); |
| 133 |
st1.s = lua_tolstring(L, first_arg, &st1.l); |
| 134 |
pdf_out_block(static_pdf, st1.s, st1.l); |
| 135 |
pdf_end_obj(static_pdf); |
| 136 |
break; |
| 137 |
case 2: |
| 138 |
case 3: |
| 139 |
if (lua_type(L,first_arg) != LUA_TSTRING) |
| 140 |
luaL_error(L, "pdf.immediateobj() 1st argument must be string"); |
| 141 |
if (!lua_isstring(L, first_arg + 1)) /* or number */ |
| 142 |
luaL_error(L, "pdf.immediateobj() 2nd argument must be string"); |
| 143 |
st1_s = lua_tostring(L, first_arg); |
| 144 |
st2.s = lua_tolstring(L, first_arg + 1, &st2.l); |
| 145 |
if (lua_key_eq(st1_s, file)) { |
| 146 |
if (n == first_arg + 2) |
| 147 |
luaL_error(L, "pdf.immediateobj() 3rd argument forbidden in file mode"); |
| 148 |
pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS); |
| 149 |
buf.s = fread_to_buf(L, st2.s, &buf.l); |
| 150 |
pdf_out_block(static_pdf, (const char *) buf.s, buf.l); |
| 151 |
xfree(buf.s); |
| 152 |
pdf_end_obj(static_pdf); |
| 153 |
} else { |
| 154 |
pdf_begin_obj(static_pdf, k, OBJSTM_NEVER); /* not an object stream candidate! */ |
| 155 |
pdf_begin_dict(static_pdf); |
| 156 |
if (n == first_arg + 2) { /* write attr text */ |
| 157 |
if (!lua_isstring(L, first_arg + 2)) /* or number (maybe only string as it's an attr) */ |
| 158 |
luaL_error(L, "pdf.immediateobj() 3rd argument must be string"); |
| 159 |
st3.s = lua_tolstring(L, first_arg + 2, &st3.l); |
| 160 |
pdf_out_block(static_pdf, st3.s, st3.l); |
| 161 |
if (st3.s[st3.l - 1] != '\n') |
| 162 |
pdf_out(static_pdf, '\n'); |
| 163 |
} |
| 164 |
pdf_dict_add_streaminfo(static_pdf); |
| 165 |
pdf_end_dict(static_pdf); |
| 166 |
pdf_begin_stream(static_pdf); |
| 167 |
if (lua_key_eq(st1_s, stream)) { |
| 168 |
pdf_out_block(static_pdf, st2.s, st2.l); |
| 169 |
} else if (lua_key_eq(st1_s, streamfile)) { |
| 170 |
buf.s = fread_to_buf(L, st2.s, &buf.l); |
| 171 |
pdf_out_block(static_pdf, (const char *) buf.s, buf.l); |
| 172 |
xfree(buf.s); |
| 173 |
} else |
| 174 |
luaL_error(L, "pdf.immediateobj() invalid argument"); |
| 175 |
pdf_end_stream(static_pdf); |
| 176 |
pdf_end_obj(static_pdf); |
| 177 |
} |
| 178 |
break; |
| 179 |
default: |
| 180 |
luaL_error(L, "pdf.immediateobj() allows max. 3 arguments"); |
| 181 |
} |
| 182 |
lua_pushinteger(L, k); |
| 183 |
return 1; |
| 184 |
} |
| 185 |
|
| 186 |
static int table_obj(lua_State * L) |
| 187 |
{ |
| 188 |
const char *type; |
| 189 |
int k, obj_compression; |
| 190 |
int compress_level = -1; /* unset */ |
| 191 |
int os_threshold = OBJSTM_ALWAYS; /* default: put non-stream objects into object streams */ |
| 192 |
int saved_compress_level = static_pdf->compress_level; |
| 193 |
const_lstring attr, st; |
| 194 |
lstring buf; |
| 195 |
int immediate = 0; /* default: not immediate */ |
| 196 |
int nolength = 0; |
| 197 |
attr.s = st.s = NULL; |
| 198 |
attr.l = 0; |
| 199 |
assert(lua_istable(L, 1)); /* t */ |
| 200 |
lua_key_rawgeti(type); |
| 201 |
if (lua_isnil(L, -1)) /* !vs t */ |
| 202 |
luaL_error(L, "pdf.obj(): object \"type\" missing"); |
| 203 |
if (lua_type(L,-1) != LUA_TSTRING) /* !vs t */ |
| 204 |
luaL_error(L, "pdf.obj(): object \"type\" must be string"); |
| 205 |
type = lua_tostring(L, -1); |
| 206 |
if (! (lua_key_eq(type, raw) || lua_key_eq(type, stream))) { |
| 207 |
luaL_error(L, "pdf.obj(): \"%s\" is not a valid object type", type); /* i vs t */ |
| 208 |
} |
| 209 |
lua_pop(L, 1); /* t */ |
| 210 |
lua_key_rawgeti(immediate); |
| 211 |
if (!lua_isnil(L, -1)) { /* b? t */ |
| 212 |
if (!lua_isboolean(L, -1)) /* !b t */ |
| 213 |
luaL_error(L, "pdf.obj(): \"immediate\" must be boolean"); |
| 214 |
immediate = lua_toboolean(L, -1); /* 0 or 1 */ |
| 215 |
} |
| 216 |
lua_pop(L, 1); /* t */ |
| 217 |
lua_key_rawgeti(nolength); |
| 218 |
if (!lua_isnil(L, -1)) { /* b? t */ |
| 219 |
if (lua_isboolean(L, -1)) /* !b t */ |
| 220 |
nolength = lua_toboolean(L, -1); /* 0 or 1 */ |
| 221 |
} |
| 222 |
lua_pop(L, 1); /* t */ |
| 223 |
|
| 224 |
/* is a reserved object referenced by "objnum"? */ |
| 225 |
|
| 226 |
lua_key_rawgeti(objnum); |
| 227 |
if (!lua_isnil(L, -1)) { /* vi? t */ |
| 228 |
if (lua_type(L,-1) != LUA_TNUMBER) /* !vi t */ |
| 229 |
luaL_error(L, "pdf.obj(): \"objnum\" must be integer"); |
| 230 |
k = (int) lua_tointeger(L, -1); /* vi t */ |
| 231 |
check_obj_type(static_pdf, obj_type_obj, k); |
| 232 |
if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0) |
| 233 |
luaL_error(L, "pdf.obj() object in use"); |
| 234 |
} else { |
| 235 |
static_pdf->obj_count++; |
| 236 |
k = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); |
| 237 |
} |
| 238 |
pdf_last_obj = k; |
| 239 |
if (immediate == 0) { |
| 240 |
obj_data_ptr(static_pdf, k) = pdf_get_mem(static_pdf, pdfmem_obj_size); |
| 241 |
init_obj_obj(static_pdf, k); |
| 242 |
} |
| 243 |
lua_pop(L, 1); /* t */ |
| 244 |
|
| 245 |
/* get optional "attr" (allowed only for stream case) */ |
| 246 |
|
| 247 |
lua_key_rawgeti(attr); |
| 248 |
if (!lua_isnil(L, -1)) { /* attr-s? t */ |
| 249 |
if (! lua_key_eq(type, stream)) |
| 250 |
luaL_error(L, "pdf.obj(): \"attr\" key not allowed for non-stream object"); |
| 251 |
if (!lua_isstring(L, -1)) /* or number */ /* !attr-s t */ |
| 252 |
luaL_error(L, "pdf.obj(): object \"attr\" must be string"); |
| 253 |
if (immediate == 1) { |
| 254 |
attr.s = lua_tolstring(L, -1, &attr.l); /* attr-s t */ |
| 255 |
lua_pop(L, 1); /* t */ |
| 256 |
} else |
| 257 |
obj_obj_stream_attr(static_pdf, k) = luaL_ref(Luas, LUA_REGISTRYINDEX); /* t */ |
| 258 |
} else { |
| 259 |
lua_pop(L, 1); /* t */ |
| 260 |
} |
| 261 |
|
| 262 |
/* get optional "compresslevel" (allowed only for stream case) */ |
| 263 |
|
| 264 |
lua_key_rawgeti(compresslevel); |
| 265 |
if (!lua_isnil(L, -1)) { /* vi? t */ |
| 266 |
if (lua_key_eq(type, raw)) |
| 267 |
luaL_error(L, "pdf.obj(): \"compresslevel\" key not allowed for raw object"); |
| 268 |
if (lua_type(L, -1) != LUA_TNUMBER) /* !vi t */ |
| 269 |
luaL_error(L, "pdf.obj(): \"compresslevel\" must be integer"); |
| 270 |
compress_level = (int) lua_tointeger(L, -1); /* vi t */ |
| 271 |
if (compress_level > 9) |
| 272 |
luaL_error(L, "pdf.obj(): \"compresslevel\" must be <= 9"); |
| 273 |
else if (compress_level < 0) |
| 274 |
luaL_error(L, "pdf.obj(): \"compresslevel\" must be >= 0"); |
| 275 |
if (immediate == 0) |
| 276 |
obj_obj_pdfcompresslevel(static_pdf, k) = compress_level; |
| 277 |
} |
| 278 |
lua_pop(L, 1); /* t */ |
| 279 |
|
| 280 |
/* get optional "objcompression" (allowed only for non-stream case) */ |
| 281 |
|
| 282 |
lua_key_rawgeti(objcompression); |
| 283 |
if (!lua_isnil(L, -1)) { /* b? t */ |
| 284 |
if (lua_key_eq(type, stream)) |
| 285 |
luaL_error(L, "pdf.obj(): \"objcompression\" key not allowed for stream object"); |
| 286 |
if (!lua_isboolean(L, -1)) /* !b t */ |
| 287 |
luaL_error(L, "pdf.obj(): \"objcompression\" must be boolean"); |
| 288 |
obj_compression = lua_toboolean(L, -1); /* 0 or 1 */ |
| 289 |
/* OBJSTM_NEVER: never into object stream; OBJSTM_ALWAYS: depends then on \pdfobjcompresslevel */ |
| 290 |
if (obj_compression > 0) |
| 291 |
os_threshold = OBJSTM_ALWAYS; |
| 292 |
else |
| 293 |
os_threshold = OBJSTM_NEVER; |
| 294 |
if (immediate == 0) |
| 295 |
obj_obj_objstm_threshold(static_pdf, k) = os_threshold; |
| 296 |
} |
| 297 |
lua_pop(L, 1); /* t */ |
| 298 |
|
| 299 |
/* now the object contents for all cases are handled */ |
| 300 |
|
| 301 |
lua_key_rawgeti(string); |
| 302 |
lua_key_rawgeti_n(file,-2); |
| 303 |
|
| 304 |
if (!lua_isnil(L, -1) && !lua_isnil(L, -2)) /* file-s? string-s? t */ |
| 305 |
luaL_error(L, "pdf.obj(): \"string\" and \"file\" must not be given together"); |
| 306 |
if (lua_isnil(L, -1) && lua_isnil(L, -2)) /* nil nil t */ |
| 307 |
luaL_error(L, "pdf.obj(): no \"string\" or \"file\" given"); |
| 308 |
|
| 309 |
if (lua_key_eq(type, raw)) { |
| 310 |
if (immediate == 1) |
| 311 |
pdf_begin_obj(static_pdf, k, os_threshold); |
| 312 |
if (!lua_isnil(L, -2)) { /* file-s? string-s? t */ |
| 313 |
/* from string */ |
| 314 |
lua_pop(L, 1); /* string-s? t */ |
| 315 |
if (!lua_isstring(L, -1)) /* or number */ /* !string-s t */ |
| 316 |
luaL_error(L, "pdf.obj(): \"string\" must be string for raw object"); |
| 317 |
if (immediate == 1) { |
| 318 |
st.s = lua_tolstring(L, -1, &st.l); |
| 319 |
pdf_out_block(static_pdf, st.s, st.l); |
| 320 |
} else |
| 321 |
obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* t */ |
| 322 |
} else { |
| 323 |
/* from file */ |
| 324 |
if (lua_type(L, -1) != LUA_TSTRING) /* !file-s nil t */ |
| 325 |
luaL_error(L, "pdf.obj(): \"file\" name must be string for raw object"); |
| 326 |
if (immediate == 1) { |
| 327 |
st.s = lua_tolstring(L, -1, &st.l); /* file-s nil t */ |
| 328 |
buf.s = fread_to_buf(L, st.s, &buf.l); |
| 329 |
pdf_out_block(static_pdf, (const char *) buf.s, buf.l); |
| 330 |
/* already in pdf_end_obj: |
| 331 |
if (buf.s[buf.l - 1] != '\n') |
| 332 |
pdf_out(static_pdf, '\n'); |
| 333 |
*/ |
| 334 |
xfree(buf.s); |
| 335 |
} else { |
| 336 |
set_obj_obj_is_file(static_pdf, k); |
| 337 |
obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* nil t */ |
| 338 |
} |
| 339 |
} |
| 340 |
if (immediate == 1) |
| 341 |
pdf_end_obj(static_pdf); |
| 342 |
} else { |
| 343 |
if (immediate == 1) { |
| 344 |
pdf_begin_obj(static_pdf, k, OBJSTM_NEVER); /* 0 = not an object stream candidate! */ |
| 345 |
if (nolength && attr.s != NULL) { |
| 346 |
/* we have a direct copy possible with compressed data */ |
| 347 |
pdf_begin_dict(static_pdf); |
| 348 |
pdf_out_block(static_pdf, attr.s, attr.l); |
| 349 |
static_pdf->compress_level = 0; |
| 350 |
static_pdf->stream_deflate = false; |
| 351 |
pdf_end_dict(static_pdf); |
| 352 |
} else { |
| 353 |
pdf_begin_dict(static_pdf); |
| 354 |
if (attr.s != NULL) { |
| 355 |
pdf_check_space(static_pdf); |
| 356 |
pdf_out_block(static_pdf, attr.s, attr.l); |
| 357 |
pdf_set_space(static_pdf); |
| 358 |
} |
| 359 |
if (compress_level > -1) |
| 360 |
static_pdf->compress_level = compress_level; |
| 361 |
pdf_dict_add_streaminfo(static_pdf); |
| 362 |
pdf_end_dict(static_pdf); |
| 363 |
} |
| 364 |
pdf_begin_stream(static_pdf); |
| 365 |
} else { |
| 366 |
set_obj_obj_is_stream(static_pdf, k); |
| 367 |
set_obj_obj_no_length(static_pdf, k); |
| 368 |
if (compress_level > -1) |
| 369 |
obj_obj_pdfcompresslevel(static_pdf, k) = compress_level; |
| 370 |
} |
| 371 |
if (!lua_isnil(L, -2)) { /* file-s? string-s? t */ |
| 372 |
/* from string */ |
| 373 |
lua_pop(L, 1); /* string-s? t */ |
| 374 |
if (!lua_isstring(L, -1)) /* or number */ /* !string-s t */ |
| 375 |
luaL_error(L, "pdf.obj(): \"string\" must be string for stream object"); |
| 376 |
if (immediate == 1) { |
| 377 |
st.s = lua_tolstring(L, -1, &st.l); /* string-s t */ |
| 378 |
pdf_out_block(static_pdf, st.s, st.l); |
| 379 |
} else |
| 380 |
obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* t */ |
| 381 |
} else { |
| 382 |
/* from file */ |
| 383 |
if (lua_type(L, -1) != LUA_TSTRING) /* !file-s nil t */ |
| 384 |
luaL_error(L, "pdf.obj(): \"file\" name must be string for stream object"); |
| 385 |
if (immediate == 1) { |
| 386 |
st.s = lua_tolstring(L, -1, &st.l); /* file-s nil t */ |
| 387 |
buf.s = fread_to_buf(L, st.s, &buf.l); |
| 388 |
pdf_out_block(static_pdf, (const char *) buf.s, buf.l); |
| 389 |
xfree(buf.s); |
| 390 |
} else { |
| 391 |
set_obj_obj_is_file(static_pdf, k); |
| 392 |
obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* nil t */ |
| 393 |
} |
| 394 |
} |
| 395 |
if (immediate == 1) { |
| 396 |
pdf_end_stream(static_pdf); |
| 397 |
pdf_end_obj(static_pdf); |
| 398 |
} |
| 399 |
} |
| 400 |
static_pdf->compress_level = saved_compress_level; |
| 401 |
return k; |
| 402 |
} |
| 403 |
|
| 404 |
static int orig_obj(lua_State * L) |
| 405 |
{ |
| 406 |
int n, first_arg = 1; |
| 407 |
int k; |
| 408 |
const char *st_s = NULL ; |
| 409 |
n = lua_gettop(L); |
| 410 |
if ((n > 0) && (lua_type(L, 1) == LUA_TNUMBER)) { |
| 411 |
first_arg++; |
| 412 |
k = (int) lua_tointeger(L, 1); |
| 413 |
check_obj_type(static_pdf, obj_type_obj, k); |
| 414 |
if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0) |
| 415 |
luaL_error(L, "pdf.obj() object in use"); |
| 416 |
} else { |
| 417 |
static_pdf->obj_count++; |
| 418 |
k = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); |
| 419 |
} |
| 420 |
pdf_last_obj = k; |
| 421 |
obj_data_ptr(static_pdf, k) = pdf_get_mem(static_pdf, pdfmem_obj_size); |
| 422 |
init_obj_obj(static_pdf, k); |
| 423 |
switch (n - first_arg + 1) { |
| 424 |
case 0: |
| 425 |
luaL_error(L, "pdf.obj() needs at least one argument"); |
| 426 |
break; |
| 427 |
case 1: |
| 428 |
if (!lua_isstring(L, first_arg)) /* or number */ |
| 429 |
luaL_error(L, "pdf.obj() 1st argument must be string"); |
| 430 |
break; |
| 431 |
case 2: |
| 432 |
case 3: |
| 433 |
if (lua_type(L, first_arg) != LUA_TSTRING) |
| 434 |
luaL_error(L, "pdf.obj() 1st argument must be string"); |
| 435 |
if (!lua_isstring(L, first_arg + 1)) /* or number */ |
| 436 |
luaL_error(L, "pdf.obj() 2nd argument must be string"); |
| 437 |
st_s = lua_tostring(L, first_arg); |
| 438 |
if (lua_key_eq(st_s, file)) { |
| 439 |
if (n == first_arg + 2) |
| 440 |
luaL_error(L, "pdf.obj() 3rd argument forbidden in file mode"); |
| 441 |
set_obj_obj_is_file(static_pdf, k); |
| 442 |
} else { |
| 443 |
if (n == first_arg + 2) { /* write attr text */ |
| 444 |
if (!lua_isstring(L, -1)) /* or number */ |
| 445 |
luaL_error(L, "pdf.obj() 3rd argument must be string"); |
| 446 |
obj_obj_stream_attr(static_pdf, k) = |
| 447 |
luaL_ref(Luas, LUA_REGISTRYINDEX); |
| 448 |
} |
| 449 |
if (lua_key_eq(st_s, stream)) { |
| 450 |
set_obj_obj_is_stream(static_pdf, k); |
| 451 |
} else if (lua_key_eq(st_s, streamfile)) { |
| 452 |
set_obj_obj_is_stream(static_pdf, k); |
| 453 |
set_obj_obj_is_file(static_pdf, k); |
| 454 |
} else |
| 455 |
luaL_error(L, "pdf.obj() invalid argument"); |
| 456 |
} |
| 457 |
break; |
| 458 |
default: |
| 459 |
luaL_error(L, "pdf.obj() allows max. 3 arguments"); |
| 460 |
} |
| 461 |
obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); |
| 462 |
return k; |
| 463 |
} |
| 464 |
|
| 465 |
static int l_obj(lua_State * L) |
| 466 |
{ |
| 467 |
int k, n; |
| 468 |
ensure_output_state(static_pdf, ST_HEADER_WRITTEN); |
| 469 |
n = lua_gettop(L); |
| 470 |
if (n == 1 && lua_istable(L, 1)) |
| 471 |
k = table_obj(L); /* new */ |
| 472 |
else |
| 473 |
k = orig_obj(L); |
| 474 |
lua_pushinteger(L, k); |
| 475 |
return 1; |
| 476 |
} |
| 477 |
|
| 478 |
static int l_refobj(lua_State * L) |
| 479 |
{ |
| 480 |
int k, n; |
| 481 |
n = lua_gettop(L); |
| 482 |
if (n != 1) |
| 483 |
luaL_error(L, "pdf.refobj() needs exactly 1 argument"); |
| 484 |
k = (int) luaL_checkinteger(L, 1); |
| 485 |
if (global_shipping_mode == NOT_SHIPPING) |
| 486 |
scan_refobj_lua(static_pdf, k); |
| 487 |
else |
| 488 |
pdf_ref_obj_lua(static_pdf, k); |
| 489 |
return 0; |
| 490 |
} |
| 491 |
|
| 492 |
static int l_reserveobj(lua_State * L) |
| 493 |
{ |
| 494 |
int n; |
| 495 |
const char *st_s = NULL; |
| 496 |
n = lua_gettop(L); |
| 497 |
switch (n) { |
| 498 |
case 0: |
| 499 |
static_pdf->obj_count++; |
| 500 |
pdf_last_obj = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); |
| 501 |
break; |
| 502 |
case 1: |
| 503 |
if (lua_type(L, -1) != LUA_TSTRING) |
| 504 |
luaL_error(L, "pdf.reserveobj() optional argument must be string"); |
| 505 |
st_s = luaL_checkstring(L, 1); |
| 506 |
if (lua_key_eq(st_s, annot)) { |
| 507 |
pdf_last_annot = pdf_create_obj(static_pdf, obj_type_annot, 0); |
| 508 |
} else { |
| 509 |
luaL_error(L, "pdf.reserveobj() optional string must be \"annot\""); |
| 510 |
} |
| 511 |
lua_pop(L, 1); |
| 512 |
break; |
| 513 |
default: |
| 514 |
luaL_error(L, "pdf.reserveobj() allows max. 1 argument"); |
| 515 |
} |
| 516 |
lua_pushinteger(L, static_pdf->obj_ptr); |
| 517 |
return 1; |
| 518 |
} |
| 519 |
|
| 520 |
static int l_registerannot(lua_State * L) |
| 521 |
{ |
| 522 |
int n, i; |
| 523 |
n = lua_gettop(L); |
| 524 |
switch (n) { |
| 525 |
case 1: |
| 526 |
if (global_shipping_mode == NOT_SHIPPING) |
| 527 |
luaL_error(L, "pdf.registerannot() can only be used in late lua"); |
| 528 |
i = (int) luaL_checkinteger(L, 1); |
| 529 |
if (i <= 0) |
| 530 |
luaL_error(L, "pdf.registerannot() can only register positive object numbers"); |
| 531 |
addto_page_resources(static_pdf, obj_type_annot, i); |
| 532 |
break; |
| 533 |
default: |
| 534 |
luaL_error(L, "pdf.registerannot() needs exactly 1 argument"); |
| 535 |
} |
| 536 |
return 0; |
| 537 |
} |
| 538 |
|
| 539 |
/* |
| 540 |
|
| 541 |
# define valid_pdf_key ( \ |
| 542 |
lua_key_eq(s,pageresources) \ |
| 543 |
lua_key_eq(s,pageattributes) || \ |
| 544 |
lua_key_eq(s,pagesattributes) || \ |
| 545 |
lua_key_eq(s,catalog) || \ |
| 546 |
lua_key_eq(s,info) || \ |
| 547 |
lua_key_eq(s,names) || \ |
| 548 |
lua_key_eq(s,trailer) || \ |
| 549 |
lua_key_eq(s,xformresources) || \ |
| 550 |
lua_key_eq(s,xformattributes) || \ |
| 551 |
lua_key_eq(s,trailerid) \ |
| 552 |
) |
| 553 |
|
| 554 |
*/ |
| 555 |
|
| 556 |
#define l_get_pdf_value(key) \ |
| 557 |
lua_get_metatablelua(pdf_data); \ |
| 558 |
lua_key_rawgeti(key); \ |
| 559 |
return 1; |
| 560 |
|
| 561 |
static int l_get_pageresources (lua_State * L) { l_get_pdf_value(pageresources); } |
| 562 |
static int l_get_pageattributes (lua_State * L) { l_get_pdf_value(pageattributes); } |
| 563 |
static int l_get_pagesattributes(lua_State * L) { l_get_pdf_value(pagesattributes); } |
| 564 |
static int l_get_catalog (lua_State * L) { l_get_pdf_value(catalog); } |
| 565 |
static int l_get_info (lua_State * L) { l_get_pdf_value(info); } |
| 566 |
static int l_get_names (lua_State * L) { l_get_pdf_value(names); } |
| 567 |
static int l_get_trailer (lua_State * L) { l_get_pdf_value(trailer); } |
| 568 |
static int l_get_xformresources (lua_State * L) { l_get_pdf_value(xformresources); } |
| 569 |
static int l_get_xformattributes(lua_State * L) { l_get_pdf_value(xformattributes); } |
| 570 |
static int l_get_trailerid (lua_State * L) { l_get_pdf_value(trailerid); } |
| 571 |
|
| 572 |
/* |
| 573 |
|
| 574 |
static int getpdf(lua_State * L) |
| 575 |
{ |
| 576 |
const char *s ; |
| 577 |
if (lua_gettop(L) != 2) { |
| 578 |
return 0; |
| 579 |
} |
| 580 |
if (lua_type(L,-1) == LUA_TSTRING) { |
| 581 |
s = lua_tostring(L, -1); |
| 582 |
if (lua_key_eq(s,h)) { |
| 583 |
lua_pushinteger(L, static_pdf->posstruct->pos.h); |
| 584 |
return 1; |
| 585 |
} else if (lua_key_eq(s,v)) { |
| 586 |
lua_pushinteger(L, static_pdf->posstruct->pos.v); |
| 587 |
return 1; |
| 588 |
} else if (valid_pdf_key) { |
| 589 |
lua_get_metatablelua(pdf_data); |
| 590 |
lua_replace(L, -3); |
| 591 |
lua_rawget(L, -2); |
| 592 |
return 1; |
| 593 |
} |
| 594 |
} |
| 595 |
return 0; |
| 596 |
} |
| 597 |
*/ |
| 598 |
|
| 599 |
#define l_set_pdf_value(key) \ |
| 600 |
if (lua_type(L,-1) == LUA_TSTRING) { \ |
| 601 |
lua_get_metatablelua(pdf_data); \ |
| 602 |
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(key)); \ |
| 603 |
lua_pushvalue(L, -3); \ |
| 604 |
lua_rawset(L,-3); \ |
| 605 |
} \ |
| 606 |
return 0; |
| 607 |
|
| 608 |
static int l_set_pageresources (lua_State * L) { l_set_pdf_value(pageresources); } |
| 609 |
static int l_set_pageattributes (lua_State * L) { l_set_pdf_value(pageattributes); } |
| 610 |
static int l_set_pagesattributes(lua_State * L) { l_set_pdf_value(pagesattributes); } |
| 611 |
static int l_set_catalog (lua_State * L) { l_set_pdf_value(catalog); } |
| 612 |
static int l_set_info (lua_State * L) { l_set_pdf_value(info); } |
| 613 |
static int l_set_names (lua_State * L) { l_set_pdf_value(names); } |
| 614 |
static int l_set_trailer (lua_State * L) { l_set_pdf_value(trailer); } |
| 615 |
static int l_set_xformresources (lua_State * L) { l_set_pdf_value(xformresources); } |
| 616 |
static int l_set_xformattributes(lua_State * L) { l_set_pdf_value(xformattributes); } |
| 617 |
static int l_set_trailerid (lua_State * L) { l_set_pdf_value(trailerid); } |
| 618 |
|
| 619 |
static int getpdfobjtype(lua_State * L) |
| 620 |
{ |
| 621 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 622 |
int n = (int) lua_tointeger(L, 1); |
| 623 |
if (n > 0 && n <= static_pdf->obj_ptr) { |
| 624 |
lua_pushstring(L, pdf_obj_typenames[obj_type(static_pdf, n)]); |
| 625 |
return 1; |
| 626 |
} |
| 627 |
} |
| 628 |
lua_pushnil(L); |
| 629 |
return 1; |
| 630 |
} |
| 631 |
|
| 632 |
static int getpdfmaxobjnum(lua_State * L) |
| 633 |
{ |
| 634 |
lua_pushinteger(L, static_pdf->obj_ptr); |
| 635 |
return 1; |
| 636 |
} |
| 637 |
|
| 638 |
static int l_mapfile(lua_State * L) |
| 639 |
{ |
| 640 |
const char *st; |
| 641 |
if ((lua_type(L, 1) == LUA_TSTRING) && (st = lua_tostring(L, 1)) != NULL) { |
| 642 |
char *s = xstrdup(st); |
| 643 |
process_map_item(s, MAPFILE); |
| 644 |
free(s); |
| 645 |
} |
| 646 |
return 0; |
| 647 |
} |
| 648 |
|
| 649 |
static int l_mapline(lua_State * L) |
| 650 |
{ |
| 651 |
const char *st; |
| 652 |
if ((lua_type(L, 1) == LUA_TSTRING) && (st = lua_tostring(L, 1)) != NULL) { |
| 653 |
char *s = xstrdup(st); |
| 654 |
process_map_item(s, MAPLINE); |
| 655 |
free(s); |
| 656 |
} |
| 657 |
return 0; |
| 658 |
} |
| 659 |
|
| 660 |
static int l_getpos(lua_State * L) |
| 661 |
{ |
| 662 |
lua_pushinteger(L, static_pdf->posstruct->pos.h); |
| 663 |
lua_pushinteger(L, static_pdf->posstruct->pos.v); |
| 664 |
return 2; |
| 665 |
} |
| 666 |
|
| 667 |
static int l_gethpos(lua_State * L) |
| 668 |
{ |
| 669 |
lua_pushinteger(L, static_pdf->posstruct->pos.h); |
| 670 |
return 1; |
| 671 |
} |
| 672 |
|
| 673 |
static int l_getvpos(lua_State * L) |
| 674 |
{ |
| 675 |
lua_pushinteger(L, static_pdf->posstruct->pos.v); |
| 676 |
return 1; |
| 677 |
} |
| 678 |
|
| 679 |
static int l_getmatrix(lua_State * L) |
| 680 |
{ |
| 681 |
if (matrix_stack_used > 0) { |
| 682 |
matrix_entry *m = &matrix_stack[matrix_stack_used - 1]; |
| 683 |
lua_pushnumber(L, m->a); |
| 684 |
lua_pushnumber(L, m->b); |
| 685 |
lua_pushnumber(L, m->c); |
| 686 |
lua_pushnumber(L, m->d); |
| 687 |
lua_pushnumber(L, m->e); |
| 688 |
lua_pushnumber(L, m->f); |
| 689 |
} else { |
| 690 |
lua_pushinteger(L, 1); |
| 691 |
lua_pushinteger(L, 0); |
| 692 |
lua_pushinteger(L, 0); |
| 693 |
lua_pushinteger(L, 1); |
| 694 |
lua_pushinteger(L, 0); |
| 695 |
lua_pushinteger(L, 0); |
| 696 |
} |
| 697 |
return 6 ; |
| 698 |
} |
| 699 |
|
| 700 |
static int l_hasmatrix(lua_State * L) |
| 701 |
{ |
| 702 |
lua_pushboolean(L, (matrix_stack_used > 0)); |
| 703 |
return 1 ; |
| 704 |
} |
| 705 |
|
| 706 |
static int l_get_lastlink(lua_State * L) |
| 707 |
{ |
| 708 |
lua_pushinteger(L, (pdf_last_link)); |
| 709 |
return 1 ; |
| 710 |
} |
| 711 |
|
| 712 |
static int l_get_retval(lua_State * L) |
| 713 |
{ |
| 714 |
lua_pushinteger(L, (pdf_retval)); |
| 715 |
return 1 ; |
| 716 |
} |
| 717 |
|
| 718 |
static int l_get_lastobj(lua_State * L) |
| 719 |
{ |
| 720 |
lua_pushinteger(L, (pdf_last_obj)); |
| 721 |
return 1 ; |
| 722 |
} |
| 723 |
|
| 724 |
static int l_get_lastannot(lua_State * L) |
| 725 |
{ |
| 726 |
lua_pushinteger(L, (pdf_last_annot)); |
| 727 |
return 1 ; |
| 728 |
} |
| 729 |
|
| 730 |
/* maybe: |
| 731 |
|
| 732 |
get_fontname : set_ff(i) obj_info(static_pdf, pdf_font_num(ff)) |
| 733 |
get_fontobjnum : set_ff(i) pdf_font_num(ff) |
| 734 |
get_fontsize : font_size(i) |
| 735 |
get_xformname : obj_info(static_pdf, i) |
| 736 |
|
| 737 |
*/ |
| 738 |
|
| 739 |
static int l_get_compress_level(lua_State * L) |
| 740 |
{ |
| 741 |
lua_pushinteger(L, (pdf_compress_level)); |
| 742 |
return 1 ; |
| 743 |
} |
| 744 |
|
| 745 |
static int l_get_obj_compress_level(lua_State * L) |
| 746 |
{ |
| 747 |
lua_pushinteger(L, (pdf_obj_compress_level)); |
| 748 |
return 1 ; |
| 749 |
} |
| 750 |
|
| 751 |
static int l_get_recompress(lua_State * L) |
| 752 |
{ |
| 753 |
lua_pushinteger(L, (pdf_recompress)); |
| 754 |
return 1 ; |
| 755 |
} |
| 756 |
|
| 757 |
static int l_set_compress_level(lua_State * L) |
| 758 |
{ |
| 759 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 760 |
int c = (int) lua_tointeger(L, 1); |
| 761 |
if (c<0) |
| 762 |
c = 0 ; |
| 763 |
else if (c>9) |
| 764 |
c = 9 ; |
| 765 |
set_pdf_compress_level(c); |
| 766 |
} |
| 767 |
return 0 ; |
| 768 |
} |
| 769 |
|
| 770 |
static int l_set_obj_compress_level(lua_State * L) |
| 771 |
{ |
| 772 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 773 |
int c = (int) lua_tointeger(L, 1); |
| 774 |
if (c<0) |
| 775 |
c = 0 ; |
| 776 |
else if (c>9) |
| 777 |
c = 9 ; |
| 778 |
set_pdf_obj_compress_level(c); |
| 779 |
} |
| 780 |
return 0 ; |
| 781 |
} |
| 782 |
|
| 783 |
static int l_set_recompress(lua_State * L) |
| 784 |
{ |
| 785 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 786 |
int c = (int) lua_tointeger(L, 1); |
| 787 |
if (c<0) |
| 788 |
c = 0 ; |
| 789 |
else if (c>9) |
| 790 |
c = 9 ; |
| 791 |
set_pdf_recompress(c); |
| 792 |
} |
| 793 |
return 0 ; |
| 794 |
} |
| 795 |
|
| 796 |
/* fonts */ |
| 797 |
|
| 798 |
static int getpdfgentounicode(lua_State * L) |
| 799 |
{ |
| 800 |
lua_pushinteger(L, (pdf_gen_tounicode)); |
| 801 |
return 1 ; |
| 802 |
} |
| 803 |
|
| 804 |
static int getpdfomitcidset(lua_State * L) |
| 805 |
{ |
| 806 |
lua_pushinteger(L, (pdf_omit_cidset)); |
| 807 |
return 1 ; |
| 808 |
} |
| 809 |
|
| 810 |
static int getpdfomitcharset(lua_State * L) |
| 811 |
{ |
| 812 |
lua_pushinteger(L, (pdf_omit_charset)); |
| 813 |
return 1 ; |
| 814 |
} |
| 815 |
|
| 816 |
static int getpdfomitinfodict(lua_State * L) |
| 817 |
{ |
| 818 |
lua_pushinteger(L, (pdf_omit_infodict)); |
| 819 |
return 1 ; |
| 820 |
} |
| 821 |
|
| 822 |
static int getpdfomitmediabox(lua_State * L) |
| 823 |
{ |
| 824 |
lua_pushinteger(L, (pdf_omit_mediabox)); |
| 825 |
return 1 ; |
| 826 |
} |
| 827 |
|
| 828 |
static int getpdfomitprocset(lua_State * L) |
| 829 |
{ |
| 830 |
lua_pushinteger(L, (pdf_omit_procset)); |
| 831 |
return 1 ; |
| 832 |
} |
| 833 |
|
| 834 |
static int getpdfptexprefix(lua_State * L) |
| 835 |
{ |
| 836 |
lua_pushinteger(L, (pdf_ptex_prefix)); |
| 837 |
return 1 ; |
| 838 |
} |
| 839 |
|
| 840 |
static int setpdfgentounicode(lua_State * L) |
| 841 |
{ |
| 842 |
/* ensures that glyph_unicode_tree is not null */ |
| 843 |
glyph_unicode_new(); |
| 844 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 845 |
set_pdf_gen_tounicode(lua_tointeger(L, 1)); |
| 846 |
} |
| 847 |
return 0 ; |
| 848 |
} |
| 849 |
|
| 850 |
static int setpdfomitcidset(lua_State * L) |
| 851 |
{ |
| 852 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 853 |
set_pdf_omit_cidset(lua_tointeger(L, 1)); |
| 854 |
} |
| 855 |
return 0 ; |
| 856 |
} |
| 857 |
|
| 858 |
static int setpdfomitcharset(lua_State * L) |
| 859 |
{ |
| 860 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 861 |
set_pdf_omit_charset(lua_tointeger(L, 1)); |
| 862 |
} |
| 863 |
return 0 ; |
| 864 |
} |
| 865 |
|
| 866 |
static int setpdfomitinfodict(lua_State * L) |
| 867 |
{ |
| 868 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 869 |
set_pdf_omit_infodict(lua_tointeger(L, 1)); |
| 870 |
} |
| 871 |
return 0 ; |
| 872 |
} |
| 873 |
|
| 874 |
static int setpdfomitmediabox(lua_State * L) |
| 875 |
{ |
| 876 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 877 |
set_pdf_omit_mediabox(lua_tointeger(L, 1)); |
| 878 |
} |
| 879 |
return 0 ; |
| 880 |
} |
| 881 |
|
| 882 |
static int setpdfomitprocset(lua_State * L) |
| 883 |
{ |
| 884 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 885 |
set_pdf_omit_procset(lua_tointeger(L, 1)); |
| 886 |
} |
| 887 |
return 0 ; |
| 888 |
} |
| 889 |
|
| 890 |
static int setpdfptexprefix(lua_State * L) |
| 891 |
{ |
| 892 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 893 |
set_pdf_ptex_prefix(lua_tointeger(L, 1)); |
| 894 |
} |
| 895 |
return 0 ; |
| 896 |
} |
| 897 |
|
| 898 |
/* for tracing purposes when no pages are flushed */ |
| 899 |
|
| 900 |
static int setforcefile(lua_State * L) |
| 901 |
{ |
| 902 |
if (lua_type(L, 1) == LUA_TBOOLEAN) { |
| 903 |
static_pdf->force_file = lua_toboolean(L,1); |
| 904 |
} else { |
| 905 |
static_pdf->force_file = 0; |
| 906 |
} |
| 907 |
return 0 ; |
| 908 |
} |
| 909 |
|
| 910 |
/* accuracy */ |
| 911 |
|
| 912 |
static int l_get_decimal_digits(lua_State * L) |
| 913 |
{ |
| 914 |
lua_pushinteger(L, (pdf_decimal_digits)); |
| 915 |
return 1 ; |
| 916 |
} |
| 917 |
|
| 918 |
static int l_set_decimal_digits(lua_State * L) |
| 919 |
{ |
| 920 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 921 |
int c = (int) lua_tointeger(L, 1); |
| 922 |
if (c<0) { |
| 923 |
c = 0 ; |
| 924 |
} |
| 925 |
set_pdf_decimal_digits(c); |
| 926 |
} |
| 927 |
return 0 ; |
| 928 |
} |
| 929 |
|
| 930 |
/* pk */ |
| 931 |
|
| 932 |
static int l_get_pk_resolution(lua_State * L) |
| 933 |
{ |
| 934 |
lua_pushinteger(L, (pdf_pk_resolution)); |
| 935 |
lua_pushinteger(L, (pdf_pk_fixed_dpi)); |
| 936 |
return 2 ; |
| 937 |
} |
| 938 |
|
| 939 |
static int l_set_pk_resolution(lua_State * L) |
| 940 |
{ |
| 941 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 942 |
int c = (int) lua_tointeger(L, 1); |
| 943 |
if (c < 72) { |
| 944 |
c = 72 ; |
| 945 |
} else if (c > 8000) { |
| 946 |
c = 8000 ; |
| 947 |
} |
| 948 |
set_pdf_pk_resolution(c); |
| 949 |
} |
| 950 |
if (lua_type(L, 2) == LUA_TNUMBER) { |
| 951 |
set_pdf_pk_fixed_dpi(lua_tointeger(L, 1)); |
| 952 |
} |
| 953 |
return 0 ; |
| 954 |
} |
| 955 |
|
| 956 |
/* pdf stuff */ |
| 957 |
|
| 958 |
static int getpdffontname(lua_State * L) |
| 959 |
{ |
| 960 |
int c, ff ; |
| 961 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 962 |
c = (int) lua_tointeger(L, 1); |
| 963 |
/* pdf_check_vf(c); */ |
| 964 |
if (!font_used(c)) { |
| 965 |
pdf_init_font(static_pdf,c); |
| 966 |
} |
| 967 |
set_ff(c); |
| 968 |
lua_pushinteger(L, (obj_info(static_pdf, pdf_font_num(ff)))); |
| 969 |
} else { |
| 970 |
lua_pushnil(L); |
| 971 |
} |
| 972 |
return 1 ; |
| 973 |
} |
| 974 |
|
| 975 |
static int getpdffontobjnum(lua_State * L) |
| 976 |
{ |
| 977 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 978 |
int ff; |
| 979 |
int c = (int) lua_tointeger(L, 1); |
| 980 |
/* pdf_check_vf(c); */ |
| 981 |
if (!font_used(c)) { |
| 982 |
pdf_init_font(static_pdf,c); |
| 983 |
} |
| 984 |
set_ff(c); |
| 985 |
lua_pushinteger(L, (pdf_font_num(ff))); |
| 986 |
} else { |
| 987 |
lua_pushnil(L); |
| 988 |
} |
| 989 |
return 1 ; |
| 990 |
} |
| 991 |
|
| 992 |
static int getpdffontsize(lua_State * L) |
| 993 |
{ |
| 994 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 995 |
int c = (int) lua_tointeger(L, 1); |
| 996 |
lua_pushinteger(L, (font_size(c))); |
| 997 |
} else { |
| 998 |
lua_pushnil(L); |
| 999 |
} |
| 1000 |
return 1 ; |
| 1001 |
} |
| 1002 |
|
| 1003 |
static int getpdfpageref(lua_State * L) |
| 1004 |
{ |
| 1005 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1006 |
int c = (int) lua_tointeger(L, 1); |
| 1007 |
if (c > 0) { |
| 1008 |
lua_pushinteger(L, (pdf_get_obj(static_pdf, obj_type_page, c, false))); |
| 1009 |
return 1; |
| 1010 |
} |
| 1011 |
} |
| 1012 |
lua_pushnil(L); |
| 1013 |
return 1 ; |
| 1014 |
} |
| 1015 |
|
| 1016 |
static int getpdfxformname(lua_State * L) |
| 1017 |
{ |
| 1018 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1019 |
int c = (int) lua_tointeger(L, 1); |
| 1020 |
check_obj_type(static_pdf, obj_type_xform, c); |
| 1021 |
lua_pushinteger(L, (obj_info(static_pdf, c))); |
| 1022 |
} else { |
| 1023 |
lua_pushnil(L); |
| 1024 |
} |
| 1025 |
return 1 ; |
| 1026 |
} |
| 1027 |
|
| 1028 |
static int getpdfcreationdate(lua_State * L) |
| 1029 |
{ |
| 1030 |
initialize_start_time(static_pdf); |
| 1031 |
lua_pushstring(L,static_pdf->start_time_str); |
| 1032 |
return 1 ; |
| 1033 |
} |
| 1034 |
|
| 1035 |
static int getpdfmajorversion(lua_State * L) |
| 1036 |
{ |
| 1037 |
/* lua_pushinteger(L,static_pdf->major_version); */ |
| 1038 |
lua_pushinteger(L,pdf_major_version); |
| 1039 |
return 1 ; |
| 1040 |
} |
| 1041 |
|
| 1042 |
static int setpdfmajorversion(lua_State * L) |
| 1043 |
{ |
| 1044 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1045 |
int c = (int) lua_tointeger(L, 1); |
| 1046 |
if ((c >= 1) && (c <= 2)) { |
| 1047 |
static_pdf->major_version = c; |
| 1048 |
set_pdf_major_version(c); |
| 1049 |
} |
| 1050 |
} |
| 1051 |
return 0 ; |
| 1052 |
} |
| 1053 |
|
| 1054 |
static int getpdfminorversion(lua_State * L) |
| 1055 |
{ |
| 1056 |
/* lua_pushinteger(L,static_pdf->minor_version); */ |
| 1057 |
lua_pushinteger(L,pdf_minor_version); |
| 1058 |
return 1 ; |
| 1059 |
} |
| 1060 |
|
| 1061 |
static int setpdfminorversion(lua_State * L) |
| 1062 |
{ |
| 1063 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1064 |
int c = (int) lua_tointeger(L, 1); |
| 1065 |
if ((c >= 0) && (c <= 9)) { |
| 1066 |
static_pdf->minor_version = c; |
| 1067 |
set_pdf_minor_version(c); |
| 1068 |
} |
| 1069 |
} |
| 1070 |
return 0 ; |
| 1071 |
} |
| 1072 |
|
| 1073 |
static int setpdforigin(lua_State * L) |
| 1074 |
{ |
| 1075 |
int h = 0 ; |
| 1076 |
int v = 0 ; |
| 1077 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1078 |
h = (int) lua_roundnumber(L, 1); |
| 1079 |
if (lua_type(L, 2) == LUA_TNUMBER) { |
| 1080 |
v = (int) lua_roundnumber(L, 2); |
| 1081 |
} else { |
| 1082 |
v = h; |
| 1083 |
} |
| 1084 |
} |
| 1085 |
set_tex_extension_dimen_register(d_pdf_h_origin,h); |
| 1086 |
set_tex_extension_dimen_register(d_pdf_v_origin,v); |
| 1087 |
return 0 ; |
| 1088 |
} |
| 1089 |
|
| 1090 |
static int getpdforigin(lua_State * L) |
| 1091 |
{ |
| 1092 |
lua_pushinteger(L,get_tex_extension_dimen_register(d_pdf_h_origin)); |
| 1093 |
lua_pushinteger(L,get_tex_extension_dimen_register(d_pdf_v_origin)); |
| 1094 |
return 2 ; |
| 1095 |
} |
| 1096 |
|
| 1097 |
static int setpdfimageresolution(lua_State * L) |
| 1098 |
{ |
| 1099 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1100 |
set_tex_extension_count_register(c_pdf_image_resolution,lua_tointeger(L, 1)); |
| 1101 |
} |
| 1102 |
return 0; |
| 1103 |
} |
| 1104 |
|
| 1105 |
static int getpdfimageresolution(lua_State * L) |
| 1106 |
{ |
| 1107 |
lua_pushinteger(L,get_tex_extension_count_register(c_pdf_image_resolution)); |
| 1108 |
return 1 ; |
| 1109 |
} |
| 1110 |
|
| 1111 |
static int setpdfthreadmargin(lua_State * L) { |
| 1112 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1113 |
set_tex_extension_dimen_register(d_pdf_thread_margin,lua_roundnumber(L, 1)); |
| 1114 |
} |
| 1115 |
return 0; |
| 1116 |
} |
| 1117 |
|
| 1118 |
static int setpdfdestmargin(lua_State * L) { |
| 1119 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1120 |
set_tex_extension_dimen_register(d_pdf_dest_margin,lua_roundnumber(L, 1)); |
| 1121 |
} |
| 1122 |
return 0; |
| 1123 |
} |
| 1124 |
|
| 1125 |
static int setpdflinkmargin(lua_State * L) { |
| 1126 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1127 |
set_tex_extension_dimen_register(d_pdf_link_margin,lua_roundnumber(L, 1)); |
| 1128 |
} |
| 1129 |
return 0; |
| 1130 |
} |
| 1131 |
|
| 1132 |
static int setpdfxformmargin(lua_State * L) { |
| 1133 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1134 |
set_tex_extension_dimen_register(d_pdf_xform_margin,lua_roundnumber(L, 1)); |
| 1135 |
} |
| 1136 |
return 0; |
| 1137 |
} |
| 1138 |
|
| 1139 |
static int getpdfthreadmargin(lua_State * L) { |
| 1140 |
lua_pushinteger(L,get_tex_extension_dimen_register(d_pdf_thread_margin)); |
| 1141 |
return 1; |
| 1142 |
} |
| 1143 |
|
| 1144 |
static int getpdfdestmargin(lua_State * L) { |
| 1145 |
lua_pushinteger(L,get_tex_extension_dimen_register(d_pdf_dest_margin)); |
| 1146 |
return 1; |
| 1147 |
} |
| 1148 |
|
| 1149 |
static int getpdflinkmargin(lua_State * L) { |
| 1150 |
lua_pushinteger(L,get_tex_extension_dimen_register(d_pdf_link_margin)); |
| 1151 |
return 1; |
| 1152 |
} |
| 1153 |
|
| 1154 |
static int getpdfxformmargin(lua_State * L) { |
| 1155 |
lua_pushinteger(L,get_tex_extension_dimen_register(d_pdf_xform_margin)); |
| 1156 |
return 1; |
| 1157 |
} |
| 1158 |
|
| 1159 |
static int setpdfinclusionerrorlevel(lua_State * L) { |
| 1160 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1161 |
set_tex_extension_count_register(c_pdf_inclusion_errorlevel,lua_tointeger(L, 1)); |
| 1162 |
} |
| 1163 |
return 0; |
| 1164 |
} |
| 1165 |
|
| 1166 |
static int setpdfignoreunknownimages(lua_State * L) { |
| 1167 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1168 |
set_tex_extension_count_register(c_pdf_ignore_unknown_images,lua_tointeger(L, 1)); |
| 1169 |
} |
| 1170 |
return 0; |
| 1171 |
} |
| 1172 |
|
| 1173 |
static int getpdfinclusionerrorlevel(lua_State * L) { |
| 1174 |
lua_pushinteger(L,get_tex_extension_count_register(c_pdf_inclusion_errorlevel)); |
| 1175 |
return 1; |
| 1176 |
} |
| 1177 |
|
| 1178 |
static int getpdfignoreunknownimages(lua_State * L) { |
| 1179 |
lua_pushinteger(L,get_tex_extension_count_register(c_pdf_ignore_unknown_images)); |
| 1180 |
return 1; |
| 1181 |
} |
| 1182 |
|
| 1183 |
static int l_set_suppress_optional_info(lua_State * L) { |
| 1184 |
if (lua_type(L, 1) == LUA_TNUMBER) { |
| 1185 |
set_tex_extension_count_register(c_pdf_suppress_optional_info,lua_tointeger(L, 1)); |
| 1186 |
} |
| 1187 |
return 0; |
| 1188 |
} |
| 1189 |
|
| 1190 |
static int l_get_suppress_optional_info(lua_State * L) { |
| 1191 |
lua_pushinteger(L,get_tex_extension_count_register(c_pdf_suppress_optional_info)); |
| 1192 |
return 1; |
| 1193 |
} |
| 1194 |
|
| 1195 |
static int newpdfcolorstack(lua_State * L) |
| 1196 |
{ |
| 1197 |
const char *s = NULL; |
| 1198 |
const char *l = NULL; |
| 1199 |
int literal_mode = 0; /* set_origin */ |
| 1200 |
boolean page_start = false; |
| 1201 |
int id ; |
| 1202 |
if (lua_type(L,1) != LUA_TSTRING) { |
| 1203 |
luaL_error(L, "pdf.newcolorstack() expects a string as first argument"); |
| 1204 |
} |
| 1205 |
s = lua_tostring(L, 1); |
| 1206 |
if (lua_type(L,2) == LUA_TSTRING) { |
| 1207 |
l = lua_tostring(L, 2); |
| 1208 |
if (lua_key_eq(l,origin)) { |
| 1209 |
literal_mode = set_origin; |
| 1210 |
} else if (lua_key_eq(l,page)) { |
| 1211 |
literal_mode = direct_page; |
| 1212 |
} else if (lua_key_eq(l,text)) { |
| 1213 |
literal_mode = direct_text; |
| 1214 |
} else if (lua_key_eq(l,direct)) { |
| 1215 |
literal_mode = direct_always; |
| 1216 |
} else if (lua_key_eq(l,raw)) { |
| 1217 |
literal_mode = direct_raw; |
| 1218 |
} else { |
| 1219 |
luaL_error(L, "invalid literal mode in pdf.newcolorstack()"); |
| 1220 |
} |
| 1221 |
} |
| 1222 |
if (lua_isboolean(L, 3)) { |
| 1223 |
page_start = lua_toboolean(L, 3); |
| 1224 |
} |
| 1225 |
id = newcolorstack(s, literal_mode, page_start); |
| 1226 |
lua_pushinteger(L, id); |
| 1227 |
return 1 ; |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
static int l_set_font_attributes(lua_State * L) |
| 1232 |
{ |
| 1233 |
int f = luaL_checkinteger(L, -2); |
| 1234 |
int i ; |
| 1235 |
/*char *s;*/ |
| 1236 |
const char *st; |
| 1237 |
if ((lua_type(L,-1) == LUA_TSTRING) && (st = lua_tostring(L, -1)) != NULL) { |
| 1238 |
/* is this dup needed? */ |
| 1239 |
/*s = xstrdup(st);*/ |
| 1240 |
i = maketexstring(st); /* brrr */ |
| 1241 |
set_pdf_font_attr(f, i); |
| 1242 |
/*free(s);*/ |
| 1243 |
} |
| 1244 |
return 0; |
| 1245 |
} |
| 1246 |
|
| 1247 |
static int pdfincludechar(lua_State * L) |
| 1248 |
{ |
| 1249 |
int f = lua_tointeger(L, 1); |
| 1250 |
if (lua_type(L,2) == LUA_TTABLE) { |
| 1251 |
int i, c; |
| 1252 |
int n = lua_rawlen(L, 2); |
| 1253 |
for (i=1; i<=n; i++) { |
| 1254 |
lua_rawgeti(L, 2, i); |
| 1255 |
c = lua_tointeger(L, 3); |
| 1256 |
pdf_mark_char(f,c); |
| 1257 |
lua_pop(L, 1); |
| 1258 |
} |
| 1259 |
} else { |
| 1260 |
int c = lua_tointeger(L, 2); |
| 1261 |
pdf_mark_char(f,c); |
| 1262 |
} |
| 1263 |
return 0; |
| 1264 |
} |
| 1265 |
|
| 1266 |
static int pdfincludefont(lua_State * L) |
| 1267 |
{ |
| 1268 |
int f = lua_tointeger(L, 1); |
| 1269 |
pdf_init_font(static_pdf,f); |
| 1270 |
return 0; |
| 1271 |
} |
| 1272 |
|
| 1273 |
static int pdfincludeimage(lua_State * L) |
| 1274 |
{ |
| 1275 |
/*tex How to check for a valid entry? */ |
| 1276 |
image_dict *idict = idict_array[lua_tointeger(L,1)]; |
| 1277 |
int objnum = img_objnum(idict); |
| 1278 |
if (img_state(idict) < DICT_OUTIMG) { |
| 1279 |
img_state(idict) = DICT_OUTIMG; |
| 1280 |
} |
| 1281 |
if (! is_obj_written(static_pdf, objnum)) { |
| 1282 |
pdf_write_image(static_pdf, objnum); |
| 1283 |
} |
| 1284 |
lua_pushinteger(L,img_type(idict)); |
| 1285 |
lua_pushinteger(L,img_xorig(idict)); |
| 1286 |
lua_pushinteger(L,img_yorig(idict)); |
| 1287 |
lua_pushinteger(L,img_xsize(idict)); |
| 1288 |
lua_pushinteger(L,img_ysize(idict)); |
| 1289 |
lua_pushinteger(L,img_rotation(idict)); |
| 1290 |
lua_pushinteger(L,objnum); |
| 1291 |
if (img_type(idict) == IMG_TYPE_PNG) { |
| 1292 |
lua_pushinteger(L,img_group_ref(idict)); |
| 1293 |
} else { |
| 1294 |
lua_pushnil(L); |
| 1295 |
} |
| 1296 |
return 8; |
| 1297 |
} |
| 1298 |
|
| 1299 |
static int getpdfnofobjects(lua_State * L) |
| 1300 |
{ |
| 1301 |
int k; |
| 1302 |
int written = 0; |
| 1303 |
int dropped = 0; |
| 1304 |
for (k = 1; k <= static_pdf->obj_ptr; k++) { |
| 1305 |
if (is_obj_written(static_pdf, k)) { |
| 1306 |
written += 1; |
| 1307 |
} else { |
| 1308 |
dropped += 1; |
| 1309 |
} |
| 1310 |
} |
| 1311 |
lua_pushinteger(L,written); |
| 1312 |
lua_pushinteger(L,dropped); |
| 1313 |
return 2; |
| 1314 |
} |
| 1315 |
|
| 1316 |
/*tex |
| 1317 |
|
| 1318 |
The following option is not official and needs testing anyway. It's a |
| 1319 |
prelude a followup where the dependencies are limited. |
| 1320 |
|
| 1321 |
*/ |
| 1322 |
|
| 1323 |
static int settypeonewidemode(lua_State * L) |
| 1324 |
{ |
| 1325 |
t1_wide_mode = lua_tointeger(L,1); |
| 1326 |
return 0; |
| 1327 |
} |
| 1328 |
|
| 1329 |
/*tex For normal output see |pdflistout.c|: */ |
| 1330 |
|
| 1331 |
static const struct luaL_Reg pdflib[] = { |
| 1332 |
{ "gethpos", l_gethpos }, |
| 1333 |
{ "getvpos", l_getvpos }, |
| 1334 |
{ "obj", l_obj }, |
| 1335 |
{ "immediateobj", l_immediateobj }, |
| 1336 |
{ "refobj", l_refobj }, |
| 1337 |
{ "registerannot", l_registerannot }, |
| 1338 |
{ "reserveobj", l_reserveobj }, |
| 1339 |
{ "getpos", l_getpos }, |
| 1340 |
{ "getpageref", getpdfpageref }, |
| 1341 |
{ "getmaxobjnum", getpdfmaxobjnum }, |
| 1342 |
{ "print", luapdfprint }, |
| 1343 |
{ "getobjtype", getpdfobjtype }, |
| 1344 |
{ "getmatrix", l_getmatrix }, |
| 1345 |
{ "hasmatrix", l_hasmatrix }, |
| 1346 |
{ "setfontattributes", l_set_font_attributes }, |
| 1347 |
{ "setcatalog", l_set_catalog }, |
| 1348 |
{ "setinfo", l_set_info }, |
| 1349 |
{ "setnames", l_set_names }, |
| 1350 |
{ "settrailer", l_set_trailer }, |
| 1351 |
{ "setpageresources", l_set_pageresources }, |
| 1352 |
{ "setpageattributes", l_set_pageattributes }, |
| 1353 |
{ "setpagesattributes", l_set_pagesattributes }, |
| 1354 |
{ "setxformresources", l_set_xformresources }, |
| 1355 |
{ "setxformattributes", l_set_xformattributes }, |
| 1356 |
{ "settrailerid", l_set_trailerid }, |
| 1357 |
{ "getcatalog", l_get_catalog }, |
| 1358 |
{ "getinfo", l_get_info }, |
| 1359 |
{ "getnames", l_get_names }, |
| 1360 |
{ "gettrailer", l_get_trailer }, |
| 1361 |
{ "getpageresources", l_get_pageresources }, |
| 1362 |
{ "getpageattributes", l_get_pageattributes }, |
| 1363 |
{ "getpagesattributes", l_get_pagesattributes }, |
| 1364 |
{ "getxformresources", l_get_xformresources }, |
| 1365 |
{ "getxformattributes", l_get_xformattributes }, |
| 1366 |
{ "gettrailerid", l_get_trailerid }, |
| 1367 |
{ "getlastlink", l_get_lastlink }, |
| 1368 |
{ "getretval", l_get_retval }, |
| 1369 |
{ "getlastobj", l_get_lastobj }, |
| 1370 |
{ "getlastannot", l_get_lastannot }, |
| 1371 |
{ "getcompresslevel", l_get_compress_level }, |
| 1372 |
{ "getobjcompresslevel", l_get_obj_compress_level }, |
| 1373 |
{ "getrecompress", l_get_recompress }, |
| 1374 |
{ "setcompresslevel", l_set_compress_level }, |
| 1375 |
{ "setobjcompresslevel", l_set_obj_compress_level }, |
| 1376 |
{ "setrecompress", l_set_recompress }, |
| 1377 |
{ "getdecimaldigits", l_get_decimal_digits }, |
| 1378 |
{ "setdecimaldigits", l_set_decimal_digits }, |
| 1379 |
{ "getpkresolution", l_get_pk_resolution }, |
| 1380 |
{ "setpkresolution", l_set_pk_resolution }, |
| 1381 |
{ "getsuppressoptionalinfo", l_get_suppress_optional_info }, |
| 1382 |
{ "setsuppressoptionalinfo", l_set_suppress_optional_info }, |
| 1383 |
{ "getfontname", getpdffontname }, |
| 1384 |
{ "getfontobjnum", getpdffontobjnum }, |
| 1385 |
{ "getfontsize", getpdffontsize }, |
| 1386 |
{ "getxformname", getpdfxformname }, |
| 1387 |
{ "getcreationdate", getpdfcreationdate }, |
| 1388 |
{ "getmajorversion", getpdfmajorversion }, |
| 1389 |
{ "setmajorversion", setpdfmajorversion }, |
| 1390 |
{ "getminorversion", getpdfminorversion }, |
| 1391 |
{ "setminorversion", setpdfminorversion }, |
| 1392 |
{ "newcolorstack", newpdfcolorstack }, |
| 1393 |
{ "setorigin", setpdforigin }, |
| 1394 |
{ "getorigin", getpdforigin }, |
| 1395 |
{ "setimageresolution", setpdfimageresolution }, |
| 1396 |
{ "getimageresolution", getpdfimageresolution }, |
| 1397 |
{ "setthreadmargin", setpdfthreadmargin }, |
| 1398 |
{ "setdestmargin", setpdfdestmargin }, |
| 1399 |
{ "setlinkmargin", setpdflinkmargin }, |
| 1400 |
{ "setxformmargin", setpdfxformmargin }, |
| 1401 |
{ "getthreadmargin", getpdfthreadmargin }, |
| 1402 |
{ "getdestmargin", getpdfdestmargin }, |
| 1403 |
{ "getlinkmargin", getpdflinkmargin }, |
| 1404 |
{ "getxformmargin", getpdfxformmargin }, |
| 1405 |
{ "getinclusionerrorlevel", getpdfinclusionerrorlevel }, |
| 1406 |
{ "getignoreunknownimages", getpdfignoreunknownimages }, |
| 1407 |
{ "getgentounicode", getpdfgentounicode }, |
| 1408 |
{ "getomitcidset", getpdfomitcidset }, |
| 1409 |
{ "getomitcharset", getpdfomitcharset }, |
| 1410 |
{ "getomitinfo", getpdfomitinfodict }, |
| 1411 |
{ "getomitmediabox", getpdfomitmediabox }, |
| 1412 |
{ "getomitprocset", getpdfomitprocset }, |
| 1413 |
{ "getptexprefix", getpdfptexprefix }, |
| 1414 |
{ "setinclusionerrorlevel", setpdfinclusionerrorlevel }, |
| 1415 |
{ "setignoreunknownimages", setpdfignoreunknownimages }, |
| 1416 |
{ "setgentounicode", setpdfgentounicode }, |
| 1417 |
{ "setomitcidset", setpdfomitcidset }, |
| 1418 |
{ "setomitcharset", setpdfomitcharset }, |
| 1419 |
{ "setomitinfo", setpdfomitinfodict }, |
| 1420 |
{ "setomitmediabox", setpdfomitmediabox }, |
| 1421 |
{ "setomitprocset", setpdfomitprocset }, |
| 1422 |
{ "setptexprefix", setpdfptexprefix }, |
| 1423 |
{ "setforcefile", setforcefile }, |
| 1424 |
{ "mapfile", l_mapfile }, |
| 1425 |
{ "mapline", l_mapline }, |
| 1426 |
{ "includechar", pdfincludechar }, |
| 1427 |
{ "includefont", pdfincludefont }, |
| 1428 |
/* might go, used when sanitizing backend */ |
| 1429 |
{ "includeimage", pdfincludeimage }, |
| 1430 |
{ "getnofobjects", getpdfnofobjects }, |
| 1431 |
/* for a while */ |
| 1432 |
{ "maxobjnum", getpdfmaxobjnum }, |
| 1433 |
{ "pageref", getpdfpageref }, |
| 1434 |
{ "objtype", getpdfobjtype }, |
| 1435 |
{ "fontname", getpdffontname }, |
| 1436 |
{ "fontobjnum", getpdffontobjnum }, |
| 1437 |
{ "fontsize", getpdffontsize }, |
| 1438 |
{ "xformname", getpdfxformname }, |
| 1439 |
/* experimental */ |
| 1440 |
{ "settypeonewidemode", settypeonewidemode}, |
| 1441 |
/* sentinel */ |
| 1442 |
{NULL, NULL} |
| 1443 |
}; |
| 1444 |
|
| 1445 |
int luaopen_pdf(lua_State * L) |
| 1446 |
{ |
| 1447 |
lua_pushstring(L,"pdf.data"); |
| 1448 |
lua_newtable(L); |
| 1449 |
lua_settable(L,LUA_REGISTRYINDEX); |
| 1450 |
/* */ |
| 1451 |
luaL_openlib(L, "pdf", pdflib, 0); |
| 1452 |
/* |
| 1453 |
luaL_newmetatable(L, "pdf.meta"); |
| 1454 |
lua_pushstring(L, "__index"); |
| 1455 |
lua_pushcfunction(L, getpdf); |
| 1456 |
lua_settable(L, -3); |
| 1457 |
lua_pushstring(L, "__newindex"); |
| 1458 |
lua_pushcfunction(L, setpdf); |
| 1459 |
lua_settable(L, -3); |
| 1460 |
lua_setmetatable(L, -2); |
| 1461 |
*/ |
| 1462 |
return 1; |
| 1463 |
} |