summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/lepdflib.cc')
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lepdflib.cc157
1 files changed, 131 insertions, 26 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc
index b003b6b1931..5bc11a38bc0 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc
+++ b/Build/source/texk/web2c/luatexdir/lua/lepdflib.cc
@@ -1,7 +1,7 @@
/* lepdflib.cc
- Copyright 2009-2012 Taco Hoekwater <taco@luatex.org>
- Copyright 2009-2012 Hartmut Henkel <hartmut@luatex.org>
+ Copyright 2009-2013 Taco Hoekwater <taco@luatex.org>
+ Copyright 2009-2013 Hartmut Henkel <hartmut@luatex.org>
This file is part of LuaTeX.
@@ -19,7 +19,7 @@
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
static const char _svn_version[] =
- "$Id: lepdflib.cc 4415 2012-05-09 19:56:06Z oneiros $ "
+ "$Id: lepdflib.cc 4573 2013-02-03 16:47:07Z hhenkel $ "
"$URL: http://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lepdflib.cc $";
#include "image/epdf.h"
@@ -53,6 +53,8 @@ static const char *ErrorCodeNames[] = { "None", "OpenFile", "BadCatalog",
#define M_Array "Array"
#define M_Catalog "Catalog"
#define M_Dict "Dict"
+#define M_EmbFile "EmbFile"
+#define M_FileSpec "FileSpec"
#define M_GooString "GooString"
#define M_LinkDest "LinkDest"
#define M_Link "Link"
@@ -85,6 +87,8 @@ new_poppler_userdata(Annot);
new_poppler_userdata(Array);
new_poppler_userdata(Catalog);
new_poppler_userdata(Dict);
+new_poppler_userdata(EmbFile);
+new_poppler_userdata(FileSpec);
new_poppler_userdata(LinkDest);
new_poppler_userdata(Links);
new_poppler_userdata(Object);
@@ -179,7 +183,7 @@ static int l_new_PDFRectangle(lua_State * L)
return 1;
}
-static const struct luaL_Reg epdflib[] = {
+static const struct luaL_Reg epdflib_f[] = {
{"open", l_open_PDFDoc},
{"Array", l_new_Array},
{"Dict", l_new_Dict},
@@ -350,7 +354,11 @@ static int m_Annot__gc(lua_State * L)
printf("\n===== Annot GC ===== uin=<%p>\n", uin);
#endif
if (uin->atype == ALLOC_LEPDF)
+#if 1 /* def HAVE_ANNOTDECREFCNT */
((Annot *) uin->d)->decRefCnt();
+#else
+ delete(Annot *) uin->d;
+#endif
return 0;
}
@@ -611,6 +619,25 @@ static int m_Catalog_findDest(lua_State * L)
m_poppler_get_poppler(Catalog, Object, getDests);
m_poppler_get_INT(Catalog, numEmbeddedFiles);
+static int m_Catalog_embeddedFile(lua_State * L)
+{
+ 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) {
+ uout = new_FileSpec_userdata(L);
+ uout->d = ((Catalog *) uin->d)->embeddedFile(i - 1);
+ uout->pc = uin->pc;
+ uout->pd = uin->pd;
+ } else
+ lua_pushnil(L);
+ return 1;
+}
+
m_poppler_get_INT(Catalog, numJS);
static int m_Catalog_getJS(lua_State * L)
@@ -652,6 +679,7 @@ static const struct luaL_Reg Catalog_m[] = {
{"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},
@@ -862,6 +890,80 @@ static const struct luaL_Reg Dict_m[] = {
};
//**********************************************************************
+// EmbFile
+
+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);
+
+m_poppler_get_BOOL(EmbFile, isOk);
+
+static int m_EmbFile_save(lua_State * L)
+{
+ const char *s;
+ size_t len;
+ udstruct *uin;
+ uin = (udstruct *) luaL_checkudata(L, 1, M_EmbFile);
+ if (uin->pd != NULL && uin->pd->pc != uin->pc)
+ pdfdoc_changed_error(L);
+ s = luaL_checklstring(L, 2, &len);
+ if (((EmbFile *) uin->d)->save(s))
+ lua_pushboolean(L, 1);
+ else
+ lua_pushboolean(L, 0);
+ return 1;
+}
+
+m_poppler__tostring(EmbFile);
+
+static const struct luaL_Reg EmbFile_m[] = {
+ {"size", m_EmbFile_size},
+ {"modDate", m_EmbFile_modDate},
+ {"createDate", m_EmbFile_createDate},
+ {"checksum", m_EmbFile_checksum},
+ {"mimeType", m_EmbFile_mimeType},
+ {"isOk", m_EmbFile_isOk},
+ {"save", m_EmbFile_save},
+ {"__tostring", m_EmbFile__tostring},
+ {NULL, NULL} // sentinel
+};
+
+//**********************************************************************
+// FileSpec
+
+m_poppler_get_BOOL(FileSpec, isOk);
+m_poppler_get_GOOSTRING(FileSpec, getFileName);
+m_poppler_get_GOOSTRING(FileSpec, getFileNameForPlatform);
+m_poppler_get_GOOSTRING(FileSpec, getDescription);
+
+static int m_FileSpec_getEmbeddedFile(lua_State * L)
+{
+ udstruct *uin, *uout;
+ uin = (udstruct *) luaL_checkudata(L, 1, M_FileSpec);
+ if (uin->pd != NULL && uin->pd->pc != uin->pc)
+ pdfdoc_changed_error(L);
+ uout = new_EmbFile_userdata(L);
+ uout->d = ((FileSpec *) uin->d)->getEmbeddedFile();
+ uout->pc = uin->pc;
+ uout->pd = uin->pd;
+ return 1;
+}
+
+m_poppler__tostring(FileSpec);
+
+static const struct luaL_Reg FileSpec_m[] = {
+ {"isOk", m_FileSpec_isOk},
+ {"getFileName", m_FileSpec_getFileName},
+ {"getFileNameForPlatform", m_FileSpec_getFileNameForPlatform},
+ {"getDescription", m_FileSpec_getDescription},
+ {"getEmbeddedFile", m_FileSpec_getEmbeddedFile},
+ {"__tostring", m_FileSpec__tostring},
+ {NULL, NULL} // sentinel
+};
+
+//**********************************************************************
// GooString
static int m_GooString__tostring(lua_State * L)
@@ -1406,7 +1508,6 @@ static int m_Object_getRefGen(lua_State * L)
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)
@@ -1767,8 +1868,10 @@ static int m_Object__gc(lua_State * L)
#ifdef DEBUG
printf("\n===== Object GC ===== uin=<%p>\n", uin);
#endif
- if (uin->atype == ALLOC_LEPDF)
+ if (uin->atype == ALLOC_LEPDF) {
+ ((Object *) uin->d)->free();
delete(Object *) uin->d;
+ }
return 0;
}
@@ -2514,33 +2617,35 @@ static const struct luaL_Reg XRefEntry_m[] = {
//**********************************************************************
-#define register_meta(type) \
+#define setfuncs_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)
+ luaL_setfuncs(L, type##_m, 0)
int luaopen_epdf(lua_State * L)
{
- register_meta(Annot);
- register_meta(Annots);
- register_meta(Array);
- register_meta(Catalog);
- 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);
+ setfuncs_meta(Annot);
+ setfuncs_meta(Annots);
+ setfuncs_meta(Array);
+ setfuncs_meta(Catalog);
+ setfuncs_meta(Dict);
+ setfuncs_meta(EmbFile);
+ setfuncs_meta(FileSpec);
+ setfuncs_meta(GooString);
+ setfuncs_meta(LinkDest);
+ setfuncs_meta(Links);
+ setfuncs_meta(Object);
+ setfuncs_meta(Page);
+ setfuncs_meta(PDFDoc);
+ setfuncs_meta(PDFRectangle);
+ setfuncs_meta(Ref);
+ setfuncs_meta(Stream);
+ setfuncs_meta(XRef);
+ setfuncs_meta(XRefEntry);
+
+ luaL_newlib(L, epdflib_f);
return 1;
}