diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2011-04-12 14:17:47 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2011-04-12 14:17:47 +0000 |
commit | 307453997ef030ec4dfa1e876feaf0b8b8125bab (patch) | |
tree | ab2054693ba95e9ac8f6e3478b4d0175d893329f /Build/source/texk/web2c/luatexdir/lua | |
parent | d95b11a25d3d9e17cc4afb9c8713ef4037567527 (diff) |
check in luatex 0.66.0
git-svn-id: svn://tug.org/texlive/trunk@22059 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua')
23 files changed, 3610 insertions, 343 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c index a3961703528..98444a9f705 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c @@ -21,7 +21,7 @@ #include "ptexlib.h" static const char _svn_version[] = - "$Id: lcallbacklib.c 3404 2010-01-28 11:17:10Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/lcallbacklib.c $"; + "$Id: lcallbacklib.c 3965 2010-11-22 12:38:45Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lcallbacklib.c $"; int callback_count = 0; int saved_callback_count = 0; @@ -35,7 +35,6 @@ static const char *const callbacknames[] = { "find_image_file", "find_format_file", "find_read_file", "open_read_file", - "find_ocp_file", "read_ocp_file", "find_vf_file", "read_vf_file", "find_data_file", "read_data_file", "find_font_file", "read_font_file", @@ -63,11 +62,19 @@ static const char *const callbacknames[] = { "linebreak_filter", "post_linebreak_filter", "mlist_to_hlist", + "finish_pdffile", + "pre_dump", NULL }; int callback_callbacks_id = 0; +int debug_callback_defined(int i) +{ + printf ("callback_defined(%s)\n", callbacknames[i]); + return callback_set[i]; +} + void get_lua_boolean(const char *table, const char *name, boolean * target) { int stacktop; diff --git a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc index 2c1bc34fc1b..66b8731acbb 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc +++ b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc @@ -1,6 +1,7 @@ /* lepdflib.cc - Copyright 2009-2010 Taco Hoekwater <taco@luatex.org> + Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> + Copyright 2009-2011 Hartmut Henkel <hartmut@luatex.org> This file is part of LuaTeX. @@ -18,41 +19,2688 @@ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ static const char _svn_version[] = - "$Id: lepdflib.cc 3366 2010-01-20 14:49:31Z taco $ " - "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/lepdflib.cc $"; + "$Id: lepdflib.cc 4134 2011-04-11 20:54:58Z hhenkel $ " + "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lepdflib.cc $"; #include "image/epdf.h" +// define DEBUG + +//********************************************************************** +// TODO: add more poppler functions (many are still missing) + +//********************************************************************** +// objects allocated by poppler may not be deleted in the lepdflib + +typedef enum { ALLOC_POPPLER, ALLOC_LEPDF } alloctype; + +typedef struct { + void *d; + alloctype atype; // was it allocated by poppler or the lepdflib.cc? + PdfDocument *pd; // reference to PdfDocument, or NULL + unsigned long pc; // counter to detect PDFDoc change +} udstruct; + +static const char *ErrorCodeNames[] = { "None", "OpenFile", "BadCatalog", + "Damaged", "Encrypted", "HighlightFile", "BadPrinter", "Printing", + "Permission", "BadPageNum", "FileIO", NULL +}; + +//********************************************************************** + +#define M_Annot "Annot" +#define M_AnnotBorder "AnnotBorder" +#define M_AnnotBorderStyle "AnnotBorderStyle" +#define M_Annots "Annots" +#define M_Array "Array" +#define M_Catalog "Catalog" +#define M_EmbFile "EmbFile" +#define M_Dict "Dict" +#define M_GooString "GooString" +#define M_LinkDest "LinkDest" +#define M_Links "Links" +#define M_Object "Object" +#define M_Page "Page" +#define M_PDFDoc "PDFDoc" +#define M_PDFRectangle "PDFRectangle" +#define M_Ref "Ref" +#define M_Stream "Stream" +#define M_XRef "XRef" +#define M_XRefEntry "XRefEntry" + +//********************************************************************** + +#define new_poppler_userdata(type) \ +static udstruct *new_##type##_userdata(lua_State * L) \ +{ \ + udstruct *a; \ + a = (udstruct *) lua_newuserdata(L, sizeof(udstruct)); /* udstruct ... */ \ + a->atype = ALLOC_POPPLER; \ + luaL_getmetatable(L, M_##type); /* m udstruct ... */ \ + lua_setmetatable(L, -2); /* udstruct ... */ \ + return a; \ +} + +new_poppler_userdata(PDFDoc); + +new_poppler_userdata(Annot); +new_poppler_userdata(AnnotBorder); +//new_poppler_userdata(AnnotBorderStyle); +new_poppler_userdata(Annots); +new_poppler_userdata(Array); +new_poppler_userdata(Catalog); +new_poppler_userdata(EmbFile); +new_poppler_userdata(Dict); +//new_poppler_userdata(GooString); +new_poppler_userdata(LinkDest); +new_poppler_userdata(Links); +new_poppler_userdata(Object); +new_poppler_userdata(Page); +new_poppler_userdata(PDFRectangle); +new_poppler_userdata(Ref); +new_poppler_userdata(Stream); +new_poppler_userdata(XRef); +//new_poppler_userdata(XRefEntry); + +//********************************************************************** + +static void pdfdoc_changed_error(lua_State * L) +{ + luaL_error(L, "PDFDoc changed or gone"); +} + +static void pdfdoc_differs_error(lua_State * L) +{ + luaL_error(L, "PDFDoc differs between arguments"); +} + +//********************************************************************** + +static int l_open_PDFDoc(lua_State * L) +{ + const char *file_path; + udstruct *uout; + PdfDocument *d; + file_path = luaL_checkstring(L, 1); // path + d = refPdfDocument((char *) file_path, FE_RETURN_NULL); + if (d == NULL) + lua_pushnil(L); + else { + uout = new_PDFDoc_userdata(L); + uout->d = d; + uout->atype = ALLOC_LEPDF; + uout->pc = d->pc; + uout->pd = d; + } + return 1; // doc path +} + +static int l_new_Annot(lua_State * L) +{ + udstruct *uxref, *udict, *ucatalog, *uref, *uout; + uxref = (udstruct *) luaL_checkudata(L, 1, M_XRef); + udict = (udstruct *) luaL_checkudata(L, 2, M_Dict); + ucatalog = (udstruct *) luaL_checkudata(L, 3, M_Catalog); + uref = (udstruct *) luaL_checkudata(L, 4, M_Ref); + if (uxref->pd != ucatalog->pd || uxref->pd != udict->pd + || uxref->pd != uref->pd) + pdfdoc_differs_error(L); + if ((uxref->pd != NULL && uxref->pd->pc != uxref->pc) || + (ucatalog->pd != NULL && ucatalog->pd->pc != ucatalog->pc) || + (udict->pd != NULL && udict->pd->pc != udict->pc) || + (uref->pd != NULL && uref->pd->pc != uref->pc)) + pdfdoc_changed_error(L); + uout = new_Annot_userdata(L); + uout->d = + new Annot((XRef *) uxref->d, (Dict *) udict->d, (Catalog *) ucatalog->d, + (Object *) uref->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uxref->pc; + uout->pd = uxref->pd; + return 1; +} + +static int l_new_Annots(lua_State * L) +{ + udstruct *uxref, *ucatalog, *uannotsobj, *uout; + uxref = (udstruct *) luaL_checkudata(L, 1, M_XRef); + ucatalog = (udstruct *) luaL_checkudata(L, 2, M_Catalog); + uannotsobj = (udstruct *) luaL_checkudata(L, 3, M_Object); + if (uxref->pd != ucatalog->pd || uxref->pd != uannotsobj->pd) + pdfdoc_differs_error(L); + if ((uxref->pd != NULL && uxref->pd->pc != uxref->pc) + || (ucatalog->pd != NULL && ucatalog->pd->pc != ucatalog->pc) + || (uannotsobj->pd != NULL && uannotsobj->pd->pc != uannotsobj->pc)) + pdfdoc_changed_error(L); + uout = new_Annots_userdata(L); + uout->d = + new Annots((XRef *) uxref->d, (Catalog *) ucatalog->d, + (Object *) uannotsobj->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uxref->pc; + uout->pd = uxref->pd; + return 1; +} + +static int l_new_Array(lua_State * L) +{ + udstruct *uxref, *uout; + uxref = (udstruct *) luaL_checkudata(L, 1, M_XRef); + if (uxref->pd != NULL && uxref->pd->pc != uxref->pc) + pdfdoc_changed_error(L); + uout = new_Array_userdata(L); + uout->d = new Array((XRef *) uxref->d); // automatic init to length 0 + uout->atype = ALLOC_LEPDF; + uout->pc = uxref->pc; + uout->pd = uxref->pd; + return 1; +} + +static int l_new_Dict(lua_State * L) +{ + udstruct *uxref, *uout; + uxref = (udstruct *) luaL_checkudata(L, 1, M_XRef); + if (uxref->pd != NULL && uxref->pd->pc != uxref->pc) + pdfdoc_changed_error(L); + uout = new_Dict_userdata(L); + uout->d = new Dict((XRef *) uxref->d); // automatic init to length 0 + uout->atype = ALLOC_LEPDF; + uout->pc = uxref->pc; + uout->pd = uxref->pd; + return 1; +} + +static int l_new_Object(lua_State * L) +{ + udstruct *uout; + uout = new_Object_userdata(L); + uout->d = new Object(); // automatic init to type "none" + uout->atype = ALLOC_LEPDF; + uout->pc = 0; + uout->pd = NULL; // not connected to any PDFDoc + return 1; +} + +// PDFRectangle see Page.h + +static int l_new_PDFRectangle(lua_State * L) +{ + udstruct *uout; + uout = new_PDFRectangle_userdata(L); + uout->d = new PDFRectangle(); // automatic init to [0, 0, 0, 0] + uout->atype = ALLOC_LEPDF; + uout->pc = 0; + uout->pd = NULL; + return 1; +} + +static const struct luaL_Reg epdflib[] = { + {"open", l_open_PDFDoc}, + {"Annot", l_new_Annot}, + {"Annots", l_new_Annots}, + {"Array", l_new_Array}, + {"Dict", l_new_Dict}, + {"Object", l_new_Object}, + {"PDFRectangle", l_new_PDFRectangle}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** + +#define m_poppler_get_poppler(in, out, function) \ +static int m_##in##_##function(lua_State * L) \ +{ \ + out *o; \ + udstruct *uin, *uout; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + o = ((in *) uin->d)->function(); \ + if (o != NULL) { \ + uout = new_##out##_userdata(L); \ + uout->d = o; \ + uout->pc = uin->pc; \ + uout->pd = uin->pd; \ + } else \ + lua_pushnil(L); \ + return 1; \ +} + +#define m_poppler_get_BOOL(in, function) \ +static int m_##in##_##function(lua_State * L) \ +{ \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + if (((in *) uin->d)->function()) \ + lua_pushboolean(L, 1); \ + else \ + lua_pushboolean(L, 0); \ + return 1; \ +} + +#define m_poppler_get_INT(in, function) \ +static int m_##in##_##function(lua_State * L) \ +{ \ + int i; \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + i = (int) ((in *) uin->d)->function(); \ + lua_pushinteger(L, i); \ + return 1; \ +} + +#define m_poppler_get_DOUBLE(in, function) \ +static int m_##in##_##function(lua_State * L) \ +{ \ + double d; \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + d = (double) ((in *) uin->d)->function(); \ + lua_pushnumber(L, d); \ + return 1; \ +} + +#define m_poppler_get_GOOSTRING(in, function) \ +static int m_##in##_##function(lua_State * L) \ +{ \ + GooString *gs; \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + gs = ((in *) uin->d)->function(); \ + if (gs != NULL) \ + lua_pushlstring(L, gs->getCString(), gs->getLength()); \ + else \ + lua_pushnil(L); \ + return 1; \ +} + +#define m_poppler_get_OBJECT(in, function) \ +static int m_##in##_##function(lua_State * L) \ +{ \ + udstruct *uin, *uout; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + uout = new_Object_userdata(L); \ + uout->d = new Object(); \ + ((in *) uin->d)->function((Object *) uout->d); \ + uout->atype = ALLOC_LEPDF; \ + uout->pc = uin->pc; \ + uout->pd = uin->pd; \ + return 1; \ +} + +#define m_poppler_do(in, function) \ +static int m_##in##_##function(lua_State * L) \ +{ \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + ((in *) uin->d)->function(); \ + return 0; \ +} + +#define m_poppler__tostring(type) \ +static int m_##type##__tostring(lua_State * L) \ +{ \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_##type); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + lua_pushfstring(L, "%s: %p", #type, (type *) uin->d); \ + return 1; \ +} + //********************************************************************** +// Annot + +m_poppler_get_BOOL(Annot, isOk); +m_poppler_get_OBJECT(Annot, getAppearance); +m_poppler_get_poppler(Annot, AnnotBorder, getBorder); -int l_new_pdfdoc(lua_State * L) +static int m_Annot_match(lua_State * L) { - PdfDocument *pdf_doc; - char *file_path; - if (lua_gettop(L) != 1) - luaL_error(L, "epdf.new() needs exactly 1 argument"); - if (!lua_isstring(L, -1)) - luaL_error(L, "epdf.new() needs filename (string)"); - file_path = (char *) lua_tostring(L, -1); + udstruct *uin, *uref; + uin = (udstruct *) luaL_checkudata(L, 1, M_Annot); + uref = (udstruct *) luaL_checkudata(L, 2, M_Ref); + if (uin->pd != NULL && uref->pd != NULL && uin->pd != uref->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uref->pd != NULL && uref->pd->pc != uref->pc)) + pdfdoc_changed_error(L); + lua_pushboolean(L, ((Annot *) uin->d)->match((Ref *) uref->d)); + return 1; +} + +m_poppler__tostring(Annot); - printf("\n======================== 1 <%s>\n", file_path); +static int m_Annot__gc(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Annot); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); +#ifdef DEBUG + printf("\n===== Annot GC ===== uin=<%p>\n", uin); +#endif + if (uin->atype == ALLOC_LEPDF) + delete(Annot *) uin->d; + return 0; +} - pdf_doc = refPdfDocument(file_path); +static const struct luaL_Reg Annot_m[] = { + {"isOk", m_Annot_isOk}, + {"getAppearance", m_Annot_getAppearance}, + {"getBorder", m_Annot_getBorder}, + {"match", m_Annot_match}, + {"__tostring", m_Annot__tostring}, + {"__gc", m_Annot__gc}, + {NULL, NULL} // sentinel +}; +//********************************************************************** +// AnnotBorderStyle + +m_poppler_get_DOUBLE(AnnotBorderStyle, getWidth); + +m_poppler__tostring(AnnotBorderStyle); + +static int m_Annots__gc(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Annots); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); +#ifdef DEBUG + printf("\n===== Annots GC ===== uin=<%p>\n", uin); +#endif + if (uin->atype == ALLOC_LEPDF) + delete(Annots *) uin->d; return 0; } +static const struct luaL_Reg AnnotBorderStyle_m[] = { + {"getWidth", m_AnnotBorderStyle_getWidth}, + {"__tostring", m_AnnotBorderStyle__tostring}, + {"__gc", m_Annots__gc}, + {NULL, NULL} // sentinel +}; + //********************************************************************** +// Annots -static const struct luaL_Reg epdflib[] = { - // {"new", l_new_pdfdoc}, - {NULL, NULL} /* sentinel */ +m_poppler_get_INT(Annots, getNumAnnots); + +static int m_Annots_getAnnot(lua_State * L) +{ + int i, annots; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Annots); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + annots = ((Annots *) uin->d)->getNumAnnots(); + if (i > 0 && i <= annots) { + uout = new_Annot_userdata(L); + uout->d = ((Annots *) uin->d)->getAnnot(i); + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +m_poppler__tostring(Annots); + +static const struct luaL_Reg Annots_m[] = { + {"getNumAnnots", m_Annots_getNumAnnots}, + {"getAnnot", m_Annots_getAnnot}, + {"__tostring", m_Annots__tostring}, + {NULL, NULL} // sentinel }; -int luaopen_epdf(lua_State * L) +//********************************************************************** +// Array + +static int m_Array_incRef(lua_State * L) { - luaL_register(L, "epdf", epdflib); + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Array); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = ((Array *) uin->d)->incRef(); + lua_pushinteger(L, i); + return 1; +} + +static int m_Array_decRef(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Array); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = ((Array *) uin->d)->decRef(); + lua_pushinteger(L, i); + return 1; +} + +m_poppler_get_INT(Array, getLength); + +static int m_Array_add(lua_State * L) +{ + udstruct *uin, *uobj; + uin = (udstruct *) luaL_checkudata(L, 1, M_Array); + uobj = (udstruct *) luaL_checkudata(L, 2, M_Object); + if (uin->pd != NULL && uobj->pd != NULL && uin->pd != uobj->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uobj->pd != NULL && uobj->pd->pc != uobj->pc)) + pdfdoc_changed_error(L); + ((Array *) uin->d)->add(((Object *) uobj->d)); + return 0; +} + +static int m_Array_get(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Array); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Array *) uin->d)->getLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Array *) uin->d)->get(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Array_getNF(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Array); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Array *) uin->d)->getLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Array *) uin->d)->getNF(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Array_getString(lua_State * L) +{ + GooString *gs; + int i, len; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Array); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Array *) uin->d)->getLength(); + if (i > 0 && i <= len) { + gs = new GooString(); + if (((Array *) uin->d)->getString(i - 1, gs)) + lua_pushlstring(L, gs->getCString(), gs->getLength()); + else + lua_pushnil(L); + delete gs; + } else + lua_pushnil(L); + return 1; +} + +m_poppler__tostring(Array); + +static const struct luaL_Reg Array_m[] = { + {"incRef", m_Array_incRef}, + {"decRef", m_Array_decRef}, + {"getLength", m_Array_getLength}, + {"add", m_Array_add}, + {"get", m_Array_get}, + {"getNF", m_Array_getNF}, + {"getString", m_Array_getString}, + {"__tostring", m_Array__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// Catalog + +m_poppler_get_BOOL(Catalog, isOk); +m_poppler_get_INT(Catalog, getNumPages); + +static int m_Catalog_getPage(lua_State * L) +{ + int i, pages; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + pages = ((Catalog *) uin->d)->getNumPages(); + if (i > 0 && i <= pages) { + uout = new_Page_userdata(L); + uout->d = ((Catalog *) uin->d)->getPage(i); + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Catalog_getPageRef(lua_State * L) +{ + int i, pages; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + pages = ((Catalog *) uin->d)->getNumPages(); + if (i > 0 && i <= pages) { + uout = new_Ref_userdata(L); + uout->d = (Ref *) gmalloc(sizeof(Ref)); + ((Ref *) uout->d)->num = ((Catalog *) uin->d)->getPageRef(i)->num; + ((Ref *) uout->d)->gen = ((Catalog *) uin->d)->getPageRef(i)->gen; + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +m_poppler_get_GOOSTRING(Catalog, getBaseURI); +m_poppler_get_GOOSTRING(Catalog, readMetadata); +m_poppler_get_poppler(Catalog, Object, getStructTreeRoot); + +static int m_Catalog_findPage(lua_State * L) +{ + int num, gen, i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + num = luaL_checkint(L, 2); + gen = luaL_checkint(L, 3); + i = ((Catalog *) uin->d)->findPage(num, gen); + if (i > 0) + lua_pushinteger(L, i); + else + lua_pushnil(L); + return 1; +} + +static int m_Catalog_findDest(lua_State * L) +{ + GooString *name; + LinkDest *dest; + const char *s; + size_t len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checklstring(L, 2, &len); + name = new GooString(s, len); + dest = ((Catalog *) uin->d)->findDest(name); + if (dest != NULL) { + uout = new_LinkDest_userdata(L); + uout->d = dest; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + delete name; + return 1; +} + +m_poppler_get_poppler(Catalog, Object, getDests); +m_poppler_get_INT(Catalog, numEmbeddedFiles); + +static int m_Catalog_embeddedFile(lua_State * L) +{ + EmbFile *ef; + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Catalog *) uin->d)->numEmbeddedFiles(); + if (i > 0 && i <= len) { + ef = ((Catalog *) uin->d)->embeddedFile(i - 1); + if (ef != NULL) { + uout = new_EmbFile_userdata(L); + uout->d = ef; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +m_poppler_get_INT(Catalog, numJS); + +static int m_Catalog_getJS(lua_State * L) +{ + GooString *gs; + int i, len; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Catalog *) uin->d)->numJS(); + if (i > 0 && i <= len) { + gs = ((Catalog *) uin->d)->getJS(i - 1); + if (gs != NULL) + lua_pushlstring(L, gs->getCString(), gs->getLength()); + else + lua_pushnil(L); + delete gs; + } else + lua_pushnil(L); + return 1; +} + +m_poppler_get_poppler(Catalog, Object, getOutline); +m_poppler_get_poppler(Catalog, Object, getAcroForm); + +m_poppler__tostring(Catalog); + +static const struct luaL_Reg Catalog_m[] = { + {"isOk", m_Catalog_isOk}, + {"getNumPages", m_Catalog_getNumPages}, + {"getPage", m_Catalog_getPage}, + {"getPageRef", m_Catalog_getPageRef}, + {"getBaseURI", m_Catalog_getBaseURI}, + {"readMetadata", m_Catalog_readMetadata}, + {"getStructTreeRoot", m_Catalog_getStructTreeRoot}, + {"findPage", m_Catalog_findPage}, + {"findDest", m_Catalog_findDest}, + {"getDests", m_Catalog_getDests}, + {"numEmbeddedFiles", m_Catalog_numEmbeddedFiles}, + {"embeddedFile", m_Catalog_embeddedFile}, + {"numJS", m_Catalog_numJS}, + {"getJS", m_Catalog_getJS}, + {"getOutline", m_Catalog_getOutline}, + {"getAcroForm", m_Catalog_getAcroForm}, + {"__tostring", m_Catalog__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// EmbFile + +m_poppler_get_GOOSTRING(EmbFile, name); +m_poppler_get_GOOSTRING(EmbFile, description); +m_poppler_get_INT(EmbFile, size); +m_poppler_get_GOOSTRING(EmbFile, modDate); +m_poppler_get_GOOSTRING(EmbFile, createDate); +m_poppler_get_GOOSTRING(EmbFile, checksum); +m_poppler_get_GOOSTRING(EmbFile, mimeType); + +static int m_EmbFile_streamObject(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_EmbFile); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + uout = new_Object_userdata(L); + uout->d = new Object(); // automatic init to type "none" + ((EmbFile *) uin->d)->streamObject().copy((Object *) uout->d); + uout->pc = uin->pc; + uout->pd = uin->pd; + return 1; +} + +m_poppler_get_BOOL(EmbFile, isOk); + +m_poppler__tostring(EmbFile); + +static const struct luaL_Reg EmbFile_m[] = { + {"name", m_EmbFile_name}, + {"description", m_EmbFile_description}, + {"size", m_EmbFile_size}, + {"modDate", m_EmbFile_modDate}, + {"createDate", m_EmbFile_createDate}, + {"checksum", m_EmbFile_checksum}, + {"mimeType", m_EmbFile_mimeType}, + {"streamObject", m_EmbFile_streamObject}, + {"isOk", m_EmbFile_isOk}, + {"__tostring", m_EmbFile__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// Dict + +static int m_Dict_incRef(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = ((Dict *) uin->d)->incRef(); + lua_pushinteger(L, i); + return 1; +} + +static int m_Dict_decRef(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = ((Dict *) uin->d)->decRef(); + lua_pushinteger(L, i); + return 1; +} + +m_poppler_get_INT(Dict, getLength); + +static int m_Dict_add(lua_State * L) +{ + char *s; + udstruct *uin, *uobj; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = copyString((char *) luaL_checkstring(L, 2)); + uobj = (udstruct *) luaL_checkudata(L, 3, M_Object); + ((Dict *) uin->d)->add(s, ((Object *) uobj->d)); + return 0; +} + +static int m_Dict_set(lua_State * L) +{ + char *s; + udstruct *uin, *uobj; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = (char *) luaL_checkstring(L, 2); + uobj = (udstruct *) luaL_checkudata(L, 3, M_Object); + ((Dict *) uin->d)->set(s, ((Object *) uobj->d)); + return 0; +} + +static int m_Dict_remove(lua_State * L) +{ + char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = (char *) luaL_checkstring(L, 2); + ((Dict *) uin->d)->remove(s); + return 0; +} + +static int m_Dict_is(lua_State * L) +{ + const char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + if (((Dict *) uin->d)->is((char *) s)) + lua_pushboolean(L, 1); + else + lua_pushboolean(L, 0); + return 1; +} + +static int m_Dict_lookup(lua_State * L) +{ + const char *s; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Dict *) uin->d)->lookup((char *) s, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + return 1; +} + +static int m_Dict_lookupNF(lua_State * L) +{ + const char *s; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Dict *) uin->d)->lookupNF((char *) s, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + return 1; +} + +static int m_Dict_lookupInt(lua_State * L) +{ + const char *s1, *s2; + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s1 = luaL_checkstring(L, 2); + s2 = luaL_checkstring(L, 3); + if (((Dict *) uin->d)->lookupInt(s1, s2, &i)) + lua_pushinteger(L, i); + else + lua_pushnil(L); + return 1; +} + +static int m_Dict_getKey(lua_State * L) +{ + int i, len; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Dict *) uin->d)->getLength(); + if (i > 0 && i <= len) + lua_pushstring(L, ((Dict *) uin->d)->getKey(i - 1)); + else + lua_pushnil(L); + return 1; +} + +static int m_Dict_getVal(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Dict *) uin->d)->getLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Dict *) uin->d)->getVal(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Dict_getValNF(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Dict); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + len = ((Dict *) uin->d)->getLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Dict *) uin->d)->getValNF(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +m_poppler__tostring(Dict); + +static const struct luaL_Reg Dict_m[] = { + {"incRef", m_Dict_incRef}, + {"decRef", m_Dict_decRef}, + {"getLength", m_Dict_getLength}, + {"add", m_Dict_add}, + {"set", m_Dict_set}, + {"remove", m_Dict_remove}, + {"is", m_Dict_is}, + {"lookup", m_Dict_lookup}, + {"lookupNF", m_Dict_lookupNF}, + {"lookupInt", m_Dict_lookupInt}, + {"getKey", m_Dict_getKey}, + {"getVal", m_Dict_getVal}, + {"getValNF", m_Dict_getValNF}, + {"__tostring", m_Dict__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// GooString + +static int m_GooString__tostring(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_GooString); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + lua_pushlstring(L, ((GooString *) uin->d)->getCString(), + ((GooString *) uin->d)->getLength()); + return 1; +} + +static const struct luaL_Reg GooString_m[] = { + {"__tostring", m_GooString__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// LinkDest + +static const char *LinkDestKindNames[] = + { "XYZ", "Fit", "FitH", "FitV", "FitR", "FitB", "FitBH", "FitBV", NULL }; + +m_poppler_get_BOOL(LinkDest, isOk); + +static int m_LinkDest_getKind(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_LinkDest); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = (int) ((LinkDest *) uin->d)->getKind(); + lua_pushinteger(L, i); + return 1; +} + +static int m_LinkDest_getKindName(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_LinkDest); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = (int) ((LinkDest *) uin->d)->getKind(); + lua_pushstring(L, LinkDestKindNames[i]); + return 1; +} + +m_poppler_get_BOOL(LinkDest, isPageRef); +m_poppler_get_INT(LinkDest, getPageNum); + +static int m_LinkDest_getPageRef(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_LinkDest); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + uout = new_Ref_userdata(L); + uout->d = (Ref *) gmalloc(sizeof(Ref)); + ((Ref *) uout->d)->num = ((LinkDest *) uin->d)->getPageRef().num; + ((Ref *) uout->d)->gen = ((LinkDest *) uin->d)->getPageRef().gen; + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + return 1; +} + +m_poppler_get_DOUBLE(LinkDest, getLeft); +m_poppler_get_DOUBLE(LinkDest, getBottom); +m_poppler_get_DOUBLE(LinkDest, getRight); +m_poppler_get_DOUBLE(LinkDest, getTop); +m_poppler_get_DOUBLE(LinkDest, getZoom); +m_poppler_get_BOOL(LinkDest, getChangeLeft); +m_poppler_get_BOOL(LinkDest, getChangeTop); +m_poppler_get_BOOL(LinkDest, getChangeZoom); + +m_poppler__tostring(LinkDest); + +static const struct luaL_Reg LinkDest_m[] = { + {"isOk", m_LinkDest_isOk}, + {"getKind", m_LinkDest_getKind}, + {"getKindName", m_LinkDest_getKindName}, // not poppler + {"isPageRef", m_LinkDest_isPageRef}, + {"getPageNum", m_LinkDest_getPageNum}, + {"getPageRef", m_LinkDest_getPageRef}, + {"getLeft", m_LinkDest_getLeft}, + {"getBottom", m_LinkDest_getBottom}, + {"getRight", m_LinkDest_getRight}, + {"getTop", m_LinkDest_getTop}, + {"getZoom", m_LinkDest_getZoom}, + {"getChangeLeft", m_LinkDest_getChangeLeft}, + {"getChangeTop", m_LinkDest_getChangeTop}, + {"getChangeZoom", m_LinkDest_getChangeZoom}, + {"__tostring", m_LinkDest__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// Links + +m_poppler__tostring(Links); + +static const struct luaL_Reg Links_m[] = { + {"__tostring", m_Links__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// Object + +// Special type checking. +#define m_Object_isType(function) \ +static int m_Object_##function(lua_State * L) \ +{ \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + if (lua_gettop(L) >= 2) { \ + if (lua_isstring(L, 2) \ + && ((Object *) uin->d)->function((char *) lua_tostring(L, 2))) \ + lua_pushboolean(L, 1); \ + else \ + lua_pushboolean(L, 0); \ + } else { \ + if (((Object *) uin->d)->function()) \ + lua_pushboolean(L, 1); \ + else \ + lua_pushboolean(L, 0); \ + } \ + return 1; \ +} + +static int m_Object_initBool(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + luaL_checktype(L, 2, LUA_TBOOLEAN); + if (lua_toboolean(L, 2) != 0) + ((Object *) uin->d)->initBool(gTrue); + else + ((Object *) uin->d)->initBool(gFalse); + return 0; +} + +static int m_Object_initInt(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + ((Object *) uin->d)->initInt(i); + return 0; +} + +static int m_Object_initReal(lua_State * L) +{ + double d; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + d = luaL_checknumber(L, 2); + ((Object *) uin->d)->initReal(d); + return 0; +} + +static int m_Object_initString(lua_State * L) +{ + GooString *gs; + const char *s; + size_t len; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checklstring(L, 2, &len); + gs = new GooString(s, len); + ((Object *) uin->d)->initString(gs); + return 0; +} + +static int m_Object_initName(lua_State * L) +{ + const char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + ((Object *) uin->d)->initName((char *) s); + return 0; +} + +static int m_Object_initNull(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + ((Object *) uin->d)->initNull(); + return 0; +} + +static int m_Object_initArray(lua_State * L) +{ + udstruct *uin, *uxref; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef); + if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uxref->pd != NULL && uxref->pd->pc != uxref->pc)) + pdfdoc_changed_error(L); + ((Object *) uin->d)->initArray((XRef *) uxref->d); + return 0; +} + +// TODO: decide betweeen +// Object *initDict(XRef *xref); +// Object *initDict(Dict *dictA); + +static int m_Object_initDict(lua_State * L) +{ + udstruct *uin, *uxref; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef); + if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uxref->pd != NULL && uxref->pd->pc != uxref->pc)) + pdfdoc_changed_error(L); + ((Object *) uin->d)->initDict((XRef *) uxref->d); + return 0; +} + +static int m_Object_initStream(lua_State * L) +{ + udstruct *uin, *ustream; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + ustream = (udstruct *) luaL_checkudata(L, 2, M_Stream); + if (uin->pd != NULL && ustream->pd != NULL && uin->pd != ustream->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (ustream->pd != NULL && ustream->pd->pc != ustream->pc)) + pdfdoc_changed_error(L); + ((Object *) uin->d)->initStream((Stream *) ustream->d); + return 0; +} + +static int m_Object_initRef(lua_State * L) +{ + int num, gen; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + num = luaL_checkint(L, 2); + gen = luaL_checkint(L, 3); + ((Object *) uin->d)->initRef(num, gen); + return 0; +} + +static int m_Object_initCmd(lua_State * L) +{ + const char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + ((Object *) uin->d)->initCmd((char *) s); + return 0; +} + +static int m_Object_initError(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + ((Object *) uin->d)->initError(); + return 0; +} + +static int m_Object_initEOF(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + ((Object *) uin->d)->initEOF(); + return 0; +} + +static int m_Object_fetch(lua_State * L) +{ + udstruct *uin, *uxref, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef); + if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uxref->pd != NULL && uxref->pd->pc != uxref->pc)) + pdfdoc_changed_error(L); + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Object *) uin->d)->fetch((XRef *) uxref->d, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + return 1; +} + +static int m_Object_getType(lua_State * L) +{ + ObjType t; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + t = ((Object *) uin->d)->getType(); + lua_pushinteger(L, (int) t); + return 1; +} + +static int m_Object_getTypeName(lua_State * L) +{ + char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = ((Object *) uin->d)->getTypeName(); + lua_pushstring(L, s); + return 1; +} + +m_poppler_get_BOOL(Object, isBool); +m_poppler_get_BOOL(Object, isInt); +m_poppler_get_BOOL(Object, isReal); +m_poppler_get_BOOL(Object, isNum); +m_poppler_get_BOOL(Object, isString); +m_Object_isType(isName); +m_poppler_get_BOOL(Object, isNull); +m_poppler_get_BOOL(Object, isArray); +m_Object_isType(isDict); +m_Object_isType(isStream); +m_poppler_get_BOOL(Object, isRef); +m_Object_isType(isCmd); +m_poppler_get_BOOL(Object, isError); +m_poppler_get_BOOL(Object, isEOF); +m_poppler_get_BOOL(Object, isNone); + +static int m_Object_getBool(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isBool()) { + if (((Object *) uin->d)->getBool()) + lua_pushboolean(L, 1); + else + lua_pushboolean(L, 0); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getInt(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isInt()) + lua_pushnumber(L, ((Object *) uin->d)->getInt()); + else + lua_pushnil(L); + return 1; +} + +static int m_Object_getReal(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isReal()) + lua_pushnumber(L, ((Object *) uin->d)->getReal()); + else + lua_pushnil(L); + return 1; +} + +static int m_Object_getNum(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isNum()) + lua_pushnumber(L, ((Object *) uin->d)->getNum()); + else + lua_pushnil(L); + return 1; +} + +static int m_Object_getString(lua_State * L) +{ + GooString *gs; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isString()) { + gs = ((Object *) uin->d)->getString(); + lua_pushlstring(L, gs->getCString(), gs->getLength()); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getName(lua_State * L) +{ + char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isName()) { + s = ((Object *) uin->d)->getName(); + lua_pushstring(L, s); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getArray(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isArray()) { + uout = new_Array_userdata(L); + uout->d = ((Object *) uin->d)->getArray(); + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getDict(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isDict()) { + uout = new_Dict_userdata(L); + uout->d = ((Object *) uin->d)->getDict(); + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getStream(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isStream()) { + uout = new_Stream_userdata(L); + uout->d = ((Object *) uin->d)->getStream(); + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getRef(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isRef()) { + uout = new_Ref_userdata(L); + uout->d = (Ref *) gmalloc(sizeof(Ref)); + ((Ref *) uout->d)->num = ((Object *) uin->d)->getRef().num; + ((Ref *) uout->d)->gen = ((Object *) uin->d)->getRef().gen; + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getRefNum(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isRef()) { + i = ((Object *) uin->d)->getRef().num; + lua_pushinteger(L, i); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getRefGen(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isRef()) { + i = ((Object *) uin->d)->getRef().gen; + lua_pushinteger(L, i); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_getCmd(lua_State * L) +{ + char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isCmd()) { + s = ((Object *) uin->d)->getCmd(); + lua_pushstring(L, s); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_arrayGetLength(lua_State * L) +{ + int len; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isArray()) { + len = ((Object *) uin->d)->arrayGetLength(); + lua_pushnumber(L, len); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_arrayAdd(lua_State * L) +{ + udstruct *uin, *uobj; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + uobj = (udstruct *) luaL_checkudata(L, 2, M_Object); + if (uin->pd != NULL && uobj->pd != NULL && uin->pd != uobj->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uobj->pd != NULL && uobj->pd->pc != uobj->pd->pc)) + pdfdoc_changed_error(L); + if (!((Object *) uin->d)->isArray()) + luaL_error(L, "Object is not an Array"); + ((Object *) uin->d)->arrayAdd((Object *) uobj->d); + return 0; +} + +static int m_Object_arrayGet(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + if (((Object *) uin->d)->isArray()) { + len = ((Object *) uin->d)->arrayGetLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Object *) uin->d)->arrayGet(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_arrayGetNF(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + if (((Object *) uin->d)->isArray()) { + len = ((Object *) uin->d)->arrayGetLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Object *) uin->d)->arrayGetNF(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_dictGetLength(lua_State * L) +{ + int len; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isDict()) { + len = ((Object *) uin->d)->dictGetLength(); + lua_pushnumber(L, len); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_dictAdd(lua_State * L) +{ + const char *s; + udstruct *uin, *uobj; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + s = luaL_checkstring(L, 2); + uobj = (udstruct *) luaL_checkudata(L, 3, M_Object); + if (uin->pd != NULL && uobj->pd != NULL && uin->pd != uobj->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uobj->pd != NULL && uobj->pd->pc != uobj->pd->pc)) + pdfdoc_changed_error(L); + if (!((Object *) uin->d)->isDict()) + luaL_error(L, "Object is not a Dict"); + ((Object *) uin->d)->dictAdd((char *) s, (Object *) uobj->d); + return 0; +} + +static int m_Object_dictSet(lua_State * L) +{ + const char *s; + udstruct *uin, *uobj; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + s = luaL_checkstring(L, 2); + uobj = (udstruct *) luaL_checkudata(L, 3, M_Object); + if (uin->pd != NULL && uobj->pd != NULL && uin->pd != uobj->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (uobj->pd != NULL && uobj->pd->pc != uobj->pd->pc)) + pdfdoc_changed_error(L); + if (!((Object *) uin->d)->isDict()) + luaL_error(L, "Object is not a Dict"); + ((Object *) uin->d)->dictSet((char *) s, (Object *) uobj->d); + return 0; +} + +static int m_Object_dictLookup(lua_State * L) +{ + const char *s; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + if (((Object *) uin->d)->isDict()) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Object *) uin->d)->dictLookup((char *) s, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_dictLookupNF(lua_State * L) +{ + const char *s; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + if (((Object *) uin->d)->isDict()) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Object *) uin->d)->dictLookupNF((char *) s, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_dictGetKey(lua_State * L) +{ + int i, len; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + if (((Object *) uin->d)->isDict()) { + len = ((Object *) uin->d)->dictGetLength(); + if (i > 0 && i <= len) + lua_pushstring(L, ((Object *) uin->d)->dictGetKey(i - 1)); + else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_dictGetVal(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + if (((Object *) uin->d)->isDict()) { + len = ((Object *) uin->d)->dictGetLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Object *) uin->d)->dictGetVal(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_dictGetValNF(lua_State * L) +{ + int i, len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + if (((Object *) uin->d)->isDict()) { + len = ((Object *) uin->d)->dictGetLength(); + if (i > 0 && i <= len) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((Object *) uin->d)->dictGetValNF(i - 1, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_streamIs(lua_State * L) +{ + const char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + if (((Object *) uin->d)->isStream()) { + if (((Object *) uin->d)->streamIs((char *) s)) + lua_pushboolean(L, 1); + else + lua_pushboolean(L, 0); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_streamReset(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isStream()) + ((Object *) uin->d)->streamReset(); + return 0; +} + +static int m_Object_streamGetChar(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isStream()) { + i = ((Object *) uin->d)->streamGetChar(); + lua_pushinteger(L, i); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_streamLookChar(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isStream()) { + i = ((Object *) uin->d)->streamLookChar(); + lua_pushinteger(L, i); + } else + lua_pushnil(L); return 1; } +static int m_Object_streamGetPos(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isStream()) { + i = (int) ((Object *) uin->d)->streamGetPos(); + lua_pushinteger(L, i); + } else + lua_pushnil(L); + return 1; +} + +static int m_Object_streamSetPos(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + if (((Object *) uin->d)->isStream()) + ((Object *) uin->d)->streamSetPos(i); + return 0; +} + +static int m_Object_streamGetDict(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((Object *) uin->d)->isStream()) { + uout = new_Dict_userdata(L); + uout->d = ((Object *) uin->d)->streamGetDict(); + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_Object__gc(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Object); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); +#ifdef DEBUG + printf("\n===== Object GC ===== uin=<%p>\n", uin); +#endif + if (uin->atype == ALLOC_LEPDF) + delete(Object *) uin->d; + return 0; +} + +m_poppler__tostring(Object); + +static const struct luaL_Reg Object_m[] = { + {"initBool", m_Object_initBool}, + {"initInt", m_Object_initInt}, + {"initReal", m_Object_initReal}, + {"initString", m_Object_initString}, + {"initName", m_Object_initName}, + {"initNull", m_Object_initNull}, + {"initArray", m_Object_initArray}, + {"initDict", m_Object_initDict}, + {"initStream", m_Object_initStream}, + {"initRef", m_Object_initRef}, + {"initCmd", m_Object_initCmd}, + {"initError", m_Object_initError}, + {"initEOF", m_Object_initEOF}, + // {"copy", m_Object_copy}, + {"fetch", m_Object_fetch}, + {"getType", m_Object_getType}, + {"getTypeName", m_Object_getTypeName}, + {"isBool", m_Object_isBool}, + {"isInt", m_Object_isInt}, + {"isReal", m_Object_isReal}, + {"isNum", m_Object_isNum}, + {"isString", m_Object_isString}, + {"isName", m_Object_isName}, + {"isNull", m_Object_isNull}, + {"isArray", m_Object_isArray}, + {"isDict", m_Object_isDict}, + {"isStream", m_Object_isStream}, + {"isRef", m_Object_isRef}, + {"isCmd", m_Object_isCmd}, + {"isError", m_Object_isError}, + {"isEOF", m_Object_isEOF}, + {"isNone", m_Object_isNone}, + {"getBool", m_Object_getBool}, + {"getInt", m_Object_getInt}, + {"getReal", m_Object_getReal}, + {"getNum", m_Object_getNum}, + {"getString", m_Object_getString}, + {"getName", m_Object_getName}, + {"getArray", m_Object_getArray}, + {"getDict", m_Object_getDict}, + {"getStream", m_Object_getStream}, + {"getRef", m_Object_getRef}, + {"getRefNum", m_Object_getRefNum}, + {"getRefGen", m_Object_getRefGen}, + {"getCmd", m_Object_getCmd}, + {"arrayGetLength", m_Object_arrayGetLength}, + {"arrayAdd", m_Object_arrayAdd}, + {"arrayGet", m_Object_arrayGet}, + {"arrayGetNF", m_Object_arrayGetNF}, + {"dictGetLength", m_Object_dictGetLength}, + {"dictAdd", m_Object_dictAdd}, + {"dictSet", m_Object_dictSet}, + {"dictLookup", m_Object_dictLookup}, + {"dictLookupNF", m_Object_dictLookupNF}, + {"dictGetKey", m_Object_dictGetKey}, + {"dictGetVal", m_Object_dictGetVal}, + {"dictGetValNF", m_Object_dictGetValNF}, + {"streamIs", m_Object_streamIs}, + {"streamReset", m_Object_streamReset}, + // {"streamClose", m_Object_streamClose}, + {"streamGetChar", m_Object_streamGetChar}, + {"streamLookChar", m_Object_streamLookChar}, + // {"streamGetLine", m_Object_streamGetLine}, + {"streamGetPos", m_Object_streamGetPos}, + {"streamSetPos", m_Object_streamSetPos}, + {"streamGetDict", m_Object_streamGetDict}, + {"__tostring", m_Object__tostring}, + {"__gc", m_Object__gc}, // finalizer + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// Page + +m_poppler_get_BOOL(Page, isOk); +m_poppler_get_INT(Page, getNum); +m_poppler_get_poppler(Page, PDFRectangle, getMediaBox); +m_poppler_get_poppler(Page, PDFRectangle, getCropBox); +m_poppler_get_BOOL(Page, isCropped); +m_poppler_get_DOUBLE(Page, getMediaWidth); +m_poppler_get_DOUBLE(Page, getMediaHeight); +m_poppler_get_DOUBLE(Page, getCropWidth); +m_poppler_get_DOUBLE(Page, getCropHeight); +m_poppler_get_poppler(Page, PDFRectangle, getBleedBox); +m_poppler_get_poppler(Page, PDFRectangle, getTrimBox); +m_poppler_get_poppler(Page, PDFRectangle, getArtBox); +m_poppler_get_INT(Page, getRotate); +m_poppler_get_GOOSTRING(Page, getLastModified); +m_poppler_get_poppler(Page, Dict, getBoxColorInfo); +m_poppler_get_poppler(Page, Dict, getGroup); +m_poppler_get_poppler(Page, Stream, getMetadata); +m_poppler_get_poppler(Page, Dict, getPieceInfo); +m_poppler_get_poppler(Page, Dict, getSeparationInfo); +m_poppler_get_poppler(Page, Dict, getResourceDict); +m_poppler_get_OBJECT(Page, getAnnots); + +static int m_Page_getLinks(lua_State * L) +{ + Links *links; + udstruct *uin, *ucat, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_Page); + ucat = (udstruct *) luaL_checkudata(L, 2, M_Catalog); + if (uin->pd != NULL && ucat->pd != NULL && uin->pd != ucat->pd) + pdfdoc_differs_error(L); + if ((uin->pd != NULL && uin->pd->pc != uin->pc) + || (ucat->pd != NULL && ucat->pd->pc != ucat->pd->pc)) + pdfdoc_changed_error(L); + links = ((Page *) uin->d)->getLinks((Catalog *) ucat->d); + if (links != NULL) { + uout = new_Links_userdata(L); + uout->d = links; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +m_poppler_get_OBJECT(Page, getContents); + +m_poppler__tostring(Page); + +static const struct luaL_Reg Page_m[] = { + {"isOk", m_Page_isOk}, + {"getNum", m_Page_getNum}, + {"getMediaBox", m_Page_getMediaBox}, + {"getCropBox", m_Page_getCropBox}, + {"isCropped", m_Page_isCropped}, + {"getMediaWidth", m_Page_getMediaWidth}, + {"getMediaHeight", m_Page_getMediaHeight}, + {"getCropWidth", m_Page_getCropWidth}, + {"getCropHeight", m_Page_getCropHeight}, + {"getBleedBox", m_Page_getBleedBox}, + {"getTrimBox", m_Page_getTrimBox}, + {"getArtBox", m_Page_getArtBox}, + {"getRotate", m_Page_getRotate}, + {"getLastModified", m_Page_getLastModified}, + {"getBoxColorInfo", m_Page_getBoxColorInfo}, + {"getGroup", m_Page_getGroup}, + {"getMetadata", m_Page_getMetadata}, + {"getPieceInfo", m_Page_getPieceInfo}, + {"getSeparationInfo", m_Page_getSeparationInfo}, + {"getResourceDict", m_Page_getResourceDict}, + {"getAnnots", m_Page_getAnnots}, + {"getLinks", m_Page_getLinks}, + {"getContents", m_Page_getContents}, + {"__tostring", m_Page__tostring}, + {NULL, NULL} // sentinel +}; + //********************************************************************** +// PDFDoc + +#define m_PDFDoc_BOOL(function) \ +static int m_PDFDoc_##function(lua_State * L) \ +{ \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + if (((PdfDocument *) uin->d)->doc->function()) \ + lua_pushboolean(L, 1); \ + else \ + lua_pushboolean(L, 0); \ + return 1; \ +} + +#define m_PDFDoc_INT(function) \ +static int m_PDFDoc_##function(lua_State * L) \ +{ \ + int i; \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + i = ((PdfDocument *) uin->d)->doc->function(); \ + lua_pushinteger(L, i); \ + return 1; \ +} + +m_PDFDoc_BOOL(isOk); +m_PDFDoc_INT(getErrorCode); + +static int m_PDFDoc_getFileName(lua_State * L) +{ + GooString *gs; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + gs = ((PdfDocument *) uin->d)->doc->getFileName(); + if (gs != NULL) + lua_pushlstring(L, gs->getCString(), gs->getLength()); + else + lua_pushnil(L); + return 1; +} + +static int m_PDFDoc_getErrorCodeName(lua_State * L) +{ + int i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = ((PdfDocument *) uin->d)->doc->getErrorCode(); + lua_pushstring(L, ErrorCodeNames[i]); + return 1; +} + +static int m_PDFDoc_getXRef(lua_State * L) +{ + XRef *xref; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + xref = ((PdfDocument *) uin->d)->doc->getXRef(); + if (xref->isOk()) { + uout = new_XRef_userdata(L); + uout->d = xref; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_PDFDoc_getCatalog(lua_State * L) +{ + Catalog *cat; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + cat = ((PdfDocument *) uin->d)->doc->getCatalog(); + if (cat->isOk()) { + uout = new_Catalog_userdata(L); + uout->d = cat; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +#define m_PDFDoc_PAGEDIMEN(function) \ +static int m_PDFDoc_##function(lua_State * L) \ +{ \ + int i, pages; \ + double d; \ + udstruct *uin; \ + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); \ + if (uin->pd != NULL && uin->pd->pc != uin->pc) \ + pdfdoc_changed_error(L); \ + i = luaL_checkint(L, 2); \ + pages = ((PdfDocument *) uin->d)->doc->getNumPages(); \ + if (i > 0 && i <= pages) { \ + d = (double) ((PdfDocument *) uin->d)->doc->function(i); \ + lua_pushnumber(L, d); \ + } else \ + lua_pushnil(L); \ + return 1; \ +} + +m_PDFDoc_PAGEDIMEN(getPageMediaWidth); +m_PDFDoc_PAGEDIMEN(getPageMediaHeight); +m_PDFDoc_PAGEDIMEN(getPageCropWidth); +m_PDFDoc_PAGEDIMEN(getPageCropHeight); +m_PDFDoc_INT(getNumPages); + +static int m_PDFDoc_readMetadata(lua_State * L) +{ + GooString *gs; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) { + gs = ((PdfDocument *) uin->d)->doc->readMetadata(); + if (gs != NULL) + lua_pushlstring(L, gs->getCString(), gs->getLength()); + else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_PDFDoc_getStructTreeRoot(lua_State * L) +{ + Object *obj; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) { + obj = ((PdfDocument *) uin->d)->doc->getStructTreeRoot(); + uout = new_Object_userdata(L); + uout->d = obj; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_PDFDoc_findPage(lua_State * L) +{ + int num, gen, i; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + num = luaL_checkint(L, 2); + gen = luaL_checkint(L, 3); + if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) { + i = ((PdfDocument *) uin->d)->doc->findPage(num, gen); + if (i > 0) + lua_pushinteger(L, i); + else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_PDFDoc_getLinks(lua_State * L) +{ + int i; + Links *links; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + i = luaL_checkint(L, 2); + links = ((PdfDocument *) uin->d)->doc->getLinks(i); + if (links != NULL) { + uout = new_Links_userdata(L); + uout->d = links; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_PDFDoc_findDest(lua_State * L) +{ + GooString *name; + LinkDest *dest; + const char *s; + size_t len; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checklstring(L, 2, &len); + name = new GooString(s, len); + if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) { + dest = ((PdfDocument *) uin->d)->doc->findDest(name); + if (dest != NULL) { + uout = new_LinkDest_userdata(L); + uout->d = dest; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + } else + lua_pushnil(L); + delete name; + return 1; +} + +m_PDFDoc_BOOL(isEncrypted); +m_PDFDoc_BOOL(okToPrint); +m_PDFDoc_BOOL(okToChange); +m_PDFDoc_BOOL(okToCopy); +m_PDFDoc_BOOL(okToAddNotes); +m_PDFDoc_BOOL(isLinearized); + +static int m_PDFDoc_getDocInfo(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((PdfDocument *) uin->d)->doc->getDocInfo((Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +static int m_PDFDoc_getDocInfoNF(lua_State * L) +{ + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) { + uout = new_Object_userdata(L); + uout->d = new Object(); + ((PdfDocument *) uin->d)->doc->getDocInfoNF((Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + } else + lua_pushnil(L); + return 1; +} + +m_PDFDoc_INT(getPDFMajorVersion); +m_PDFDoc_INT(getPDFMinorVersion); + +static int m_PDFDoc__gc(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); +#ifdef DEBUG + printf("\n===== PDFDoc GC ===== file_path=<%s>\n", + ((PdfDocument *) uin->d)->file_path); +#endif + assert(uin->atype == ALLOC_LEPDF); + unrefPdfDocument(((PdfDocument *) uin->d)->file_path); + return 0; +} + +static const struct luaL_Reg PDFDoc_m[] = { + {"isOk", m_PDFDoc_isOk}, + {"getErrorCode", m_PDFDoc_getErrorCode}, + {"getErrorCodeName", m_PDFDoc_getErrorCodeName}, // not poppler + {"getFileName", m_PDFDoc_getFileName}, + {"getXRef", m_PDFDoc_getXRef}, + {"getCatalog", m_PDFDoc_getCatalog}, + // {"getBaseStream", m_PDFDoc_getBaseStream}, + {"getPageMediaWidth", m_PDFDoc_getPageMediaWidth}, + {"getPageMediaHeight", m_PDFDoc_getPageMediaHeight}, + {"getPageCropWidth", m_PDFDoc_getPageCropWidth}, + {"getPageCropHeight", m_PDFDoc_getPageCropHeight}, + {"getNumPages", m_PDFDoc_getNumPages}, + {"readMetadata", m_PDFDoc_readMetadata}, + {"getStructTreeRoot", m_PDFDoc_getStructTreeRoot}, + {"findPage", m_PDFDoc_findPage}, + {"getLinks", m_PDFDoc_getLinks}, + {"findDest", m_PDFDoc_findDest}, + {"isEncrypted", m_PDFDoc_isEncrypted}, + {"okToPrint", m_PDFDoc_okToPrint}, + {"okToChange", m_PDFDoc_okToChange}, + {"okToCopy", m_PDFDoc_okToCopy}, + {"okToAddNotes", m_PDFDoc_okToAddNotes}, + {"isLinearized", m_PDFDoc_isLinearized}, + {"getDocInfo", m_PDFDoc_getDocInfo}, + {"getDocInfoNF", m_PDFDoc_getDocInfoNF}, + {"getPDFMajorVersion", m_PDFDoc_getPDFMajorVersion}, + {"getPDFMinorVersion", m_PDFDoc_getPDFMinorVersion}, + {"__gc", m_PDFDoc__gc}, // finalizer + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// PDFRectangle + +m_poppler_get_BOOL(PDFRectangle, isValid); + +m_poppler__tostring(PDFRectangle); + +static int m_PDFRectangle__index(lua_State * L) +{ + const char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFRectangle); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + if (strlen(s) == 2) { + if (s[0] == 'x') { + if (s[1] == '1') + lua_pushnumber(L, ((PDFRectangle *) uin->d)->x1); + else if (s[1] == '2') + lua_pushnumber(L, ((PDFRectangle *) uin->d)->x2); + else + lua_pushnil(L); + } else if (s[0] == 'y') { + if (s[1] == '1') + lua_pushnumber(L, ((PDFRectangle *) uin->d)->y1); + else if (s[1] == '2') + lua_pushnumber(L, ((PDFRectangle *) uin->d)->y2); + else + lua_pushnil(L); + } else + lua_pushnil(L); + } else + lua_pushnil(L); + return 1; +} + +static int m_PDFRectangle__newindex(lua_State * L) +{ + double d; + const char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFRectangle); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + d = luaL_checknumber(L, 3); + if (strlen(s) == 2) { + if (s[0] == 'x') { + if (s[1] == '1') + ((PDFRectangle *) uin->d)->x1 = d; + else if (s[1] == '2') + ((PDFRectangle *) uin->d)->x2 = d; + else + luaL_error(L, "wrong PDFRectangle coordinate (%s)", s); + } else if (s[0] == 'y') { + if (s[1] == '1') + ((PDFRectangle *) uin->d)->y1 = d; + else if (s[1] == '2') + ((PDFRectangle *) uin->d)->y2 = d; + } else + luaL_error(L, "wrong PDFRectangle coordinate (%s)", s); + } else + luaL_error(L, "wrong PDFRectangle coordinate (%s)", s); + return 0; +} + +static int m_PDFRectangle__gc(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_PDFRectangle); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); +#ifdef DEBUG + printf("\n===== PDFRectangle GC ===== uin=<%p>\n", uin); +#endif + if (uin->atype == ALLOC_LEPDF) + delete(PDFRectangle *) uin->d; + return 0; +} + +static const struct luaL_Reg PDFRectangle_m[] = { + {"isValid", m_PDFRectangle_isValid}, + {"__index", m_PDFRectangle__index}, + {"__newindex", m_PDFRectangle__newindex}, + {"__tostring", m_PDFRectangle__tostring}, + {"__gc", m_PDFRectangle__gc}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// Ref + +static int m_Ref__index(lua_State * L) +{ + const char *s; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Ref); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + s = luaL_checkstring(L, 2); + if (strcmp(s, "num") == 0) + lua_pushinteger(L, ((Ref *) uin->d)->num); + else if (strcmp(s, "gen") == 0) + lua_pushinteger(L, ((Ref *) uin->d)->gen); + else + lua_pushnil(L); + return 1; +} + +m_poppler__tostring(Ref); + +static int m_Ref__gc(lua_State * L) +{ + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Ref); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); +#ifdef DEBUG + printf("\n===== Ref GC ===== uin=<%p>\n", uin); +#endif + if (uin->atype == ALLOC_LEPDF && ((Ref *) uin->d) != NULL) + gfree(((Ref *) uin->d)); + return 0; +} + +static const struct luaL_Reg Ref_m[] = { + {"__index", m_Ref__index}, + {"__tostring", m_Ref__tostring}, + {"__gc", m_Ref__gc}, // finalizer + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// Stream + +static const char *StreamKindNames[] = + { "File", "ASCIIHex", "ASCII85", "LZW", "RunLength", "CCITTFax", "DCT", + "Flate", "JBIG2", "JPX", "Weird", NULL +}; + +#if 0 +static const char *StreamColorSpaceModeNames[] = + { "CSNone", "CSDeviceGray", "CSDeviceRGB", "CSDeviceCMYK", NULL }; +#endif + +m_poppler_get_INT(Stream, getKind); + +static int m_Stream_getKindName(lua_State * L) +{ + StreamKind t; + udstruct *uin; + uin = (udstruct *) luaL_checkudata(L, 1, M_Stream); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + t = ((Stream *) uin->d)->getKind(); + lua_pushstring(L, StreamKindNames[t]); + return 1; +} + +m_poppler_do(Stream, reset); +m_poppler_do(Stream, close); +m_poppler_get_INT(Stream, getChar); +m_poppler_get_INT(Stream, lookChar); +m_poppler_get_INT(Stream, getRawChar); +m_poppler_get_INT(Stream, getUnfilteredChar); +m_poppler_do(Stream, unfilteredReset); +m_poppler_get_INT(Stream, getPos); +m_poppler_get_BOOL(Stream, isBinary); +m_poppler_get_poppler(Stream, Stream, getUndecodedStream); +m_poppler_get_poppler(Stream, Dict, getDict); + +m_poppler__tostring(Stream); + +static const struct luaL_Reg Stream_m[] = { + {"getKind", m_Stream_getKind}, + {"getKindName", m_Stream_getKindName}, // not poppler + {"reset", m_Stream_reset}, + {"close", m_Stream_close}, + {"getUndecodedStream", m_Stream_getUndecodedStream}, + {"getChar", m_Stream_getChar}, + {"lookChar", m_Stream_lookChar}, + {"getRawChar", m_Stream_getRawChar}, + {"getUnfilteredChar", m_Stream_getUnfilteredChar}, + {"unfilteredReset", m_Stream_unfilteredReset}, + // {"getLine", m_Stream_getLine}, + {"getPos", m_Stream_getPos}, + {"isBinary", m_Stream_isBinary}, + {"getUndecodedStream", m_Stream_getUndecodedStream}, + {"getDict", m_Stream_getDict}, + {"__tostring", m_Stream__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// XRef + +m_poppler_get_BOOL(XRef, isOk); +m_poppler_get_INT(XRef, getErrorCode); +m_poppler_get_BOOL(XRef, isEncrypted); +m_poppler_get_BOOL(XRef, okToPrint); +m_poppler_get_BOOL(XRef, okToPrintHighRes); +m_poppler_get_BOOL(XRef, okToChange); +m_poppler_get_BOOL(XRef, okToCopy); +m_poppler_get_BOOL(XRef, okToAddNotes); +m_poppler_get_BOOL(XRef, okToFillForm); +m_poppler_get_BOOL(XRef, okToAccessibility); +m_poppler_get_BOOL(XRef, okToAssemble); +m_poppler_get_OBJECT(XRef, getCatalog); + +static int m_XRef_fetch(lua_State * L) +{ + int num, gen; + udstruct *uin, *uout; + uin = (udstruct *) luaL_checkudata(L, 1, M_XRef); + if (uin->pd != NULL && uin->pd->pc != uin->pc) + pdfdoc_changed_error(L); + num = luaL_checkint(L, 2); + gen = luaL_checkint(L, 3); + uout = new_Object_userdata(L); + uout->d = new Object(); + ((XRef *) uin->d)->fetch(num, gen, (Object *) uout->d); + uout->atype = ALLOC_LEPDF; + uout->pc = uin->pc; + uout->pd = uin->pd; + return 1; +} + +m_poppler_get_OBJECT(XRef, getDocInfo); +m_poppler_get_OBJECT(XRef, getDocInfoNF); +m_poppler_get_INT(XRef, getNumObjects); +// getLastXRefPos +m_poppler_get_INT(XRef, getRootNum); +m_poppler_get_INT(XRef, getRootGen); +// getStreamEnd +m_poppler_get_INT(XRef, getSize); +// getEntry +m_poppler_get_poppler(XRef, Object, getTrailerDict); + +m_poppler__tostring(XRef); + +static const struct luaL_Reg XRef_m[] = { + {"isOk", m_XRef_isOk}, + {"getErrorCode", m_XRef_getErrorCode}, + {"isEncrypted", m_XRef_isEncrypted}, + {"okToPrint", m_XRef_okToPrint}, + {"okToPrintHighRes", m_XRef_okToPrintHighRes}, + {"okToChange", m_XRef_okToChange}, + {"okToCopy", m_XRef_okToCopy}, + {"okToAddNotes", m_XRef_okToAddNotes}, + {"okToFillForm", m_XRef_okToFillForm}, + {"okToAccessibility", m_XRef_okToAccessibility}, + {"okToAssemble", m_XRef_okToAssemble}, + {"getCatalog", m_XRef_getCatalog}, + {"fetch", m_XRef_fetch}, + {"getDocInfo", m_XRef_getDocInfo}, + {"getDocInfoNF", m_XRef_getDocInfoNF}, + {"getNumObjects", m_XRef_getNumObjects}, + // + {"getRootNum", m_XRef_getRootNum}, + {"getRootGen", m_XRef_getRootGen}, + // + {"getSize", m_XRef_getSize}, + {"getTrailerDict", m_XRef_getTrailerDict}, + {"__tostring", m_XRef__tostring}, + {NULL, NULL} // sentinel +}; + +//********************************************************************** +// XRefEntry + +static const struct luaL_Reg XRefEntry_m[] = { + {NULL, NULL} // sentinel +}; + +//********************************************************************** + +#define register_meta(type) \ + luaL_newmetatable(L, M_##type); \ + lua_pushvalue(L, -1); \ + lua_setfield(L, -2, "__index"); \ + lua_pushstring(L, "no user access"); \ + lua_setfield(L, -2, "__metatable"); \ + luaL_register(L, NULL, type##_m) + +int luaopen_epdf(lua_State * L) +{ + register_meta(Annot); + // TODO register_meta(AnnotBorder); + register_meta(AnnotBorderStyle); + register_meta(Annots); + register_meta(Array); + register_meta(Catalog); + register_meta(EmbFile); + register_meta(Dict); + register_meta(GooString); + register_meta(LinkDest); + register_meta(Links); + register_meta(Object); + register_meta(Page); + register_meta(PDFDoc); + register_meta(PDFRectangle); + register_meta(Ref); + register_meta(Stream); + register_meta(XRef); + register_meta(XRefEntry); + + luaL_register(L, "epdf", epdflib); + return 1; +} diff --git a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c index da7a69cb571..e6b45578d55 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c @@ -22,7 +22,7 @@ static const char _svn_version[] = - "$Id: lfontlib.c 3551 2010-03-26 14:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/lfontlib.c $"; + "$Id: lfontlib.c 3551 2010-03-26 14:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lfontlib.c $"; #define TIMERS 0 diff --git a/Build/source/texk/web2c/luatexdir/lua/limglib.c b/Build/source/texk/web2c/luatexdir/lua/limglib.c index 5245e31d0a3..4cc13454c22 100644 --- a/Build/source/texk/web2c/luatexdir/lua/limglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/limglib.c @@ -18,8 +18,8 @@ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ static const char _svn_version[] = - "$Id: limglib.c 3612 2010-04-13 09:29:42Z taco $ " - "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/limglib.c $"; + "$Id: limglib.c 4051 2011-01-09 22:41:33Z hhenkel $ " + "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/limglib.c $"; #include <stdio.h> #include <string.h> @@ -94,9 +94,9 @@ static const parm_struct img_parms[] = { {NULL, P__SENTINEL} }; -#define imgtype_max 5 +#define imgtype_max 6 const char *imgtype_s[] = - { "none", "pdf", "png", "jpg", "jbig2", "stream", NULL }; + { "none", "pdf", "png", "jpg", "jp2", "jbig2", "stream", NULL }; #define pagebox_max 5 const char *pdfboxspec_s[] = @@ -558,8 +558,8 @@ static void setup_image(PDF pdf, image * a, wrtype_e writetype) read_scale_img(a); if (img_objnum(ad) == 0) { /* latest needed just before out_img() */ pdf->ximage_count++; - pdf_create_obj(pdf, obj_type_ximage, pdf->ximage_count); - img_objnum(ad) = pdf->obj_ptr; + 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); @@ -609,6 +609,8 @@ static int l_write_image(lua_State * L) 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 */ } diff --git a/Build/source/texk/web2c/luatexdir/lua/liolib.c b/Build/source/texk/web2c/luatexdir/lua/liolib.c index 93d21b23697..a85b38b8683 100644 --- a/Build/source/texk/web2c/luatexdir/lua/liolib.c +++ b/Build/source/texk/web2c/luatexdir/lua/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c 3404 2010-01-28 11:17:10Z taco $ +** $Id: liolib.c 3794 2010-08-03 07:02:06Z taco $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -165,7 +165,13 @@ static int io_open(lua_State * L) const char *mode = luaL_optstring(L, 2, "r"); FILE **pf = newfile(L); *pf = fopen(filename, mode); - return (*pf == NULL) ? pushresult(L, 0, filename) : 1; + if (*pf == NULL) + return pushresult(L, 0, filename); + if (mode[0]=='r') + recorder_record_input(filename); + else + recorder_record_output(filename); + return 1; } static int io_open_ro(lua_State * L) @@ -177,7 +183,10 @@ static int io_open_ro(lua_State * L) return pushresult(L, 0, filename); pf = newfile(L); *pf = fopen(filename, mode); - return (*pf == NULL) ? pushresult(L, 0, filename) : 1; + if (*pf == NULL) + return pushresult(L, 0, filename); + recorder_record_input(filename); + return 1; } @@ -250,8 +259,14 @@ static int g_iofile(lua_State * L, int f, const char *mode) if (filename) { FILE **pf = newfile(L); *pf = fopen(filename, mode); - if (*pf == NULL) + if (*pf == NULL) { fileerror(L, 1, filename); + } else { + if (mode[0]=='r') + recorder_record_input(filename); + else + recorder_record_output(filename); + } } else { tofile(L); /* check that it's a valid file handle */ lua_pushvalue(L, 1); @@ -307,6 +322,8 @@ static int io_lines(lua_State * L) *pf = fopen(filename, "r"); if (*pf == NULL) fileerror(L, 1, filename); + else + recorder_record_input(filename); aux_lines(L, lua_gettop(L), 1); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c index 35191538f0b..2949fae16f1 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c @@ -28,7 +28,7 @@ #include <kpathsea/tex-file.h> static const char _svn_version[] = - "$Id: lkpselib.c 3551 2010-03-26 14:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/lkpselib.c $"; + "$Id: lkpselib.c 4020 2010-11-30 13:43:25Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lkpselib.c $"; static const unsigned filetypes[] = { kpse_gf_format, @@ -564,7 +564,7 @@ static int do_lua_kpathsea_lookup(lua_State * L, kpathsea kpse, int idx) lua_pop(L, 1); - lua_pushstring(L, "must-exist"); + lua_pushstring(L, "mustexist"); lua_gettable(L, idx + 1); if (lua_type(L, -1) == LUA_TBOOLEAN) { must_exist = lua_toboolean(L, -1); @@ -756,7 +756,7 @@ static int readable_file(lua_State * L) { const char *name = luaL_checkstring(L, 1); TEST_PROGRAM_NAME_SET; - lua_pushstring(L, (char *) kpse_readable_file(name)); + lua_pushstring(L, kpse_readable_file(name)); return 1; } @@ -764,7 +764,7 @@ static int lua_kpathsea_readable_file(lua_State * L) { kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *name = luaL_checkstring(L, 2); - lua_pushstring(L, (char *) kpathsea_readable_file(*kp, name)); + lua_pushstring(L, kpathsea_readable_file(*kp, name)); return 1; } diff --git a/Build/source/texk/web2c/luatexdir/lua/llanglib.c b/Build/source/texk/web2c/luatexdir/lua/llanglib.c index 7b880b4293e..76cd921c2a2 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llanglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llanglib.c @@ -23,7 +23,7 @@ static const char _svn_version[] = - "$Id: llanglib.c 3551 2010-03-26 14:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/llanglib.c $"; + "$Id: llanglib.c 3551 2010-03-26 14:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/llanglib.c $"; #define LANG_METATABLE "luatex.lang" diff --git a/Build/source/texk/web2c/luatexdir/lua/llfslibext.c b/Build/source/texk/web2c/luatexdir/lua/llfslibext.c new file mode 100644 index 00000000000..5168d9c24de --- /dev/null +++ b/Build/source/texk/web2c/luatexdir/lua/llfslibext.c @@ -0,0 +1,173 @@ +/* llfslibext.c + + Copyright 2010 Taco Hoekwater <taco@luatex.org> + + This file is part of LuaTeX. + + LuaTeX is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at your + option) any later version. + + LuaTeX is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU General Public License along + with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ + +#include "lua/luatex-api.h" +#include "ptexlib.h" + +#include <kpathsea/c-stat.h> +#include <kpathsea/c-dir.h> +#include <time.h> + +static const char _svn_version[] = + "$Id: llfslibext.c 4084 2011-02-10 09:06:29Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/llfslibext.c $"; + +#ifdef _WIN32 +# include <windows.h> +#else +#endif + +#ifdef _WIN32 + +static int get_short_name(lua_State * L) +{ + long length = 0; + TCHAR *buffer = NULL; + const char *lpszPath = luaL_checkstring(L, 1); + length = GetShortPathName(lpszPath, NULL, 0); + if (length == 0) { + lua_pushnil(L); + lua_pushfstring(L, "operating system error: %d", (int) GetLastError()); + return 2; + } + buffer = (TCHAR *) xmalloc(length * sizeof(TCHAR)); + length = GetShortPathName(lpszPath, buffer, length); + if (length == 0) { + lua_pushnil(L); + lua_pushfstring(L, "operating system error: %d", (int) GetLastError()); + return 2; + } + lua_pushlstring(L, (const char *) buffer, (size_t) length); + return 1; +} + +static int read_link(lua_State * L) +{ + lua_pushboolean(L, 0); + lua_pushliteral(L, "readlink not supported on this platform"); + return 2; +} + +#else + +static int pusherror(lua_State * L, const char *info) +{ + lua_pushnil(L); + if (info == NULL) + lua_pushstring(L, strerror(errno)); + else + lua_pushfstring(L, "%s: %s", info, strerror(errno)); + lua_pushinteger(L, errno); + return 3; +} + +static int Preadlink(lua_State * L) +{ +/** readlink(path) */ + const char *path = luaL_checkstring(L, 1); + char *b = NULL; + size_t allocated = 128; + int n; + while (1) { + b = malloc(allocated); + if (!b) + return pusherror(L, path); + n = readlink(path, b, allocated); + if (n == -1) { + free(b); + return pusherror(L, path); + } + if (n < allocated) + break; + /* Not enough room, try bigger */ + allocated *= 2; + free(b); + } + lua_pushlstring(L, b, n); + free(b); + return 1; +} + + +static int read_link(lua_State * L) +{ + return Preadlink(L); +} + +static int get_short_name(lua_State * L) +{ + /* simply do nothing */ + return 1; +} +#endif + + +/* +** Get file information +*/ +static int file_is_directory(lua_State * L) +{ + struct stat info; + const char *file = luaL_checkstring(L, 1); + + if (stat(file, &info)) { + lua_pushnil(L); + lua_pushfstring(L, "cannot obtain information from file `%s'", file); + return 2; + } + if (S_ISDIR(info.st_mode)) + lua_pushboolean(L, 1); + else + lua_pushboolean(L, 0); + + return 1; +} + +static int file_is_file(lua_State * L) +{ + struct stat info; + const char *file = luaL_checkstring(L, 1); + + if (stat(file, &info)) { + lua_pushnil(L); + lua_pushfstring(L, "cannot obtain information from file `%s'", file); + return 2; + } + if (S_ISREG(info.st_mode)) + lua_pushboolean(L, 1); + else + lua_pushboolean(L, 0); + + return 1; +} + + +void open_lfslibext(lua_State * L) +{ + + lua_getglobal(L, "lfs"); + lua_pushcfunction(L, file_is_directory); + lua_setfield(L, -2, "isdir"); + lua_pushcfunction(L, file_is_file); + lua_setfield(L, -2, "isfile"); + lua_pushcfunction(L, read_link); + lua_setfield(L, -2, "readlink"); + lua_pushcfunction(L, get_short_name); + lua_setfield(L, -2, "shortname"); + lua_pop(L, 1); /* pop the table */ +} diff --git a/Build/source/texk/web2c/luatexdir/lua/llualib.c b/Build/source/texk/web2c/luatexdir/lua/llualib.c index ec247e88010..de1ec5d5d2c 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llualib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llualib.c @@ -21,7 +21,7 @@ #include "ptexlib.h" static const char _svn_version[] = - "$Id: llualib.c 3612 2010-04-13 09:29:42Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/llualib.c $"; + "$Id: llualib.c 3615 2010-04-13 21:59:59Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/llualib.c $"; #define LOAD_BUF_SIZE 256 #define UINT_MAX32 0xFFFFFFFF diff --git a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c index ba81322a209..8fa1fb0d4cc 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c @@ -18,8 +18,8 @@ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ static const char _svn_version[] = - "$Id: lnodelib.c 3726 2010-06-24 12:13:43Z taco $ " - "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.2/source/texk/web2c/luatexdir/lua/lnodelib.c $"; + "$Id: lnodelib.c 4140 2011-04-12 10:18:37Z taco $ " + "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lnodelib.c $"; #include "lua/luatex-api.h" #include "ptexlib.h" @@ -39,23 +39,35 @@ static const char _svn_version[] = #define luaS_ptr_eq(a,b) (a==luaS_##b##_ptr) #define NODE_METATABLE "luatex_node" + +#define DEBUG 0 +#define DEBUG_OUT stdout make_luaS_index(luatex_node); -halfword *check_isnode(lua_State * L, int ud) +static halfword *maybe_isnode(lua_State * L, int ud) { - register halfword *p = lua_touserdata(L, ud); + halfword *p = lua_touserdata(L, ud); if (p != NULL) { if (lua_getmetatable(L, ud)) { lua_rawgeti(L, LUA_REGISTRYINDEX, luaS_index(luatex_node)); lua_gettable(L, LUA_REGISTRYINDEX); - if (lua_rawequal(L, -1, -2)) { - lua_pop(L, 2); - return p; + if (!lua_rawequal(L, -1, -2)) { + p = NULL; } + lua_pop(L, 2); } } - luaL_typerror(L, ud, NODE_METATABLE); + return p; +} + +halfword *check_isnode(lua_State * L, int ud) +{ + halfword *p = maybe_isnode(L, ud); + if (p != NULL) { + return p; + } + pdftex_fail("There should have been a lua <node> here, not an object with type %s!", luaL_typename(L, ud)); return NULL; } @@ -115,6 +127,40 @@ int get_valid_node_subtype_id(lua_State * L, int n) return i; } +/* returns true is the argument is a userdata object of type node */ + +static int lua_nodelib_isnode(lua_State * L) +{ + if (maybe_isnode(L,1) != NULL) + lua_pushboolean(L,1); + else + lua_pushboolean(L,0); + return 1; +} + +/* two simple helpers to speed up and simplify lua code: */ + +static int lua_nodelib_next(lua_State * L) +{ + halfword *p = maybe_isnode(L,1); + if (p != NULL && *p && vlink(*p)) { + lua_nodelib_push_fast(L,vlink(*p)); + } else { + lua_pushnil(L); + } + return 1; +} + +static int lua_nodelib_prev(lua_State * L) +{ + halfword *p = maybe_isnode(L,1); + if (p != NULL && *p && alink(*p)) { + lua_nodelib_push_fast(L,alink(*p)); + } else { + lua_pushnil(L); + } + return 1; +} /* Creates a userdata object for a number found at the stack top, @@ -209,12 +255,17 @@ static int lua_nodelib_subtype(lua_State * L) static int lua_nodelib_type(lua_State * L) { - int i = get_node_type_id(L, 1); - if (i >= 0) { - lua_pushstring(L, node_data[i].name); - } else { - lua_pushnil(L); + if (lua_type(L,1) == LUA_TNUMBER) { + int i = get_node_type_id(L, 1); + if (i >= 0) { + lua_pushstring(L, node_data[i].name); + return 1; + } + } else if (maybe_isnode(L, 1) != NULL) { + lua_pushstring(L,"node"); + return 1; } + lua_pushnil(L); return 1; } @@ -293,7 +344,17 @@ static int lua_nodelib_flush_list(lua_State * L) /* remove a node from a list */ - +#if DEBUG +static void show_node_links (halfword l, const char * p) +{ + halfword t = l; + while (t) { + fprintf(DEBUG_OUT, "%s t = %d, prev = %d, next = %d\n", p, (int)t, (int)alink(t), (int)vlink(t)); + t = vlink(t); + } +} +#endif + static int lua_nodelib_remove(lua_State * L) { halfword head, current, t; @@ -301,6 +362,9 @@ static int lua_nodelib_remove(lua_State * L) luaL_error(L, "Not enough arguments for node.remove()"); } head = *(check_isnode(L, 1)); +#if DEBUG + show_node_links(head, "before"); +#endif if (lua_isnil(L, 2)) { return 2; /* the arguments, as they are */ } @@ -328,6 +392,9 @@ static int lua_nodelib_remove(lua_State * L) } current = vlink(current); } +#if DEBUG + show_node_links(head, "after"); +#endif lua_pushnumber(L, head); lua_nodelib_push(L); lua_pushnumber(L, current); @@ -573,7 +640,7 @@ static int lua_nodelib_dimensions(lua_State * L) return 3; } else { luaL_error(L, - "missing argument to 'dimensions' (luatex_node expected)"); + "missing argument to 'dimensions' (node expected)"); } return 0; /* not reached */ } @@ -683,6 +750,8 @@ make_luaS_index(width); make_luaS_index(height); make_luaS_index(depth); make_luaS_index(expansion_factor); +make_luaS_index(list); +make_luaS_index(head); static void initialize_luaS_indexes(lua_State * L) @@ -705,12 +774,17 @@ static void initialize_luaS_indexes(lua_State * L) init_luaS_index(height); init_luaS_index(depth); init_luaS_index(expansion_factor); + init_luaS_index(list); + init_luaS_index(head); } static int get_node_field_id(lua_State * L, int n, int node) { register int t = type(node); register const char *s = lua_tostring(L, n); + if (luaS_ptr_eq(s, list)) { + s = luaS_head_ptr; /* create a |head| alias for now */ + } if (luaS_ptr_eq(s, next)) { return 0; } else if (luaS_ptr_eq(s, id)) { @@ -749,19 +823,21 @@ static int get_node_field_id(lua_State * L, int n, int node) } else if (luaS_ptr_eq(s, expansion_factor)) { return 16; } - } else if (luaS_ptr_eq(s, prev)) { + } else if (luaS_ptr_eq(s, prev) && nodetype_has_prev(t)) { return -1; - } else if (luaS_ptr_eq(s, subtype)) { + } else if (luaS_ptr_eq(s, subtype) && nodetype_has_subtype(t)) { return 2; } else { int j; const char **fields = node_data[t].fields; if (t == whatsit_node) fields = whatsit_node_data[subtype(node)].fields; - for (j = 0; fields[j] != NULL; j++) { - if (strcmp(s, fields[j]) == 0) { - return j + 3; - } + if (fields != NULL) { + for (j = 0; fields[j] != NULL; j++) { + if (strcmp(s, fields[j]) == 0) { + return j + 3; + } + } } } return -2; @@ -819,6 +895,7 @@ static int lua_nodelib_whatsits(lua_State * L) static int lua_nodelib_fields(lua_State * L) { int i = -1; + int offset = 3; const char **fields; int t = get_valid_node_type_id(L, 1); if (t == whatsit_node) { @@ -833,14 +910,19 @@ static int lua_nodelib_fields(lua_State * L) lua_rawseti(L, -2, 0); lua_pushstring(L, "id"); lua_rawseti(L, -2, 1); - lua_pushstring(L, "subtype"); - lua_rawseti(L, -2, 2); + if (nodetype_has_subtype(t)) { + lua_pushstring(L, "subtype"); + lua_rawseti(L, -2, 2); + offset--; + } if (fields != NULL) { - lua_pushstring(L, "prev"); - lua_rawseti(L, -2, -1); + if (nodetype_has_prev(t)) { + lua_pushstring(L, "prev"); + lua_rawseti(L, -2, -1); + } for (i = 0; fields[i] != NULL; i++) { lua_pushstring(L, fields[i]); - lua_rawseti(L, -2, (i + 3)); + lua_rawseti(L, -2, (i + offset)); } } return 1; @@ -858,7 +940,7 @@ static int lua_nodelib_tail(lua_State * L) t = *n; if (t == null) return 1; /* the old userdata */ - alink(t) = null; + /* alink(t) = null; */ /* don't do this, |t|'s |alink| may be a valid pointer */ while (vlink(t) != null) { alink(vlink(t)) = t; t = vlink(t); @@ -1374,15 +1456,20 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, int field) break; case late_lua_node: switch (field) { - case 4: + case 4: /* regid (obsolete?)*/ lua_pushnumber(L, late_lua_reg(n)); break; - case 5: - tokenlist_to_luastring(L, late_lua_data(n)); - break; - case 6: + case 6: /* name */ tokenlist_to_luastring(L, late_lua_name(n)); break; + case 5: /* data */ + case 7: /* string */ + if (late_lua_type(n) == lua_refid_literal) { + lua_rawgeti(Luas, LUA_REGISTRYINDEX, late_lua_data(n)); + } else { + tokenlist_to_luastring(L, late_lua_data(n)); + } + break; default: lua_pushnil(L); } @@ -1520,6 +1607,9 @@ static int lua_nodelib_getfield(lua_State * L) lua_pushnumber(L, (double) glue_set(n)); break; case 12: + if (list_ptr(n)) { + alink(list_ptr(n)) = null; + } nodelib_pushlist(L, list_ptr(n)); break; default: @@ -1559,6 +1649,9 @@ static int lua_nodelib_getfield(lua_State * L) lua_pushnumber(L, span_count(n)); break; case 13: + if (list_ptr(n)) { + alink(list_ptr(n)) = null; + } nodelib_pushlist(L, list_ptr(n)); break; default: @@ -1604,6 +1697,9 @@ static int lua_nodelib_getfield(lua_State * L) nodelib_pushspec(L, split_top_ptr(n)); break; case 8: + if (ins_ptr(n)) { + alink(ins_ptr(n)) = null; + } nodelib_pushlist(L, ins_ptr(n)); break; default: @@ -1631,6 +1727,9 @@ static int lua_nodelib_getfield(lua_State * L) lua_pushnumber(L, subtype(n)); break; case 4: + if (adjust_ptr(n)) { + alink(adjust_ptr(n)) = null; + } nodelib_pushlist(L, adjust_ptr(n)); break; default: @@ -1944,6 +2043,9 @@ static int lua_nodelib_getfield(lua_State * L) lua_pushnumber(L, subtype(n)); break; case 4: + if (math_list(n)) { + alink(math_list(n)) = null; + } nodelib_pushlist(L, math_list(n)); break; default: @@ -2458,12 +2560,23 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, int field) case 4: late_lua_reg(n) = (halfword) lua_tointeger(L, 3); break; - case 5: + case 5: /* data */ late_lua_data(n) = nodelib_gettoks(L, 3); + late_lua_type(n) = normal; break; case 6: late_lua_name(n) = nodelib_gettoks(L, 3); break; + case 7: /* string */ + if (ini_version) { + late_lua_data(n) = nodelib_gettoks(L, 3); + late_lua_type(n) = normal; + } else { + lua_pushvalue(L, 3); + late_lua_data(n) = luaL_ref(L, LUA_REGISTRYINDEX); + late_lua_type(n) = lua_refid_literal; + } + break; default: return nodelib_cantset(L, field, n); } @@ -2561,9 +2674,17 @@ static int lua_nodelib_setfield(lua_State * L) /* return implied */ } if (field == 0) { - vlink(n) = nodelib_getlist(L, 3); + halfword x = nodelib_getlist(L, 3); + if (x>0 && type(x) == glue_spec_node) { + return luaL_error(L, "You can't assign a %s node to a next field\n", node_data[type(x)].name); + } + vlink(n) = x; } else if (field == -1) { - alink(n) = nodelib_getlist(L, 3); + halfword x = nodelib_getlist(L, 3); + if (x>0 && type(x) == glue_spec_node) { + return luaL_error(L, "You can't assign a %s node to a prev field\n", node_data[type(x)].name); + } + alink(n) = x; } else if (field == 3 && nodetype_has_attributes(type(n))) { nodelib_setattr(L, 3, n); } else if (type(n) == glyph_node) { @@ -3278,8 +3399,7 @@ static int lua_nodelib_unprotect_glyphs(lua_State * L) return 2; } - -static int lua_nodelib_first_character(lua_State * L) +static int lua_nodelib_first_glyph(lua_State * L) { /* on the stack are two nodes and a direction */ halfword h, savetail = null, t = null; @@ -3294,7 +3414,7 @@ static int lua_nodelib_first_character(lua_State * L) savetail = vlink(t); vlink(t) = null; } - while (h != null && !is_simple_character(h)) { + while (h != null && (type(h) != glyph_node || !is_simple_character(h))) { h = vlink(h); } if (savetail != null) { @@ -3306,6 +3426,13 @@ static int lua_nodelib_first_character(lua_State * L) return 2; } +static int lua_nodelib_first_character(lua_State * L) +{ + pdftex_warn("node.first_character() is deprecated, please update to node.first_glyph()"); + return lua_nodelib_first_glyph(L); +} + + /* this is too simplistic, but it helps Hans to get going */ @@ -3356,47 +3483,79 @@ static int lua_nodelib_cp_skipable(lua_State * L) return 1; } +static int lua_nodelib_currentattr(lua_State * L) +{ + int n = lua_gettop(L); + if (n == 0) { + /* query */ + if (max_used_attr >= 0) { + if (attr_list_cache == cache_disabled) { + update_attribute_cache(); + if (attr_list_cache == null) { + lua_pushnil (L); + return 1; + } + } + attr_list_ref(attr_list_cache)++; + lua_pushnumber(L, attr_list_cache); + lua_nodelib_push(L); + } else { + lua_pushnil (L); + } + return 1; + } else { + /* assign */ + pdftex_warn("Assignment via node.current_attr(<list>) is not supported (yet)"); + return 0; + } +} + + static const struct luaL_reg nodelib_f[] = { - {"id", lua_nodelib_id}, - {"subtype", lua_nodelib_subtype}, - {"type", lua_nodelib_type}, - {"new", lua_nodelib_new}, - {"length", lua_nodelib_length}, + {"copy", lua_nodelib_copy}, + {"copy_list", lua_nodelib_copy_list}, {"count", lua_nodelib_count}, - {"traverse", lua_nodelib_traverse}, - {"traverse_id", lua_nodelib_traverse_filtered}, - {"tail", lua_nodelib_tail_only}, - {"slide", lua_nodelib_tail}, - {"types", lua_nodelib_types}, - {"whatsits", lua_nodelib_whatsits}, + {"current_attr", lua_nodelib_currentattr}, + {"dimensions", lua_nodelib_dimensions}, + {"do_ligature_n", lua_nodelib_do_ligature_n}, + {"family_font", lua_nodelib_mfont}, {"fields", lua_nodelib_fields}, - {"has_field", lua_nodelib_has_field}, - {"free", lua_nodelib_free}, + {"first_character", lua_nodelib_first_character}, + {"first_glyph", lua_nodelib_first_glyph}, {"flush_list", lua_nodelib_flush_list}, - {"remove", lua_nodelib_remove}, - {"insert_before", lua_nodelib_insert_before}, + {"free", lua_nodelib_free}, + {"has_attribute", lua_nodelib_has_attribute}, + {"has_field", lua_nodelib_has_field}, + {"hpack", lua_nodelib_hpack}, + {"id", lua_nodelib_id}, {"insert_after", lua_nodelib_insert_after}, - {"write", lua_nodelib_append}, + {"insert_before", lua_nodelib_insert_before}, + {"is_node", lua_nodelib_isnode}, + {"kerning", font_tex_kerning}, {"last_node", lua_nodelib_last_node}, - {"copy", lua_nodelib_copy}, - {"copy_list", lua_nodelib_copy_list}, - {"dimensions", lua_nodelib_dimensions}, - {"hpack", lua_nodelib_hpack}, - {"vpack", lua_nodelib_vpack}, + {"length", lua_nodelib_length}, + {"ligaturing", font_tex_ligaturing}, {"mlist_to_hlist", lua_nodelib_mlist_to_hlist}, - {"family_font", lua_nodelib_mfont}, - {"has_attribute", lua_nodelib_has_attribute}, + {"new", lua_nodelib_new}, + {"next", lua_nodelib_next}, + {"prev", lua_nodelib_prev}, + {"protect_glyphs", lua_nodelib_protect_glyphs}, + {"protrusion_skippable", lua_nodelib_cp_skipable}, + {"remove", lua_nodelib_remove}, {"set_attribute", lua_nodelib_set_attribute}, + {"slide", lua_nodelib_tail}, + {"subtype", lua_nodelib_subtype}, + {"tail", lua_nodelib_tail_only}, + {"traverse", lua_nodelib_traverse}, + {"traverse_id", lua_nodelib_traverse_filtered}, + {"type", lua_nodelib_type}, + {"types", lua_nodelib_types}, + {"unprotect_glyphs", lua_nodelib_unprotect_glyphs}, {"unset_attribute", lua_nodelib_unset_attribute}, - {"do_ligature_n", lua_nodelib_do_ligature_n}, - {"ligaturing", font_tex_ligaturing}, - {"kerning", font_tex_kerning}, - {"first_character", lua_nodelib_first_character}, {"usedlist", lua_nodelib_usedlist}, - {"protect_glyphs", lua_nodelib_protect_glyphs}, - {"unprotect_glyphs", lua_nodelib_unprotect_glyphs}, - {"protrusion_skipable", lua_nodelib_cp_skipable}, - {"protrusion_skippable", lua_nodelib_cp_skipable}, + {"vpack", lua_nodelib_vpack}, + {"whatsits", lua_nodelib_whatsits}, + {"write", lua_nodelib_append}, {NULL, NULL} /* sentinel */ }; @@ -3432,5 +3591,5 @@ int nodelist_from_lua(lua_State * L) if (lua_isnil(L, -1)) return null; n = check_isnode(L, -1); - return *n; + return (n ? *n : null); } diff --git a/Build/source/texk/web2c/luatexdir/lua/loslibext.c b/Build/source/texk/web2c/luatexdir/lua/loslibext.c index 3efdd07d1e0..b0bf0d5abea 100644 --- a/Build/source/texk/web2c/luatexdir/lua/loslibext.c +++ b/Build/source/texk/web2c/luatexdir/lua/loslibext.c @@ -25,7 +25,7 @@ #include <time.h> static const char _svn_version[] = - "$Id: loslibext.c 3648 2010-04-24 08:04:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.60.1/source/texk/web2c/luatexdir/lua/loslibext.c $"; + "$Id: loslibext.c 3682 2010-05-11 08:07:11Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/loslibext.c $"; #if defined(_WIN32) || defined(__NT__) # define MKDIR(a,b) mkdir(a) diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c index e5f688400e9..c3d16111e6b 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c @@ -18,23 +18,15 @@ with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ static const char _svn_version[] = - "$Id: lpdflib.c 3618 2010-04-15 05:54:45Z taco $ " - "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/lpdflib.c $"; + "$Id: lpdflib.c 3941 2010-11-01 23:31:27Z hhenkel $ " + "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lpdflib.c $"; #include "lua/luatex-api.h" #include "ptexlib.h" -#define buf_to_pdfbuf_macro(p, s, l) \ -for (i = 0; i < (l); i++) { \ - if (i % 16 == 0) \ - pdf_room(p, 16); \ - pdf_quick_out(p, ((const unsigned char *) (s))[i]); \ -} - static int luapdfprint(lua_State * L) { int n; - unsigned i; const_lstring st, modestr; ctm_transform_modes literal_mode; st.s = modestr.s = NULL; @@ -79,19 +71,19 @@ static int luapdfprint(lua_State * L) assert(0); } st.s = lua_tolstring(L, n, &st.l); - buf_to_pdfbuf_macro(static_pdf, st.s, st.l); + pdf_out_block(static_pdf, st.s, st.l); return 0; } -static unsigned char *fread_to_buf(lua_State * L, const char *filename, size_t * len) +static unsigned char *fread_to_buf(lua_State * L, const char *filename, + size_t * len) { - int i = 0; int ilen = 0; FILE *f; unsigned char *buf = NULL; if ((f = fopen(filename, "rb")) == NULL) luaL_error(L, "pdf.immediateobj() cannot open input file"); - if ((i = readbinfile(f, &buf, &ilen)) == 0) + if (readbinfile(f, &buf, &ilen) == 0) luaL_error(L, "pdf.immediateobj() cannot read input file"); fclose(f); *len = (size_t) ilen; @@ -101,23 +93,23 @@ static unsigned char *fread_to_buf(lua_State * L, const char *filename, size_t * static int l_immediateobj(lua_State * L) { int n, first_arg = 1; - unsigned i; int k; lstring buf; const_lstring st1, st2, st3; 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++; lua_number2int(k, lua_tonumber(L, 1)); - check_obj_exists(static_pdf, obj_type_obj, k); + 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 { - incr(static_pdf->obj_count); - pdf_create_obj(static_pdf, obj_type_obj, static_pdf->sys_obj_ptr + 1); - k = static_pdf->sys_obj_ptr; + 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) { @@ -129,7 +121,7 @@ static int l_immediateobj(lua_State * L) luaL_error(L, "pdf.immediateobj() 1st argument must be string"); pdf_begin_obj(static_pdf, k, 1); st1.s = lua_tolstring(L, first_arg, &st1.l); - buf_to_pdfbuf_macro(static_pdf, st1.s, st1.l); + pdf_out_block(static_pdf, st1.s, st1.l); if (st1.s[st1.l - 1] != '\n') pdf_puts(static_pdf, "\n"); pdf_end_obj(static_pdf); @@ -148,7 +140,7 @@ static int l_immediateobj(lua_State * L) "pdf.immediateobj() 3rd argument forbidden in file mode"); pdf_begin_obj(static_pdf, k, 1); buf.s = fread_to_buf(L, st2.s, &buf.l); - buf_to_pdfbuf_macro(static_pdf, buf.s, buf.l); + pdf_out_block(static_pdf, (const char *) buf.s, buf.l); if (buf.s[buf.l - 1] != '\n') pdf_puts(static_pdf, "\n"); xfree(buf.s); @@ -160,18 +152,18 @@ static int l_immediateobj(lua_State * L) luaL_error(L, "pdf.immediateobj() 3rd argument must be string"); st3.s = lua_tolstring(L, first_arg + 2, &st3.l); - buf_to_pdfbuf_macro(static_pdf, st3.s, st3.l); + pdf_out_block(static_pdf, st3.s, st3.l); if (st3.s[st3.l - 1] != '\n') pdf_puts(static_pdf, "\n"); } pdf_begin_stream(static_pdf); if (st1.l == 6 && strncmp((const char *) st1.s, "stream", 6) == 0) { - buf_to_pdfbuf_macro(static_pdf, st2.s, st2.l); + pdf_out_block(static_pdf, st2.s, st2.l); } else if (st1.l == 10 && strncmp((const char *) st1.s, "streamfile", 10) == 0) { buf.s = fread_to_buf(L, st2.s, &buf.l); - buf_to_pdfbuf_macro(static_pdf, buf.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"); @@ -193,9 +185,6 @@ typedef enum { P__ZERO, P_H, P_INFO, P_NAMES, - P_PAGEATTRIBUTES, - P_PAGERESOURCES, - P_PAGESATTRIBUTES, P_PDFCATALOG, P_PDFINFO, P_PDFNAMES, @@ -213,9 +202,6 @@ static const parm_struct pdf_parms[] = { {"h", P_H}, {"info", P_INFO}, {"names", P_NAMES}, - {"pageattributes", P_PAGEATTRIBUTES}, - {"pageresources", P_PAGERESOURCES}, - {"pagesattributes", P_PAGESATTRIBUTES}, {"pdfcatalog", P_PDFCATALOG}, /* obsolescent */ {"pdfinfo", P_PDFINFO}, /* obsolescent */ {"pdfnames", P_PDFNAMES}, /* obsolescent */ @@ -237,7 +223,6 @@ static int table_obj(lua_State * L) int saved_compress_level = static_pdf->compress_level; const_lstring attr, st; lstring buf; - size_t i; int immediate = 0; /* default: not immediate */ attr.s = st.s = NULL; attr.l = 0; @@ -285,13 +270,12 @@ static int table_obj(lua_State * L) if (!lua_isnumber(L, -1)) /* !vi t */ luaL_error(L, "pdf.obj(): \"objnum\" must be integer"); k = (int) lua_tointeger(L, -1); /* vi t */ - check_obj_exists(static_pdf, obj_type_obj, k); + 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.obj() object in use"); } else { - incr(static_pdf->obj_count); - pdf_create_obj(static_pdf, obj_type_obj, static_pdf->sys_obj_ptr + 1); - k = static_pdf->sys_obj_ptr; + static_pdf->obj_count++; + k = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); } pdf_last_obj = k; if (immediate == 0) { @@ -379,7 +363,7 @@ static int table_obj(lua_State * L) "pdf.obj(): \"string\" must be string for raw object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); - buf_to_pdfbuf_macro(static_pdf, st.s, st.l); + pdf_out_block(static_pdf, st.s, st.l); if (st.s[st.l - 1] != '\n') pdf_puts(static_pdf, "\n"); } else @@ -392,7 +376,7 @@ static int table_obj(lua_State * L) 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); - buf_to_pdfbuf_macro(static_pdf, buf.s, buf.l); + pdf_out_block(static_pdf, (const char *) buf.s, buf.l); if (buf.s[buf.l - 1] != '\n') pdf_puts(static_pdf, "\n"); xfree(buf.s); @@ -408,7 +392,7 @@ static int table_obj(lua_State * L) if (immediate == 1) { pdf_begin_dict(static_pdf, k, 0); /* 0 = not an object stream candidate! */ if (attr.s != NULL) { - buf_to_pdfbuf_macro(static_pdf, attr.s, attr.l); + pdf_out_block(static_pdf, attr.s, attr.l); if (attr.s[attr.l - 1] != '\n') pdf_puts(static_pdf, "\n"); } @@ -428,7 +412,7 @@ static int table_obj(lua_State * L) "pdf.obj(): \"string\" must be string for stream object"); if (immediate == 1) { st.s = lua_tolstring(L, -1, &st.l); /* string-s t */ - buf_to_pdfbuf_macro(static_pdf, st.s, st.l); + pdf_out_block(static_pdf, st.s, st.l); } else obj_obj_data(static_pdf, k) = luaL_ref(L, LUA_REGISTRYINDEX); /* t */ } else { @@ -439,7 +423,7 @@ static int table_obj(lua_State * L) 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); - buf_to_pdfbuf_macro(static_pdf, buf.s, buf.l); + pdf_out_block(static_pdf, (const char *) buf.s, buf.l); xfree(buf.s); } else { set_obj_obj_is_file(static_pdf, k); @@ -466,13 +450,12 @@ static int orig_obj(lua_State * L) if (n > 0 && lua_type(L, 1) == LUA_TNUMBER) { first_arg++; lua_number2int(k, lua_tonumber(L, 1)); - check_obj_exists(static_pdf, obj_type_obj, k); + 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.obj() object in use"); } else { - incr(static_pdf->obj_count); - pdf_create_obj(static_pdf, obj_type_obj, static_pdf->sys_obj_ptr + 1); - k = static_pdf->sys_obj_ptr; + static_pdf->obj_count++; + k = pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); } pdf_last_obj = k; obj_data_ptr(static_pdf, k) = pdf_get_mem(static_pdf, pdfmem_obj_size); @@ -522,8 +505,7 @@ static int orig_obj(lua_State * L) static int l_obj(lua_State * L) { - int n; - int k; + int k, n; ensure_output_state(static_pdf, ST_HEADER_WRITTEN); n = lua_gettop(L); if (n == 1 && lua_istable(L, 1)) @@ -534,6 +516,20 @@ static int l_obj(lua_State * L) return 1; } +static int l_refobj(lua_State * L) +{ + int k, n; + n = lua_gettop(L); + if (n != 1) + luaL_error(L, "pdf.refobj() needs exactly 1 argument"); + k = (int) luaL_checkinteger(L, 1); + if (global_shipping_mode == NOT_SHIPPING) + scan_refobj_lua(static_pdf, k); + else + pdf_ref_obj_lua(static_pdf, k); + return 0; +} + static int l_reserveobj(lua_State * L) { int n; @@ -542,17 +538,16 @@ static int l_reserveobj(lua_State * L) n = lua_gettop(L); switch (n) { case 0: - incr(static_pdf->obj_count); - pdf_create_obj(static_pdf, obj_type_obj, static_pdf->sys_obj_ptr + 1); - pdf_last_obj = static_pdf->sys_obj_ptr; + static_pdf->obj_count++; + pdf_last_obj = + pdf_create_obj(static_pdf, obj_type_obj, static_pdf->obj_ptr + 1); break; 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) { - pdf_create_obj(static_pdf, obj_type_annot, 0); - pdf_last_annot = static_pdf->sys_obj_ptr; + pdf_last_annot = pdf_create_obj(static_pdf, obj_type_annot, 0); } else { luaL_error(L, "pdf.reserveobj() optional string must be \"annot\""); } @@ -571,7 +566,7 @@ static int l_registerannot(lua_State * L) n = lua_gettop(L); switch (n) { case 1: - if (!is_shipping_page) + if (global_shipping_mode == NOT_SHIPPING) luaL_error(L, "pdf.registerannot() can only be used in late lua"); i = (int) luaL_checkinteger(L, 1); if (i <= 0) @@ -588,27 +583,14 @@ static int l_registerannot(lua_State * L) static int getpdf(lua_State * L) { char *s; - const char *st; int i, l; - if (lua_isstring(L, 2) && (st = lua_tostring(L, 2)) != NULL) { + if (lua_isstring(L, 2) && (lua_tostring(L, 2) != NULL)) { lua_pushvalue(L, 2); /* st ... */ lua_gettable(L, LUA_ENVIRONINDEX); /* i? ... */ if (lua_isnumber(L, -1)) { /* i ... */ i = (int) lua_tointeger(L, -1); /* i ... */ lua_pop(L, 1); /* ... */ switch (i) { - case P_PAGEATTRIBUTES: - s = tokenlist_to_cstring(pdf_pageattributes_toks, true, &l); - lua_pushlstring(L, s, (size_t) l); - break; - case P_PAGERESOURCES: - s = tokenlist_to_cstring(pdf_pageresources_toks, true, &l); - lua_pushlstring(L, s, (size_t) l); - break; - case P_PAGESATTRIBUTES: - s = tokenlist_to_cstring(pdf_pagesattributes_toks, true, &l); - lua_pushlstring(L, s, (size_t) l); - break; case P_PDFCATALOG: case P_CATALOG: s = tokenlist_to_cstring(pdf_catalog_toks, true, &l); @@ -661,15 +643,6 @@ static int setpdf(lua_State * L) i = (int) lua_tointeger(L, -1); /* i ... */ lua_pop(L, 1); /* ... */ switch (i) { - case P_PAGEATTRIBUTES: - pdf_pageattributes_toks = tokenlist_from_lua(L); - break; - case P_PAGERESOURCES: - pdf_pageresources_toks = tokenlist_from_lua(L); - break; - case P_PAGESATTRIBUTES: - pdf_pagesattributes_toks = tokenlist_from_lua(L); - break; case P_PDFCATALOG: case P_CATALOG: pdf_catalog_toks = tokenlist_from_lua(L); @@ -699,6 +672,28 @@ static int setpdf(lua_State * L) return 0; } +static int l_objtype(lua_State * L) +{ + int n = lua_gettop(L); + if (n != 1) + luaL_error(L, "pdf.objtype() needs exactly 1 argument"); + n = (int) luaL_checkinteger(L, 1); + if (n < 0 || n > static_pdf->obj_ptr) + lua_pushnil(L); + else + lua_pushstring(L, pdf_obj_typenames[obj_type(static_pdf, n)]); + return 1; +} + +static int l_maxobjnum(lua_State * L) +{ + int n = lua_gettop(L); + if (n != 0) + luaL_error(L, "pdf.maxobjnum() needs 0 arguments"); + lua_pushinteger(L, static_pdf->obj_ptr); + return 1; +} + static int l_mapfile(lua_State * L) { char *s; @@ -735,14 +730,31 @@ static int l_pdfmapline(lua_State * L) return 0; } +static int l_pageref(lua_State * L) +{ + int n = lua_gettop(L); + if (n != 1) + luaL_error(L, "pdf.pageref() needs exactly 1 argument"); + n = (int) luaL_checkinteger(L, 1); + if (n <= 0) + luaL_error(L, "pdf.pageref() needs page number > 0"); + n = get_obj(static_pdf, obj_type_page, n, false); + lua_pushnumber(L, n); + return 1; +} + static const struct luaL_reg pdflib[] = { {"immediateobj", l_immediateobj}, {"mapfile", l_mapfile}, {"mapline", l_mapline}, + {"maxobjnum", l_maxobjnum}, {"obj", l_obj}, + {"objtype", l_objtype}, + {"pageref", l_pageref}, {"pdfmapfile", l_pdfmapfile}, /* obsolete */ {"pdfmapline", l_pdfmapline}, /* obsolete */ {"print", luapdfprint}, + {"refobj", l_refobj}, {"registerannot", l_registerannot}, {"reserveobj", l_reserveobj}, {NULL, NULL} /* sentinel */ diff --git a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c index 020fe6d616a..49a72210577 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c @@ -19,7 +19,7 @@ static const char _svn_version[] = "$Id: lstatslib.c 3477 2010-03-12 13:59:34Z taco $ " - "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/lstatslib.c $"; + "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/lstatslib.c $"; #include "lua/luatex-api.h" #include "ptexlib.h" diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c index 63ab77d9f65..6acd371161c 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c @@ -21,7 +21,7 @@ #include "ptexlib.h" static const char _svn_version[] = - "$Id: ltexiolib.c 3550 2010-03-26 14:37:09Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/ltexiolib.c $"; + "$Id: ltexiolib.c 3550 2010-03-26 14:37:09Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/ltexiolib.c $"; typedef void (*texio_printer) (const char *); diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c index 317dbbd9afd..f40e173a108 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c @@ -23,7 +23,7 @@ static const char _svn_version[] = - "$Id: ltexlib.c 3612 2010-04-13 09:29:42Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/ltexlib.c $"; + "$Id: ltexlib.c 4132 2011-04-11 14:04:10Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/ltexlib.c $"; #define attribute(A) eqtb[attribute_base+(A)].hh.rh #define dimen(A) eqtb[scaled_base+(A)].hh.rh @@ -574,6 +574,46 @@ static int tex_scaledimen(lua_State * L) return 1; } +static int texerror (lua_State * L) +{ + int i, n, l; + const char **errhlp = NULL; + const char *error = luaL_checkstring(L,1); + n = lua_gettop(L); + if (n==2 && lua_type(L, n) == LUA_TTABLE) { + l = 1; /* |errhlp| is terminated by a NULL entry */ + for (i = 1;; i++) { + lua_rawgeti(L, n, i); + if (lua_isstring(L, -1)) { + l++; + lua_pop(L, 1); + } else { + lua_pop(L, 1); + break; + } + } + if (l>1) { + errhlp = xmalloc(l * sizeof(char *)); + memset(errhlp,0,l * sizeof(char *)); + for (i = 1;; i++) { + lua_rawgeti(L, n, i); + if (lua_isstring(L, -1)) { + errhlp[(i-1)] = lua_tostring(L,-1); + lua_pop(L, 1); + } else { + break; + } + } + } + } + deletions_allowed = false; + tex_error(error, errhlp); + if (errhlp) + xfree(errhlp); + deletions_allowed = true; + return 0; +} + static int get_item_index(lua_State * L, int i, int base) { @@ -783,6 +823,8 @@ static int vsettoks(lua_State * L, int is_global) int i, err; int k; lstring str; + char *s; + const char *ss; int save_global_defs = int_par(global_defs_code); if (is_global) int_par(global_defs_code) = 1; @@ -790,7 +832,10 @@ static int vsettoks(lua_State * L, int is_global) if (!lua_isstring(L, i)) { luaL_error(L, "unsupported value type"); } - str.s = (unsigned char *) xstrdup(lua_tolstring(L, i, &str.l)); + ss = lua_tolstring(L, i, &str.l); + s = xmalloc (str.l+1); + memcpy (s, ss, str.l+1); + str.s = (unsigned char *)s; k = get_item_index(L, (i - 1), toks_base); check_index_range(k, "settoks"); err = set_tex_toks_register(k, str); @@ -903,114 +948,238 @@ static int setbox(lua_State * L) return vsetbox(L, isglobal); } -static int getboxdim(lua_State * L, int whichdim) +#define check_char_range(j,s,lim) \ + if (j<0 || j >= lim) { \ + luaL_error(L, "incorrect character value %d for tex.%s()", (int)j, s); } + + +static int setcode (lua_State *L, void (*setone)(int,halfword,quarterword), + void (*settwo)(int,halfword,quarterword), const char *name, int lim) { - int i, j; - i = lua_gettop(L); - j = get_box_id(L, i); - lua_settop(L, (i - 2)); /* table at -1 */ - if (j < 0 || j > 65535) { - luaL_error(L, "incorrect index"); - } - switch (whichdim) { - case width_offset: - lua_pushnumber(L, get_tex_box_width(j)); - break; - case height_offset: - lua_pushnumber(L, get_tex_box_height(j)); - break; - case depth_offset: - lua_pushnumber(L, get_tex_box_depth(j)); + int ch; + halfword val, ucval; + int level = cur_level; + int n = lua_gettop(L); + int f = 1; + if (n>1 && lua_type(L,1) == LUA_TTABLE) + f++; + if (n>2 && lua_isstring(L, f)) { + const char *s = lua_tostring(L, f); + if (strcmp(s, "global") == 0) { + level = level_one; + f++; + } + } + ch = (int) luaL_checkinteger(L, f); + check_char_range(ch, name, 65536*17); + val = (halfword) luaL_checkinteger(L, f+1); + check_char_range(val, name, lim); + (setone)(ch, val, level); + if (settwo != NULL && n-f == 2) { + ucval = (halfword) luaL_checkinteger(L, f+2); + check_char_range(ucval, name, lim); + (settwo)(ch, ucval, level); } + return 0; +} + +static int setlccode(lua_State * L) +{ + return setcode(L, &set_lc_code, &set_uc_code, "setlccode", 65536*17); +} + +static int getlccode(lua_State * L) +{ + int ch = (int) luaL_checkinteger(L, -1); + check_char_range(ch, "getlccode", 65536*17); + lua_pushnumber(L, get_lc_code(ch)); return 1; } -static int getboxwd(lua_State * L) +static int setuccode(lua_State * L) { - return getboxdim(L, width_offset); + return setcode(L, &set_uc_code, &set_lc_code, "setuccode", 65536*17); } -static int getboxht(lua_State * L) +static int getuccode(lua_State * L) { - return getboxdim(L, height_offset); + int ch = (int) luaL_checkinteger(L, -1); + check_char_range(ch, "getuccode", 65536*17); + lua_pushnumber(L, get_uc_code(ch)); + return 1; } -static int getboxdp(lua_State * L) +static int setsfcode(lua_State * L) { - return getboxdim(L, depth_offset); + return setcode(L, &set_sf_code, NULL, "setsfcode", 32768); } -static int vsetboxdim(lua_State * L, int whichdim, int is_global) +static int getsfcode(lua_State * L) { - int i, j, k, err; - int save_global_defs = int_par(global_defs_code); - if (is_global) - int_par(global_defs_code) = 1; - i = lua_gettop(L); - if (!lua_isnumber(L, i)) { - j = dimen_to_number(L, lua_tostring(L, i)); - } else { - lua_number2int(j, lua_tonumber(L, i)); - } - k = get_box_id(L, (i - 1)); - lua_settop(L, (i - 3)); /* table at -2 */ - if (k < 0 || k > 65535) { - luaL_error(L, "incorrect index"); - } - err = 0; - switch (whichdim) { - case width_offset: - err = set_tex_box_width(k, j); - break; - case height_offset: - err = set_tex_box_height(k, j); - break; - case depth_offset: - err = set_tex_box_depth(k, j); + int ch = (int) luaL_checkinteger(L, -1); + check_char_range(ch, "getsfcode", 65536*17); + lua_pushnumber(L, get_sf_code(ch)); + return 1; +} + +static int setcatcode(lua_State * L) +{ + int ch; + halfword val; + int level = cur_level; + int cattable = int_par(cat_code_table_code); + int n = lua_gettop(L); + int f = 1; + if (n>1 && lua_type(L,1) == LUA_TTABLE) + f++; + if (n>2 && lua_isstring(L, f)) { + const char *s = lua_tostring(L, f); + if (strcmp(s, "global") == 0) { + level = level_one; + f++; + } } - int_par(global_defs_code) = save_global_defs; - if (err) { - luaL_error(L, "not a box"); + if (n-f == 2) { + cattable = (int) luaL_checkinteger(L, -3); } + ch = (int) luaL_checkinteger(L, -2); + check_char_range(ch, "setcatcode", 65536*17); + val = (halfword) luaL_checkinteger(L, -1); + check_char_range(val, "setcatcode", 16); + set_cat_code(cattable, ch, val, level); return 0; } -static int setboxwd(lua_State * L) +static int getcatcode(lua_State * L) { - int isglobal = 0; - int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { - const char *s = lua_tostring(L, 1); - if (strcmp(s, "global") == 0) - isglobal = 1; + int cattable = int_par(cat_code_table_code); + int ch = (int) luaL_checkinteger(L, -1); + if (lua_gettop(L)>=2 && lua_type(L,-2)==LUA_TNUMBER) { + cattable = luaL_checkinteger(L, -2); } - return vsetboxdim(L, width_offset, isglobal); + check_char_range(ch, "getcatcode", 65536*17); + lua_pushnumber(L, get_cat_code(cattable, ch)); + return 1; } -static int setboxht(lua_State * L) + +static int setmathcode(lua_State * L) { - int isglobal = 0; + int ch; + halfword cval, fval, chval; + int level = cur_level; int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { - const char *s = lua_tostring(L, 1); - if (strcmp(s, "global") == 0) - isglobal = 1; + int f = 1; + if (n>1 && lua_type(L,1) == LUA_TTABLE) + f++; + if (n>2 && lua_isstring(L, f)) { + const char *s = lua_tostring(L, f); + if (strcmp(s, "global") == 0) { + level = level_one; + f++; + } + } + if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) { + luaL_error(L, "Bad arguments for tex.setmathcode()"); } - return vsetboxdim(L, height_offset, isglobal); + ch = (int) luaL_checkinteger(L, -2); + check_char_range(ch, "setmathcode", 65536*17); + + lua_rawgeti(L, -1, 1); + cval = (halfword) luaL_checkinteger(L, -1); + lua_rawgeti(L, -2, 2); + fval = (halfword) luaL_checkinteger(L, -1); + lua_rawgeti(L, -3, 3); + chval = (halfword) luaL_checkinteger(L, -1); + lua_pop(L,3); + + check_char_range(cval, "setmathcode", 8); + check_char_range(fval, "setmathcode", 256); + check_char_range(chval, "setmathcode", 65536*17); + set_math_code(ch, xetex_mathcode, cval,fval, chval, (quarterword) (level)); + return 0; } -static int setboxdp(lua_State * L) +static int getmathcode(lua_State * L) { - int isglobal = 0; + mathcodeval mval = { 0, 0, 0, 0 }; + int ch = (int) luaL_checkinteger(L, -1); + check_char_range(ch, "getmathcode", 65536*17); + mval = get_math_code(ch); + lua_newtable(L); + lua_pushnumber(L,mval.class_value); + lua_rawseti(L, -2, 1); + lua_pushnumber(L,mval.family_value); + lua_rawseti(L, -2, 2); + lua_pushnumber(L,mval.character_value); + lua_rawseti(L, -2, 3); + return 1; +} + + + +static int setdelcode(lua_State * L) +{ + int ch; + halfword sfval, scval, lfval, lcval; + int level = cur_level; int n = lua_gettop(L); - if (n == 3 && lua_isstring(L, 1)) { - const char *s = lua_tostring(L, 1); - if (strcmp(s, "global") == 0) - isglobal = 1; + int f = 1; + if (n>1 && lua_type(L,1) == LUA_TTABLE) + f++; + if (n>2 && lua_isstring(L, f)) { + const char *s = lua_tostring(L, f); + if (strcmp(s, "global") == 0) { + level = level_one; + f++; + } } - return vsetboxdim(L, depth_offset, isglobal); + if (n-f!=1 || lua_type(L,f+1) != LUA_TTABLE) { + luaL_error(L, "Bad arguments for tex.setdelcode()"); + } + ch = (int) luaL_checkinteger(L, -2); + check_char_range(ch, "setdelcode", 65536*17); + lua_rawgeti(L, -1, 1); + sfval = (halfword) luaL_checkinteger(L, -1); + lua_rawgeti(L, -2, 2); + scval = (halfword) luaL_checkinteger(L, -1); + lua_rawgeti(L, -3, 3); + lfval = (halfword) luaL_checkinteger(L, -1); + lua_rawgeti(L, -4, 4); + lcval = (halfword) luaL_checkinteger(L, -1); + lua_pop(L,4); + + check_char_range(sfval, "setdelcode", 256); + check_char_range(scval, "setdelcode", 65536*17); + check_char_range(lfval, "setdelcode", 256); + check_char_range(lcval, "setdelcode", 65536*17); + set_del_code(ch, xetex_mathcode, sfval, scval, lfval, lcval, (quarterword) (level)); + + return 0; +} + +static int getdelcode(lua_State * L) +{ + delcodeval mval = { 0, 0, 0, 0, 0, 0 }; + int ch = (int) luaL_checkinteger(L, -1); + check_char_range(ch, "getdelcode", 65536*17); + mval = get_del_code(ch); + /* lua_pushnumber(L, mval.class_value); */ + /* lua_pushnumber(L, mval.origin_value); */ + lua_newtable(L); + lua_pushnumber(L,mval.small_family_value); + lua_rawseti(L, -2, 1); + lua_pushnumber(L,mval.small_character_value); + lua_rawseti(L, -2, 2); + lua_pushnumber(L,mval.large_family_value); + lua_rawseti(L, -2, 3); + lua_pushnumber(L,mval.large_character_value); + lua_rawseti(L, -2, 4); + return 1; } + + static int settex(lua_State * L) { const char *st; @@ -1052,6 +1221,11 @@ static int settex(lua_State * L) lua_number2int(j, lua_tonumber(L, i)); } assign_internal_value((isglobal ? 4 : 0), equiv(cur_cs), j); + } else if (is_glue_assign(cur_cmd)) { + halfword *j = check_isnode(L, i); /* the value */ + { int a = isglobal; + define(equiv(cur_cs), assign_glue_cmd, *j); + } } else if (is_toks_assign(cur_cmd)) { if (lua_isstring(L, i)) { j = tokenlist_from_lua(L); /* uses stack -1 */ @@ -1062,7 +1236,12 @@ static int settex(lua_State * L) } } else { - luaL_error(L, "unsupported tex internal assignment"); + /* people may want to add keys that are also primitives + (|tex.wd| for example) so creating an error is not + right here */ + if (lua_istable(L, (i - 2))) + lua_rawset(L, (i - 2)); + /* luaL_error(L, "unsupported tex internal assignment"); */ } } else { if (lua_istable(L, (i - 2))) @@ -2018,10 +2197,10 @@ static int tex_run_linebreak(lua_State * L) pdflastlinedepth, pdfignoreddimen, parshape; int fewest_demerits = 0, actual_looseness = 0; halfword clubpenalties, interlinepenalties, widowpenalties; - + int save_vlink_tmp_head; /* push a new nest level */ push_nest(); - /* save_vlink_cur_head = vlink(cur_list.head_field); */ + save_vlink_tmp_head = vlink(temp_head); j = check_isnode(L, 1); /* the value */ vlink(temp_head) = *j; @@ -2139,6 +2318,7 @@ static int tex_run_linebreak(lua_State * L) lua_settable(L, -3); /* restore nest stack */ + vlink(temp_head) = save_vlink_tmp_head; pop_nest(); if (parshape != equiv(par_shape_loc)) flush_node(parshape); @@ -2148,7 +2328,7 @@ static int tex_run_linebreak(lua_State * L) static int tex_shipout(lua_State * L) { int boxnum = get_box_id(L, 1); - ship_out(static_pdf, box(boxnum), true); + ship_out(static_pdf, box(boxnum), SHIPPING_PAGE); box(boxnum) = null; return 0; } @@ -2250,6 +2430,7 @@ static const struct luaL_reg texlib[] = { {"write", luacwrite}, {"print", luacprint}, {"tprint", luactprint}, + {"error", texerror}, {"sprint", luacsprint}, {"set", settex}, {"get", gettex}, @@ -2267,14 +2448,20 @@ static const struct luaL_reg texlib[] = { {"getbox", getbox}, {"setlist", setlist}, {"getlist", getlist}, - {"setboxwd", setboxwd}, - {"getboxwd", getboxwd}, - {"setboxht", setboxht}, - {"getboxht", getboxht}, - {"setboxdp", setboxdp}, - {"getboxdp", getboxdp}, {"setnest", setnest}, {"getnest", getnest}, + {"setcatcode", setcatcode}, + {"getcatcode", getcatcode}, + {"setdelcode", setdelcode}, + {"getdelcode", getdelcode}, + {"setlccode", setlccode}, + {"getlccode", getlccode}, + {"setmathcode", setmathcode}, + {"getmathcode", getmathcode}, + {"setsfcode", setsfcode}, + {"getsfcode", getsfcode}, + {"setuccode", setuccode}, + {"getuccode", getuccode}, {"round", tex_roundnumber}, {"scale", tex_scaletable}, {"sp", tex_scaledimen}, @@ -2311,9 +2498,12 @@ int luaopen_tex(lua_State * L) make_table(L, "count", "getcount", "setcount"); make_table(L, "toks", "gettoks", "settoks"); make_table(L, "box", "getbox", "setbox"); - make_table(L, "wd", "getboxwd", "setboxwd"); - make_table(L, "ht", "getboxht", "setboxht"); - make_table(L, "dp", "getboxdp", "setboxdp"); + make_table(L, "sfcode", "getsfcode", "setsfcode"); + make_table(L, "lccode", "getlccode", "setlccode"); + make_table(L, "uccode", "getuccode", "setuccode"); + make_table(L, "catcode", "getcatcode", "setcatcode"); + make_table(L, "mathcode", "getmathcode", "setmathcode"); + make_table(L, "delcode", "getdelcode", "setdelcode"); make_table(L, "lists", "getlist", "setlist"); make_table(L, "nest", "getnest", "setnest"); /* *INDENT-ON* */ diff --git a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c index 0f1c5332466..4f3913e0bc3 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c @@ -21,7 +21,7 @@ #include "ptexlib.h" static const char _svn_version[] = - "$Id: ltokenlib.c 3404 2010-01-28 11:17:10Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/ltokenlib.c $"; + "$Id: ltokenlib.c 3404 2010-01-28 11:17:10Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/ltokenlib.c $"; #define is_valid_token(L,i) (lua_istable(L,i) && lua_objlen(L,i)==3) #define get_token_cmd(L,i) lua_rawgeti(L,i,1) diff --git a/Build/source/texk/web2c/luatexdir/lua/luagen.w b/Build/source/texk/web2c/luatexdir/lua/luagen.w index 69589ba04e0..f992a15b17e 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luagen.w +++ b/Build/source/texk/web2c/luatexdir/lua/luagen.w @@ -20,7 +20,7 @@ @ @c static const char _svn_version[] = "$Id: luagen.w 3583 2010-04-02 17:40:44Z hhenkel $ " - "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/luagen.w $"; + "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luagen.w $"; #include "ptexlib.h" #include "pdf/pdfpage.h" diff --git a/Build/source/texk/web2c/luatexdir/lua/luainit.w b/Build/source/texk/web2c/luatexdir/lua/luainit.w index 3efeb7a949c..aa63118624c 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luainit.w +++ b/Build/source/texk/web2c/luatexdir/lua/luainit.w @@ -28,7 +28,7 @@ #include "ptexlib.h" static const char _svn_version[] = - "$Id: luainit.w 3621 2010-04-15 16:08:22Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/luainit.w $"; + "$Id: luainit.w 4114 2011-04-11 06:44:43Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luainit.w $"; @ TH: TODO @@ -331,7 +331,7 @@ static void parse_options(int argc, char **argv) "the terms of the GNU General Public License, version 2. For more\n" "information about these matters, see the file named COPYING and\n" "the LuaTeX source.\n\n" - "Copyright 2009 Taco Hoekwater, the LuaTeX Team.\n"); + "Copyright 2010 Taco Hoekwater, the LuaTeX Team.\n"); /* *INDENT-ON* */ uexit(0); } else if (ARGUMENT_IS("credits")) { @@ -350,7 +350,7 @@ static void parse_options(int argc, char **argv) "lua by Roberto Ierusalimschy, Waldemar Celes,\n" " Luiz Henrique de Figueiredo\n" "metapost by John Hobby, Taco Hoekwater and friends.\n" - "xpdf by Derek Noonburg (partial)\n" + "poppler by Derek Noonburg, Kristian Høgsberg (partial)\n" "fontforge by George Williams (partial)\n\n" "Some extensions to lua and additional lua libraries are used, as well as\n" "libraries for graphic inclusion. More details can be found in the source.\n" @@ -731,13 +731,13 @@ void lua_initialize(int ac, char **av) argv = av; if (luatex_svn < 0) { - if (asprintf(&banner, "This is LuaTeX, Version %s-%d%s", - luatex_version_string, luatex_date_info, WEB2CVERSION) < 0) { + if (asprintf(&banner, "This is LuaTeX, Version %s-%d", + luatex_version_string, luatex_date_info) < 0) { exit(EXIT_FAILURE); } } else { - if (asprintf(&banner, "This is LuaTeX, Version %s-%d%s (rev %d)", - luatex_version_string, luatex_date_info, WEB2CVERSION, luatex_svn) < 0) { + if (asprintf(&banner, "This is LuaTeX, Version %s-%d (rev %d)", + luatex_version_string, luatex_date_info, luatex_svn) < 0) { exit(EXIT_FAILURE); } } @@ -816,7 +816,7 @@ void lua_initialize(int ac, char **av) if (!dump_name) { get_lua_string("texconfig", "formatname", &dump_name); } - if ((lua_only) || ((!input_name) && (!dump_name))) { + if (lua_only) { if (given_file) free(given_file); /* this is not strictly needed but it pleases valgrind */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luanode.w b/Build/source/texk/web2c/luatexdir/lua/luanode.w index ce157f0767a..56f6cf734b2 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luanode.w +++ b/Build/source/texk/web2c/luatexdir/lua/luanode.w @@ -23,8 +23,8 @@ static const char _svn_version[] = - "$Id: luanode.w 3583 2010-04-02 17:40:44Z hhenkel $ " -"$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/luanode.w $"; + "$Id: luanode.w 4092 2011-03-16 14:53:39Z taco $ " +"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luanode.w $"; @ @c static const char *group_code_names[] = { @@ -60,10 +60,12 @@ const char *pack_type_name[] = { "exactly", "additional" }; void lua_node_filter_s(int filterid, const char *extrainfo) { lua_State *L = Luas; - int s_top = lua_gettop(L); int callback_id = callback_defined(filterid); - if (callback_id <= 0) + int s_top = lua_gettop(L); + if (callback_id <= 0) { + lua_settop(L, s_top); return; + } if (!get_callback(L, callback_id)) { lua_settop(L, s_top); return; @@ -87,19 +89,22 @@ lua_node_filter(int filterid, int xextrainfo, halfword head_node, halfword ret; int a; lua_State *L = Luas; + int s_top = lua_gettop(L); const char *extrainfo = group_code_names[xextrainfo]; int callback_id = callback_defined(filterid); - if (head_node == null || vlink(head_node) == null || callback_id <= 0) + if (head_node == null || vlink(head_node) == null || callback_id <= 0) { + lua_settop(L, s_top); return; + } if (!get_callback(L, callback_id)) { - lua_pop(L, 2); + lua_settop(L, s_top); return; } nodelist_to_lua(L, vlink(head_node)); /* arg 1 */ lua_pushstring(L, extrainfo); /* arg 2 */ if (lua_pcall(L, 2, 1, 0) != 0) { /* no arg, 1 result */ fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); - lua_pop(L, 2); + lua_settop(L, s_top); error(); return; } @@ -110,7 +115,7 @@ lua_node_filter(int filterid, int xextrainfo, halfword head_node, } } else { a = nodelist_from_lua(L); - vlink(head_node) = a; + try_couple_nodes(head_node,a); } lua_pop(L, 2); /* result and callback container table */ if (fix_node_lists) @@ -123,6 +128,7 @@ lua_node_filter(int filterid, int xextrainfo, halfword head_node, } else { *tail_node = head_node; } + lua_settop(L, s_top); return; } @@ -135,18 +141,21 @@ lua_linebreak_callback(int is_broken, halfword head_node, halfword * new_head) register halfword *p; int ret = 0; /* failure */ lua_State *L = Luas; + int s_top = lua_gettop(L); int callback_id = callback_defined(linebreak_filter_callback); - if (head_node == null || vlink(head_node) == null || callback_id <= 0) + if (head_node == null || vlink(head_node) == null || callback_id <= 0) { + lua_settop(L, s_top); return ret; + } if (!get_callback(L, callback_id)) { - lua_pop(L, 2); + lua_settop(L, s_top); return ret; } nodelist_to_lua(L, vlink(head_node)); /* arg 1 */ lua_pushboolean(L, is_broken); /* arg 2 */ if (lua_pcall(L, 2, 1, 0) != 0) { /* no arg, 1 result */ fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); - lua_pop(L, 2); + lua_settop(L, s_top); error(); return ret; } @@ -154,10 +163,10 @@ lua_linebreak_callback(int is_broken, halfword head_node, halfword * new_head) p = lua_touserdata(L, -1); if (p != NULL) { a = nodelist_from_lua(L); - vlink(*new_head) = a; + try_couple_nodes(*new_head,a); ret = 1; } - lua_pop(L, 2); /* result and callback container table */ + lua_settop(L, s_top); return ret; } @@ -170,11 +179,14 @@ lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo, { halfword ret; lua_State *L = Luas; + int s_top = lua_gettop(L); int callback_id = callback_defined(hpack_filter_callback); - if (head_node == null || callback_id <= 0) + if (head_node == null || callback_id <= 0) { + lua_settop(L, s_top); return head_node; + } if (!get_callback(L, callback_id)) { - lua_pop(L, 2); + lua_settop(L, s_top); return head_node; } nodelist_to_lua(L, head_node); @@ -187,7 +199,7 @@ lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo, lua_pushnil(L); if (lua_pcall(L, 5, 1, 0) != 0) { /* no arg, 1 result */ fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); - lua_pop(L, 2); + lua_settop(L, s_top); error(); return head_node; } @@ -200,7 +212,7 @@ lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo, } else { ret = nodelist_from_lua(L); } - lua_pop(L, 2); /* result and callback container table */ + lua_settop(L, s_top); #if 0 lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE); #endif @@ -217,18 +229,22 @@ lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, halfword ret; int callback_id; lua_State *L = Luas; - if (head_node == null) + int s_top = lua_gettop(L); + if (head_node == null) { + lua_settop(L, s_top); return head_node; + } if (strcmp("output", group_code_names[extrainfo]) == 0) { callback_id = callback_defined(pre_output_filter_callback); } else { callback_id = callback_defined(vpack_filter_callback); } if (callback_id <= 0) { + lua_settop(L, s_top); return head_node; } if (!get_callback(L, callback_id)) { - lua_pop(L, 2); + lua_settop(L, s_top); return head_node; } nodelist_to_lua(L, head_node); @@ -242,7 +258,7 @@ lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, lua_pushnil(L); if (lua_pcall(L, 6, 1, 0) != 0) { /* no arg, 1 result */ fprintf(stdout, "error: %s\n", lua_tostring(L, -1)); - lua_pop(L, 2); + lua_settop(L, s_top); error(); return head_node; } @@ -255,7 +271,7 @@ lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, } else { ret = nodelist_from_lua(L); } - lua_pop(L, 2); /* result and callback container table */ + lua_settop(L, s_top); #if 0 lua_gc(L,LUA_GCSTEP, LUA_GC_STEP_SIZE); #endif @@ -297,13 +313,7 @@ void lua_pdf_literal(PDF pdf, int i) size_t l = 0; lua_rawgeti(Luas, LUA_REGISTRYINDEX, i); s = lua_tolstring(Luas, -1, &l); - if (l < max_single_pdf_print) { - pdf_out_block(pdf, s, l); - } else { - while (l--) { - pdf_out(pdf, *s++); - } - } + pdf_out_block(pdf, s, l); pdf_out(pdf, 10); /* |pdf_print_nl| */ lua_pop(Luas, 1); } @@ -322,6 +332,20 @@ void copy_pdf_literal(pointer r, pointer p) } } +void copy_late_lua(pointer r, pointer p) +{ + late_lua_type(r) = late_lua_type(p); + if (late_lua_name(p) > 0) + add_token_ref(late_lua_name(p)); + if (late_lua_type(p) == normal) { + late_lua_data(r) = late_lua_data(p); + add_token_ref(late_lua_data(p)); + } else { + lua_rawgeti(Luas, LUA_REGISTRYINDEX, late_lua_data(p)); + late_lua_data(r) = luaL_ref(Luas, LUA_REGISTRYINDEX); + } +} + @ @c void free_pdf_literal(pointer p) @@ -333,6 +357,17 @@ void free_pdf_literal(pointer p) } } +void free_late_lua(pointer p) +{ + if (late_lua_name(p) > 0) + delete_token_ref(late_lua_name(p)); + if (late_lua_type(p) == normal) { + delete_token_ref(late_lua_data(p)); + } else { + luaL_unref(Luas, LUA_REGISTRYINDEX, late_lua_data(p)); + } +} + @ @c void show_pdf_literal(pointer p) { @@ -354,7 +389,24 @@ void show_pdf_literal(pointer p) print_mark(pdf_literal_data(p)); } else { lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(p)); + tprint("\""); + tprint(lua_tostring(Luas, -1)); + tprint("\""); + lua_pop(Luas, 1); + } +} + +void show_late_lua(pointer p) +{ + tprint_esc("latelua"); + print_int(late_lua_reg(p)); + if (late_lua_type(p) == normal) { + print_mark(late_lua_data(p)); + } else { + lua_rawgeti(Luas, LUA_REGISTRYINDEX, late_lua_data(p)); + tprint("\""); tprint(lua_tostring(Luas, -1)); + tprint("\""); lua_pop(Luas, 1); } } diff --git a/Build/source/texk/web2c/luatexdir/lua/luastuff.w b/Build/source/texk/web2c/luatexdir/lua/luastuff.w index e8a3c5b9321..fdd38dbd798 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luastuff.w +++ b/Build/source/texk/web2c/luatexdir/lua/luastuff.w @@ -19,8 +19,8 @@ @ @c static const char _svn_version[] = - "$Id: luastuff.w 3612 2010-04-13 09:29:42Z taco $ " - "$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/luastuff.w $"; + "$Id: luastuff.w 4001 2010-11-28 15:49:46Z taco $ " + "$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luastuff.w $"; #include "lua/luatex-api.h" #include "ptexlib.h" @@ -189,6 +189,7 @@ void luainterpreter(void) luatex_md5_lua_open(L); open_oslibext(L, safer_option); + open_lfslibext(L); /* luasockets */ /* socket and mime are a bit tricky to open because @@ -344,24 +345,35 @@ int lua_traceback(lua_State * L) } @ @c -static void luacall(int p, int nameptr) +static void luacall(int p, int nameptr, boolean is_string) { LoadS ls; - int i, l; + int i; + size_t ll = 0; char *lua_id; char *s = NULL; if (Luas == NULL) { luainterpreter(); } - l = 0; lua_active++; - s = tokenlist_to_cstring(p, 1, &l); + if (is_string) { + const char *ss = NULL; + lua_rawgeti(Luas, LUA_REGISTRYINDEX, p); + ss = lua_tolstring(Luas, -1, &ll); + s = xmalloc(ll+1); + memcpy(s,ss,ll+1); + lua_pop(Luas,1); + } else { + int l = 0; + s = tokenlist_to_cstring(p, 1, &l); + ll = (size_t)l; + } ls.s = s; - ls.size = (size_t) l; - + ls.size = ll; if (ls.size > 0) { if (nameptr > 0) { + int l = 0; /* not used */ lua_id = tokenlist_to_cstring(nameptr, 1, &l); } else if (nameptr < 0) { char *tmp = get_lua_name((nameptr + 65536)); @@ -390,6 +402,7 @@ static void luacall(int p, int nameptr) } } xfree(lua_id); + xfree(ls.s); } lua_active--; } @@ -398,9 +411,13 @@ static void luacall(int p, int nameptr) void late_lua(PDF pdf, halfword p) { (void) pdf; - expand_macros_in_tokenlist(p); /* sets |def_ref| */ - luacall(def_ref, late_lua_name(p)); - flush_list(def_ref); + if (late_lua_type(p)==normal) { + expand_macros_in_tokenlist(p); /* sets |def_ref| */ + luacall(def_ref, late_lua_name(p), false); + flush_list(def_ref); + } else { + luacall(late_lua_data(p), late_lua_name(p), true); + } } @ @c diff --git a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h index e754a498d8d..e25f3ca8d40 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h +++ b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: luatex-api.h 3612 2010-04-13 09:29:42Z taco $ */ +/* $Id: luatex-api.h 4001 2010-11-28 15:49:46Z taco $ */ #ifndef LUATEX_API_H # define LUATEX_API_H 1 @@ -30,7 +30,7 @@ # include "lua51/lualib.h" typedef struct LoadS { - const char *s; + char *s; size_t size; } LoadS; @@ -75,6 +75,7 @@ extern int luaopen_epdf(lua_State * L); extern int luaopen_mplib(lua_State * L); extern void open_oslibext(lua_State * L, int safer_option); +extern void open_lfslibext(lua_State * L); extern void initfilecallbackids(int max); extern void setinputfilecallbackid(int n, int i); @@ -167,12 +168,10 @@ extern int program_name_set; /* in lkpselib.c */ extern char **argv; extern int argc; - extern int loader_C_luatex(lua_State * L, const char *name, const char *filename); -extern int loader_Call_luatex (lua_State *L, const char *name, - const char *filename); - +extern int loader_Call_luatex(lua_State * L, const char *name, + const char *filename); extern void init_tex_table(lua_State * L); @@ -198,6 +197,6 @@ extern char charsetstr[]; /* from mpdir/psout.w */ extern char **environ; -extern int luac_main(int argc, char *argv[]); /* texluac.w */ +extern int luac_main(int argc, char *argv[]); /* texluac.w */ -#endif +#endif /* LUATEX_API_H */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luatoken.w b/Build/source/texk/web2c/luatexdir/lua/luatoken.w index 7647eec5f9b..d41dd78db88 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatoken.w +++ b/Build/source/texk/web2c/luatexdir/lua/luatoken.w @@ -22,8 +22,8 @@ #include "ptexlib.h" static const char _svn_version[] = - "$Id: luatoken.w 3583 2010-04-02 17:40:44Z hhenkel $ " -"$URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/luatoken.w $"; + "$Id: luatoken.w 3849 2010-09-01 09:10:48Z taco $ " +"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/luatoken.w $"; @ @c command_item command_names[] = { @@ -144,15 +144,6 @@ command_item command_names[] = { {"set_interaction", set_interaction_cmd, NULL}, {"letterspace_font", letterspace_font_cmd, NULL}, {"pdf_copy_font", pdf_copy_font_cmd, NULL}, - {"set_ocp", set_ocp_cmd, NULL}, - {"def_ocp", def_ocp_cmd, NULL}, - {"set_ocp_list", set_ocp_list_cmd, NULL}, - {"def_ocp_list", def_ocp_list_cmd, NULL}, - {"clear_ocp_lists", clear_ocp_lists_cmd, NULL}, - {"push_ocp_list", push_ocp_list_cmd, NULL}, - {"pop_ocp_list", pop_ocp_list_cmd, NULL}, - {"ocp_list_op", ocp_list_op_cmd, NULL}, - {"ocp_trace_level", ocp_trace_level_cmd, NULL}, {"undefined_cs", undefined_cs_cmd, NULL}, {"expand_after", expand_after_cmd, NULL}, {"no_expand", no_expand_cmd, NULL}, diff --git a/Build/source/texk/web2c/luatexdir/lua/texluac.w b/Build/source/texk/web2c/luatexdir/lua/texluac.w index 3bc7cc2069d..153ae7a8934 100644 --- a/Build/source/texk/web2c/luatexdir/lua/texluac.w +++ b/Build/source/texk/web2c/luatexdir/lua/texluac.w @@ -49,7 +49,7 @@ @ @c static const char _svn_version[] = - "$Id: texluac.w 3705 2010-05-28 07:19:20Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/branches/0.60.x/source/texk/web2c/luatexdir/lua/texluac.w $"; + "$Id: texluac.w 3707 2010-05-28 13:24:16Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/lua/texluac.w $"; /* fix for non-gcc compilation: */ #if !defined(__GNUC__) || (__GNUC__ < 2) |