Debian Codegraph @

texk/web2c/luatexdir/lua/lepdflib.cc.orig

raw
1 /* lepdflib.cc
2
3 Copyright 2009-2015 Taco Hoekwater <[email protected]>
4 Copyright 2009-2013 Hartmut Henkel <[email protected]>
5
6 This file is part of LuaTeX.
7
8 LuaTeX is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
12
13 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
20
21
22 #include "image/epdf.h"
23
24 /*
25 Patches for the new poppler 0.59 from:
26
27 https://www.mail-archive.com/[email protected]/msg357548.html
28
29 with some modifications to comply the poppler API.
30 */
31
32 /* define DEBUG */
33
34 /* objects allocated by poppler may not be deleted in the lepdflib */
35
36 typedef enum { ALLOC_POPPLER, ALLOC_LEPDF } alloctype;
37
38 typedef struct {
39 void *d;
40 alloctype atype; // was it allocated by poppler or the lepdflib.cc?
41 PdfDocument *pd; // reference to PdfDocument, or NULL
42 unsigned long pc; // counter to detect PDFDoc change
43 } udstruct;
44
45 static const char *ErrorCodeNames[] = {
46 "None", "OpenFile", "BadCatalog",
47 "Damaged", "Encrypted", "HighlightFile", "BadPrinter", "Printing",
48 "Permission", "BadPageNum", "FileIO",
49 NULL
50 };
51
52 #define M_Annot "epdf.Annot" /* ls-hh: epdf.* gives better protection in registry */
53 #define M_Annots "epdf.Annots"
54 #define M_Array "epdf.Array"
55 #define M_Catalog "epdf.Catalog"
56 #define M_Dict "epdf.Dict"
57 #define M_EmbFile "epdf.EmbFile"
58 #define M_FileSpec "epdf.FileSpec"
59 #define M_GooString "epdf.GooString"
60 #define M_LinkDest "epdf.LinkDest"
61 #define M_Link "epdf.Link"
62 #define M_Links "epdf.Links"
63 #define M_Object "epdf.Object"
64 #define M_Page "epdf.Page"
65 #define M_PDFDoc "epdf.PDFDoc"
66 #define M_PDFRectangle "epdf.PDFRectangle"
67 #define M_Ref "epdf.Ref"
68 #define M_Stream "epdf.Stream"
69 #define M_StructElement "epdf.StructElement"
70 #define M_Attribute "epdf.Attribute"
71 #define M_TextSpan "epdf.TextSpan"
72 #define M_StructTreeRoot "epdf.StructTreeRoot"
73 #define M_XRefEntry "epdf.XRefEntry"
74 #define M_XRef "epdf.XRef"
75
76 #define new_poppler_userdata(type) \
77 static udstruct *new_##type##_userdata(lua_State * L) \
78 { \
79 udstruct *a; \
80 a = (udstruct *) lua_newuserdata(L, sizeof(udstruct)); /* udstruct ... */ \
81 a->atype = ALLOC_POPPLER; \
82 luaL_getmetatable(L, M_##type); /* m udstruct ... */ \
83 lua_setmetatable(L, -2); /* udstruct ... */ \
84 return a; \
85 }
86
87 new_poppler_userdata(PDFDoc);
88 new_poppler_userdata(Annot);
89 new_poppler_userdata(Array);
90 new_poppler_userdata(Catalog);
91 new_poppler_userdata(Dict);
92 new_poppler_userdata(EmbFile);
93 new_poppler_userdata(FileSpec);
94 new_poppler_userdata(LinkDest);
95 new_poppler_userdata(Links);
96 new_poppler_userdata(Object);
97 new_poppler_userdata(Page);
98 new_poppler_userdata(PDFRectangle);
99 new_poppler_userdata(Ref);
100 new_poppler_userdata(Stream);
101 new_poppler_userdata(StructElement);
102 new_poppler_userdata(Attribute);
103 new_poppler_userdata(TextSpan);
104 new_poppler_userdata(StructTreeRoot);
105 new_poppler_userdata(XRef);
106
107 /* These two can go away as we don't change the document. */
108
109 static void pdfdoc_changed_error(lua_State * L)
110 {
111 luaL_error(L, "PDFDoc changed or gone");
112 }
113
114 static void pdfdoc_differs_error(lua_State * L)
115 {
116 luaL_error(L, "PDFDoc differs between arguments");
117 }
118
119 static int l_open_PDFDoc(lua_State * L)
120 {
121 const char *file_path;
122 udstruct *uout;
123 PdfDocument *d;
124 file_path = luaL_checkstring(L, 1); // path
125 d = refPdfDocument(file_path, FE_RETURN_NULL);
126 if (d == NULL)
127 lua_pushnil(L);
128 else {
129 if (!(globalParams)) // globalParams could be already created
130 globalParams = new GlobalParams();
131 uout = new_PDFDoc_userdata(L);
132 uout->d = d;
133 uout->atype = ALLOC_LEPDF;
134 uout->pc = d->pc;
135 uout->pd = d;
136 }
137 return 1;
138 }
139
140 static int l_open_MemStreamPDFDoc(lua_State * L)
141 {
142 const char *docstream = NULL;
143 char *docstream_usr = NULL ;
144 const char *file_id;
145 unsigned long long stream_size;
146 udstruct *uout;
147 PdfDocument *d;
148 switch (lua_type(L, 1)) {
149 case LUA_TSTRING:
150 docstream = luaL_checkstring(L, 1); // stream as Lua string
151 break;
152 case LUA_TLIGHTUSERDATA:
153 docstream = (const char *) lua_touserdata(L, 1); // stream as sequence of bytes
154 break;
155 default:
156 luaL_error(L, "bad argument: string or lightuserdata expected");
157 }
158 if (docstream==NULL)
159 luaL_error(L, "bad document");
160 stream_size = (unsigned long long) luaL_checkint(L, 2);// size of the stream
161 file_id = luaL_checkstring(L, 3); // a symbolic name for this stream, mandatory
162 if (file_id == NULL)
163 luaL_error(L, "PDFDoc has an invalid id");
164 if (strlen(file_id) >STREAM_FILE_ID_LEN ) // a limit to the length of the string
165 luaL_error(L, "PDFDoc has a too long id");
166 docstream_usr = (char *)gmalloc((unsigned) (stream_size + 1));
167 if (!docstream_usr)
168 luaL_error(L, "no room for PDFDoc");
169 memcpy(docstream_usr, docstream, (stream_size + 1));
170 docstream_usr[stream_size]='\0';
171 d = refMemStreamPdfDocument(docstream_usr, stream_size, file_id);
172 if (d == NULL) {
173 lua_pushnil(L);
174 lua_pushnil(L);
175 lua_pushnil(L);
176 } else if (d->file_path == NULL ) {
177 lua_pushnil(L);
178 lua_pushnil(L);
179 lua_pushnil(L);
180 }
181 else {
182 if (!(globalParams)) // globalParams could be already created
183 globalParams = new GlobalParams();
184 uout = new_PDFDoc_userdata(L);
185 uout->d = d;
186 uout->atype = ALLOC_LEPDF;
187 uout->pc = d->pc;
188 uout->pd = d;
189 lua_pushstring(L,d->file_path);
190 lua_pushstring(L,STREAM_URI);
191 }
192 return 3; // stream, stream_id, stream_uri
193 }
194
195 #define ATTRIBUTE_TYPE_ENTRY(name) \
196 lua_pushstring(L, #name); \
197 lua_pushinteger(L, Attribute::name); \
198 lua_settable(L,-3)
199
200
201 #define OBJECT_TYPE(name) \
202 lua_pushstring(L, #name); \
203 lua_pushinteger(L, (int)name); \
204 lua_settable(L,-3)
205
206
207 #define STRUCTELEMENT_TYPE_ENTRY(name) \
208 lua_pushstring(L, #name); \
209 lua_pushinteger(L, StructElement::name); \
210 lua_settable(L,-3)
211
212
213 static int l_Attribute_Type(lua_State * L) {
214 lua_createtable (L, 0, 42);
215 ATTRIBUTE_TYPE_ENTRY(BBox);
216 ATTRIBUTE_TYPE_ENTRY(BackgroundColor);
217 ATTRIBUTE_TYPE_ENTRY(BorderColor);
218 ATTRIBUTE_TYPE_ENTRY(BorderThickness);
219 ATTRIBUTE_TYPE_ENTRY(Color);
220 ATTRIBUTE_TYPE_ENTRY(ColumnGap);
221 ATTRIBUTE_TYPE_ENTRY(ColumnWidths);
222 ATTRIBUTE_TYPE_ENTRY(Desc);
223 ATTRIBUTE_TYPE_ENTRY(Role);
224 ATTRIBUTE_TYPE_ENTRY(TextDecorationColor);
225 ATTRIBUTE_TYPE_ENTRY(TextDecorationThickness);
226 ATTRIBUTE_TYPE_ENTRY(BaselineShift);
227 ATTRIBUTE_TYPE_ENTRY(BlockAlign);
228 ATTRIBUTE_TYPE_ENTRY(BorderStyle);
229 ATTRIBUTE_TYPE_ENTRY(ColSpan);
230 ATTRIBUTE_TYPE_ENTRY(ColumnCount);
231 ATTRIBUTE_TYPE_ENTRY(EndIndent);
232 ATTRIBUTE_TYPE_ENTRY(GlyphOrientationVertical);
233 ATTRIBUTE_TYPE_ENTRY(Headers);
234 ATTRIBUTE_TYPE_ENTRY(Height);
235 ATTRIBUTE_TYPE_ENTRY(InlineAlign);
236 ATTRIBUTE_TYPE_ENTRY(LineHeight);
237 ATTRIBUTE_TYPE_ENTRY(ListNumbering);
238 ATTRIBUTE_TYPE_ENTRY(Padding);
239 ATTRIBUTE_TYPE_ENTRY(Placement);
240 ATTRIBUTE_TYPE_ENTRY(RowSpan);
241 ATTRIBUTE_TYPE_ENTRY(RubyAlign);
242 ATTRIBUTE_TYPE_ENTRY(RubyPosition);
243 ATTRIBUTE_TYPE_ENTRY(Scope);
244 ATTRIBUTE_TYPE_ENTRY(SpaceAfter);
245 ATTRIBUTE_TYPE_ENTRY(SpaceBefore);
246 ATTRIBUTE_TYPE_ENTRY(StartIndent);
247 ATTRIBUTE_TYPE_ENTRY(Summary);
248 ATTRIBUTE_TYPE_ENTRY(TBorderStyle);
249 ATTRIBUTE_TYPE_ENTRY(TPadding);
250 ATTRIBUTE_TYPE_ENTRY(TextAlign);
251 ATTRIBUTE_TYPE_ENTRY(TextDecorationType);
252 ATTRIBUTE_TYPE_ENTRY(TextIndent);
253 ATTRIBUTE_TYPE_ENTRY(Width);
254 ATTRIBUTE_TYPE_ENTRY(WritingMode);
255 ATTRIBUTE_TYPE_ENTRY(Unknown);
256 ATTRIBUTE_TYPE_ENTRY(checked);
257 return 1;
258 }
259
260 static int l_Object_Type(lua_State * L) {
261 lua_createtable(L,0,16);/*nr of ObjType values*/ ;
262 OBJECT_TYPE(objBool);
263 OBJECT_TYPE(objInt);
264 OBJECT_TYPE(objReal);
265 OBJECT_TYPE(objString);
266 OBJECT_TYPE(objName);
267 OBJECT_TYPE(objNull);
268 OBJECT_TYPE(objArray);
269 OBJECT_TYPE(objDict);
270 OBJECT_TYPE(objStream);
271 OBJECT_TYPE(objRef);
272 OBJECT_TYPE(objCmd);
273 OBJECT_TYPE(objError);
274 OBJECT_TYPE(objEOF);
275 OBJECT_TYPE(objNone);
276 OBJECT_TYPE(objInt64);
277 OBJECT_TYPE(objDead);
278 return 1;
279 }
280
281 static int l_StructElement_Type(lua_State * L) {
282 lua_createtable (L, 0, 50);
283 STRUCTELEMENT_TYPE_ENTRY(Document);
284 STRUCTELEMENT_TYPE_ENTRY(Part);
285 STRUCTELEMENT_TYPE_ENTRY(Art);
286 STRUCTELEMENT_TYPE_ENTRY(Sect);
287 STRUCTELEMENT_TYPE_ENTRY(Div);
288 STRUCTELEMENT_TYPE_ENTRY(BlockQuote);
289 STRUCTELEMENT_TYPE_ENTRY(Caption);
290 STRUCTELEMENT_TYPE_ENTRY(NonStruct);
291 STRUCTELEMENT_TYPE_ENTRY(Index);
292 STRUCTELEMENT_TYPE_ENTRY(Private);
293 STRUCTELEMENT_TYPE_ENTRY(Span);
294 STRUCTELEMENT_TYPE_ENTRY(Quote);
295 STRUCTELEMENT_TYPE_ENTRY(Note);
296 STRUCTELEMENT_TYPE_ENTRY(Reference);
297 STRUCTELEMENT_TYPE_ENTRY(BibEntry);
298 STRUCTELEMENT_TYPE_ENTRY(Code);
299 STRUCTELEMENT_TYPE_ENTRY(Link);
300 STRUCTELEMENT_TYPE_ENTRY(Annot);
301 STRUCTELEMENT_TYPE_ENTRY(Ruby);
302 STRUCTELEMENT_TYPE_ENTRY(RB);
303 STRUCTELEMENT_TYPE_ENTRY(RT);
304 STRUCTELEMENT_TYPE_ENTRY(RP);
305 STRUCTELEMENT_TYPE_ENTRY(Warichu);
306 STRUCTELEMENT_TYPE_ENTRY(WT);
307 STRUCTELEMENT_TYPE_ENTRY(WP);
308 STRUCTELEMENT_TYPE_ENTRY(P);
309 STRUCTELEMENT_TYPE_ENTRY(H);
310 STRUCTELEMENT_TYPE_ENTRY(H1);
311 STRUCTELEMENT_TYPE_ENTRY(H2);
312 STRUCTELEMENT_TYPE_ENTRY(H3);
313 STRUCTELEMENT_TYPE_ENTRY(H4);
314 STRUCTELEMENT_TYPE_ENTRY(H5);
315 STRUCTELEMENT_TYPE_ENTRY(H6);
316 STRUCTELEMENT_TYPE_ENTRY(L);
317 STRUCTELEMENT_TYPE_ENTRY(LI);
318 STRUCTELEMENT_TYPE_ENTRY(Lbl);
319 STRUCTELEMENT_TYPE_ENTRY(LBody);
320 STRUCTELEMENT_TYPE_ENTRY(Table);
321 STRUCTELEMENT_TYPE_ENTRY(TR);
322 STRUCTELEMENT_TYPE_ENTRY(TH);
323 STRUCTELEMENT_TYPE_ENTRY(TD);
324 STRUCTELEMENT_TYPE_ENTRY(THead);
325 STRUCTELEMENT_TYPE_ENTRY(TFoot);
326 STRUCTELEMENT_TYPE_ENTRY(TBody);
327 STRUCTELEMENT_TYPE_ENTRY(Figure);
328 STRUCTELEMENT_TYPE_ENTRY(Formula);
329 STRUCTELEMENT_TYPE_ENTRY(Form);
330 STRUCTELEMENT_TYPE_ENTRY(TOC);
331 STRUCTELEMENT_TYPE_ENTRY(TOCI);
332 lua_pushstring(L, "Unknown");
333 lua_pushinteger(L, 0);
334 lua_settable(L,-3);
335 return 1;
336 }
337
338 static int l_AttributeOwner_Type(lua_State * L) {
339 lua_createtable (L, 0, 12);
340 lua_pushstring(L, "XML-1.00"); lua_pushinteger(L, Attribute::XML_1_00); lua_settable(L,-3);
341 lua_pushstring(L, "HTML-3.20"); lua_pushinteger(L, Attribute::HTML_3_20); lua_settable(L,-3);
342 lua_pushstring(L, "HTML-4.01"); lua_pushinteger(L, Attribute::HTML_4_01); lua_settable(L,-3);
343 lua_pushstring(L, "OEB-1.00"); lua_pushinteger(L, Attribute::OEB_1_00); lua_settable(L,-3);
344 lua_pushstring(L, "RTF-1.05"); lua_pushinteger(L, Attribute::RTF_1_05); lua_settable(L,-3);
345 lua_pushstring(L, "CSS-1.00"); lua_pushinteger(L, Attribute::CSS_1_00); lua_settable(L,-3);
346 lua_pushstring(L, "CSS-2.00"); lua_pushinteger(L, Attribute::CSS_2_00); lua_settable(L,-3);
347 lua_pushstring(L, "Layout"); lua_pushinteger(L, Attribute::Layout); lua_settable(L,-3);
348 lua_pushstring(L, "PrintField"); lua_pushinteger(L, Attribute::PrintField); lua_settable(L,-3);
349 lua_pushstring(L, "Table"); lua_pushinteger(L, Attribute::Table); lua_settable(L,-3);
350 lua_pushstring(L, "List"); lua_pushinteger(L, Attribute::List); lua_settable(L,-3);
351 lua_pushstring(L, "UserProperties"); lua_pushinteger(L, Attribute::UserProperties);lua_settable(L,-3);
352 return 1;
353 }
354
355 static const struct luaL_Reg epdflib_f[] = {
356 {"open", l_open_PDFDoc},
357 {"openMemStream", l_open_MemStreamPDFDoc},
358 {"StructElement_Type", l_StructElement_Type},
359 {"Attribute_Type", l_Attribute_Type},
360 {"AttributeOwner_Type",l_AttributeOwner_Type},
361 {"Object_Type", l_Object_Type},
362 {NULL, NULL}
363 };
364
365 #define m_poppler_get_poppler(in, out, function) \
366 static int m_##in##_##function(lua_State * L) \
367 { \
368 out *o; \
369 udstruct *uin, *uout; \
370 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
371 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
372 pdfdoc_changed_error(L); \
373 o = ((in *) uin->d)->function(); \
374 if (o != NULL) { \
375 uout = new_##out##_userdata(L); \
376 uout->d = o; \
377 uout->pc = uin->pc; \
378 uout->pd = uin->pd; \
379 } else \
380 lua_pushnil(L); \
381 return 1; \
382 }
383
384 #define m_poppler_get_BOOL(in, function) \
385 static int m_##in##_##function(lua_State * L) \
386 { \
387 udstruct *uin; \
388 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
389 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
390 pdfdoc_changed_error(L); \
391 if (((in *) uin->d)->function()) \
392 lua_pushboolean(L, 1); \
393 else \
394 lua_pushboolean(L, 0); \
395 return 1; \
396 }
397
398 #define m_poppler_get_INT(in, function) \
399 static int m_##in##_##function(lua_State * L) \
400 { \
401 int i; \
402 udstruct *uin; \
403 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
404 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
405 pdfdoc_changed_error(L); \
406 i = (int) ((in *) uin->d)->function(); \
407 lua_pushinteger(L, i); \
408 return 1; \
409 }
410
411
412 #define m_poppler_get_GUINT(in, function) \
413 static int m_##in##_##function(lua_State * L) \
414 { \
415 unsigned int i; \
416 udstruct *uin; \
417 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
418 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
419 pdfdoc_changed_error(L); \
420 i = (unsigned int) ((in *) uin->d)->function(); \
421 lua_pushinteger(L, i); \
422 return 1; \
423 }
424
425 #define m_poppler_get_UINT(in, function) \
426 m_poppler_get_GUINT(in, function)
427
428
429
430 #define m_poppler_get_DOUBLE(in, function) \
431 static int m_##in##_##function(lua_State * L) \
432 { \
433 double d; \
434 udstruct *uin; \
435 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
436 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
437 pdfdoc_changed_error(L); \
438 d = (double) ((in *) uin->d)->function(); \
439 lua_pushnumber(L, d); /* float */ \
440 return 1; \
441 }
442
443 #define m_poppler_get_GOOSTRING(in, function) \
444 static int m_##in##_##function(lua_State * L) \
445 { \
446 GooString *gs; \
447 udstruct *uin; \
448 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
449 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
450 pdfdoc_changed_error(L); \
451 gs = ((in *) uin->d)->function(); \
452 if (gs != NULL) \
453 lua_pushlstring(L, gs->getCString(), gs->getLength()); \
454 else \
455 lua_pushnil(L); \
456 return 1; \
457 }
458
459 #define m_poppler_get_OBJECT(in, function) \
460 static int m_##in##_##function(lua_State * L) \
461 { \
462 udstruct *uin, *uout; \
463 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
464 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
465 pdfdoc_changed_error(L); \
466 uout = new_Object_userdata(L); \
467 uout->d = new Object(); \
468 *((Object *)uout->d) = ((in *) uin->d)->function(); \
469 uout->atype = ALLOC_LEPDF; \
470 uout->pc = uin->pc; \
471 uout->pd = uin->pd; \
472 return 1; \
473 }
474
475 #define m_poppler_do(in, function) \
476 static int m_##in##_##function(lua_State * L) \
477 { \
478 udstruct *uin; \
479 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
480 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
481 pdfdoc_changed_error(L); \
482 ((in *) uin->d)->function(); \
483 return 0; \
484 }
485
486 #define m_poppler__tostring(type) \
487 static int m_##type##__tostring(lua_State * L) \
488 { \
489 udstruct *uin; \
490 uin = (udstruct *) luaL_checkudata(L, 1, M_##type); \
491 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
492 pdfdoc_changed_error(L); \
493 lua_pushfstring(L, "%s: %p", #type, (type *) uin->d); \
494 return 1; \
495 }
496
497 #define m_poppler_check_string(in, function) \
498 static int m_##in##_##function(lua_State * L) \
499 { \
500 const char *s; \
501 udstruct *uin; \
502 uin = (udstruct *) luaL_checkudata(L, 1, M_##in); \
503 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
504 pdfdoc_changed_error(L); \
505 s = luaL_checkstring(L, 2); \
506 if (((in *) uin->d)->function(s)) \
507 lua_pushboolean(L, 1); \
508 else \
509 lua_pushboolean(L, 0); \
510 return 1; \
511 }
512
513 /* Annot */
514
515 m_poppler_get_BOOL(Annot, isOk);
516
517 static int m_Annot_match(lua_State * L)
518 {
519 udstruct *uin, *uref;
520 uin = (udstruct *) luaL_checkudata(L, 1, M_Annot);
521 uref = (udstruct *) luaL_checkudata(L, 2, M_Ref);
522 if (uin->pd != NULL && uref->pd != NULL && uin->pd != uref->pd)
523 pdfdoc_differs_error(L);
524 if ((uin->pd != NULL && uin->pd->pc != uin->pc)
525 || (uref->pd != NULL && uref->pd->pc != uref->pc))
526 pdfdoc_changed_error(L);
527 lua_pushboolean(L, ((Annot *) uin->d)->match((Ref *) uref->d));
528 return 1;
529 }
530
531 m_poppler__tostring(Annot);
532
533 static int m_Annot__gc(lua_State * L)
534 {
535 udstruct *uin;
536 uin = (udstruct *) luaL_checkudata(L, 1, M_Annot);
537 if (uin->pd != NULL && uin->pd->pc != uin->pc)
538 pdfdoc_changed_error(L);
539 #ifdef DEBUG
540 printf("\n===== Annot GC ===== uin=<%p>\n", uin);
541 #endif
542 if (uin->atype == ALLOC_LEPDF)
543 #if 1 /* def HAVE_ANNOTDECREFCNT */
544 ((Annot *) uin->d)->decRefCnt();
545 #else
546 delete(Annot *) uin->d;
547 #endif
548 return 0;
549 }
550
551 static const struct luaL_Reg Annot_m[] = {
552 {"isOk", m_Annot_isOk},
553 {"match", m_Annot_match},
554 {"__tostring", m_Annot__tostring},
555 {"__gc", m_Annot__gc},
556 {NULL, NULL}
557 };
558
559 /* Annots */
560
561 m_poppler_get_INT(Annots, getNumAnnots);
562
563 static int m_Annots_getAnnot(lua_State * L)
564 {
565 int i, annots;
566 udstruct *uin, *uout;
567 uin = (udstruct *) luaL_checkudata(L, 1, M_Annots);
568 if (uin->pd != NULL && uin->pd->pc != uin->pc)
569 pdfdoc_changed_error(L);
570 i = luaL_checkint(L, 2);
571 annots = ((Annots *) uin->d)->getNumAnnots();
572 if (i > 0 && i <= annots) {
573 uout = new_Annot_userdata(L);
574 uout->d = ((Annots *) uin->d)->getAnnot(i);
575 uout->pc = uin->pc;
576 uout->pd = uin->pd;
577 } else
578 lua_pushnil(L);
579 return 1;
580 }
581
582 m_poppler__tostring(Annots);
583
584 static const struct luaL_Reg Annots_m[] = {
585 {"getNumAnnots", m_Annots_getNumAnnots},
586 {"getAnnot", m_Annots_getAnnot},
587 {"__tostring", m_Annots__tostring},
588 {NULL, NULL}
589 };
590
591 /* Array */
592
593 m_poppler_get_INT(Array, getLength);
594
595 static int m_Array_get(lua_State * L)
596 {
597 int i, len;
598 udstruct *uin, *uout;
599 uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
600 if (uin->pd != NULL && uin->pd->pc != uin->pc)
601 pdfdoc_changed_error(L);
602 i = luaL_checkint(L, 2);
603 len = ((Array *) uin->d)->getLength();
604 if (i > 0 && i <= len) {
605 uout = new_Object_userdata(L);
606 uout->d = new Object();
607 *((Object *) uout->d) = ((Array *) uin->d)->get(i - 1);
608 uout->atype = ALLOC_LEPDF;
609 uout->pc = uin->pc;
610 uout->pd = uin->pd;
611 } else
612 lua_pushnil(L);
613 return 1;
614 }
615
616 static int m_Array_getNF(lua_State * L)
617 {
618 int i, len;
619 udstruct *uin, *uout;
620 uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
621 if (uin->pd != NULL && uin->pd->pc != uin->pc)
622 pdfdoc_changed_error(L);
623 i = luaL_checkint(L, 2);
624 len = ((Array *) uin->d)->getLength();
625 if (i > 0 && i <= len) {
626 uout = new_Object_userdata(L);
627 uout->d = new Object();
628 *((Object *) uout->d) = ((Array *) uin->d)->getNF(i - 1);
629 uout->atype = ALLOC_LEPDF;
630 uout->pc = uin->pc;
631 uout->pd = uin->pd;
632 } else
633 lua_pushnil(L);
634 return 1;
635 }
636
637 static int m_Array_getString(lua_State * L)
638 {
639 GooString *gs;
640 int i, len;
641 udstruct *uin;
642 uin = (udstruct *) luaL_checkudata(L, 1, M_Array);
643 if (uin->pd != NULL && uin->pd->pc != uin->pc)
644 pdfdoc_changed_error(L);
645 i = luaL_checkint(L, 2);
646 len = ((Array *) uin->d)->getLength();
647 if (i > 0 && i <= len) {
648 gs = new GooString();
649 if (((Array *) uin->d)->getString(i - 1, gs))
650 lua_pushlstring(L, gs->getCString(), gs->getLength());
651 else
652 lua_pushnil(L);
653 delete gs;
654 } else
655 lua_pushnil(L);
656 return 1;
657 }
658
659 m_poppler__tostring(Array);
660
661 static const struct luaL_Reg Array_m[] = {
662 {"getLength", m_Array_getLength},
663 {"get", m_Array_get},
664 {"getNF", m_Array_getNF},
665 {"getString", m_Array_getString},
666 {"__tostring", m_Array__tostring},
667 {NULL, NULL}
668 };
669
670 /* Catalog */
671
672 m_poppler_get_BOOL(Catalog, isOk);
673 m_poppler_get_INT(Catalog, getNumPages);
674
675 static int m_Catalog_getPage(lua_State * L)
676 {
677 int i, pages;
678 udstruct *uin, *uout;
679 uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog);
680 if (uin->pd != NULL && uin->pd->pc != uin->pc)
681 pdfdoc_changed_error(L);
682 i = luaL_checkint(L, 2);
683 pages = ((Catalog *) uin->d)->getNumPages();
684 if (i > 0 && i <= pages) {
685 uout = new_Page_userdata(L);
686 uout->d = ((Catalog *) uin->d)->getPage(i);
687 uout->pc = uin->pc;
688 uout->pd = uin->pd;
689 } else
690 lua_pushnil(L);
691 return 1;
692 }
693
694 static int m_Catalog_getPageRef(lua_State * L)
695 {
696 int i, pages;
697 udstruct *uin, *uout;
698 uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog);
699 if (uin->pd != NULL && uin->pd->pc != uin->pc)
700 pdfdoc_changed_error(L);
701 i = luaL_checkint(L, 2);
702 pages = ((Catalog *) uin->d)->getNumPages();
703 if (i > 0 && i <= pages) {
704 uout = new_Ref_userdata(L);
705 uout->d = (Ref *) gmalloc(sizeof(Ref));
706 ((Ref *) uout->d)->num = ((Catalog *) uin->d)->getPageRef(i)->num;
707 ((Ref *) uout->d)->gen = ((Catalog *) uin->d)->getPageRef(i)->gen;
708 uout->atype = ALLOC_LEPDF;
709 uout->pc = uin->pc;
710 uout->pd = uin->pd;
711 } else
712 lua_pushnil(L);
713 return 1;
714 }
715
716 m_poppler_get_GOOSTRING(Catalog, getBaseURI);
717 m_poppler_get_GOOSTRING(Catalog, readMetadata);
718 m_poppler_get_poppler(Catalog, StructTreeRoot, getStructTreeRoot);
719
720 static int m_Catalog_findPage(lua_State * L)
721 {
722 int num, gen, i;
723 udstruct *uin;
724 uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog);
725 if (uin->pd != NULL && uin->pd->pc != uin->pc)
726 pdfdoc_changed_error(L);
727 num = luaL_checkint(L, 2);
728 gen = luaL_checkint(L, 3);
729 i = ((Catalog *) uin->d)->findPage(num, gen);
730 if (i > 0)
731 lua_pushinteger(L, i);
732 else
733 lua_pushnil(L);
734 return 1;
735 }
736
737 static int m_Catalog_findDest(lua_State * L)
738 {
739 GooString *name;
740 LinkDest *dest;
741 const char *s;
742 size_t len;
743 udstruct *uin, *uout;
744 uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog);
745 if (uin->pd != NULL && uin->pd->pc != uin->pc)
746 pdfdoc_changed_error(L);
747 s = luaL_checklstring(L, 2, &len);
748 name = new GooString(s, len);
749 dest = ((Catalog *) uin->d)->findDest(name);
750 if (dest != NULL) {
751 uout = new_LinkDest_userdata(L);
752 uout->d = dest;
753 uout->pc = uin->pc;
754 uout->pd = uin->pd;
755 } else
756 lua_pushnil(L);
757 delete name;
758 return 1;
759 }
760
761 m_poppler_get_poppler(Catalog, Object, getDests);
762 m_poppler_get_INT(Catalog, numEmbeddedFiles);
763
764 static int m_Catalog_embeddedFile(lua_State * L)
765 {
766 int i, len;
767 udstruct *uin, *uout;
768 uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog);
769 if (uin->pd != NULL && uin->pd->pc != uin->pc)
770 pdfdoc_changed_error(L);
771 i = luaL_checkint(L, 2);
772 len = ((Catalog *) uin->d)->numEmbeddedFiles();
773 if (i > 0 && i <= len) {
774 uout = new_FileSpec_userdata(L);
775 uout->d = ((Catalog *) uin->d)->embeddedFile(i - 1);
776 uout->pc = uin->pc;
777 uout->pd = uin->pd;
778 } else
779 lua_pushnil(L);
780 return 1;
781 }
782
783 m_poppler_get_INT(Catalog, numJS);
784
785 static int m_Catalog_getJS(lua_State * L)
786 {
787 GooString *gs;
788 int i, len;
789 udstruct *uin;
790 uin = (udstruct *) luaL_checkudata(L, 1, M_Catalog);
791 if (uin->pd != NULL && uin->pd->pc != uin->pc)
792 pdfdoc_changed_error(L);
793 i = luaL_checkint(L, 2);
794 len = ((Catalog *) uin->d)->numJS();
795 if (i > 0 && i <= len) {
796 gs = ((Catalog *) uin->d)->getJS(i - 1);
797 if (gs != NULL)
798 lua_pushlstring(L, gs->getCString(), gs->getLength());
799 else
800 lua_pushnil(L);
801 delete gs;
802 } else
803 lua_pushnil(L);
804 return 1;
805 }
806
807 m_poppler_get_poppler(Catalog, Object, getOutline);
808 m_poppler_get_poppler(Catalog, Object, getAcroForm);
809
810 m_poppler__tostring(Catalog);
811
812 static const struct luaL_Reg Catalog_m[] = {
813 {"isOk", m_Catalog_isOk},
814 {"getNumPages", m_Catalog_getNumPages},
815 {"getPage", m_Catalog_getPage},
816 {"getPageRef", m_Catalog_getPageRef},
817 {"getBaseURI", m_Catalog_getBaseURI},
818 {"readMetadata", m_Catalog_readMetadata},
819 {"getStructTreeRoot", m_Catalog_getStructTreeRoot},
820 {"findPage", m_Catalog_findPage},
821 {"findDest", m_Catalog_findDest},
822 {"getDests", m_Catalog_getDests},
823 {"numEmbeddedFiles", m_Catalog_numEmbeddedFiles},
824 {"embeddedFile", m_Catalog_embeddedFile},
825 {"numJS", m_Catalog_numJS},
826 {"getJS", m_Catalog_getJS},
827 {"getOutline", m_Catalog_getOutline},
828 {"getAcroForm", m_Catalog_getAcroForm},
829 {"__tostring", m_Catalog__tostring},
830 {NULL, NULL}
831 };
832
833 /* Dict */
834
835 m_poppler_get_INT(Dict, getLength);
836
837 m_poppler_check_string(Dict, is);
838
839 static int m_Dict_lookup(lua_State * L)
840 {
841 const char *s;
842 udstruct *uin, *uout;
843 uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
844 if (uin->pd != NULL && uin->pd->pc != uin->pc)
845 pdfdoc_changed_error(L);
846 s = luaL_checkstring(L, 2);
847 uout = new_Object_userdata(L);
848 uout->d = new Object();
849 *((Object *) uout->d) = ((Dict *) uin->d)->lookup(s);
850 uout->atype = ALLOC_LEPDF;
851 uout->pc = uin->pc;
852 uout->pd = uin->pd;
853 return 1;
854 }
855
856 static int m_Dict_lookupNF(lua_State * L)
857 {
858 const char *s;
859 udstruct *uin, *uout;
860 uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
861 if (uin->pd != NULL && uin->pd->pc != uin->pc)
862 pdfdoc_changed_error(L);
863 s = luaL_checkstring(L, 2);
864 uout = new_Object_userdata(L);
865 uout->d = new Object();
866 *((Object *) uout->d) = ((Dict *) uin->d)->lookupNF(s);
867 uout->atype = ALLOC_LEPDF;
868 uout->pc = uin->pc;
869 uout->pd = uin->pd;
870 return 1;
871 }
872
873 static int m_Dict_lookupInt(lua_State * L)
874 {
875 const char *s1, *s2;
876 int i;
877 udstruct *uin;
878 uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
879 if (uin->pd != NULL && uin->pd->pc != uin->pc)
880 pdfdoc_changed_error(L);
881 s1 = luaL_checkstring(L, 2);
882 s2 = luaL_checkstring(L, 3);
883 if (((Dict *) uin->d)->lookupInt(s1, s2, &i))
884 lua_pushinteger(L, i);
885 else
886 lua_pushnil(L);
887 return 1;
888 }
889
890 static int m_Dict_getKey(lua_State * L)
891 {
892 int i, len;
893 udstruct *uin;
894 uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
895 if (uin->pd != NULL && uin->pd->pc != uin->pc)
896 pdfdoc_changed_error(L);
897 i = luaL_checkint(L, 2);
898 len = ((Dict *) uin->d)->getLength();
899 if (i > 0 && i <= len)
900 lua_pushstring(L, ((Dict *) uin->d)->getKey(i - 1));
901 else
902 lua_pushnil(L);
903 return 1;
904 }
905
906 static int m_Dict_getVal(lua_State * L)
907 {
908 int i, len;
909 udstruct *uin, *uout;
910 uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
911 if (uin->pd != NULL && uin->pd->pc != uin->pc)
912 pdfdoc_changed_error(L);
913 i = luaL_checkint(L, 2);
914 len = ((Dict *) uin->d)->getLength();
915 if (i > 0 && i <= len) {
916 uout = new_Object_userdata(L);
917 uout->d = new Object();
918 *((Object *) uout->d) = ((Dict *) uin->d)->getVal(i - 1);
919 uout->atype = ALLOC_LEPDF;
920 uout->pc = uin->pc;
921 uout->pd = uin->pd;
922 } else
923 lua_pushnil(L);
924 return 1;
925 }
926
927 static int m_Dict_getValNF(lua_State * L)
928 {
929 int i, len;
930 udstruct *uin, *uout;
931 uin = (udstruct *) luaL_checkudata(L, 1, M_Dict);
932 if (uin->pd != NULL && uin->pd->pc != uin->pc)
933 pdfdoc_changed_error(L);
934 i = luaL_checkint(L, 2);
935 len = ((Dict *) uin->d)->getLength();
936 if (i > 0 && i <= len) {
937 uout = new_Object_userdata(L);
938 uout->d = new Object();
939 *((Object *) uout->d) = ((Dict *) uin->d)->getValNF(i - 1);
940 uout->atype = ALLOC_LEPDF;
941 uout->pc = uin->pc;
942 uout->pd = uin->pd;
943 } else
944 lua_pushnil(L);
945 return 1;
946 }
947
948 m_poppler_check_string(Dict, hasKey);
949
950 m_poppler__tostring(Dict);
951
952 static const struct luaL_Reg Dict_m[] = {
953 {"getLength", m_Dict_getLength},
954 {"is", m_Dict_is},
955 {"lookup", m_Dict_lookup},
956 {"lookupNF", m_Dict_lookupNF},
957 {"lookupInt", m_Dict_lookupInt},
958 {"getKey", m_Dict_getKey},
959 {"getVal", m_Dict_getVal},
960 {"getValNF", m_Dict_getValNF},
961 {"hasKey", m_Dict_hasKey},
962 {"__tostring", m_Dict__tostring},
963 {NULL, NULL}
964 };
965
966 /* EmbFile */
967
968 m_poppler_get_INT(EmbFile, size);
969 m_poppler_get_GOOSTRING(EmbFile, modDate);
970 m_poppler_get_GOOSTRING(EmbFile, createDate);
971 m_poppler_get_GOOSTRING(EmbFile, checksum);
972 m_poppler_get_GOOSTRING(EmbFile, mimeType);
973
974 m_poppler_get_BOOL(EmbFile, isOk);
975
976 static int m_EmbFile_save(lua_State * L)
977 {
978 const char *s;
979 size_t len;
980 udstruct *uin;
981 uin = (udstruct *) luaL_checkudata(L, 1, M_EmbFile);
982 if (uin->pd != NULL && uin->pd->pc != uin->pc)
983 pdfdoc_changed_error(L);
984 s = luaL_checklstring(L, 2, &len);
985 if (((EmbFile *) uin->d)->save(s))
986 lua_pushboolean(L, 1);
987 else
988 lua_pushboolean(L, 0);
989 return 1;
990 }
991
992 m_poppler__tostring(EmbFile);
993
994 static const struct luaL_Reg EmbFile_m[] = {
995 {"size", m_EmbFile_size},
996 {"modDate", m_EmbFile_modDate},
997 {"createDate", m_EmbFile_createDate},
998 {"checksum", m_EmbFile_checksum},
999 {"mimeType", m_EmbFile_mimeType},
1000 {"isOk", m_EmbFile_isOk},
1001 {"save", m_EmbFile_save},
1002 {"__tostring", m_EmbFile__tostring},
1003 {NULL, NULL}
1004 };
1005
1006 /* FileSpec */
1007
1008 m_poppler_get_BOOL(FileSpec, isOk);
1009 m_poppler_get_GOOSTRING(FileSpec, getFileName);
1010 m_poppler_get_GOOSTRING(FileSpec, getFileNameForPlatform);
1011 m_poppler_get_GOOSTRING(FileSpec, getDescription);
1012
1013 static int m_FileSpec_getEmbeddedFile(lua_State * L)
1014 {
1015 udstruct *uin, *uout;
1016 uin = (udstruct *) luaL_checkudata(L, 1, M_FileSpec);
1017 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1018 pdfdoc_changed_error(L);
1019 uout = new_EmbFile_userdata(L);
1020 uout->d = ((FileSpec *) uin->d)->getEmbeddedFile();
1021 uout->pc = uin->pc;
1022 uout->pd = uin->pd;
1023 return 1;
1024 }
1025
1026 m_poppler__tostring(FileSpec);
1027
1028 static const struct luaL_Reg FileSpec_m[] = {
1029 {"isOk", m_FileSpec_isOk},
1030 {"getFileName", m_FileSpec_getFileName},
1031 {"getFileNameForPlatform", m_FileSpec_getFileNameForPlatform},
1032 {"getDescription", m_FileSpec_getDescription},
1033 {"getEmbeddedFile", m_FileSpec_getEmbeddedFile},
1034 {"__tostring", m_FileSpec__tostring},
1035 {NULL, NULL}
1036 };
1037
1038 /* GooString */
1039
1040 static int m_GooString__tostring(lua_State * L)
1041 {
1042 udstruct *uin;
1043 uin = (udstruct *) luaL_checkudata(L, 1, M_GooString);
1044 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1045 pdfdoc_changed_error(L);
1046 lua_pushlstring(L, ((GooString *) uin->d)->getCString(),
1047 ((GooString *) uin->d)->getLength());
1048 return 1;
1049 }
1050
1051 static const struct luaL_Reg GooString_m[] = {
1052 {"__tostring", m_GooString__tostring},
1053 {NULL, NULL}
1054 };
1055
1056 /* LinkDest */
1057
1058 static const char *LinkDestKindNames[] = {
1059 "XYZ", "Fit", "FitH", "FitV", "FitR", "FitB", "FitBH", "FitBV",
1060 NULL
1061 };
1062
1063 m_poppler_get_BOOL(LinkDest, isOk);
1064
1065 static int m_LinkDest_getKind(lua_State * L)
1066 {
1067 int i;
1068 udstruct *uin;
1069 uin = (udstruct *) luaL_checkudata(L, 1, M_LinkDest);
1070 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1071 pdfdoc_changed_error(L);
1072 i = (int) ((LinkDest *) uin->d)->getKind();
1073 lua_pushinteger(L, i);
1074 return 1;
1075 }
1076
1077 static int m_LinkDest_getKindName(lua_State * L)
1078 {
1079 int i;
1080 udstruct *uin;
1081 uin = (udstruct *) luaL_checkudata(L, 1, M_LinkDest);
1082 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1083 pdfdoc_changed_error(L);
1084 i = (int) ((LinkDest *) uin->d)->getKind();
1085 lua_pushstring(L, LinkDestKindNames[i]);
1086 return 1;
1087 }
1088
1089 m_poppler_get_BOOL(LinkDest, isPageRef);
1090 m_poppler_get_INT(LinkDest, getPageNum);
1091
1092 static int m_LinkDest_getPageRef(lua_State * L)
1093 {
1094 udstruct *uin, *uout;
1095 uin = (udstruct *) luaL_checkudata(L, 1, M_LinkDest);
1096 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1097 pdfdoc_changed_error(L);
1098 uout = new_Ref_userdata(L);
1099 uout->d = (Ref *) gmalloc(sizeof(Ref));
1100 ((Ref *) uout->d)->num = ((LinkDest *) uin->d)->getPageRef().num;
1101 ((Ref *) uout->d)->gen = ((LinkDest *) uin->d)->getPageRef().gen;
1102 uout->atype = ALLOC_LEPDF;
1103 uout->pc = uin->pc;
1104 uout->pd = uin->pd;
1105 return 1;
1106 }
1107
1108 m_poppler_get_DOUBLE(LinkDest, getLeft);
1109 m_poppler_get_DOUBLE(LinkDest, getBottom);
1110 m_poppler_get_DOUBLE(LinkDest, getRight);
1111 m_poppler_get_DOUBLE(LinkDest, getTop);
1112 m_poppler_get_DOUBLE(LinkDest, getZoom);
1113 m_poppler_get_BOOL(LinkDest, getChangeLeft);
1114 m_poppler_get_BOOL(LinkDest, getChangeTop);
1115 m_poppler_get_BOOL(LinkDest, getChangeZoom);
1116
1117 m_poppler__tostring(LinkDest);
1118
1119 static const struct luaL_Reg LinkDest_m[] = {
1120 {"isOk", m_LinkDest_isOk},
1121 {"getKind", m_LinkDest_getKind},
1122 {"getKindName", m_LinkDest_getKindName}, // not poppler
1123 {"isPageRef", m_LinkDest_isPageRef},
1124 {"getPageNum", m_LinkDest_getPageNum},
1125 {"getPageRef", m_LinkDest_getPageRef},
1126 {"getLeft", m_LinkDest_getLeft},
1127 {"getBottom", m_LinkDest_getBottom},
1128 {"getRight", m_LinkDest_getRight},
1129 {"getTop", m_LinkDest_getTop},
1130 {"getZoom", m_LinkDest_getZoom},
1131 {"getChangeLeft", m_LinkDest_getChangeLeft},
1132 {"getChangeTop", m_LinkDest_getChangeTop},
1133 {"getChangeZoom", m_LinkDest_getChangeZoom},
1134 {"__tostring", m_LinkDest__tostring},
1135 {NULL, NULL}
1136 };
1137
1138 /* Links */
1139
1140 m_poppler_get_INT(Links, getNumLinks);
1141
1142 m_poppler__tostring(Links);
1143
1144 static const struct luaL_Reg Links_m[] = {
1145 {"getNumLinks", m_Links_getNumLinks},
1146 {"__tostring", m_Links__tostring},
1147 {NULL, NULL}
1148 };
1149
1150 /* Object */
1151
1152 #ifdef HAVE_OBJECT_INITCMD_CONST_CHARP
1153 #define CHARP_CAST
1154 #else
1155 /*
1156 Must cast arg of Object::initCmd, Object::isStream, and Object::streamIs
1157 from 'const char *' to 'char *', although they are not modified.
1158 */
1159 #define CHARP_CAST (char *)
1160 #endif
1161
1162 /* Special type checking. */
1163
1164 #define m_Object_isType_(function, cast) \
1165 static int m_Object_##function(lua_State * L) \
1166 { \
1167 udstruct *uin; \
1168 uin = (udstruct *) luaL_checkudata(L, 1, M_Object); \
1169 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
1170 pdfdoc_changed_error(L); \
1171 if (lua_gettop(L) >= 2) { \
1172 if (lua_isstring(L, 2) \
1173 && ((Object *) uin->d)->function(cast lua_tostring(L, 2))) \
1174 lua_pushboolean(L, 1); \
1175 else \
1176 lua_pushboolean(L, 0); \
1177 } else { \
1178 if (((Object *) uin->d)->function()) \
1179 lua_pushboolean(L, 1); \
1180 else \
1181 lua_pushboolean(L, 0); \
1182 } \
1183 return 1; \
1184 }
1185
1186 #define m_Object_isType(function) m_Object_isType_(function, )
1187 #define m_Object_isType_nonconst(function) m_Object_isType_(function, CHARP_CAST)
1188
1189 static int m_Object_fetch(lua_State * L)
1190 {
1191 udstruct *uin, *uxref, *uout;
1192 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1193 uxref = (udstruct *) luaL_checkudata(L, 2, M_XRef);
1194 if (uin->pd != NULL && uxref->pd != NULL && uin->pd != uxref->pd)
1195 pdfdoc_differs_error(L);
1196 if ((uin->pd != NULL && uin->pd->pc != uin->pc)
1197 || (uxref->pd != NULL && uxref->pd->pc != uxref->pc))
1198 pdfdoc_changed_error(L);
1199 uout = new_Object_userdata(L);
1200 uout->d = new Object();
1201 *((Object *) uout->d) = ((Object *) uin->d)->fetch((XRef *) uxref->d);
1202 uout->atype = ALLOC_LEPDF;
1203 uout->pc = uin->pc;
1204 uout->pd = uin->pd;
1205 return 1;
1206 }
1207
1208 static int m_Object_getType(lua_State * L)
1209 {
1210 ObjType t;
1211 udstruct *uin;
1212 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1213 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1214 pdfdoc_changed_error(L);
1215 t = ((Object *) uin->d)->getType();
1216 lua_pushinteger(L, (int) t);
1217 return 1;
1218 }
1219
1220 static int m_Object_getTypeName(lua_State * L)
1221 {
1222 udstruct *uin;
1223 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1224 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1225 pdfdoc_changed_error(L);
1226 lua_pushstring(L, ((Object *) uin->d)->getTypeName());
1227 return 1;
1228 }
1229
1230 m_poppler_get_BOOL(Object, isBool);
1231 m_poppler_get_BOOL(Object, isInt);
1232 m_poppler_get_BOOL(Object, isReal);
1233 m_poppler_get_BOOL(Object, isNum);
1234 m_poppler_get_BOOL(Object, isString);
1235 m_Object_isType(isName);
1236 m_poppler_get_BOOL(Object, isNull);
1237 m_poppler_get_BOOL(Object, isArray);
1238 m_Object_isType(isDict);
1239 m_Object_isType_nonconst(isStream);
1240 m_poppler_get_BOOL(Object, isRef);
1241 m_Object_isType(isCmd);
1242 m_poppler_get_BOOL(Object, isError);
1243 m_poppler_get_BOOL(Object, isEOF);
1244 m_poppler_get_BOOL(Object, isNone);
1245
1246 static int m_Object_getBool(lua_State * L)
1247 {
1248 udstruct *uin;
1249 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1250 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1251 pdfdoc_changed_error(L);
1252 if (((Object *) uin->d)->isBool()) {
1253 if (((Object *) uin->d)->getBool())
1254 lua_pushboolean(L, 1);
1255 else
1256 lua_pushboolean(L, 0);
1257 } else
1258 lua_pushnil(L);
1259 return 1;
1260 }
1261
1262 static int m_Object_getInt(lua_State * L)
1263 {
1264 udstruct *uin;
1265 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1266 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1267 pdfdoc_changed_error(L);
1268 if (((Object *) uin->d)->isInt())
1269 lua_pushinteger(L, ((Object *) uin->d)->getInt());
1270 else
1271 lua_pushnil(L);
1272 return 1;
1273 }
1274
1275 static int m_Object_getReal(lua_State * L)
1276 {
1277 udstruct *uin;
1278 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1279 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1280 pdfdoc_changed_error(L);
1281 if (((Object *) uin->d)->isReal())
1282 lua_pushnumber(L, ((Object *) uin->d)->getReal()); /* float */
1283 else
1284 lua_pushnil(L);
1285 return 1;
1286 }
1287
1288 static int m_Object_getNum(lua_State * L)
1289 {
1290 udstruct *uin;
1291 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1292 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1293 pdfdoc_changed_error(L);
1294 if (((Object *) uin->d)->isInt())
1295 lua_pushinteger(L, ((Object *) uin->d)->getInt());
1296 else if (((Object *) uin->d)->isReal())
1297 lua_pushinteger(L, ((Object *) uin->d)->getReal());
1298 else if (((Object *) uin->d)->isNum()) /* redundant */
1299 lua_pushnumber(L, ((Object *) uin->d)->getNum()); /* integer or float */
1300 else
1301 lua_pushnil(L);
1302 return 1;
1303 }
1304
1305 static int m_Object_getString(lua_State * L)
1306 {
1307 GooString *gs;
1308 udstruct *uin;
1309 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1310 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1311 pdfdoc_changed_error(L);
1312 if (((Object *) uin->d)->isString()) {
1313 gs = ((Object *) uin->d)->getString();
1314 lua_pushlstring(L, gs->getCString(), gs->getLength());
1315 } else
1316 lua_pushnil(L);
1317 return 1;
1318 }
1319
1320 static int m_Object_getName(lua_State * L)
1321 {
1322 udstruct *uin;
1323 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1324 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1325 pdfdoc_changed_error(L);
1326 if (((Object *) uin->d)->isName())
1327 lua_pushstring(L, ((Object *) uin->d)->getName());
1328 else
1329 lua_pushnil(L);
1330 return 1;
1331 }
1332
1333 static int m_Object_getArray(lua_State * L)
1334 {
1335 udstruct *uin, *uout;
1336 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1337 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1338 pdfdoc_changed_error(L);
1339 if (((Object *) uin->d)->isArray()) {
1340 uout = new_Array_userdata(L);
1341 uout->d = ((Object *) uin->d)->getArray();
1342 uout->pc = uin->pc;
1343 uout->pd = uin->pd;
1344 } else
1345 lua_pushnil(L);
1346 return 1;
1347 }
1348
1349 static int m_Object_getDict(lua_State * L)
1350 {
1351 udstruct *uin, *uout;
1352 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1353 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1354 pdfdoc_changed_error(L);
1355 if (((Object *) uin->d)->isDict()) {
1356 uout = new_Dict_userdata(L);
1357 uout->d = ((Object *) uin->d)->getDict();
1358 uout->pc = uin->pc;
1359 uout->pd = uin->pd;
1360 } else
1361 lua_pushnil(L);
1362 return 1;
1363 }
1364
1365 static int m_Object_getStream(lua_State * L)
1366 {
1367 udstruct *uin, *uout;
1368 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1369 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1370 pdfdoc_changed_error(L);
1371 if (((Object *) uin->d)->isStream()) {
1372 uout = new_Stream_userdata(L);
1373 uout->d = ((Object *) uin->d)->getStream();
1374 uout->pc = uin->pc;
1375 uout->pd = uin->pd;
1376 } else
1377 lua_pushnil(L);
1378 return 1;
1379 }
1380
1381 static int m_Object_getRef(lua_State * L)
1382 {
1383 udstruct *uin, *uout;
1384 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1385 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1386 pdfdoc_changed_error(L);
1387 if (((Object *) uin->d)->isRef()) {
1388 uout = new_Ref_userdata(L);
1389 uout->d = (Ref *) gmalloc(sizeof(Ref));
1390 ((Ref *) uout->d)->num = ((Object *) uin->d)->getRef().num;
1391 ((Ref *) uout->d)->gen = ((Object *) uin->d)->getRef().gen;
1392 uout->atype = ALLOC_LEPDF;
1393 uout->pc = uin->pc;
1394 uout->pd = uin->pd;
1395 } else
1396 lua_pushnil(L);
1397 return 1;
1398 }
1399
1400 static int m_Object_getRefNum(lua_State * L)
1401 {
1402 int i;
1403 udstruct *uin;
1404 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1405 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1406 pdfdoc_changed_error(L);
1407 if (((Object *) uin->d)->isRef()) {
1408 i = ((Object *) uin->d)->getRef().num;
1409 lua_pushinteger(L, i);
1410 } else
1411 lua_pushnil(L);
1412 return 1;
1413 }
1414
1415 static int m_Object_getRefGen(lua_State * L)
1416 {
1417 int i;
1418 udstruct *uin;
1419 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1420 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1421 pdfdoc_changed_error(L);
1422 if (((Object *) uin->d)->isRef()) {
1423 i = ((Object *) uin->d)->getRef().gen;
1424 lua_pushinteger(L, i);
1425 } else
1426 lua_pushnil(L);
1427 return 1;
1428 }
1429
1430 static int m_Object_getCmd(lua_State * L)
1431 {
1432 udstruct *uin;
1433 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1434 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1435 pdfdoc_changed_error(L);
1436 if (((Object *) uin->d)->isCmd())
1437 lua_pushstring(L, ((Object *) uin->d)->getCmd());
1438 else
1439 lua_pushnil(L);
1440 return 1;
1441 }
1442
1443 static int m_Object_arrayGetLength(lua_State * L)
1444 {
1445 int len;
1446 udstruct *uin;
1447 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1448 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1449 pdfdoc_changed_error(L);
1450 if (((Object *) uin->d)->isArray()) {
1451 len = ((Object *) uin->d)->arrayGetLength();
1452 lua_pushinteger(L, len);
1453 } else
1454 lua_pushnil(L);
1455 return 1;
1456 }
1457
1458 static int m_Object_arrayGet(lua_State * L)
1459 {
1460 int i, len;
1461 udstruct *uin, *uout;
1462 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1463 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1464 pdfdoc_changed_error(L);
1465 i = luaL_checkint(L, 2);
1466 if (((Object *) uin->d)->isArray()) {
1467 len = ((Object *) uin->d)->arrayGetLength();
1468 if (i > 0 && i <= len) {
1469 uout = new_Object_userdata(L);
1470 uout->d = new Object();
1471 *((Object *) uout->d) = ((Object *) uin->d)->arrayGet(i - 1);
1472 uout->atype = ALLOC_LEPDF;
1473 uout->pc = uin->pc;
1474 uout->pd = uin->pd;
1475 } else
1476 lua_pushnil(L);
1477 } else
1478 lua_pushnil(L);
1479 return 1;
1480 }
1481
1482 static int m_Object_arrayGetNF(lua_State * L)
1483 {
1484 int i, len;
1485 udstruct *uin, *uout;
1486 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1487 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1488 pdfdoc_changed_error(L);
1489 i = luaL_checkint(L, 2);
1490 if (((Object *) uin->d)->isArray()) {
1491 len = ((Object *) uin->d)->arrayGetLength();
1492 if (i > 0 && i <= len) {
1493 uout = new_Object_userdata(L);
1494 uout->d = new Object();
1495 *((Object *) uout->d) = ((Object *) uin->d)->arrayGetNF(i - 1);
1496 uout->atype = ALLOC_LEPDF;
1497 uout->pc = uin->pc;
1498 uout->pd = uin->pd;
1499 } else
1500 lua_pushnil(L);
1501 } else
1502 lua_pushnil(L);
1503 return 1;
1504 }
1505
1506 static int m_Object_dictGetLength(lua_State * L)
1507 {
1508 int len;
1509 udstruct *uin;
1510 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1511 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1512 pdfdoc_changed_error(L);
1513 if (((Object *) uin->d)->isDict()) {
1514 len = ((Object *) uin->d)->dictGetLength();
1515 lua_pushinteger(L, len);
1516 } else
1517 lua_pushnil(L);
1518 return 1;
1519 }
1520
1521 static int m_Object_dictLookup(lua_State * L)
1522 {
1523 const char *s;
1524 udstruct *uin, *uout;
1525 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1526 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1527 pdfdoc_changed_error(L);
1528 s = luaL_checkstring(L, 2);
1529 if (((Object *) uin->d)->isDict()) {
1530 uout = new_Object_userdata(L);
1531 uout->d = new Object();
1532 *((Object *) uout->d) = ((Object *) uin->d)->dictLookup(s);
1533 uout->atype = ALLOC_LEPDF;
1534 uout->pc = uin->pc;
1535 uout->pd = uin->pd;
1536 } else
1537 lua_pushnil(L);
1538 return 1;
1539 }
1540
1541 static int m_Object_dictLookupNF(lua_State * L)
1542 {
1543 const char *s;
1544 udstruct *uin, *uout;
1545 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1546 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1547 pdfdoc_changed_error(L);
1548 s = luaL_checkstring(L, 2);
1549 if (((Object *) uin->d)->isDict()) {
1550 uout = new_Object_userdata(L);
1551 uout->d = new Object();
1552 *((Object *) uout->d) = ((Object *) uin->d)->dictLookupNF(s);
1553 uout->atype = ALLOC_LEPDF;
1554 uout->pc = uin->pc;
1555 uout->pd = uin->pd;
1556 } else
1557 lua_pushnil(L);
1558 return 1;
1559 }
1560
1561 static int m_Object_dictGetKey(lua_State * L)
1562 {
1563 int i, len;
1564 udstruct *uin;
1565 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1566 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1567 pdfdoc_changed_error(L);
1568 i = luaL_checkint(L, 2);
1569 if (((Object *) uin->d)->isDict()) {
1570 len = ((Object *) uin->d)->dictGetLength();
1571 if (i > 0 && i <= len)
1572 lua_pushstring(L, ((Object *) uin->d)->dictGetKey(i - 1));
1573 else
1574 lua_pushnil(L);
1575 } else
1576 lua_pushnil(L);
1577 return 1;
1578 }
1579
1580 static int m_Object_dictGetVal(lua_State * L)
1581 {
1582 int i, len;
1583 udstruct *uin, *uout;
1584 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1585 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1586 pdfdoc_changed_error(L);
1587 i = luaL_checkint(L, 2);
1588 if (((Object *) uin->d)->isDict()) {
1589 len = ((Object *) uin->d)->dictGetLength();
1590 if (i > 0 && i <= len) {
1591 uout = new_Object_userdata(L);
1592 uout->d = new Object();
1593 *((Object *) uout->d) = ((Object *) uin->d)->dictGetVal(i - 1);
1594 uout->atype = ALLOC_LEPDF;
1595 uout->pc = uin->pc;
1596 uout->pd = uin->pd;
1597 } else
1598 lua_pushnil(L);
1599 } else
1600 lua_pushnil(L);
1601 return 1;
1602 }
1603
1604 static int m_Object_dictGetValNF(lua_State * L)
1605 {
1606 int i, len;
1607 udstruct *uin, *uout;
1608 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1609 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1610 pdfdoc_changed_error(L);
1611 i = luaL_checkint(L, 2);
1612 if (((Object *) uin->d)->isDict()) {
1613 len = ((Object *) uin->d)->dictGetLength();
1614 if (i > 0 && i <= len) {
1615 uout = new_Object_userdata(L);
1616 uout->d = new Object();
1617 *((Object *) uout->d) = ((Object *) uin->d)->dictGetValNF(i - 1);
1618 uout->atype = ALLOC_LEPDF;
1619 uout->pc = uin->pc;
1620 uout->pd = uin->pd;
1621 } else
1622 lua_pushnil(L);
1623 } else
1624 lua_pushnil(L);
1625 return 1;
1626 }
1627
1628 static int m_Object_streamIs(lua_State * L)
1629 {
1630 const char *s;
1631 udstruct *uin;
1632 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1633 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1634 pdfdoc_changed_error(L);
1635 s = luaL_checkstring(L, 2);
1636 if (((Object *) uin->d)->isStream()) {
1637 if (((Object *) uin->d)->streamIs(CHARP_CAST s))
1638 lua_pushboolean(L, 1);
1639 else
1640 lua_pushboolean(L, 0);
1641 } else
1642 lua_pushnil(L);
1643 return 1;
1644 }
1645
1646 static int m_Object_streamReset(lua_State * L)
1647 {
1648 udstruct *uin;
1649 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1650 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1651 pdfdoc_changed_error(L);
1652 if (((Object *) uin->d)->isStream())
1653 ((Object *) uin->d)->streamReset();
1654 return 0;
1655 }
1656
1657 static int m_Object_streamGetChar(lua_State * L)
1658 {
1659 int i;
1660 udstruct *uin;
1661 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1662 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1663 pdfdoc_changed_error(L);
1664 if (((Object *) uin->d)->isStream()) {
1665 i = ((Object *) uin->d)->streamGetChar();
1666 lua_pushinteger(L, i);
1667 } else
1668 lua_pushnil(L);
1669 return 1;
1670 }
1671
1672 static int m_Object_streamLookChar(lua_State * L)
1673 {
1674 int i;
1675 udstruct *uin;
1676 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1677 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1678 pdfdoc_changed_error(L);
1679 if (((Object *) uin->d)->isStream()) {
1680 i = ((Object *) uin->d)->streamLookChar();
1681 lua_pushinteger(L, i);
1682 } else
1683 lua_pushnil(L);
1684 return 1;
1685 }
1686
1687 static int m_Object_streamGetPos(lua_State * L)
1688 {
1689 int i;
1690 udstruct *uin;
1691 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1692 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1693 pdfdoc_changed_error(L);
1694 if (((Object *) uin->d)->isStream()) {
1695 i = (int) ((Object *) uin->d)->streamGetPos();
1696 lua_pushinteger(L, i);
1697 } else
1698 lua_pushnil(L);
1699 return 1;
1700 }
1701
1702 static int m_Object_streamSetPos(lua_State * L)
1703 {
1704 int i;
1705 udstruct *uin;
1706 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1707 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1708 pdfdoc_changed_error(L);
1709 i = luaL_checkint(L, 2);
1710 if (((Object *) uin->d)->isStream())
1711 ((Object *) uin->d)->streamSetPos(i);
1712 return 0;
1713 }
1714
1715 static int m_Object_streamGetDict(lua_State * L)
1716 {
1717 udstruct *uin, *uout;
1718 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1719 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1720 pdfdoc_changed_error(L);
1721 if (((Object *) uin->d)->isStream()) {
1722 uout = new_Dict_userdata(L);
1723 uout->d = ((Object *) uin->d)->streamGetDict();
1724 uout->pc = uin->pc;
1725 uout->pd = uin->pd;
1726 } else
1727 lua_pushnil(L);
1728 return 1;
1729 }
1730
1731 static int m_Object__gc(lua_State * L)
1732 {
1733 udstruct *uin;
1734 uin = (udstruct *) luaL_checkudata(L, 1, M_Object);
1735 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1736 pdfdoc_changed_error(L);
1737 #ifdef DEBUG
1738 printf("\n===== Object GC ===== uin=<%p>\n", uin);
1739 #endif
1740 if (uin->atype == ALLOC_LEPDF) {
1741 /* free() seems to collide with the lua gc */
1742 /* */
1743 /* ((Object *) uin->d)->free(); */
1744 /* */
1745 delete(Object *) uin->d;
1746 }
1747 return 0;
1748 }
1749
1750 m_poppler__tostring(Object);
1751
1752 static const struct luaL_Reg Object_m[] = {
1753 {"fetch", m_Object_fetch},
1754 {"getType", m_Object_getType},
1755 {"getTypeName", m_Object_getTypeName},
1756 {"isBool", m_Object_isBool},
1757 {"isInt", m_Object_isInt},
1758 {"isReal", m_Object_isReal},
1759 {"isNum", m_Object_isNum},
1760 {"isString", m_Object_isString},
1761 {"isName", m_Object_isName},
1762 {"isNull", m_Object_isNull},
1763 {"isArray", m_Object_isArray},
1764 {"isDict", m_Object_isDict},
1765 {"isStream", m_Object_isStream},
1766 {"isRef", m_Object_isRef},
1767 {"isCmd", m_Object_isCmd},
1768 {"isError", m_Object_isError},
1769 {"isEOF", m_Object_isEOF},
1770 {"isNone", m_Object_isNone},
1771 {"getBool", m_Object_getBool},
1772 {"getInt", m_Object_getInt},
1773 {"getReal", m_Object_getReal},
1774 {"getNum", m_Object_getNum},
1775 {"getString", m_Object_getString},
1776 {"getName", m_Object_getName},
1777 {"getArray", m_Object_getArray},
1778 {"getDict", m_Object_getDict},
1779 {"getStream", m_Object_getStream},
1780 {"getRef", m_Object_getRef},
1781 {"getRefNum", m_Object_getRefNum},
1782 {"getRefGen", m_Object_getRefGen},
1783 {"getCmd", m_Object_getCmd},
1784 {"arrayGetLength", m_Object_arrayGetLength},
1785 {"arrayGet", m_Object_arrayGet},
1786 {"arrayGetNF", m_Object_arrayGetNF},
1787 {"dictGetLength", m_Object_dictGetLength},
1788 {"dictLookup", m_Object_dictLookup},
1789 {"dictLookupNF", m_Object_dictLookupNF},
1790 {"dictGetKey", m_Object_dictGetKey},
1791 {"dictGetVal", m_Object_dictGetVal},
1792 {"dictGetValNF", m_Object_dictGetValNF},
1793 {"streamIs", m_Object_streamIs},
1794 {"streamReset", m_Object_streamReset},
1795 {"streamGetChar", m_Object_streamGetChar},
1796 {"streamLookChar", m_Object_streamLookChar},
1797 {"streamGetPos", m_Object_streamGetPos},
1798 {"streamSetPos", m_Object_streamSetPos},
1799 {"streamGetDict", m_Object_streamGetDict},
1800 {"__tostring", m_Object__tostring},
1801 {"__gc", m_Object__gc},
1802 {NULL, NULL}
1803 };
1804
1805 /* Page */
1806
1807 m_poppler_get_BOOL(Page, isOk);
1808 m_poppler_get_INT(Page, getNum);
1809 m_poppler_get_poppler(Page, PDFRectangle, getMediaBox);
1810 m_poppler_get_poppler(Page, PDFRectangle, getCropBox);
1811 m_poppler_get_BOOL(Page, isCropped);
1812 m_poppler_get_DOUBLE(Page, getMediaWidth);
1813 m_poppler_get_DOUBLE(Page, getMediaHeight);
1814 m_poppler_get_DOUBLE(Page, getCropWidth);
1815 m_poppler_get_DOUBLE(Page, getCropHeight);
1816 m_poppler_get_poppler(Page, PDFRectangle, getBleedBox);
1817 m_poppler_get_poppler(Page, PDFRectangle, getTrimBox);
1818 m_poppler_get_poppler(Page, PDFRectangle, getArtBox);
1819 m_poppler_get_INT(Page, getRotate);
1820 m_poppler_get_GOOSTRING(Page, getLastModified);
1821 m_poppler_get_poppler(Page, Dict, getBoxColorInfo);
1822 m_poppler_get_poppler(Page, Dict, getGroup);
1823 m_poppler_get_poppler(Page, Stream, getMetadata);
1824 m_poppler_get_poppler(Page, Dict, getPieceInfo);
1825 m_poppler_get_poppler(Page, Dict, getSeparationInfo);
1826 m_poppler_get_poppler(Page, Dict, getResourceDict);
1827 m_poppler_get_OBJECT(Page, getAnnotsObject);
1828
1829 m_poppler_get_OBJECT(Page, getContents);
1830
1831 m_poppler__tostring(Page);
1832
1833 static const struct luaL_Reg Page_m[] = {
1834 {"isOk", m_Page_isOk},
1835 {"getNum", m_Page_getNum},
1836 {"getMediaBox", m_Page_getMediaBox},
1837 {"getCropBox", m_Page_getCropBox},
1838 {"isCropped", m_Page_isCropped},
1839 {"getMediaWidth", m_Page_getMediaWidth},
1840 {"getMediaHeight", m_Page_getMediaHeight},
1841 {"getCropWidth", m_Page_getCropWidth},
1842 {"getCropHeight", m_Page_getCropHeight},
1843 {"getBleedBox", m_Page_getBleedBox},
1844 {"getTrimBox", m_Page_getTrimBox},
1845 {"getArtBox", m_Page_getArtBox},
1846 {"getRotate", m_Page_getRotate},
1847 {"getLastModified", m_Page_getLastModified},
1848 {"getBoxColorInfo", m_Page_getBoxColorInfo},
1849 {"getGroup", m_Page_getGroup},
1850 {"getMetadata", m_Page_getMetadata},
1851 {"getPieceInfo", m_Page_getPieceInfo},
1852 {"getSeparationInfo", m_Page_getSeparationInfo},
1853 {"getResourceDict", m_Page_getResourceDict},
1854 {"getAnnotsObject", m_Page_getAnnotsObject},
1855 {"getContents", m_Page_getContents},
1856 {"__tostring", m_Page__tostring},
1857 {NULL, NULL}
1858 };
1859
1860 /* PDFDoc */
1861
1862 #define m_PDFDoc_BOOL(function) \
1863 static int m_PDFDoc_##function(lua_State * L) \
1864 { \
1865 udstruct *uin; \
1866 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); \
1867 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
1868 pdfdoc_changed_error(L); \
1869 if (((PdfDocument *) uin->d)->doc->function()) \
1870 lua_pushboolean(L, 1); \
1871 else \
1872 lua_pushboolean(L, 0); \
1873 return 1; \
1874 }
1875
1876 #define m_PDFDoc_INT(function) \
1877 static int m_PDFDoc_##function(lua_State * L) \
1878 { \
1879 int i; \
1880 udstruct *uin; \
1881 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); \
1882 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
1883 pdfdoc_changed_error(L); \
1884 i = ((PdfDocument *) uin->d)->doc->function(); \
1885 lua_pushinteger(L, i); \
1886 return 1; \
1887 }
1888
1889 m_PDFDoc_BOOL(isOk);
1890 m_PDFDoc_INT(getErrorCode);
1891
1892 static int m_PDFDoc_getFileName(lua_State * L)
1893 {
1894 GooString *gs;
1895 udstruct *uin;
1896 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
1897 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1898 pdfdoc_changed_error(L);
1899 gs = ((PdfDocument *) uin->d)->doc->getFileName();
1900 if (gs != NULL)
1901 lua_pushlstring(L, gs->getCString(), gs->getLength());
1902 else
1903 lua_pushnil(L);
1904 return 1;
1905 }
1906
1907 static int m_PDFDoc_getErrorCodeName(lua_State * L)
1908 {
1909 int i;
1910 udstruct *uin;
1911 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
1912 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1913 pdfdoc_changed_error(L);
1914 i = ((PdfDocument *) uin->d)->doc->getErrorCode();
1915 lua_pushstring(L, ErrorCodeNames[i]);
1916 return 1;
1917 }
1918
1919 static int m_PDFDoc_getXRef(lua_State * L)
1920 {
1921 XRef *xref;
1922 udstruct *uin, *uout;
1923 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
1924 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1925 pdfdoc_changed_error(L);
1926 xref = ((PdfDocument *) uin->d)->doc->getXRef();
1927 if (xref->isOk()) {
1928 uout = new_XRef_userdata(L);
1929 uout->d = xref;
1930 uout->pc = uin->pc;
1931 uout->pd = uin->pd;
1932 } else
1933 lua_pushnil(L);
1934 return 1;
1935 }
1936
1937 static int m_PDFDoc_getCatalog(lua_State * L)
1938 {
1939 Catalog *cat;
1940 udstruct *uin, *uout;
1941 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
1942 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1943 pdfdoc_changed_error(L);
1944 cat = ((PdfDocument *) uin->d)->doc->getCatalog();
1945 if (cat->isOk()) {
1946 uout = new_Catalog_userdata(L);
1947 uout->d = cat;
1948 uout->pc = uin->pc;
1949 uout->pd = uin->pd;
1950 } else
1951 lua_pushnil(L);
1952 return 1;
1953 }
1954
1955 #define m_PDFDoc_PAGEDIMEN(function) \
1956 static int m_PDFDoc_##function(lua_State * L) \
1957 { \
1958 int i, pages; \
1959 double d; \
1960 udstruct *uin; \
1961 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc); \
1962 if (uin->pd != NULL && uin->pd->pc != uin->pc) \
1963 pdfdoc_changed_error(L); \
1964 i = luaL_checkint(L, 2); \
1965 pages = ((PdfDocument *) uin->d)->doc->getNumPages(); \
1966 if (i > 0 && i <= pages) { \
1967 d = (double) ((PdfDocument *) uin->d)->doc->function(i); \
1968 lua_pushnumber(L, d); /* float */ \
1969 } else \
1970 lua_pushnil(L); \
1971 return 1; \
1972 }
1973
1974 m_PDFDoc_PAGEDIMEN(getPageMediaWidth);
1975 m_PDFDoc_PAGEDIMEN(getPageMediaHeight);
1976 m_PDFDoc_PAGEDIMEN(getPageCropWidth);
1977 m_PDFDoc_PAGEDIMEN(getPageCropHeight);
1978 m_PDFDoc_INT(getNumPages);
1979
1980 static int m_PDFDoc_readMetadata(lua_State * L)
1981 {
1982 GooString *gs;
1983 udstruct *uin;
1984 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
1985 if (uin->pd != NULL && uin->pd->pc != uin->pc)
1986 pdfdoc_changed_error(L);
1987 if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) {
1988 gs = ((PdfDocument *) uin->d)->doc->readMetadata();
1989 if (gs != NULL)
1990 lua_pushlstring(L, gs->getCString(), gs->getLength());
1991 else
1992 lua_pushnil(L);
1993 } else
1994 lua_pushnil(L);
1995 return 1;
1996 }
1997
1998 static int m_PDFDoc_getStructTreeRoot(lua_State * L)
1999 {
2000 StructTreeRoot *obj;
2001 udstruct *uin, *uout;
2002 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2003 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2004 pdfdoc_changed_error(L);
2005 if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) {
2006 obj = ((PdfDocument *) uin->d)->doc->getStructTreeRoot();
2007 uout = new_StructTreeRoot_userdata(L);
2008 uout->d = obj;
2009 uout->pc = uin->pc;
2010 uout->pd = uin->pd;
2011 } else
2012 lua_pushnil(L);
2013 return 1;
2014 }
2015
2016 static int m_PDFDoc_findPage(lua_State * L)
2017 {
2018 int num, gen, i;
2019 udstruct *uin;
2020 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2021 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2022 pdfdoc_changed_error(L);
2023 num = luaL_checkint(L, 2);
2024 gen = luaL_checkint(L, 3);
2025 if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) {
2026 i = ((PdfDocument *) uin->d)->doc->findPage(num, gen);
2027 if (i > 0)
2028 lua_pushinteger(L, i);
2029 else
2030 lua_pushnil(L);
2031 } else
2032 lua_pushnil(L);
2033 return 1;
2034 }
2035
2036 static int m_PDFDoc_getLinks(lua_State * L)
2037 {
2038 int i, pages;
2039 Links *links;
2040 udstruct *uin, *uout;
2041 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2042 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2043 pdfdoc_changed_error(L);
2044 i = luaL_checkint(L, 2);
2045 pages = ((PdfDocument *) uin->d)->doc->getNumPages();
2046 if (i > 0 && i <= pages) {
2047 links = ((PdfDocument *) uin->d)->doc->getLinks(i);
2048 if (links != NULL) {
2049 uout = new_Links_userdata(L);
2050 uout->d = links;
2051 uout->pc = uin->pc;
2052 uout->pd = uin->pd;
2053 } else
2054 lua_pushnil(L);
2055 } else
2056 lua_pushnil(L);
2057 return 1;
2058 }
2059
2060 static int m_PDFDoc_findDest(lua_State * L)
2061 {
2062 GooString *name;
2063 LinkDest *dest;
2064 const char *s;
2065 size_t len;
2066 udstruct *uin, *uout;
2067 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2068 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2069 pdfdoc_changed_error(L);
2070 s = luaL_checklstring(L, 2, &len);
2071 name = new GooString(s, len);
2072 if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) {
2073 dest = ((PdfDocument *) uin->d)->doc->findDest(name);
2074 if (dest != NULL) {
2075 uout = new_LinkDest_userdata(L);
2076 uout->d = dest;
2077 uout->pc = uin->pc;
2078 uout->pd = uin->pd;
2079 } else
2080 lua_pushnil(L);
2081 } else
2082 lua_pushnil(L);
2083 delete name;
2084 return 1;
2085 }
2086
2087 m_PDFDoc_BOOL(isEncrypted);
2088 m_PDFDoc_BOOL(okToPrint);
2089 m_PDFDoc_BOOL(okToChange);
2090 m_PDFDoc_BOOL(okToCopy);
2091 m_PDFDoc_BOOL(okToAddNotes);
2092 m_PDFDoc_BOOL(isLinearized);
2093
2094 static int m_PDFDoc_getDocInfo(lua_State * L)
2095 {
2096 udstruct *uin, *uout;
2097 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2098 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2099 pdfdoc_changed_error(L);
2100 if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
2101 uout = new_Object_userdata(L);
2102 uout->d = new Object();
2103 *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfo();
2104 uout->atype = ALLOC_LEPDF;
2105 uout->pc = uin->pc;
2106 uout->pd = uin->pd;
2107 } else
2108 lua_pushnil(L);
2109 return 1;
2110 }
2111
2112 static int m_PDFDoc_getDocInfoNF(lua_State * L)
2113 {
2114 udstruct *uin, *uout;
2115 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2116 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2117 pdfdoc_changed_error(L);
2118 if (((PdfDocument *) uin->d)->doc->getXRef()->isOk()) {
2119 uout = new_Object_userdata(L);
2120 uout->d = new Object();
2121 *((Object *) uout->d) = ((PdfDocument *) uin->d)->doc->getDocInfoNF();
2122 uout->atype = ALLOC_LEPDF;
2123 uout->pc = uin->pc;
2124 uout->pd = uin->pd;
2125 } else
2126 lua_pushnil(L);
2127 return 1;
2128 }
2129
2130 m_PDFDoc_INT(getPDFMajorVersion);
2131 m_PDFDoc_INT(getPDFMinorVersion);
2132
2133 m_poppler__tostring(PDFDoc);
2134
2135 static int m_PDFDoc__gc(lua_State * L)
2136 {
2137 udstruct *uin;
2138 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
2139 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2140 pdfdoc_changed_error(L);
2141 #ifdef DEBUG
2142 printf("\n===== PDFDoc GC ===== file_path=<%s>\n",
2143 ((PdfDocument *) uin->d)->file_path);
2144 #endif
2145 assert(uin->atype == ALLOC_LEPDF);
2146 unrefPdfDocument(((PdfDocument *) uin->d)->file_path);
2147 return 0;
2148 }
2149
2150 static const struct luaL_Reg PDFDoc_m[] = {
2151 {"isOk", m_PDFDoc_isOk},
2152 {"getErrorCode", m_PDFDoc_getErrorCode},
2153 {"getErrorCodeName", m_PDFDoc_getErrorCodeName}, // not poppler
2154 {"getFileName", m_PDFDoc_getFileName},
2155 {"getXRef", m_PDFDoc_getXRef},
2156 {"getCatalog", m_PDFDoc_getCatalog},
2157 {"getPageMediaWidth", m_PDFDoc_getPageMediaWidth},
2158 {"getPageMediaHeight", m_PDFDoc_getPageMediaHeight},
2159 {"getPageCropWidth", m_PDFDoc_getPageCropWidth},
2160 {"getPageCropHeight", m_PDFDoc_getPageCropHeight},
2161 {"getNumPages", m_PDFDoc_getNumPages},
2162 {"readMetadata", m_PDFDoc_readMetadata},
2163 {"getStructTreeRoot", m_PDFDoc_getStructTreeRoot},
2164 {"findPage", m_PDFDoc_findPage},
2165 {"getLinks", m_PDFDoc_getLinks},
2166 {"findDest", m_PDFDoc_findDest},
2167 {"isEncrypted", m_PDFDoc_isEncrypted},
2168 {"okToPrint", m_PDFDoc_okToPrint},
2169 {"okToChange", m_PDFDoc_okToChange},
2170 {"okToCopy", m_PDFDoc_okToCopy},
2171 {"okToAddNotes", m_PDFDoc_okToAddNotes},
2172 {"isLinearized", m_PDFDoc_isLinearized},
2173 {"getDocInfo", m_PDFDoc_getDocInfo},
2174 {"getDocInfoNF", m_PDFDoc_getDocInfoNF},
2175 {"getPDFMajorVersion", m_PDFDoc_getPDFMajorVersion},
2176 {"getPDFMinorVersion", m_PDFDoc_getPDFMinorVersion},
2177 {"__tostring", m_PDFDoc__tostring},
2178 {"__gc", m_PDFDoc__gc},
2179 {NULL, NULL}
2180 };
2181
2182 /* PDFRectangle */
2183
2184 m_poppler_get_BOOL(PDFRectangle, isValid);
2185
2186 m_poppler__tostring(PDFRectangle);
2187
2188 static int m_PDFRectangle__index(lua_State * L)
2189 {
2190 const char *s;
2191 udstruct *uin;
2192 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFRectangle);
2193 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2194 pdfdoc_changed_error(L);
2195 s = luaL_checkstring(L, 2);
2196 if (strlen(s) == 2) {
2197 if (s[0] == 'x') {
2198 if (s[1] == '1')
2199 lua_pushnumber(L, ((PDFRectangle *) uin->d)->x1); /* float */
2200 else if (s[1] == '2')
2201 lua_pushnumber(L, ((PDFRectangle *) uin->d)->x2); /* float */
2202 else
2203 lua_pushnil(L);
2204 } else if (s[0] == 'y') {
2205 if (s[1] == '1')
2206 lua_pushnumber(L, ((PDFRectangle *) uin->d)->y1); /* float */
2207 else if (s[1] == '2')
2208 lua_pushnumber(L, ((PDFRectangle *) uin->d)->y2); /* float */
2209 else
2210 lua_pushnil(L);
2211 } else
2212 lua_pushnil(L);
2213 } else
2214 lua_pushnil(L);
2215 return 1;
2216 }
2217
2218 static int m_PDFRectangle__newindex(lua_State * L)
2219 {
2220 double d;
2221 const char *s;
2222 udstruct *uin;
2223 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFRectangle);
2224 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2225 pdfdoc_changed_error(L);
2226 s = luaL_checkstring(L, 2);
2227 d = luaL_checknumber(L, 3);
2228 if (strlen(s) == 2) {
2229 if (s[0] == 'x') {
2230 if (s[1] == '1')
2231 ((PDFRectangle *) uin->d)->x1 = d;
2232 else if (s[1] == '2')
2233 ((PDFRectangle *) uin->d)->x2 = d;
2234 else
2235 luaL_error(L, "wrong PDFRectangle coordinate (%s)", s);
2236 } else if (s[0] == 'y') {
2237 if (s[1] == '1')
2238 ((PDFRectangle *) uin->d)->y1 = d;
2239 else if (s[1] == '2')
2240 ((PDFRectangle *) uin->d)->y2 = d;
2241 } else
2242 luaL_error(L, "wrong PDFRectangle coordinate (%s)", s);
2243 } else
2244 luaL_error(L, "wrong PDFRectangle coordinate (%s)", s);
2245 return 0;
2246 }
2247
2248 static int m_PDFRectangle__gc(lua_State * L)
2249 {
2250 udstruct *uin;
2251 uin = (udstruct *) luaL_checkudata(L, 1, M_PDFRectangle);
2252 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2253 pdfdoc_changed_error(L);
2254 #ifdef DEBUG
2255 printf("\n===== PDFRectangle GC ===== uin=<%p>\n", uin);
2256 #endif
2257 if (uin->atype == ALLOC_LEPDF)
2258 delete(PDFRectangle *) uin->d;
2259 return 0;
2260 }
2261
2262 static const struct luaL_Reg PDFRectangle_m[] = {
2263 {"isValid", m_PDFRectangle_isValid},
2264 {"__index", m_PDFRectangle__index},
2265 {"__newindex", m_PDFRectangle__newindex},
2266 {"__tostring", m_PDFRectangle__tostring},
2267 {"__gc", m_PDFRectangle__gc},
2268 {NULL, NULL}
2269 };
2270
2271 /* Ref */
2272
2273 static int m_Ref__index(lua_State * L)
2274 {
2275 const char *s;
2276 udstruct *uin;
2277 uin = (udstruct *) luaL_checkudata(L, 1, M_Ref);
2278 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2279 pdfdoc_changed_error(L);
2280 s = luaL_checkstring(L, 2);
2281 if (strcmp(s, "num") == 0)
2282 lua_pushinteger(L, ((Ref *) uin->d)->num);
2283 else if (strcmp(s, "gen") == 0)
2284 lua_pushinteger(L, ((Ref *) uin->d)->gen);
2285 else
2286 lua_pushnil(L);
2287 return 1;
2288 }
2289
2290 m_poppler__tostring(Ref);
2291
2292 static int m_Ref__gc(lua_State * L)
2293 {
2294 udstruct *uin;
2295 uin = (udstruct *) luaL_checkudata(L, 1, M_Ref);
2296 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2297 pdfdoc_changed_error(L);
2298 #ifdef DEBUG
2299 printf("\n===== Ref GC ===== uin=<%p>\n", uin);
2300 #endif
2301 if (uin->atype == ALLOC_LEPDF && ((Ref *) uin->d) != NULL)
2302 gfree(((Ref *) uin->d));
2303 return 0;
2304 }
2305
2306 static const struct luaL_Reg Ref_m[] = {
2307 {"__index", m_Ref__index},
2308 {"__tostring", m_Ref__tostring},
2309 {"__gc", m_Ref__gc},
2310 {NULL, NULL}
2311 };
2312
2313 /* Stream */
2314
2315 static const char *StreamKindNames[] = {
2316 "File", "ASCIIHex", "ASCII85", "LZW", "RunLength", "CCITTFax", "DCT",
2317 "Flate", "JBIG2", "JPX", "Weird",
2318 NULL
2319 };
2320
2321 m_poppler_get_INT(Stream, getKind);
2322
2323 static int m_Stream_getKindName(lua_State * L)
2324 {
2325 StreamKind t;
2326 udstruct *uin;
2327 uin = (udstruct *) luaL_checkudata(L, 1, M_Stream);
2328 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2329 pdfdoc_changed_error(L);
2330 t = ((Stream *) uin->d)->getKind();
2331 lua_pushstring(L, StreamKindNames[t]);
2332 return 1;
2333 }
2334
2335 m_poppler_do(Stream, reset);
2336 m_poppler_do(Stream, close);
2337 m_poppler_get_INT(Stream, getChar);
2338 m_poppler_get_INT(Stream, lookChar);
2339 m_poppler_get_INT(Stream, getRawChar);
2340 m_poppler_get_INT(Stream, getUnfilteredChar);
2341 m_poppler_do(Stream, unfilteredReset);
2342 m_poppler_get_INT(Stream, getPos);
2343 m_poppler_get_BOOL(Stream, isBinary);
2344 m_poppler_get_poppler(Stream, Stream, getUndecodedStream);
2345 m_poppler_get_poppler(Stream, Dict, getDict);
2346
2347 m_poppler__tostring(Stream);
2348
2349 static const struct luaL_Reg Stream_m[] = {
2350 {"getKind", m_Stream_getKind},
2351 {"getKindName", m_Stream_getKindName}, // not poppler
2352 {"reset", m_Stream_reset},
2353 {"close", m_Stream_close},
2354 {"getUndecodedStream", m_Stream_getUndecodedStream},
2355 {"getChar", m_Stream_getChar},
2356 {"lookChar", m_Stream_lookChar},
2357 {"getRawChar", m_Stream_getRawChar},
2358 {"getUnfilteredChar", m_Stream_getUnfilteredChar},
2359 {"unfilteredReset", m_Stream_unfilteredReset},
2360 {"getPos", m_Stream_getPos},
2361 {"isBinary", m_Stream_isBinary},
2362 {"getUndecodedStream", m_Stream_getUndecodedStream},
2363 {"getDict", m_Stream_getDict},
2364 {"__tostring", m_Stream__tostring},
2365 {NULL, NULL}
2366 };
2367
2368 /* TextSpan */
2369
2370 m_poppler_get_GOOSTRING(TextSpan, getText);
2371 m_poppler__tostring(TextSpan);
2372
2373 static const struct luaL_Reg TextSpan_m[] = {
2374 {"getText", m_TextSpan_getText},
2375 {"__tostring", m_TextSpan__tostring},
2376 {NULL, NULL}
2377 };
2378
2379 /* Attribute */
2380
2381 m_poppler_get_BOOL(Attribute,isOk);
2382 m_poppler_get_INT(Attribute,getType);
2383 m_poppler_get_INT(Attribute,getOwner);
2384 m_poppler_get_GOOSTRING(Attribute,getName);
2385
2386 static int m_Attribute_getTypeName(lua_State * L)
2387 {
2388 udstruct *uin;
2389 uin = (udstruct *) luaL_checkudata(L, 1, M_Attribute);
2390 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2391 pdfdoc_changed_error(L);
2392 lua_pushstring(L, ((Attribute *) uin->d)->getTypeName());
2393 return 1;
2394 }
2395
2396 static int m_Attribute_getOwnerName(lua_State * L)
2397 {
2398 udstruct *uin;
2399 uin = (udstruct *) luaL_checkudata(L, 1, M_Attribute);
2400 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2401 pdfdoc_changed_error(L);
2402 lua_pushstring(L, ((Attribute *) uin->d)->getOwnerName());
2403 return 1;
2404 }
2405
2406 static int m_Attribute_getValue(lua_State * L)
2407 {
2408 udstruct *uin, *uout;
2409 Object *origin;
2410 uin = (udstruct *) luaL_checkudata(L, 1, M_Attribute);
2411 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2412 pdfdoc_changed_error(L);
2413 uout = new_Object_userdata(L);
2414 uout->d = new Object();
2415 origin = (Object *) (((Attribute *) uin->d)->getValue());
2416 *((Object *) uout->d) = origin->copy();
2417 uout->atype = ALLOC_LEPDF;
2418 uout->pc = uin->pc;
2419 uout->pd = uin->pd;
2420 return 1;
2421 }
2422
2423 static int m_Attribute_getDefaultValue(lua_State * L)
2424 {
2425 Attribute::Type t;
2426 udstruct *uin, *uout;
2427 uin = (udstruct *) luaL_checkudata(L, 1, M_Attribute);
2428 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2429 pdfdoc_changed_error(L);
2430 t = (Attribute::Type) luaL_checkint(L, 2);
2431 uout = new_Object_userdata(L);
2432 uout->d = ((Attribute *)uin->d)->getDefaultValue(t) ;
2433 //uout->atype = ALLOC_LEPDF;
2434 uout->pc = uin->pc;
2435 uout->pd = uin->pd;
2436 return 1;
2437 }
2438
2439 m_poppler_get_GUINT(Attribute,getRevision);
2440
2441 m_poppler_get_BOOL(Attribute, isHidden);
2442
2443 static int m_Attribute_getFormattedValue(lua_State * L)
2444 {
2445 udstruct *uin;
2446 uin = (udstruct *) luaL_checkudata(L, 1, M_Attribute);
2447 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2448 pdfdoc_changed_error(L);
2449 lua_pushstring(L, ((Attribute *) uin->d)->getFormattedValue());
2450 return 1;
2451 }
2452
2453 static int m_Attribute__gc(lua_State * L)
2454 {
2455 udstruct *uin;
2456 uin = (udstruct *) luaL_checkudata(L, 1, M_Attribute);
2457 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2458 pdfdoc_changed_error(L);
2459 #ifdef DEBUG
2460 printf("\n===== Attribute GC ===== uin=<%p>\n", uin);
2461 #endif
2462 if (uin->atype == ALLOC_LEPDF) {
2463 delete(Attribute *) uin->d;
2464 }
2465 return 0;
2466 }
2467
2468 m_poppler__tostring(Attribute);
2469
2470
2471 static const struct luaL_Reg Attribute_m[] = {
2472 {"isOk",m_Attribute_isOk},
2473 {"getType",m_Attribute_getType},
2474 {"getOwner",m_Attribute_getOwner},
2475 {"getTypeName",m_Attribute_getTypeName},
2476 {"getOwnerName",m_Attribute_getOwnerName},
2477 {"getValue",m_Attribute_getValue},
2478 {"getDefaultValue",m_Attribute_getDefaultValue},
2479 {"getName",m_Attribute_getName},
2480 {"getRevision",m_Attribute_getRevision},
2481 {"isHidden",m_Attribute_isHidden},
2482 {"getFormattedValue",m_Attribute_getFormattedValue},
2483 {"__gc", m_Attribute__gc},
2484 {"__tostring", m_Attribute__tostring},
2485 {NULL, NULL}
2486 };
2487
2488 /* StructElement */
2489
2490 m_poppler_get_INT(StructElement,getType);
2491 m_poppler_get_BOOL(StructElement,isOk);
2492 m_poppler_get_BOOL(StructElement,isBlock);
2493 m_poppler_get_BOOL(StructElement,isInline);
2494 m_poppler_get_BOOL(StructElement,isGrouping);
2495 m_poppler_get_BOOL(StructElement,isContent);
2496 m_poppler_get_BOOL(StructElement,isObjectRef);
2497 m_poppler_get_BOOL(StructElement,hasPageRef);
2498 m_poppler_get_INT(StructElement,getMCID);
2499 m_poppler_get_INT(StructElement, getNumChildren);
2500
2501 m_poppler_get_GUINT(StructElement,getRevision);
2502 m_poppler_get_UINT(StructElement,getNumAttributes);
2503
2504 m_poppler_get_GOOSTRING(StructElement, getID);
2505 m_poppler_get_GOOSTRING(StructElement, getLanguage);
2506 m_poppler_get_GOOSTRING(StructElement, getTitle);
2507 m_poppler_get_GOOSTRING(StructElement, getExpandedAbbr);
2508 m_poppler_get_GOOSTRING(StructElement, getAltText);
2509 m_poppler_get_GOOSTRING(StructElement, getActualText);
2510
2511 m_poppler_get_poppler(StructElement, StructTreeRoot, getStructTreeRoot);
2512 m_poppler__tostring(StructElement);
2513
2514 static int m_StructElement_getObjectRef(lua_State * L)
2515 {
2516 udstruct *uin, *uout;
2517 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2518 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2519 pdfdoc_changed_error(L);
2520 uout = new_Ref_userdata(L);
2521 uout->d = (Ref *) gmalloc(sizeof(Ref));
2522 ((Ref *) uout->d)->num = ((StructElement *) uin->d)->getObjectRef().num;
2523 ((Ref *) uout->d)->gen = ((StructElement *) uin->d)->getObjectRef().gen;
2524 uout->atype = ALLOC_LEPDF;
2525 uout->pc = uin->pc;
2526 uout->pd = uin->pd;
2527 return 1;
2528 }
2529
2530 static int m_StructElement_getParentRef(lua_State * L)
2531 {
2532 udstruct *uin, *uout;
2533 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2534 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2535 pdfdoc_changed_error(L);
2536 uout = new_Ref_userdata(L);
2537 uout->d = (Ref *) gmalloc(sizeof(Ref));
2538 ((Ref *) uout->d)->num = ((StructElement *) uin->d)->getParentRef().num;
2539 ((Ref *) uout->d)->gen = ((StructElement *) uin->d)->getParentRef().gen;
2540 uout->atype = ALLOC_LEPDF;
2541 uout->pc = uin->pc;
2542 uout->pd = uin->pd;
2543 return 1;
2544 }
2545
2546 /*
2547 Not exactly as the header:
2548
2549 Ref = StructElement:getPageRef()
2550
2551 Ref is false if the C++ function return false
2552
2553 */
2554
2555 static int m_StructElement_getPageRef(lua_State * L)
2556 {
2557 GBool b;
2558 Ref *r;
2559 udstruct *uin, *uout;
2560 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2561 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2562 pdfdoc_changed_error(L);
2563 r = (Ref *) gmalloc(sizeof(Ref));
2564 b = ((StructElement *) uin->d)->getPageRef( *r );
2565 if (b) {
2566 uout = new_Ref_userdata(L);
2567 uout->d = r ;
2568 /* uout->atype = ALLOC_LEPDF; */
2569 uout->pc = uin->pc;
2570 uout->pd = uin->pd;
2571 } else
2572 lua_pushboolean(L,0);
2573 return 1;
2574 }
2575
2576 static int m_StructElement_getTypeName(lua_State * L)
2577 {
2578 udstruct *uin;
2579 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2580 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2581 pdfdoc_changed_error(L);
2582 lua_pushstring(L, ((StructElement *) uin->d)->getTypeName());
2583 return 1;
2584 }
2585
2586 static int m_StructElement_getText(lua_State * L)
2587 {
2588 GBool i;
2589 GooString *gs;
2590 udstruct *uin;
2591 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2592 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2593 pdfdoc_changed_error(L);
2594 i = (GBool) lua_toboolean(L, 2);
2595 gs = ((StructElement *) uin->d)->getText(i);
2596 if (gs != NULL)
2597 lua_pushlstring(L, gs->getCString(), gs->getLength());
2598 else
2599 lua_pushnil(L);
2600 return 1;
2601 }
2602
2603 static int m_StructElement_getChild(lua_State * L)
2604 {
2605 StructElement *c;
2606 int i;
2607 udstruct *uin, *uout;
2608 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2609 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2610 pdfdoc_changed_error(L);
2611 i = (int) luaL_checkint(L, 2);
2612 c = ((StructElement *) uin->d)->getChild(i-1);
2613 if (c != NULL) {
2614 uout = new_StructElement_userdata(L);
2615 uout->d = c ;
2616 /* uout->atype = ALLOC_LEPDF; */
2617 uout->pc = uin->pc;
2618 uout->pd = uin->pd;
2619 }
2620 else
2621 lua_pushnil(L);
2622 return 1;
2623 }
2624
2625 static int m_StructElement_getAttribute(lua_State * L)
2626 {
2627 Attribute *a;
2628 int i;
2629 udstruct *uin, *uout;
2630 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2631 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2632 pdfdoc_changed_error(L);
2633 i = (int) luaL_checkint(L, 2);
2634 a = ((StructElement *) uin->d)->getAttribute(i-1);
2635 if (a != NULL) {
2636 uout = new_Attribute_userdata(L);
2637 uout->d = a ;
2638 uout->pc = uin->pc;
2639 uout->pd = uin->pd;
2640 }
2641 else
2642 lua_pushnil(L);
2643 return 1;
2644 }
2645
2646 static int m_StructElement_findAttribute(lua_State * L)
2647 {
2648 Attribute::Type t;
2649 Attribute::Owner o;
2650 GBool g;
2651 udstruct *uin, *uout;
2652 const Attribute *a;
2653 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2654 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2655 pdfdoc_changed_error(L);
2656 t = (Attribute::Type) luaL_checkint(L,1);
2657 o = (Attribute::Owner) luaL_checkint(L,2);
2658 g = (GBool) lua_toboolean(L, 3);
2659 a = ((StructElement *) uin->d)->findAttribute(t,g,o);
2660
2661 if (a!=NULL){
2662 uout = new_Attribute_userdata(L);
2663 uout->d = new Attribute(a->getType(),a->getValue());
2664 uout->atype = ALLOC_LEPDF;
2665 uout->pc = uin->pc;
2666 uout->pd = uin->pd;
2667 } else
2668 lua_pushnil(L);
2669 return 1;
2670 }
2671
2672 /* This returns a lua table */
2673
2674 static int m_StructElement_getTextSpans(lua_State * L)
2675 {
2676 int i ;
2677 udstruct *uin, *uout;
2678 uin = (udstruct *) luaL_checkudata(L, 1, M_StructElement);
2679 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2680 pdfdoc_changed_error(L);
2681
2682 if ((((StructElement *) uin->d)->getTextSpans()).size()>0) {
2683 lua_createtable (L,
2684 (int) (((StructElement *) uin->d)->getTextSpans()).size(),
2685 0);
2686 for(i=0;i<(int) (((StructElement *) uin->d)->getTextSpans()).size(); i++){
2687 uout = new_TextSpan_userdata(L);
2688 uout->d = new TextSpan( (((StructElement *) uin->d)->getTextSpans())[i] );
2689 uout->atype = ALLOC_LEPDF;
2690 uout->pc = uin->pc;
2691 uout->pd = uin->pd;
2692 lua_rawseti(L,-2,i+1);
2693 }
2694 } else
2695 lua_pushnil(L);
2696 return 1;
2697 }
2698
2699 static const struct luaL_Reg StructElement_m[] = {
2700 {"getTypeName", m_StructElement_getTypeName},
2701 {"getType",m_StructElement_getType},
2702 {"isOk",m_StructElement_isOk},
2703 {"isBlock",m_StructElement_isBlock},
2704 {"isInline",m_StructElement_isInline},
2705 {"isGrouping",m_StructElement_isGrouping},
2706 {"isContent",m_StructElement_isContent},
2707 {"isObjectRef",m_StructElement_isObjectRef},
2708 {"getMCID",m_StructElement_getMCID},
2709 {"getObjectRef",m_StructElement_getObjectRef},
2710 {"getParentRef",m_StructElement_getParentRef},
2711 {"hasPageRef",m_StructElement_hasPageRef},
2712 {"getPageRef",m_StructElement_getPageRef},
2713 {"getStructTreeRoot",m_StructElement_getStructTreeRoot},
2714 {"getID",m_StructElement_getID},
2715 {"getLanguage",m_StructElement_getLanguage},
2716 {"getRevision",m_StructElement_getRevision},
2717 {"getTitle",m_StructElement_getTitle},
2718 {"getExpandedAbbr",m_StructElement_getExpandedAbbr},
2719 {"getNumChildren",m_StructElement_getNumChildren},
2720 {"getChild",m_StructElement_getChild},
2721 {"getNumAttributes",m_StructElement_getNumAttributes},
2722 {"getAttribute",m_StructElement_getAttribute},
2723 {"findAttribute",m_StructElement_findAttribute},
2724 {"getAltText",m_StructElement_getAltText},
2725 {"getActualText",m_StructElement_getActualText},
2726 {"getText",m_StructElement_getText},
2727 {"getTextSpans",m_StructElement_getTextSpans},
2728 {"__tostring", m_StructElement__tostring},
2729 {NULL, NULL}
2730 };
2731
2732 /* StructTreeRoot */
2733
2734 m_poppler_get_INT(StructTreeRoot, getNumChildren);
2735 m_poppler_get_poppler(StructTreeRoot, PDFDoc, getDoc);
2736 m_poppler_get_poppler(StructTreeRoot, Dict, getRoleMap);
2737 m_poppler_get_poppler(StructTreeRoot, Dict, getClassMap);
2738 m_poppler__tostring(StructTreeRoot);
2739
2740 static int m_StructTreeRoot_getChild(lua_State * L)
2741 {
2742 unsigned int i;
2743 udstruct *uin, *uout;
2744 StructElement *child ;
2745 StructTreeRoot *root ;
2746
2747 uin = (udstruct *) luaL_checkudata(L, 1, M_StructTreeRoot);
2748 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2749 pdfdoc_changed_error(L);
2750 i = (unsigned) luaL_checkint(L, 2);
2751 root = (StructTreeRoot *) uin->d;
2752 if (i-1 < root->getNumChildren() ){
2753 child = root->getChild(i-1);
2754 uout = new_StructElement_userdata(L);
2755 uout->d = child;
2756 /* uout->atype = ALLOC_LEPDF; */
2757 uout->pc = uin->pc;
2758 uout->pd = uin->pd;
2759 } else
2760 lua_pushnil(L);
2761 return 1;
2762 }
2763
2764 static int m_StructTreeRoot_findParentElement(lua_State * L)
2765 {
2766 unsigned int i;
2767 udstruct *uin, *uout;
2768 const StructElement *parent ;
2769 StructTreeRoot *root ;
2770
2771 uin = (udstruct *) luaL_checkudata(L, 1, M_StructTreeRoot);
2772 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2773 pdfdoc_changed_error(L);
2774 i = (unsigned) luaL_checkint(L, 2);
2775 root = (StructTreeRoot *) uin->d;
2776 parent = root->findParentElement(i-1);
2777 if (parent != NULL) {
2778 uout = new_StructElement_userdata(L);
2779 /* see https://isocpp.org/wiki/faq/const-correctness#aliasing-and-const */
2780 uout->d = (StructElement *) parent;
2781 uout->atype = ALLOC_LEPDF;
2782 uout->pc = uin->pc;
2783 uout->pd = uin->pd;
2784 } else
2785 lua_pushnil(L);
2786 return 1;
2787 }
2788
2789 static const struct luaL_Reg StructTreeRoot_m[] = {
2790 {"getDoc",m_StructTreeRoot_getDoc},
2791 {"getRoleMap",m_StructTreeRoot_getRoleMap},
2792 {"getClassMap",m_StructTreeRoot_getClassMap},
2793 {"getNumChildren",m_StructTreeRoot_getNumChildren},
2794 {"getChild",m_StructTreeRoot_getChild},
2795 {"findParentElement",m_StructTreeRoot_findParentElement},
2796 {"__tostring", m_StructTreeRoot__tostring},
2797 {NULL, NULL}
2798 };
2799
2800 /* XRef */
2801
2802 m_poppler_get_BOOL(XRef, isOk);
2803 m_poppler_get_INT(XRef, getErrorCode);
2804 m_poppler_get_BOOL(XRef, isEncrypted);
2805 m_poppler_get_BOOL(XRef, okToPrint);
2806 m_poppler_get_BOOL(XRef, okToPrintHighRes);
2807 m_poppler_get_BOOL(XRef, okToChange);
2808 m_poppler_get_BOOL(XRef, okToCopy);
2809 m_poppler_get_BOOL(XRef, okToAddNotes);
2810 m_poppler_get_BOOL(XRef, okToFillForm);
2811 m_poppler_get_BOOL(XRef, okToAccessibility);
2812 m_poppler_get_BOOL(XRef, okToAssemble);
2813 m_poppler_get_OBJECT(XRef, getCatalog);
2814
2815 static int m_XRef_fetch(lua_State * L)
2816 {
2817 int num, gen;
2818 udstruct *uin, *uout;
2819 uin = (udstruct *) luaL_checkudata(L, 1, M_XRef);
2820 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2821 pdfdoc_changed_error(L);
2822 num = luaL_checkint(L, 2);
2823 gen = luaL_checkint(L, 3);
2824 uout = new_Object_userdata(L);
2825 uout->d = new Object();
2826 *((Object *) uout->d) = ((XRef *) uin->d)->fetch(num, gen);
2827 uout->atype = ALLOC_LEPDF;
2828 uout->pc = uin->pc;
2829 uout->pd = uin->pd;
2830 return 1;
2831 }
2832
2833 m_poppler_get_OBJECT(XRef, getDocInfo);
2834 m_poppler_get_OBJECT(XRef, getDocInfoNF);
2835 m_poppler_get_INT(XRef, getNumObjects);
2836 m_poppler_get_INT(XRef, getRootNum);
2837 m_poppler_get_INT(XRef, getRootGen);
2838
2839 static int m_XRef_getNumEntry(lua_State * L)
2840 {
2841 int i, offset;
2842 udstruct *uin;
2843 uin = (udstruct *) luaL_checkudata(L, 1, M_XRef);
2844 if (uin->pd != NULL && uin->pd->pc != uin->pc)
2845 pdfdoc_changed_error(L);
2846 offset = luaL_checkint(L, 2);
2847 i = ((XRef *) uin->d)->getNumEntry(offset);
2848 if (i >= 0)
2849 lua_pushinteger(L, i);
2850 else
2851 lua_pushnil(L);
2852 return 1;
2853 }
2854
2855 m_poppler_get_poppler(XRef, Object, getTrailerDict);
2856
2857 m_poppler__tostring(XRef);
2858
2859 static const struct luaL_Reg XRef_m[] = {
2860 {"isOk", m_XRef_isOk},
2861 {"getErrorCode", m_XRef_getErrorCode},
2862 {"isEncrypted", m_XRef_isEncrypted},
2863 {"okToPrint", m_XRef_okToPrint},
2864 {"okToPrintHighRes", m_XRef_okToPrintHighRes},
2865 {"okToChange", m_XRef_okToChange},
2866 {"okToCopy", m_XRef_okToCopy},
2867 {"okToAddNotes", m_XRef_okToAddNotes},
2868 {"okToFillForm", m_XRef_okToFillForm},
2869 {"okToAccessibility", m_XRef_okToAccessibility},
2870 {"okToAssemble", m_XRef_okToAssemble},
2871 {"getCatalog", m_XRef_getCatalog},
2872 {"fetch", m_XRef_fetch},
2873 {"getDocInfo", m_XRef_getDocInfo},
2874 {"getDocInfoNF", m_XRef_getDocInfoNF},
2875 {"getNumObjects", m_XRef_getNumObjects},
2876 {"getRootNum", m_XRef_getRootNum},
2877 {"getRootGen", m_XRef_getRootGen},
2878 {"getNumEntry", m_XRef_getNumEntry},
2879 {"getTrailerDict", m_XRef_getTrailerDict},
2880 {"__tostring", m_XRef__tostring},
2881 {NULL, NULL}
2882 };
2883
2884 /* XRefEntry */
2885
2886 m_poppler__tostring(XRefEntry);
2887
2888 static const struct luaL_Reg XRefEntry_m[] = {
2889 {"__tostring", m_XRefEntry__tostring},
2890 {NULL, NULL}
2891 };
2892
2893 /* Done */
2894
2895 #ifdef LuajitTeX
2896 #define setfuncs_meta(type) \
2897 luaL_newmetatable(L, M_##type); \
2898 lua_pushvalue(L, -1); \
2899 lua_setfield(L, -2, "__index"); \
2900 lua_pushstring(L, "no user access"); \
2901 lua_setfield(L, -2, "__metatable"); \
2902 luaL_openlib(L, NULL, type##_m, 0)
2903 #else
2904 #define setfuncs_meta(type) \
2905 luaL_newmetatable(L, M_##type); \
2906 lua_pushvalue(L, -1); \
2907 lua_setfield(L, -2, "__index"); \
2908 lua_pushstring(L, "no user access"); \
2909 lua_setfield(L, -2, "__metatable"); \
2910 luaL_setfuncs(L, type##_m, 0)
2911 #endif
2912
2913 int luaopen_epdf(lua_State * L)
2914 {
2915 setfuncs_meta(Annot);
2916 setfuncs_meta(Annots);
2917 setfuncs_meta(Array);
2918 setfuncs_meta(Catalog);
2919 setfuncs_meta(Dict);
2920 setfuncs_meta(EmbFile);
2921 setfuncs_meta(FileSpec);
2922 setfuncs_meta(GooString);
2923 setfuncs_meta(LinkDest);
2924 setfuncs_meta(Links);
2925 setfuncs_meta(Object);
2926 setfuncs_meta(Page);
2927 setfuncs_meta(PDFDoc);
2928 setfuncs_meta(PDFRectangle);
2929 setfuncs_meta(Ref);
2930 setfuncs_meta(Stream);
2931 setfuncs_meta(Attribute);
2932 setfuncs_meta(StructElement);
2933 setfuncs_meta(StructTreeRoot);
2934 setfuncs_meta(TextSpan);
2935 setfuncs_meta(XRef);
2936 setfuncs_meta(XRefEntry);
2937 luaL_openlib(L, "epdf", epdflib_f, 0);
2938 return 1;
2939 }