static int l_immediatewrite_image(lua_State * L) { check_o_mode(static_pdf, "img.immediatewrite()", 1 << OMODE_PDF, true); if (global_shipping_mode != NOT_SHIPPING) luaL_error(L, "pdf.immediatewrite() can not be used with \\latelua"); write_image_or_node(L, WR_IMMEDIATEWRITE); return 1; /* image */ }
static int l_scan_image(lua_State * L) { image *a, **aa; if (lua_gettop(L) != 1) luaL_error(L, "img.scan needs exactly 1 argument"); if (lua_istable(L, 1)) (void) l_new_image(L); aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); a = *aa; check_o_mode(static_pdf, "img.scan", 1 << OMODE_PDF, false); read_scale_img(a); return 1; }
static int l_scan_image(lua_State * L) { image *a, **aa; if (lua_gettop(L) != 1) luaL_error(L, "img.scan() needs exactly 1 argument"); if (lua_istable(L, 1)) (void) l_new_image(L); /* image --- if everything worked well */ aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* image */ a = *aa; check_o_mode(static_pdf, "img.scan()", 1 << OMODE_PDF, false); /* flush_str(last_tex_string); *//* ?? */ read_scale_img(a); return 1; /* image */ }
static int luapdfprint(lua_State * L) { int n; const_lstring st, modestr; ctm_transform_modes literal_mode; st.s = modestr.s = NULL; n = lua_gettop(L); if (!lua_isstring(L, -1)) { luaL_error(L, "no string to print"); } literal_mode = set_origin; if (n == 2) { if (!lua_isstring(L, -2)) { luaL_error(L, "invalid argument for print literal mode"); } else { modestr.s = lua_tolstring(L, -2, &modestr.l); if (modestr.l == 6 && strncmp(modestr.s, "direct", 6) == 0) literal_mode = direct_always; else if (modestr.l == 4 && strncmp(modestr.s, "page", 4) == 0) literal_mode = direct_page; else { luaL_error(L, "invalid argument for print literal mode"); } } } else { if (n != 1) { luaL_error(L, "invalid number of arguments"); } } check_o_mode(static_pdf, "pdf.print()", 1 << OMODE_PDF, true); switch (literal_mode) { case (set_origin): pdf_goto_pagemode(static_pdf); pdf_set_pos(static_pdf, static_pdf->posstruct->pos); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_page): pdf_goto_pagemode(static_pdf); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_always): pdf_end_string_nl(static_pdf); break; default: assert(0); } st.s = lua_tolstring(L, n, &st.l); pdf_out_block(static_pdf, st.s, st.l); return 0; }
static int luapdfprint(lua_State * L) { int n; const_lstring st; const char *modestr_s; ctm_transform_modes literal_mode; st.s = modestr_s = NULL; n = lua_gettop(L); if (!lua_isstring(L, -1)) { /* or number */ luaL_error(L, "no string to print"); } literal_mode = set_origin; if (n == 2) { if (lua_type(L,-2) != LUA_TSTRING) { luaL_error(L, "invalid first argument for print literal mode"); } else { modestr_s = lua_tostring(L, -2); if (lua_key_eq(modestr_s,direct)) literal_mode = direct_always; else if (lua_key_eq(modestr_s,page)) literal_mode = direct_page; else { luaL_error(L, "invalid first argument for print literal mode"); } } } else if (n != 1) { luaL_error(L, "invalid number of arguments"); } check_o_mode(static_pdf, "pdf.print()", 1 << OMODE_PDF, true); switch (literal_mode) { case (set_origin): pdf_goto_pagemode(static_pdf); pdf_set_pos(static_pdf, static_pdf->posstruct->pos); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_page): pdf_goto_pagemode(static_pdf); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_always): pdf_end_string_nl(static_pdf); break; default: assert(0); } st.s = lua_tolstring(L, n, &st.l); pdf_out_block(static_pdf, st.s, st.l); return 0; }
static void setup_image(PDF pdf, image * a, wrtype_e writetype) { image_dict *ad; if (a == NULL) luaL_error(Luas, "no valid image passed"); /* todo, also check in caller */ ad = img_dict(a); check_o_mode(pdf, wrtype_s[writetype], 1 << OMODE_PDF, false); read_scale_img(a); if (img_objnum(ad) == 0) { /* latest needed just before out_img() */ pdf->ximage_count++; img_objnum(ad) = pdf_create_obj(pdf, obj_type_ximage, pdf->ximage_count); img_index(ad) = pdf->ximage_count; idict_to_array(ad); /* from now on ad is read-only */ obj_data_ptr(pdf, pdf->obj_ptr) = img_index(ad); } }
static void setup_image(PDF pdf, image * a, wrtype_e writetype) { image_dict *ad; assert(a != NULL); ad = img_dict(a); check_o_mode(pdf, wrtype_s[writetype], 1 << OMODE_PDF, false); /* flush_str(last_tex_string); *//* ?? */ read_scale_img(a); if (img_objnum(ad) == 0) { /* latest needed just before out_img() */ pdf->ximage_count++; img_objnum(ad) = pdf_create_obj(pdf, obj_type_ximage, pdf->ximage_count); img_index(ad) = pdf->ximage_count; idict_to_array(ad); /* now ad is read-only */ obj_data_ptr(pdf, pdf->obj_ptr) = img_index(ad); } }
static int l_immediateobj(lua_State * L) { int n, first_arg = 1; int k; lstring buf; const_lstring st1,st2, st3; const char *st1_s = NULL; st1.s = st2.s = st3.s = NULL; check_o_mode(static_pdf, "immediateobj()", 1 << OMODE_PDF, true); if (global_shipping_mode != NOT_SHIPPING) luaL_error(L, "pdf.immediateobj() can not be used with \\latelua"); n = lua_gettop(L); if ((n > 0) && (lua_type(L, 1) == LUA_TNUMBER)) { first_arg++; k = (int) lua_tointeger(L, 1); check_obj_type(static_pdf, obj_type_obj, k); if (is_obj_scheduled(static_pdf, k) || obj_data_ptr(static_pdf, k) != 0) luaL_error(L, "pdf.immediateobj() object in use"); } else { static_pdf->obj_count++; k = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); } pdf_last_obj = k; switch (n - first_arg + 1) { case 0: luaL_error(L, "pdf.immediateobj() needs at least one argument"); break; case 1: if (!lua_isstring(L, first_arg)) /* or number */ luaL_error(L, "pdf.immediateobj() 1st argument must be string"); pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS); st1.s = lua_tolstring(L, first_arg, &st1.l); pdf_out_block(static_pdf, st1.s, st1.l); pdf_end_obj(static_pdf); break; case 2: case 3: if (lua_type(L,first_arg) != LUA_TSTRING) luaL_error(L, "pdf.immediateobj() 1st argument must be string"); if (!lua_isstring(L, first_arg + 1)) /* or number */ luaL_error(L, "pdf.immediateobj() 2nd argument must be string"); st1_s = lua_tostring(L, first_arg); st2.s = lua_tolstring(L, first_arg + 1, &st2.l); if (lua_key_eq(st1_s, file)) { if (n == first_arg + 2) luaL_error(L, "pdf.immediateobj() 3rd argument forbidden in file mode"); pdf_begin_obj(static_pdf, k, OBJSTM_ALWAYS); buf.s = fread_to_buf(L, st2.s, &buf.l); pdf_out_block(static_pdf, (const char *) buf.s, buf.l); xfree(buf.s); pdf_end_obj(static_pdf); } else { pdf_begin_obj(static_pdf, k, OBJSTM_NEVER); /* not an object stream candidate! */ pdf_begin_dict(static_pdf); if (n == first_arg + 2) { /* write attr text */ if (!lua_isstring(L, first_arg + 2)) /* or number (maybe only string as it's an attr) */ luaL_error(L, "pdf.immediateobj() 3rd argument must be string"); st3.s = lua_tolstring(L, first_arg + 2, &st3.l); pdf_out_block(static_pdf, st3.s, st3.l); if (st3.s[st3.l - 1] != '\n') pdf_out(static_pdf, '\n'); } pdf_dict_add_streaminfo(static_pdf); pdf_end_dict(static_pdf); pdf_begin_stream(static_pdf); if (lua_key_eq(st1_s, stream)) { pdf_out_block(static_pdf, st2.s, st2.l); } else if (lua_key_eq(st1_s, streamfile)) { buf.s = fread_to_buf(L, st2.s, &buf.l); pdf_out_block(static_pdf, (const char *) buf.s, buf.l); xfree(buf.s); } else luaL_error(L, "pdf.immediateobj() invalid argument"); pdf_end_stream(static_pdf); pdf_end_obj(static_pdf); } break; default: luaL_error(L, "pdf.immediateobj() allows max. 3 arguments"); } lua_pushinteger(L, k); return 1; }