diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2014-03-15 12:21:15 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2014-03-15 12:21:15 +0000 |
commit | a22d9897afbabdd07f13d2bc5c7c5b9c5865ab53 (patch) | |
tree | 70829ffa23329ca4c04efa8da7a18cfe9c44a1f4 /Build/source/texk/web2c/luatexdir/lua/lpdflib.c | |
parent | 5909dbd7ee4290cc486c9c12e4ef0b2bfb9067d4 (diff) |
here is luatex 0.79.0
git-svn-id: svn://tug.org/texlive/trunk@33180 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/lpdflib.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/lpdflib.c | 206 |
1 files changed, 130 insertions, 76 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c index 6f7c0842637..00cffd398d7 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c @@ -18,20 +18,21 @@ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ static const char _svn_version[] = - "$Id: lpdflib.c 4524 2012-12-20 15:38:02Z taco $ " - "$URL: https://foundry.supelec.fr/svn/luatex/branches/ex-glyph/source/texk/web2c/luatexdir/lua/lpdflib.c $"; + "$Id: lpdflib.c 4877 2014-03-14 01:26:05Z luigi $ " + "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lpdflib.c $"; #include "ptexlib.h" #include "lua/luatex-api.h" -#define PDF_ENV "pdf_env" +#define PDF_ENV "pdf.env" static int luapdfprint(lua_State * L) { int n; - const_lstring st, modestr; + const_lstring st; + const char *modestr_s; ctm_transform_modes literal_mode; - st.s = modestr.s = NULL; + st.s = modestr_s = NULL; n = lua_gettop(L); if (!lua_isstring(L, -1)) { luaL_error(L, "no string to print"); @@ -41,10 +42,10 @@ static int luapdfprint(lua_State * L) 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) + 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 argument for print literal mode"); @@ -97,7 +98,8 @@ static int l_immediateobj(lua_State * L) int n, first_arg = 1; int k; lstring buf; - const_lstring st1, st2, st3; + 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) @@ -124,8 +126,10 @@ static int l_immediateobj(lua_State * L) 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); - if (st1.s[st1.l - 1] != '\n') - pdf_out(static_pdf, '\n'); + /* already in pdf_end_obj: + if (st1.s[st1.l - 1] != '\n') + pdf_out(static_pdf, '\n'); + */ pdf_end_obj(static_pdf); break; case 2: @@ -134,17 +138,18 @@ static int l_immediateobj(lua_State * L) luaL_error(L, "pdf.immediateobj() 1st argument must be string"); if (!lua_isstring(L, first_arg + 1)) luaL_error(L, "pdf.immediateobj() 2nd argument must be string"); - st1.s = lua_tolstring(L, first_arg, &st1.l); + st1_s = lua_tostring(L, first_arg); st2.s = lua_tolstring(L, first_arg + 1, &st2.l); - if (st1.l == 4 && strncmp((const char *) st1.s, "file", 4) == 0) { + if (lua_key_eq(st1_s, file)) { if (n == first_arg + 2) - luaL_error(L, - "pdf.immediateobj() 3rd argument forbidden in file mode"); + 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); - if (buf.s[buf.l - 1] != '\n') - pdf_out(static_pdf, '\n'); + /* already in pdf_end_obj: + if (buf.s[buf.l - 1] != '\n') + pdf_out(static_pdf, '\n'); + */ xfree(buf.s); pdf_end_obj(static_pdf); } else { @@ -152,8 +157,7 @@ static int l_immediateobj(lua_State * L) pdf_begin_dict(static_pdf); if (n == first_arg + 2) { /* write attr text */ if (!lua_isstring(L, first_arg + 2)) - luaL_error(L, - "pdf.immediateobj() 3rd argument must be string"); + 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') @@ -162,11 +166,9 @@ static int l_immediateobj(lua_State * L) pdf_dict_add_streaminfo(static_pdf); pdf_end_dict(static_pdf); pdf_begin_stream(static_pdf); - if (st1.l == 6 && strncmp((const char *) st1.s, "stream", 6) == 0) { + if (lua_key_eq(st1_s, stream)) { pdf_out_block(static_pdf, st2.s, st2.l); - } else if (st1.l == 10 - && strncmp((const char *) st1.s, "streamfile", - 10) == 0) { + } 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); @@ -236,8 +238,9 @@ static int table_obj(lua_State * L) /* get object "type" */ - lua_pushstring(L, "type"); /* ks t */ - lua_gettable(L, -2); /* vs? t */ + /* lua_pushstring(L, "type"); /\* ks t *\/ */ + /* lua_gettable(L, -2); /\* vs? t *\/ */ + lua_key_rawgeti(type); if (lua_isnil(L, -1)) /* !vs t */ luaL_error(L, "pdf.obj(): object \"type\" missing"); if (!lua_isstring(L, -1)) /* !vs t */ @@ -247,8 +250,7 @@ static int table_obj(lua_State * L) lua_pushvalue(L, -2); /* vs t vs t */ lua_gettable(L, -2); /* i? t vs t */ if (!lua_isnumber(L, -1)) /* !i t vs t */ - luaL_error(L, "pdf.obj(): \"%s\" is not a valid object type", - lua_tostring(L, -3)); + luaL_error(L, "pdf.obj(): \"%s\" is not a valid object type", lua_tostring(L, -3)); type = (int) lua_tointeger(L, -1); /* i t vs t */ switch (type) { case P_RAW: @@ -261,8 +263,9 @@ static int table_obj(lua_State * L) /* get optional "immediate" */ - lua_pushstring(L, "immediate"); /* ks t */ - lua_gettable(L, -2); /* b? t */ + /* lua_pushstring(L, "immediate"); /\* ks t *\/ */ + /* lua_gettable(L, -2); /\* b? t *\/ */ + lua_key_rawgeti(immediate); if (!lua_isnil(L, -1)) { /* b? t */ if (!lua_isboolean(L, -1)) /* !b t */ luaL_error(L, "pdf.obj(): \"immediate\" must be boolean"); @@ -272,8 +275,9 @@ static int table_obj(lua_State * L) /* is a reserved object referenced by "objnum"? */ - lua_pushstring(L, "objnum"); /* ks t */ - lua_gettable(L, -2); /* vi? t */ + /* lua_pushstring(L, "objnum"); /\* ks t *\/ */ + /* lua_gettable(L, -2); /\* vi? t *\/ */ + lua_key_rawgeti(objnum); if (!lua_isnil(L, -1)) { /* vi? t */ if (!lua_isnumber(L, -1)) /* !vi t */ luaL_error(L, "pdf.obj(): \"objnum\" must be integer"); @@ -294,12 +298,12 @@ static int table_obj(lua_State * L) /* get optional "attr" (allowed only for stream case) */ - lua_pushstring(L, "attr"); /* ks t */ - lua_gettable(L, -2); /* attr-s? t */ + /* lua_pushstring(L, "attr"); /\* ks t *\/ */ + /* lua_gettable(L, -2); /\* attr-s? t *\/ */ + lua_key_rawgeti(attr); if (!lua_isnil(L, -1)) { /* attr-s? t */ if (type != P_STREAM) - luaL_error(L, - "pdf.obj(): \"attr\" key not allowed for non-stream object"); + luaL_error(L, "pdf.obj(): \"attr\" key not allowed for non-stream object"); if (!lua_isstring(L, -1)) /* !attr-s t */ luaL_error(L, "pdf.obj(): object \"attr\" must be string"); if (immediate == 1) { @@ -312,12 +316,12 @@ static int table_obj(lua_State * L) /* get optional "compresslevel" (allowed only for stream case) */ - lua_pushstring(L, "compresslevel"); /* ks t */ - lua_gettable(L, -2); /* vi? t */ + /* lua_pushstring(L, "compresslevel"); /\* ks t *\/ */ + /* lua_gettable(L, -2); /\* vi? t *\/ */ + lua_key_rawgeti(compresslevel); if (!lua_isnil(L, -1)) { /* vi? t */ if (type == P_RAW) - luaL_error(L, - "pdf.obj(): \"compresslevel\" key not allowed for raw object"); + luaL_error(L, "pdf.obj(): \"compresslevel\" key not allowed for raw object"); if (!lua_isnumber(L, -1)) /* !vi t */ luaL_error(L, "pdf.obj(): \"compresslevel\" must be integer"); compress_level = (int) lua_tointeger(L, -1); /* vi t */ @@ -332,12 +336,12 @@ static int table_obj(lua_State * L) /* get optional "objcompression" (allowed only for non-stream case) */ - lua_pushstring(L, "objcompression"); /* ks t */ - lua_gettable(L, -2); /* b? t */ + /* lua_pushstring(L, "objcompression"); /\* ks t *\/ */ + /* lua_gettable(L, -2); /\* b? t *\/ */ + lua_key_rawgeti(objcompression); if (!lua_isnil(L, -1)) { /* b? t */ if (type == P_STREAM) - luaL_error(L, - "pdf.obj(): \"objcompression\" key not allowed for stream object"); + luaL_error(L, "pdf.obj(): \"objcompression\" key not allowed for stream object"); if (!lua_isboolean(L, -1)) /* !b t */ luaL_error(L, "pdf.obj(): \"objcompression\" must be boolean"); obj_compression = lua_toboolean(L, -1); /* 0 or 1 */ @@ -353,13 +357,16 @@ static int table_obj(lua_State * L) /* now the object contents for all cases are handled */ - lua_pushstring(L, "string"); /* ks t */ - lua_gettable(L, -2); /* string-s? t */ - lua_pushstring(L, "file"); /* ks string-s? t */ - lua_gettable(L, -3); /* file-s? string-s? t */ + /* lua_pushstring(L, "string"); /\* ks t *\/ */ + /* lua_gettable(L, -2); /\* string-s? t *\/ */ + lua_key_rawgeti(string); + /* lua_pushstring(L, "file"); /\* ks string-s? t *\/ */ + /* lua_gettable(L, -3); /\* file-s? string-s? t *\/ */ + lua_rawgeti(L, LUA_REGISTRYINDEX, lua_key_index(file)); + lua_gettable(L, -3); + if (!lua_isnil(L, -1) && !lua_isnil(L, -2)) /* file-s? string-s? t */ - luaL_error(L, - "pdf.obj(): \"string\" and \"file\" must not be given together"); + luaL_error(L, "pdf.obj(): \"string\" and \"file\" must not be given together"); if (lua_isnil(L, -1) && lua_isnil(L, -2)) /* nil nil t */ luaL_error(L, "pdf.obj(): no \"string\" or \"file\" given"); @@ -371,26 +378,28 @@ static int table_obj(lua_State * L) /* from string */ lua_pop(L, 1); /* string-s? t */ if (!lua_isstring(L, -1)) /* !string-s t */ - luaL_error(L, - "pdf.obj(): \"string\" must be string for raw object"); + luaL_error(L, "pdf.obj(): \"string\" must be string for raw object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); pdf_out_block(static_pdf, st.s, st.l); - if (st.s[st.l - 1] != '\n') - pdf_out(static_pdf, '\n'); + /* already in pdf_end_obj: + if (st.s[st.l - 1] != '\n') + pdf_out(static_pdf, '\n'); + */ } else obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* t */ } else { /* from file */ if (!lua_isstring(L, -1)) /* !file-s nil t */ - luaL_error(L, - "pdf.obj(): \"file\" name must be string for raw object"); + luaL_error(L, "pdf.obj(): \"file\" name must be string for raw object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); /* file-s nil t */ buf.s = fread_to_buf(L, st.s, &buf.l); pdf_out_block(static_pdf, (const char *) buf.s, buf.l); - if (buf.s[buf.l - 1] != '\n') - pdf_out(static_pdf, '\n'); + /* already in pdf_end_obj: + if (buf.s[buf.l - 1] != '\n') + pdf_out(static_pdf, '\n'); + */ xfree(buf.s); } else { set_obj_obj_is_file(static_pdf, k); @@ -423,8 +432,7 @@ static int table_obj(lua_State * L) /* from string */ lua_pop(L, 1); /* string-s? t */ if (!lua_isstring(L, -1)) /* !string-s t */ - luaL_error(L, - "pdf.obj(): \"string\" must be string for stream object"); + luaL_error(L, "pdf.obj(): \"string\" must be string for stream object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); /* string-s t */ pdf_out_block(static_pdf, st.s, st.l); @@ -433,8 +441,7 @@ static int table_obj(lua_State * L) } else { /* from file */ if (!lua_isstring(L, -1)) /* !file-s nil t */ - luaL_error(L, - "pdf.obj(): \"file\" name must be string for stream object"); + luaL_error(L, "pdf.obj(): \"file\" name must be string for stream object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); /* file-s nil t */ buf.s = fread_to_buf(L, st.s, &buf.l); @@ -461,8 +468,7 @@ static int orig_obj(lua_State * L) { int n, first_arg = 1; int k; - const_lstring st; - st.s = NULL; + const char *st_s = NULL ; n = lua_gettop(L); if (n > 0 && lua_type(L, 1) == LUA_TNUMBER) { first_arg++; @@ -491,8 +497,8 @@ static int orig_obj(lua_State * L) luaL_error(L, "pdf.obj() 1st argument must be string"); if (!lua_isstring(L, first_arg + 1)) luaL_error(L, "pdf.obj() 2nd argument must be string"); - st.s = lua_tolstring(L, first_arg, &st.l); - if (st.l == 4 && strncmp((const char *) st.s, "file", 4) == 0) { + st_s = lua_tostring(L, first_arg); + if (lua_key_eq(st_s, file)) { if (n == first_arg + 2) luaL_error(L, "pdf.obj() 3rd argument forbidden in file mode"); set_obj_obj_is_file(static_pdf, k); @@ -503,10 +509,9 @@ static int orig_obj(lua_State * L) obj_obj_stream_attr(static_pdf, k) = luaL_ref(Luas, LUA_REGISTRYINDEX); } - if (st.l == 6 && strncmp((const char *) st.s, "stream", 6) == 0) { + if (lua_key_eq(st_s, stream)) { set_obj_obj_is_stream(static_pdf, k); - } else if (st.l == 10 - && strncmp((const char *) st.s, "streamfile", 10) == 0) { + } else if (lua_key_eq(st_s, streamfile)) { set_obj_obj_is_stream(static_pdf, k); set_obj_obj_is_file(static_pdf, k); } else @@ -550,8 +555,7 @@ static int l_refobj(lua_State * L) static int l_reserveobj(lua_State * L) { int n; - const_lstring st; - st.s = 0; + const char *st_s = NULL; n = lua_gettop(L); switch (n) { case 0: @@ -562,8 +566,7 @@ static int l_reserveobj(lua_State * L) case 1: if (!lua_isstring(L, -1)) luaL_error(L, "pdf.reserveobj() optional argument must be string"); - st.s = lua_tolstring(L, 1, &st.l); - if (st.l == 5 && strncmp((const char *) st.s, "annot", 5) == 0) { + if (lua_key_eq(st_s, annot)) { pdf_last_annot = pdf_create_obj(static_pdf, obj_type_annot, 0); } else { luaL_error(L, "pdf.reserveobj() optional string must be \"annot\""); @@ -587,8 +590,7 @@ static int l_registerannot(lua_State * L) luaL_error(L, "pdf.registerannot() can only be used in late lua"); i = (int) luaL_checkinteger(L, 1); if (i <= 0) - luaL_error(L, - "pdf.registerannot() can only register positive object numbers"); + luaL_error(L, "pdf.registerannot() can only register positive object numbers"); addto_page_resources(static_pdf, obj_type_annot, i); break; default: @@ -764,6 +766,53 @@ static int l_pageref(lua_State * L) return 1; } +static int l_getpos(lua_State * L) +{ + lua_pushnumber(L, static_pdf->posstruct->pos.h); + lua_pushnumber(L, static_pdf->posstruct->pos.v); + return 2; +} + +static int l_gethpos(lua_State * L) +{ + lua_pushnumber(L, static_pdf->posstruct->pos.h); + return 1; +} + +static int l_getvpos(lua_State * L) +{ + lua_pushnumber(L, static_pdf->posstruct->pos.v); + return 1; +} + +static int l_getmatrix(lua_State * L) +{ + if (matrix_stack_used > 0) { + matrix_entry *m = &matrix_stack[matrix_stack_used - 1]; + lua_pushnumber(L, m->a); + lua_pushnumber(L, m->b); + lua_pushnumber(L, m->c); + lua_pushnumber(L, m->d); + lua_pushnumber(L, m->e); + lua_pushnumber(L, m->f); + } else { + lua_pushnumber(L, 1); + lua_pushnumber(L, 0); + lua_pushnumber(L, 0); + lua_pushnumber(L, 1); + lua_pushnumber(L, 0); + lua_pushnumber(L, 0); + } + return 6 ; +} + +static int l_hasmatrix(lua_State * L) +{ + lua_pushboolean(L, (matrix_stack_used > 0)); + return 1 ; +} + + static const struct luaL_Reg pdflib[] = { {"immediateobj", l_immediateobj}, {"mapfile", l_mapfile}, @@ -778,6 +827,11 @@ static const struct luaL_Reg pdflib[] = { {"refobj", l_refobj}, {"registerannot", l_registerannot}, {"reserveobj", l_reserveobj}, + {"getpos", l_getpos}, + {"gethpos", l_gethpos}, + {"getvpos", l_getvpos}, + {"getmatrix", l_getmatrix}, + {"hasmatrix", l_hasmatrix}, {NULL, NULL} /* sentinel */ }; @@ -788,7 +842,7 @@ int luaopen_pdf(lua_State * L) preset_environment(L, pdf_parms, PDF_ENV); luaL_register(L, "pdf", pdflib); /* build meta table */ - luaL_newmetatable(L, "pdf_meta"); + luaL_newmetatable(L, "pdf.meta"); lua_pushstring(L, "__index"); lua_pushcfunction(L, getpdf); /* do these later, NYI */ |