3 % Copyright 2010 Taco Hoekwater <taco@@luatex.org>
5 % This file is part of LuaTeX.
7 % LuaTeX is free software; you can redistribute it and/or modify it under
8 % the terms of the GNU General Public License as published by the Free
9 % Software Foundation; either version 2 of the License, or (at your
10 % option) any later version.
12 % LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 % FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 % License for more details.
17 % You should have received a copy of the GNU General Public License along
18 % with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
30 const zlib_struct *zp = pdflua_zlib_struct_ptr;
31 uLong uncomprLen = zp->uncomprLen;
32 if ((uncompr = xtalloc(zp->uncomprLen, Byte)) == NULL)
33 luatex_fail("new_pdflua(): xtalloc()");
34 err = uncompress(uncompr, &uncomprLen, zp->compr, zp->comprLen);
36 luatex_fail("new_pdflua(): uncompress()");
37 assert(uncomprLen == zp->uncomprLen);
38 if (luaL_loadbuffer(Luas, (const char *) uncompr, uncomprLen, "pdflua")
39 || lua_pcall(Luas, 0, 1, 0))
40 luatex_fail("new_pdflua(): lua_pcall()");
41 luaL_checktype(Luas, -1, LUA_TTABLE); /* t */
42 i = luaL_ref(Luas, LUA_REGISTRYINDEX); /* - */
48 void pdflua_begin_page(PDF pdf)
51 lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf->pdflua_ref); /* t ... */
52 lua_pushstring(Luas, "beginpage"); /* s t ... */
53 lua_gettable(Luas, -2); /* f t ... */
54 lua_newtable(Luas); /* t f t ... */
55 lua_pushnumber(Luas, total_pages + 1); /* i t f t ... */
56 lua_setfield(Luas, -2, "pagenum"); /* t f t ... */
57 lua_pushnumber(Luas, pdf->last_page); /* i t f t ... */
58 lua_setfield(Luas, -2, "page_objnum"); /* t f t ... */
59 lua_pushnumber(Luas, pdf->last_stream); /* i t f t ... */
60 lua_setfield(Luas, -2, "stream_objnum"); /* t f t ... */
61 lua_pushnumber(Luas, pdf->page_resources->last_resources); /* i t f t ... */
62 lua_setfield(Luas, -2, "resources_objnum"); /* t f t ... */
63 err = lua_pcall(Luas, 1, 0, 0); /* (e) t ... */
65 luatex_fail("pdflua.lua: beginpage()");
67 lua_pop(Luas, 1); /* ... */
71 void pdflua_end_page(PDF pdf, int annots, int beads)
74 lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf->pdflua_ref); /* t ... */
75 lua_pushstring(Luas, "endpage"); /* s t ... */
76 lua_gettable(Luas, -2); /* f t ... */
77 lua_newtable(Luas); /* t f t ... */
78 lua_pushnumber(Luas, total_pages); /* i t f t ... */
79 lua_setfield(Luas, -2, "pagenum"); /* t f t ... */
80 lua_pushnumber(Luas, pdf->page_size.h); /* i t f t ... */
81 lua_setfield(Luas, -2, "hsize"); /* t f t ... */
82 lua_pushnumber(Luas, pdf->page_size.v); /* i t f t ... */
83 lua_setfield(Luas, -2, "vsize"); /* t f t ... */
85 lua_pushnumber(Luas, annots); /* i t f t ... */
86 lua_setfield(Luas, -2, "annots"); /* t f t ... */
89 lua_pushnumber(Luas, beads); /* i t f t ... */
90 lua_setfield(Luas, -2, "beads"); /* t f t ... */
92 if (pdf->img_page_group_val != 0) {
93 lua_pushnumber(Luas, pdf->img_page_group_val); /* i t f t ... */
94 lua_setfield(Luas, -2, "imggroup"); /* t f t ... */
96 err = lua_pcall(Luas, 1, 0, 0); /* (e) t ... */
98 luatex_fail("pdflua.lua: endpage()");
100 lua_pop(Luas, 1); /* ... */
104 void pdflua_output_pages_tree(PDF pdf)
107 lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf->pdflua_ref); /* t */
108 lua_pushstring(Luas, "outputpagestree"); /* s t */
109 lua_gettable(Luas, -2); /* f */
110 err = lua_pcall(Luas, 0, 0, 0); /* - */
112 luatex_fail("pdflua.lua: outputpagestree()");