beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / pdf / pdfluaapi.w.old
blobebd20d6e20d237280209ce598a85fd0679a9bf07
1 % pdfluaapi.w
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/>.
20 @ @c
23 #include "ptexlib.h"
25 @ @c
26 int new_pdflua(void)
28     int i, err;
29     Byte *uncompr;
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);
35     if (err != Z_OK)
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);       /* - */
43     xfree(uncompr);
44     return i;
47 @ @c
48 void pdflua_begin_page(PDF pdf)
50     int err;                    /* ... */
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 ... */
64     if (err != 0)
65         luatex_fail("pdflua.lua: beginpage()");
66     /* t ... */
67     lua_pop(Luas, 1);           /* ... */
70 @ @c
71 void pdflua_end_page(PDF pdf, int annots, int beads)
73     int err;                    /* ... */
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 ... */
84     if (annots != 0) {
85         lua_pushnumber(Luas, annots);   /* i t f t ... */
86         lua_setfield(Luas, -2, "annots");       /* t f t ... */
87     }
88     if (beads != 0) {
89         lua_pushnumber(Luas, beads);    /* i t f t ... */
90         lua_setfield(Luas, -2, "beads");        /* t f t ... */
91     }
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 ... */
95     }
96     err = lua_pcall(Luas, 1, 0, 0);     /* (e) t ... */
97     if (err != 0)
98         luatex_fail("pdflua.lua: endpage()");
99     /* t ... */
100     lua_pop(Luas, 1);           /* ... */
103 @ @c
104 void pdflua_output_pages_tree(PDF pdf)
106     int err;
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);     /* - */
111     if (err != 0)
112         luatex_fail("pdflua.lua: outputpagestree()");