static int getpdf(lua_State * L) { char *s; int i, l; if (lua_isstring(L, 2) && (lua_tostring(L, 2) != NULL)) { lua_pushstring(L, PDF_ENV); /* s ... */ lua_gettable(L, LUA_REGISTRYINDEX); /* t ... */ lua_pushvalue(L, 2); /* st t ... */ lua_gettable(L, -2); /* i? t ... */ if (lua_isnumber(L, -1)) { /* i t ... */ i = (int) lua_tointeger(L, -1); /* i t ... */ lua_pop(L, 2); /* ... */ switch (i) { case P_PDFCATALOG: case P_CATALOG: s = tokenlist_to_cstring(pdf_catalog_toks, true, &l); lua_pushlstring(L, s, (size_t) l); break; case P_PDFINFO: case P_INFO: s = tokenlist_to_cstring(pdf_info_toks, true, &l); lua_pushlstring(L, s, (size_t) l); break; case P_PDFNAMES: case P_NAMES: s = tokenlist_to_cstring(pdf_names_toks, true, &l); lua_pushlstring(L, s, (size_t) l); break; case P_PDFTRAILER: case P_TRAILER: s = tokenlist_to_cstring(pdf_trailer_toks, true, &l); lua_pushlstring(L, s, (size_t) l); break; case P_H: lua_pushnumber(L, static_pdf->posstruct->pos.h); break; case P_V: lua_pushnumber(L, static_pdf->posstruct->pos.v); break; default: lua_rawget(L, -2); } } else { lua_pop(L, 2); /* ... */ lua_rawget(L, -2); } } else { lua_pushnil(L); } return 1; }
void tokenlist_to_luastring(lua_State * L, int p) { int l; char *s; s = tokenlist_to_cstring(p, 1, &l); lua_pushlstring(L, s, (size_t) l); free(s); }
void write_out(halfword p) { int old_setting; int j; char*s,*ss; int callback_id; int lua_retval; expand_macros_in_tokenlist(p); old_setting= selector; j= write_stream(p); if(file_can_be_written(j)){ selector= j; }else if((j==term_only)&&(selector==term_and_log)){ selector= log_only; tprint_nl(""); }else{ tprint_nl(""); } s= tokenlist_to_cstring(def_ref,false,NULL); if(selector<no_print){ callback_id= callback_defined(process_output_buffer_callback); if(callback_id> 0){ lua_retval= run_callback(callback_id,"S->S",s,&ss); if((lua_retval==true)&&(ss!=NULL)){ xfree(s); s= ss; } } } tprint(s); xfree(s); print_ln(); flush_list(def_ref); selector= old_setting; }
void scan_pdfximage(PDF pdf) { scaled_whd alt_rule; image_dict *idict; int transform = 0, page = 1, pagebox, colorspace = 0; char *named = NULL, *attr = NULL, *file_name = NULL, *user = NULL, *owner = NULL, *visible = NULL; alt_rule = scan_alt_rule(); if (scan_keyword("attr")) { scan_toks(false, true); attr = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("named")) { scan_toks(false, true); if (0) { named = tokenlist_to_cstring(def_ref, true, NULL); page = 0; } else { normal_warning("pdf backend","named pages are not supported, using page 1"); page = 1; } delete_token_ref(def_ref); } else if (scan_keyword("page")) { scan_int(); page = cur_val; } if (scan_keyword("userpassword")) { scan_toks(false, true); user = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("ownerpassword")) { scan_toks(false, true); owner = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("visiblefilename")) { scan_toks(false, true); visible = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("colorspace")) { scan_int(); colorspace = cur_val; } pagebox = scan_pdf_box_spec(); if (pagebox == PDF_BOX_SPEC_NONE) { pagebox = pdf_pagebox; if (pagebox == PDF_BOX_SPEC_NONE) pagebox = PDF_BOX_SPEC_CROP; } scan_toks(false, true); file_name = tokenlist_to_cstring(def_ref, true, NULL); if (file_name == NULL) { normal_error("pdf backend","no image filename given"); } delete_token_ref(def_ref); idict = read_image(file_name, page, named, colorspace, pagebox, user, owner, visible); img_attr(idict) = attr; img_dimen(idict) = alt_rule; img_transform(idict) = transform; last_saved_image_index = img_objnum(idict); last_saved_image_pages = img_totalpages(idict); }