wok view gambas2/stuff/CPdfDocument.cpp @ rev 21572

tmate: inserted some environment variables in recipe
author Hans-G?nter Theisgen
date Sat May 18 17:29:21 2019 +0100 (2019-05-18)
parents
children
line source
1 /***************************************************************************
3 CPdfDocument.cpp
5 gb.pdf Component
7 (C) 2005-2007 Daniel Campos Fernández <dcamposf@gmail.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 1, or (at your option)
13 any later version.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 1, or (at your option)
18 any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 ***************************************************************************/
31 #define __CPDFDOCUMENT_C
33 #include "CPdfDocument.h"
35 #include "gambas.h"
36 #include "main.h"
38 #include <stdio.h>
39 #include <stdint.h>
40 #include <math.h>
42 #include <PDFDoc.h>
43 #include <Stream.h>
44 #include <ErrorCodes.h>
45 #include <Page.h>
46 #include <Catalog.h>
47 #include <TextOutputDev.h>
48 #include <SplashOutputDev.h>
49 #include <splash/SplashBitmap.h>
50 #include <goo/GooList.h>
51 #include <Outline.h>
52 #include <Link.h>
53 #include <Gfx.h>
55 /*****************************************************************************
57 Translations from Poppler universe to Gambas universe
59 ******************************************************************************/
60 typedef struct
61 {
62 int32_t x0;
63 int32_t y0;
64 int32_t x1;
65 int32_t y1;
66 } FoundRect;
68 static void aux_return_string_info(void *_object, const char *key)
69 {
70 Object obj;
71 Object dst;
72 GooString *goo_value;
73 Dict *info_dict;
74 char *tmpstr;
76 THIS->doc->getDocInfo (&obj);
77 if (!obj.isDict()) { GB.ReturnNewZeroString(""); return; }
79 info_dict=obj.getDict();
80 info_dict->lookup ((char *)key, &dst);
81 if (!dst.isString ()) { GB.ReturnNewZeroString(""); }
82 else {
83 goo_value = dst.getString();
85 if (goo_value->hasUnicodeMarker())
86 {
87 GB.ConvString (&tmpstr,goo_value->getCString()+2,goo_value->getLength()-2,"UTF-16BE","UTF-8");
88 GB.ReturnNewZeroString(tmpstr);
89 }
90 else
91 GB.ReturnNewString(goo_value->getCString(),goo_value->getLength());
92 }
93 dst.free();
94 obj.free();
95 }
97 static void aux_return_date_info(void *_object, const char *key)
98 {
99 // TODO: Y2K effect
100 GB_DATE_SERIAL ds;
101 GB_DATE ret;
102 Object obj;
103 Object dst;
104 GooString *goo;
105 Dict *info_dict;
106 char *datestr=NULL,*tofree=NULL;
107 int nnum;
109 THIS->doc->getDocInfo (&obj);
110 if (!obj.isDict()) { GB.ReturnNull(); return; }
112 info_dict=obj.getDict();
113 info_dict->lookup ((char *)key, &dst);
114 if (!dst.isString ()) { GB.ReturnNull(); }
115 else {
116 goo = dst.getString();
117 if (goo->hasUnicodeMarker())
118 GB.ConvString (&datestr,goo->getCString()+2,goo->getLength()-2,"UTF-16BE","UTF-8");
119 else
120 {
121 GB.NewString(&datestr,goo->getCString(),goo->getLength());
122 tofree=datestr;
123 }
125 if (!datestr) { GB.ReturnNull(); }
126 else
127 {
128 if (datestr[0] == 'D' && datestr[1] == ':') datestr += 2;
129 nnum=sscanf(datestr, "%4hd%2hd%2hd%2hd%2hd%2hd",&ds.year, &ds.month, \
130 &ds.day, &ds.hour, &ds.min, &ds.sec);
131 if (nnum != 6) { GB.ReturnNull(); }
132 else
133 {
134 if (GB.MakeDate(&ds,&ret))
135 GB.ReturnNull();
136 else
137 GB.ReturnDate(&ret);
138 }
139 }
141 }
143 if (tofree) GB.FreeString(&tofree);
144 dst.free();
145 obj.free();
146 }
148 static void aux_return_unicode_string(Unicode *uni, int32_t len)
149 {
150 int32_t bc;
151 char *ret=NULL;
153 for (bc=0; bc<len; bc++)
154 GB.AddString(&ret,(const char*)&uni[bc],0);
156 GB.ReturnNewString(ret,0);
157 GB.FreeString(&ret);
158 }
160 static LinkDest *get_dest(LinkAction *act)
161 {
162 switch (act->getKind())
163 {
164 case actionGoTo: return ((LinkGoTo*)act)->getDest();
165 case actionGoToR: return ((LinkGoToR*)act)->getDest();
166 default: return 0;
167 }
168 }
170 static uint32_t aux_get_page_from_action(void *_object, LinkAction *act)
171 {
172 Ref pref;
173 LinkDest *dest = get_dest(act);
174 #if POPPLER_VERSION_0_6
175 GooString *name;
176 #else
177 UGooString *name;
178 #endif
180 if (!dest)
181 {
182 // try to use NamedDest to get dest
183 if (!act)
184 return 0;
185 if (act->getKind () == actionGoTo)
186 {
187 name = ((LinkGoTo*)act)->getNamedDest();
188 if (name)
189 dest = THIS->doc->findDest(name);
190 }
191 }
193 if (!dest)
194 return 0;
196 if (dest->isPageRef() )
197 {
198 pref= dest->getPageRef();
199 return THIS->doc->findPage(pref.num, pref.gen);
200 }
201 else
202 return dest->getPageNum();
203 }
205 static void aux_get_dimensions_from_action(LinkAction *act,int *left, int32_t *right, int32_t *top, int32_t *bottom)
206 {
207 LinkDest *dest = get_dest(act);
208 if (!dest)
209 {
210 if (left) *left=0;
211 if (right) *right=0;
212 if (top) *top=0;
213 if (bottom) *bottom=0;
214 return;
215 }
217 if (left) *left=(int32_t)dest->getLeft();
218 if (right) *right=(int32_t)dest->getRight();
219 if (top) *top=(int32_t)dest->getTop();
220 if (bottom) *bottom=(int32_t)dest->getBottom();
221 }
223 static double aux_get_zoom_from_action(LinkAction *act)
224 {
225 LinkDest *dest = get_dest(act);
226 if (dest)
227 return dest->getZoom();
228 else
229 return 1;
230 }
232 static char* aux_get_target_from_action(LinkAction *act)
233 {
234 char *vl=NULL;
235 char *uni=NULL;
236 GooString *tmp=NULL;
238 switch (act->getKind())
239 {
240 case actionGoToR:
241 tmp=((LinkGoToR*)act)->getFileName(); break;
243 case actionLaunch:
244 tmp=((LinkLaunch*)act)->getFileName(); break;
246 case actionURI:
247 tmp=((LinkURI*)act)->getURI(); break;
249 case actionNamed:
250 tmp=((LinkNamed*)act)->getName(); break;
252 case actionMovie:
253 #if POPPLER_VERSION_0_8
254 tmp=((LinkMovie*)act)->getAnnotTitle(); break;
255 #else
256 tmp=((LinkMovie*)act)->getTitle(); break;
257 #endif
259 default:
260 break;
261 }
263 if (!tmp) return NULL;
265 if (tmp->hasUnicodeMarker())
266 {
267 GB.ConvString (&uni,tmp->getCString()+2,tmp->getLength()-2,"UTF-16BE","UTF-8");
268 GB.AddString (&vl,uni,0);
269 }
270 else
271 GB.AddString(&vl,tmp->getCString(),tmp->getLength());
274 return vl;
276 }
278 /*****************************************************************************
280 PDF document
282 ******************************************************************************/
285 static void free_all(void *_object)
286 {
287 if (THIS->doc)
288 {
289 delete THIS->doc;
290 THIS->doc=NULL;
291 }
293 if (THIS->dev)
294 {
295 delete THIS->dev;
296 THIS->dev=NULL;
297 }
299 if (THIS->buf)
300 {
301 GB.ReleaseFile(&THIS->buf,THIS->len);
302 THIS->buf=NULL;
303 }
305 if (THIS->Found)
306 {
307 GB.FreeArray(POINTER(&THIS->Found));
308 THIS->Found=NULL;
309 }
311 if (THIS->links)
312 {
313 delete THIS->links;
314 THIS->links=NULL;
315 }
317 if (THIS->pindex)
318 {
319 GB.FreeArray(POINTER(&THIS->pindex));
320 GB.FreeArray(POINTER(&THIS->oldindex));
321 THIS->pindex=NULL;
322 THIS->oldindex=NULL;
323 }
325 THIS->index=NULL;
326 THIS->currpage=-1;
327 }
329 BEGIN_METHOD_VOID (PDFDOCUMENT_free)
331 free_all(_object);
333 END_METHOD
335 BEGIN_PROPERTY(PDFDOCUMENT_scale)
337 if (READ_PROPERTY){ GB.ReturnFloat(THIS->scale); return; }
339 if (VPROP(GB_FLOAT)>0) { THIS->scale = VPROP(GB_FLOAT); return; }
341 GB.Error("Zoom must be a positive value");
343 END_PROPERTY
345 BEGIN_PROPERTY(PDFDOCUMENT_rotation)
347 int32_t rot;
349 if (READ_PROPERTY)
350 {
351 GB.ReturnInteger(THIS->rotation);
352 return;
353 }
355 rot=VPROP(GB_INTEGER);
357 while (rot<0) rot+=360;
358 while (rot>=360) rot-=360;
360 switch (rot)
361 {
362 case 0:
363 case 90:
364 case 180:
365 case 270:
366 THIS->rotation = VPROP(GB_INTEGER);
367 break;
368 }
370 END_PROPERTY
373 int32_t open_document (void *_object, char *sfile, int32_t lfile)
374 {
375 SplashColor white;
376 PDFDoc *test;
377 MemStream *stream;
378 Object obj;
379 Outline *outline;
380 char *buf=NULL;
381 int32_t len=0;
382 int32_t ret;
385 if ( GB.LoadFile(sfile,lfile,&buf,&len) ) return -1;
387 obj.initNull();
388 stream=new MemStream(buf,0,(Guint)len,&obj);
389 test=new PDFDoc (stream,0,0);
391 if (!test->isOk())
392 {
393 GB.ReleaseFile(&buf,len);
394 ret=test->getErrorCode();
395 delete test;
396 test=NULL;
397 if (ret == errEncrypted) return -2;
398 return -3;
399 }
401 free_all(_object);
403 THIS->doc=test;
404 THIS->buf=buf;
405 THIS->len=len;
407 white[0] = 0xFF; white[1] = 0xFF; white[2] = 0xFF;
408 THIS->dev=new SplashOutputDev(splashModeRGB8, 3, gFalse, white);
410 #if POPPLER_VERSION_0_20
411 THIS->dev->startDoc(THIS->doc);
412 #else
413 THIS->dev->startDoc(THIS->doc->getXRef ());
414 #endif
416 outline=THIS->doc->getOutline();
417 if (outline) THIS->index=outline->getItems();
419 //if (THIS->index)
420 // if (!THIS->index->getLength()) THIS->index=NULL;
422 THIS->currindex=0;
423 THIS->currpage=-1;
425 return 0;
427 }
430 BEGIN_METHOD(PDFDOCUMENT_new, GB_STRING File)
432 THIS->scale = 1;
433 THIS->rotation = 0;
435 if (!MISSING(File))
436 {
437 switch (open_document( _object, STRING(File), LENGTH(File)) )
438 {
439 case -1: GB.Error("File not found"); return;
440 case -2: GB.Error("PDF is encrypted"); return;
441 case -3: GB.Error("Bad PDF File"); return;
442 }
443 }
445 END_METHOD
447 BEGIN_METHOD (PDFDOCUMENT_open, GB_STRING File;)
449 switch (open_document( _object, STRING(File), LENGTH(File)) )
450 {
451 case -1: GB.Error("File not found"); return;
452 case -2: GB.Error("PDF is encrypted"); return;
453 case -3: GB.Error("Bad PDF File"); return;
454 }
456 END_METHOD
458 BEGIN_METHOD_VOID(PDFDOCUMENT_close)
460 free_all(_object);
462 END_METHOD
464 BEGIN_METHOD(PDFDOCUMENT_get,GB_INTEGER index;)
466 if (!THIS->doc || (VARG(index)<1) || ( VARG(index)>THIS->doc->getNumPages() ) )
467 {
468 GB.Error("Invalid page number");
469 GB.ReturnNull();
470 return;
471 }
473 if (THIS->currpage != (uint32_t)VARG(index) )
474 {
475 if (THIS->Found)
476 {
477 GB.FreeArray(POINTER(&THIS->Found));
478 THIS->Found=NULL;
479 }
481 if (THIS->links)
482 {
483 delete THIS->links;
484 THIS->links=NULL;
485 }
487 THIS->page=THIS->doc->getCatalog()->getPage(VARG(index));
488 THIS->currpage=VARG(index);
489 }
491 RETURN_SELF();
493 END_METHOD
495 BEGIN_PROPERTY(PDFDOCUMENT_ready)
497 GB.ReturnBoolean( (bool)THIS->doc );
499 END_PROPERTY
501 BEGIN_PROPERTY(PDFDOCUMENT_count)
503 GB.ReturnInteger( (int32_t) (THIS->doc ? THIS->doc->getNumPages() : 0));
505 END_PROPERTY
507 BEGIN_PROPERTY(PDFDOCUMENT_info)
509 if (THIS->doc) RETURN_SELF();
510 else GB.ReturnNull();
512 END_PROPERTY
514 /*****************************************************************************
516 PDF document information
518 ******************************************************************************/
520 BEGIN_PROPERTY(PDFINFO_title)
522 aux_return_string_info(_object,"Title");
524 END_PROPERTY
526 BEGIN_PROPERTY(PDFINFO_format)
528 char ctx[16];
529 #if POPPLER_VERSION_0_11_3
530 snprintf(ctx, sizeof(ctx), "%.2g", THIS->doc->getPDFMajorVersion () + THIS->doc->getPDFMinorVersion() / 10.0);
531 #else
532 snprintf(ctx, sizeof(ctx), "%.2g", THIS->doc->getPDFVersion());
533 #endif
534 GB.ReturnNewZeroString(ctx);
536 END_PROPERTY
538 BEGIN_PROPERTY(PDFINFO_author)
540 aux_return_string_info(_object,"Author");
542 END_PROPERTY
544 BEGIN_PROPERTY(PDFINFO_subject)
546 aux_return_string_info(_object,"Subject");
548 END_PROPERTY
550 BEGIN_PROPERTY(PDFINFO_keywords)
552 aux_return_string_info(_object,"Keywords");
554 END_PROPERTY
556 BEGIN_PROPERTY(PDFINFO_creator)
558 aux_return_string_info(_object,"Creator");
560 END_PROPERTY
562 BEGIN_PROPERTY(PDFINFO_producer)
564 aux_return_string_info(_object,"Producer");
566 END_PROPERTY
568 BEGIN_PROPERTY(PDFINFO_linearized)
570 GB.ReturnBoolean(THIS->doc->isLinearized());
572 END_PROPERTY
574 BEGIN_PROPERTY(PDFINFO_layout)
576 Catalog *catalog;
578 catalog=THIS->doc->getCatalog();
579 if (!catalog) { GB.ReturnInteger(Catalog::pageLayoutNone); return; }
580 if (!catalog->isOk()) { GB.ReturnInteger(Catalog::pageLayoutNone); return; }
582 GB.ReturnInteger(catalog->getPageLayout());
584 END_PROPERTY
586 BEGIN_PROPERTY(PDFINFO_mode)
588 Catalog *catalog;
590 catalog=THIS->doc->getCatalog();
591 if (!catalog) { GB.ReturnInteger(Catalog::pageModeNone); return; }
592 if (!catalog->isOk()) { GB.ReturnInteger(Catalog::pageModeNone); return; }
594 GB.ReturnInteger(catalog->getPageMode());
597 END_PROPERTY
599 BEGIN_PROPERTY(PDFINFO_canprint)
601 GB.ReturnBoolean(THIS->doc->okToPrint());
603 END_PROPERTY
605 BEGIN_PROPERTY(PDFINFO_canmodify)
607 GB.ReturnBoolean(THIS->doc->okToChange());
609 END_PROPERTY
611 BEGIN_PROPERTY(PDFINFO_cancopy)
613 GB.ReturnBoolean(THIS->doc->okToCopy());
615 END_PROPERTY
617 BEGIN_PROPERTY(PDFINFO_canaddnotes)
619 GB.ReturnBoolean(THIS->doc->okToAddNotes());
621 END_PROPERTY
623 BEGIN_PROPERTY(PDFINFO_creation)
625 aux_return_date_info(_object,"CreationDate");
627 END_PROPERTY
629 BEGIN_PROPERTY(PDFINFO_modification)
631 aux_return_date_info(_object,"ModDate");
633 END_PROPERTY
636 /*****************************************************************************
638 PDF document index
640 ******************************************************************************/
643 BEGIN_PROPERTY(PDFDOCUMENT_has_index)
645 GB.ReturnBoolean(THIS->index && THIS->index->getLength());
647 END_PROPERTY
649 BEGIN_PROPERTY(PDFDOCUMENT_index)
651 if (!THIS->index) { GB.ReturnNull(); return; }
653 THIS->action=((OutlineItem*)THIS->index->get(THIS->currindex))->getAction();
654 RETURN_SELF();
656 END_PROPERTY
658 BEGIN_PROPERTY(PDFINDEX_count)
660 GB.ReturnInteger(THIS->index->getLength());
662 END_PROPERTY
664 BEGIN_PROPERTY(PDFINDEX_has_children)
666 OutlineItem *item;
668 item = (OutlineItem *)THIS->index->get (THIS->currindex);
669 GB.ReturnBoolean(item->getKids() && item->getKids()->getLength());
671 END_PROPERTY
673 BEGIN_PROPERTY(PDFINDEX_is_open)
675 OutlineItem *item;
677 item = (OutlineItem *)THIS->index->get (THIS->currindex);
679 if (READ_PROPERTY)
680 { GB.ReturnBoolean(item->isOpen()); return; }
682 if (VPROP(GB_INTEGER)) item->open();
683 else item->close();
685 END_PROPERTY
687 BEGIN_PROPERTY(PDFINDEX_title)
689 OutlineItem *item;
691 item = (OutlineItem *)THIS->index->get (THIS->currindex);
692 aux_return_unicode_string(item->getTitle(),item->getTitleLength());
694 END_PROPERTY
697 BEGIN_METHOD_VOID(PDFINDEX_root)
699 Outline *outline;
701 outline=THIS->doc->getOutline();
702 if (outline) THIS->index=outline->getItems();
703 THIS->currindex=0;
704 if (THIS->pindex) { GB.FreeArray(POINTER(&THIS->pindex)); THIS->pindex=NULL; }
705 if (THIS->oldindex) { GB.FreeArray(POINTER(&THIS->oldindex)); THIS->oldindex=NULL; }
707 END_METHOD
709 BEGIN_METHOD_VOID(PDFINDEX_prev)
711 if (!THIS->currindex) { GB.ReturnBoolean(true); return; }
713 THIS->currindex--;
714 GB.ReturnBoolean(false);
716 END_METHOD
718 BEGIN_METHOD_VOID(PDFINDEX_next)
720 if ( (THIS->currindex+1) >= (uint32_t)THIS->index->getLength() )
721 { GB.ReturnBoolean(true); return; }
723 THIS->currindex++;
724 GB.ReturnBoolean(false);
726 END_METHOD
728 BEGIN_METHOD_VOID(PDFINDEX_child)
730 OutlineItem *item;
732 item = (OutlineItem *)THIS->index->get (THIS->currindex);
734 if (!item->hasKids() || item->getKids()->getLength() == 0) { GB.ReturnBoolean(true); return; }
736 if (THIS->pindex)
737 {
738 GB.Add(POINTER(&THIS->pindex));
739 GB.Add(POINTER(&THIS->oldindex));
740 }
741 else
742 {
743 GB.NewArray(POINTER(&THIS->pindex),sizeof(void*),1);
744 GB.NewArray(POINTER(&THIS->oldindex),sizeof(uint32_t),1);
745 }
747 if (!item->isOpen()) item->open();
748 THIS->pindex[GB.Count(POINTER(THIS->pindex))-1]=(void*)THIS->index;
749 THIS->oldindex[GB.Count(POINTER(THIS->pindex))-1]=THIS->currindex;
750 THIS->index=item->getKids();
751 THIS->currindex=0;
753 GB.ReturnBoolean(false);
755 END_METHOD
757 BEGIN_METHOD_VOID(PDFINDEX_parent)
759 if (!THIS->pindex) { GB.ReturnBoolean(true); return; }
761 THIS->index=(GooList*)THIS->pindex[GB.Count(POINTER(THIS->pindex))-1];
762 THIS->currindex=THIS->oldindex[GB.Count(POINTER(THIS->pindex))-1];
763 if (GB.Count(POINTER(THIS->pindex))==1)
764 {
765 GB.FreeArray(POINTER(&THIS->pindex));
766 GB.FreeArray(POINTER(&THIS->oldindex));
767 THIS->oldindex=NULL;
768 THIS->pindex=NULL;
769 }
770 else
771 {
772 GB.Remove(POINTER(&THIS->pindex),GB.Count(POINTER(THIS->pindex))-1,1);
773 GB.Remove(POINTER(&THIS->oldindex),GB.Count(POINTER(THIS->oldindex))-1,1);
774 }
776 GB.ReturnBoolean(false);
778 END_METHOD
780 /*****************************************************************************
782 PDF pages
784 ******************************************************************************/
786 BEGIN_PROPERTY (PDFPAGE_width)
788 if ( (THIS->rotation==90) || (THIS->rotation==270) )
789 GB.ReturnInteger((int32_t)(THIS->page->getMediaHeight()*THIS->scale));
790 else
791 GB.ReturnInteger((int32_t)(THIS->page->getMediaWidth()*THIS->scale));
793 END_PROPERTY
795 BEGIN_PROPERTY (PDFPAGE_height)
797 if ( (THIS->rotation==90) || (THIS->rotation==270) )
798 GB.ReturnInteger((int32_t)(THIS->page->getMediaWidth()*THIS->scale));
799 else
800 GB.ReturnInteger((int32_t)(THIS->page->getMediaHeight()*THIS->scale));
802 END_PROPERTY
804 static uint32_t *get_page_data(CPDFDOCUMENT *_object, int32_t x, int32_t y, int32_t *width, int32_t *height, double scale, int32_t rotation)
805 {
806 SplashBitmap *map;
807 uint32_t *data;
808 int32_t w, h;
809 int32_t rw;
810 int32_t rh;
812 if ( (THIS->rotation==90) || (THIS->rotation==270) )
813 {
814 rh=(int32_t)(THIS->page->getMediaWidth()*THIS->scale);
815 rw=(int32_t)(THIS->page->getMediaHeight()*THIS->scale);
816 }
817 else
818 {
819 rw=(int32_t)(THIS->page->getMediaWidth()*THIS->scale);
820 rh=(int32_t)(THIS->page->getMediaHeight()*THIS->scale);
821 }
823 w = *width;
824 h = *height;
826 if (w < 0) w = rw;
827 if (h < 0) h = rh;
829 if (x<0) x=0;
830 if (y<0) y=0;
831 if (w<1) w=1;
832 if (h<1) h=1;
835 if ( (x+w) > rw ) w=rw-x;
836 if ( (y+h) > rh ) h=rh-y;
838 if ( (w<0) || (h<0) ) return NULL;
840 #if POPPLER_VERSION_0_20
841 THIS->page->displaySlice(THIS->dev,72.0*scale,72.0*scale,
842 rotation,
843 gFalse,
844 gTrue,
845 x,y,w,h,
846 gFalse);
847 #else
848 THIS->page->displaySlice(THIS->dev,72.0*scale,72.0*scale,
849 rotation,
850 gFalse,
851 gTrue,
852 x,y,w,h,
853 gFalse,
854 THIS->doc->getCatalog ());
855 #endif
857 map=THIS->dev->getBitmap();
859 data=(uint32_t*)map->getDataPtr();
862 *width = w;
863 *height = h;
865 return data;
866 }
868 BEGIN_METHOD(PDFPAGE_image, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h)
870 GB_IMAGE img = NULL;
871 uint32_t *data;
872 int32_t x,y, w, h;
874 x = VARGOPT(x, 0);
875 y = VARGOPT(y, 0);
876 w = VARGOPT(w, -1);
877 h = VARGOPT(h, -1);
879 data = get_page_data(THIS, x, y, &w, &h, THIS->scale, THIS->rotation);
880 if (!data) { GB.ReturnNull(); return; }
881 GB.Image.Create(&img, data, w, h, GB_IMAGE_RGB);
882 GB.ReturnObject(img);
884 END_METHOD
886 BEGIN_PROPERTY (PDFPAGE_property_image)
888 int32_t w=-1;
889 int32_t h=-1;
890 GB_IMAGE img = NULL;
891 uint32_t *data;
893 data = get_page_data(THIS, 0, 0, &w, &h, THIS->scale, THIS->rotation);
894 if (!data) { GB.ReturnNull(); return; }
895 GB.Image.Create(&img, data, w, h, GB_IMAGE_RGB);
896 GB.ReturnObject(img);
898 END_PROPERTY
901 BEGIN_METHOD(PDFPAGE_picture, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h)
903 GB_IMAGE img = NULL;
904 uint32_t *data;
905 int32_t x,y, w, h;
907 x = VARGOPT(x, 0);
908 y = VARGOPT(y, 0);
909 w = VARGOPT(w, -1);
910 h = VARGOPT(h, -1);
912 data = get_page_data(THIS, x, y, &w, &h, THIS->scale, THIS->rotation);
913 if (!data) { GB.ReturnNull(); return; }
914 GB.Picture.Create(&img, data, w, h, GB_IMAGE_RGB);
915 GB.ReturnObject(img);
917 END_METHOD
919 BEGIN_PROPERTY (PDFPAGE_property_picture)
921 int32_t w=-1;
922 int32_t h=-1;
923 GB_IMAGE img = NULL;
924 uint32_t *data;
926 data = get_page_data(THIS, 0, 0, &w, &h, THIS->scale, THIS->rotation);
927 if (!data) { GB.ReturnNull(); return; }
928 GB.Picture.Create(&img, data, w, h, GB_IMAGE_RGB);
929 GB.ReturnObject(img);
931 END_PROPERTY
933 BEGIN_METHOD(PDFPAGE_select, GB_INTEGER X; GB_INTEGER Y; GB_INTEGER W; GB_INTEGER H)
935 TextOutputDev *dev;
936 GooString *str;
937 Gfx *gfx;
938 int32_t x,y,w,h;
940 x = VARGOPT(X, 0);
941 y = VARGOPT(Y, 0);
942 w = VARGOPT(W, (int32_t)THIS->page->getMediaWidth());
943 h = VARGOPT(H, (int32_t)THIS->page->getMediaHeight());
945 #if POPPLER_VERSION_0_20
946 dev = new TextOutputDev (NULL, gTrue, 0, gFalse, gFalse);
947 gfx = THIS->page->createGfx(dev,72.0,72.0,0,gFalse,gTrue,-1, -1, -1, -1, gFalse, NULL, NULL);
948 #else
949 dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
950 gfx = THIS->page->createGfx(dev,72.0,72.0,0,gFalse,gTrue,-1, -1, -1, -1, \
951 gFalse,THIS->doc->getCatalog (),NULL, NULL, NULL, NULL);
952 #endif
954 THIS->page->display(gfx);
955 dev->endPage();
957 str=dev->getText((double)x,(double)y,(double)(w+x),(double)(h+y));
959 delete gfx;
960 delete dev;
962 if (!str)
963 {
964 GB.ReturnNewZeroString("");
965 return;
966 }
968 GB.ReturnNewString(str->getCString(),str->getLength());
969 delete str;
971 END_METHOD
973 /*****************************************************************************
975 Bookmarks of a PDF page
977 ******************************************************************************/
979 void aux_fill_links(void *_object)
980 {
981 #if POPPLER_VERSION_0_20
982 THIS->links = new Links (THIS->page->getAnnots ());
983 #elif POPPLER_VERSION_0_17
984 THIS->links = new Links (THIS->page->getAnnots (THIS->doc->getCatalog()));
985 #else
986 Object obj;
988 THIS->links = new Links (THIS->page->getAnnots (&obj),THIS->doc->getCatalog()->getBaseURI ());
989 obj.free();
990 #endif
991 }
993 BEGIN_PROPERTY (PDFPAGELINKS_count)
995 if (!THIS->links) aux_fill_links(_object);
996 if (!THIS->links) { GB.ReturnInteger(0); return; }
997 GB.ReturnInteger(THIS->links->getNumLinks());
1000 END_PROPERTY
1002 BEGIN_METHOD (PDFPAGELINKS_get,GB_INTEGER ind;)
1004 bool pok=true;
1006 if (!THIS->links) aux_fill_links(_object);
1007 if (!THIS->links) pok=false;
1008 else
1010 if (VARG(ind)<0) pok=false;
1011 else
1013 if (VARG(ind)>=THIS->links->getNumLinks()) pok=false;
1017 if (!pok) { GB.Error("Out of bounds"); GB.ReturnNull(); return; }
1019 THIS->lcurrent=VARG(ind);
1020 THIS->action=THIS->links->getLink(THIS->lcurrent)->getAction();
1022 RETURN_SELF();
1024 END_METHOD
1026 BEGIN_PROPERTY (PDFPAGELINKDATA_parameters)
1028 if (THIS->action->getKind() != actionLaunch )
1030 GB.ReturnNewZeroString("");
1031 return;
1034 GB.ReturnNewZeroString(((LinkLaunch*)THIS->action)->getParams()->getCString());
1036 END_PROPERTY
1038 BEGIN_PROPERTY (PDFPAGELINKDATA_uri)
1040 char *uri;
1042 uri=aux_get_target_from_action(THIS->action);
1044 GB.ReturnNewZeroString(uri);
1045 if (uri) GB.FreeString(&uri);
1047 END_PROPERTY
1049 BEGIN_PROPERTY(PDFPAGELINKDATA_left)
1051 int32_t vl;
1053 aux_get_dimensions_from_action(THIS->action,&vl, NULL, NULL, NULL);
1054 GB.ReturnInteger(vl);
1056 END_PROPERTY
1058 BEGIN_PROPERTY(PDFPAGELINKDATA_right)
1060 int32_t vl;
1062 aux_get_dimensions_from_action(THIS->action,NULL,&vl, NULL, NULL);
1063 GB.ReturnInteger(vl);
1065 END_PROPERTY
1067 BEGIN_PROPERTY(PDFPAGELINKDATA_top)
1069 int32_t vl;
1071 aux_get_dimensions_from_action(THIS->action,NULL,NULL,&vl, NULL);
1072 GB.ReturnInteger(vl);
1074 END_PROPERTY
1076 BEGIN_PROPERTY(PDFPAGELINKDATA_bottom)
1078 int32_t vl;
1080 aux_get_dimensions_from_action(THIS->action,NULL, NULL, NULL,&vl);
1082 GB.ReturnInteger(vl);
1084 END_PROPERTY
1086 BEGIN_PROPERTY(PDFPAGELINKDATA_zoom)
1088 GB.ReturnFloat(aux_get_zoom_from_action(THIS->action));
1090 END_PROPERTY
1092 BEGIN_PROPERTY(PDFPAGELINKDATA_page)
1094 GB.ReturnInteger(aux_get_page_from_action(_object,THIS->action));
1096 END_PROPERTY
1098 BEGIN_PROPERTY (PDFPAGELINKDATA_type)
1100 GB.ReturnInteger ( (int32_t)THIS->action->getKind() );
1102 END_PROPERTY
1104 BEGIN_PROPERTY(PDFPAGELINKDATA_check)
1106 if (THIS->action)
1107 RETURN_SELF();
1108 else
1109 GB.ReturnNull();
1111 END_PROPERTY
1113 void aux_get_link_dimensions(void *_object,int32_t *left, int32_t *top, int32_t *width, int32_t *height)
1115 double l,t,w,h;
1116 double pw,ph;
1118 pw=THIS->page->getMediaWidth();
1119 ph=THIS->page->getMediaHeight();
1121 THIS->links->getLink(THIS->lcurrent)->getRect(&l, &t, &w, &h);
1122 w=w-l;
1123 h=h-t;
1125 switch (THIS->rotation)
1127 case 0:
1128 if (left) *left=(int32_t)(l*THIS->scale);
1129 if (top) *top=(int32_t)((ph-t-h)*THIS->scale);
1130 if (width) *width=(int32_t)(w*THIS->scale);
1131 if (height) *height=(int32_t)(h*THIS->scale);
1132 break;
1134 case 90:
1135 if (top) *top=(int32_t)(l*THIS->scale);
1136 if (left) *left=(int32_t)(t*THIS->scale);
1137 if (height) *height=(int32_t)(w*THIS->scale);
1138 if (width) *width=(int32_t)(h*THIS->scale);
1139 break;
1141 case 180:
1142 if (left) *left=(int32_t)((l-w)*THIS->scale);
1143 if (top) *top=(int32_t)(t*THIS->scale);
1144 if (width) *width=(int32_t)(w*THIS->scale);
1145 if (height) *height=(int32_t)(h*THIS->scale);
1146 break;
1148 case 270:
1149 if (top) *top=(int32_t)((pw-l-w)*THIS->scale);
1150 if (left) *left=(int32_t)((ph-t-h)*THIS->scale);
1151 if (height) *height=(int32_t)(w*THIS->scale);
1152 if (width) *width=(int32_t)(h*THIS->scale);
1153 break;
1158 BEGIN_PROPERTY (PDFPAGELINK_width)
1160 int32_t vl;
1162 aux_get_link_dimensions(_object,NULL,NULL,&vl,NULL);
1163 GB.ReturnInteger(vl);
1165 END_PROPERTY
1167 BEGIN_PROPERTY (PDFPAGELINK_height)
1169 int32_t vl;
1171 aux_get_link_dimensions(_object,NULL,NULL,NULL,&vl);
1172 GB.ReturnInteger(vl);
1175 END_PROPERTY
1177 BEGIN_PROPERTY (PDFPAGELINK_left)
1179 int32_t vl;
1181 aux_get_link_dimensions(_object,&vl,NULL,NULL,NULL);
1182 GB.ReturnInteger(vl);
1185 END_PROPERTY
1187 BEGIN_PROPERTY (PDFPAGELINK_top)
1189 int32_t vl;
1191 aux_get_link_dimensions(_object,NULL,&vl,NULL,NULL);
1192 GB.ReturnInteger(vl);
1194 END_PROPERTY
1196 /*****************************************************************************
1198 Finding a text in a PDF page
1200 ******************************************************************************/
1202 BEGIN_METHOD (PDFPAGE_find,GB_STRING Text; GB_BOOLEAN Sensitive;)
1204 TextOutputDev *textdev;
1205 double x0=0, y0=0;
1206 double x1, y1;
1207 FoundRect *el;
1208 Unicode *block=NULL;
1209 int32_t nlen=0;
1210 bool sensitive=false;
1212 // TODO: Use UCS-4BE on big endian systems?
1213 if (GB.ConvString ((char **)(void *)&block,STRING(Text),LENGTH(Text),"UTF-8","UCS-4LE"))
1215 GB.Error("Invalid UTF-8 string");
1216 return;
1219 nlen=GB.StringLength((char*)block)/sizeof(Unicode);
1221 if (!MISSING(Sensitive)) sensitive=VARG(Sensitive);
1223 #if POPPLER_VERSION_0_20
1224 textdev = new TextOutputDev (NULL, true, 0, false, false);
1225 THIS->page->display (textdev, 72, 72, 0, false, false, false);
1226 #else
1227 textdev = new TextOutputDev (NULL, true, false, false);
1228 THIS->page->display (textdev, 72, 72, 0, false, false, false, THIS->doc->getCatalog());
1229 #endif
1231 if (THIS->Found) { GB.FreeArray(POINTER(&THIS->Found)); THIS->Found=NULL; }
1233 #if POPPLER_VERSION_0_20
1234 while (textdev->findText (block,nlen,gFalse,gTrue,gTrue,gFalse,sensitive,gFalse,gFalse,&x0,&y0,&x1,&y1))
1235 #else
1236 while (textdev->findText (block,nlen,gFalse,gTrue,gTrue,gFalse,sensitive,gFalse,&x0,&y0,&x1,&y1))
1237 #endif
1239 if (!THIS->Found) {
1240 GB.NewArray(POINTER(&THIS->Found),sizeof(FoundRect),1);
1242 else {
1243 GB.Add(POINTER(&THIS->Found));
1246 el=(FoundRect*)&((FoundRect*)THIS->Found)[GB.Count(POINTER(THIS->Found))-1];
1248 switch (THIS->rotation)
1250 case 0:
1251 el->x0=(int32_t)(x0*THIS->scale);
1252 el->y0=(int32_t)(y0*THIS->scale);
1253 el->x1=(int32_t)((x1-x0)*THIS->scale);
1254 el->y1=(int32_t)((y1-y0)*THIS->scale);
1255 break;
1257 case 90:
1258 el->y1=(int32_t)((x1-x0)*THIS->scale);
1259 el->x1=(int32_t)(y1-y0);
1260 el->y0=(int32_t)(x0*THIS->scale);
1261 el->x0=(int32_t)((THIS->page->getMediaHeight()-y0-el->x1)*THIS->scale);
1262 el->x1=(int32_t)(el->x1*THIS->scale);
1263 break;
1265 case 180:
1266 el->x1=(int32_t)(x1-x0);
1267 el->y1=(int32_t)(y1-y0);
1268 el->x0=(int32_t)((THIS->page->getMediaWidth()-x0-el->x1)*THIS->scale);
1269 el->y0=(int32_t)((THIS->page->getMediaHeight()-y0-el->y1)*THIS->scale);
1270 el->x1=(int32_t)(el->x1*THIS->scale);
1271 el->y1=(int32_t)(el->y1*THIS->scale);
1272 break;
1274 case 270:
1275 el->x1=(int32_t)((y1-y0)*THIS->scale);
1276 el->y1=(int32_t)(x1-x0);
1277 el->x0=(int32_t)(y0*THIS->scale);
1278 el->y0=(int32_t)((THIS->page->getMediaWidth()-x0-el->y1)*THIS->scale);
1279 el->y1=(int32_t)(el->y1*THIS->scale);
1280 break;
1285 delete textdev;
1288 END_METHOD
1291 BEGIN_METHOD (PDFPAGERESULT_get,GB_INTEGER Index;)
1293 bool bok=true;
1295 if (!THIS->Found) bok=false;
1296 else
1298 if (VARG(Index)<0) bok=false;
1299 if (VARG(Index)>= GB.Count(POINTER(THIS->Found)) ) bok=false;
1301 if (!bok) { GB.Error("Out of bounds"); GB.ReturnNull(); return; }
1303 THIS->fcurrent=VARG(Index);
1304 RETURN_SELF();
1306 END_METHOD
1308 BEGIN_PROPERTY (PDFPAGERESULT_count)
1310 if (!THIS->Found) { GB.ReturnInteger(0); return; }
1311 GB.ReturnInteger( GB.Count(POINTER(THIS->Found)) );
1313 END_PROPERTY
1315 BEGIN_PROPERTY (PDFPAGERESULT_width)
1317 FoundRect *el=(FoundRect*)&((FoundRect*)THIS->Found)[THIS->fcurrent];
1318 GB.ReturnInteger((int32_t)el->x1);
1320 END_PROPERTY
1322 BEGIN_PROPERTY (PDFPAGERESULT_height)
1324 FoundRect *el=(FoundRect*)&((FoundRect*)THIS->Found)[THIS->fcurrent];
1325 GB.ReturnInteger((int32_t)el->y1);
1327 END_PROPERTY
1329 BEGIN_PROPERTY (PDFPAGERESULT_left)
1331 FoundRect *el=(FoundRect*)&((FoundRect*)THIS->Found)[THIS->fcurrent];
1332 GB.ReturnInteger((int32_t)el->x0);
1334 END_PROPERTY
1336 BEGIN_PROPERTY (PDFPAGERESULT_top)
1338 FoundRect *el=(FoundRect*)&((FoundRect*)THIS->Found)[THIS->fcurrent];
1339 GB.ReturnInteger((int32_t)el->y0);
1341 END_PROPERTY
1343 /**********************************************************************
1345 Gambas Interface
1347 ***********************************************************************/
1350 GB_DESC PdfResultItemDesc[]=
1352 GB_DECLARE(".PdfResultItem",0), GB_VIRTUAL_CLASS(),
1354 GB_PROPERTY_READ("Left","i",PDFPAGERESULT_left),
1355 GB_PROPERTY_READ("Top","i",PDFPAGERESULT_top),
1356 GB_PROPERTY_READ("Width","i",PDFPAGERESULT_width),
1357 GB_PROPERTY_READ("Height","i",PDFPAGERESULT_height),
1359 GB_END_DECLARE
1360 };
1362 GB_DESC PdfResultDesc[]=
1364 GB_DECLARE(".PdfResult",0), GB_VIRTUAL_CLASS(),
1366 GB_METHOD("_get",".PdfResultItem",PDFPAGERESULT_get,"(Index)i"),
1367 GB_PROPERTY_READ("Count","i",PDFPAGERESULT_count),
1369 GB_END_DECLARE
1370 };
1373 GB_DESC PdfLinkDataDesc[]=
1375 GB_DECLARE(".PdfLinkData",0), GB_VIRTUAL_CLASS(),
1377 GB_PROPERTY_READ("Type","i",PDFPAGELINKDATA_type),
1378 GB_PROPERTY_READ("Target","s",PDFPAGELINKDATA_uri),
1379 GB_PROPERTY_READ("Parameters","s",PDFPAGELINKDATA_parameters),
1380 GB_PROPERTY_READ("Page","i",PDFPAGELINKDATA_page),
1381 GB_PROPERTY_READ("Left","i",PDFPAGELINKDATA_left),
1382 GB_PROPERTY_READ("Top","i",PDFPAGELINKDATA_top),
1383 GB_PROPERTY_READ("Right","i",PDFPAGELINKDATA_right),
1384 GB_PROPERTY_READ("Bottom","i",PDFPAGELINKDATA_bottom),
1385 GB_PROPERTY_READ("Zoom","f",PDFPAGELINKDATA_zoom),
1387 GB_END_DECLARE
1388 };
1390 GB_DESC PdfLinkDesc[]=
1392 GB_DECLARE(".PdfLink",0), GB_VIRTUAL_CLASS(),
1394 GB_PROPERTY_READ("Left","i",PDFPAGELINK_left),
1395 GB_PROPERTY_READ("Top","i",PDFPAGELINK_top),
1396 GB_PROPERTY_READ("Width","i",PDFPAGELINK_width),
1397 GB_PROPERTY_READ("Height","i",PDFPAGELINK_height),
1398 GB_PROPERTY_READ("Data", ".PdfLinkData", PDFPAGELINKDATA_check),
1400 GB_END_DECLARE
1401 };
1403 GB_DESC PdfIndexDesc[]=
1405 GB_DECLARE(".PdfIndex",0), GB_VIRTUAL_CLASS(),
1407 GB_PROPERTY("Expanded","b",PDFINDEX_is_open),
1408 GB_PROPERTY_READ("Count","i",PDFINDEX_count),
1409 GB_PROPERTY_READ("HasChildren","b",PDFINDEX_has_children),
1410 GB_PROPERTY_READ("Title","s",PDFINDEX_title),
1412 GB_PROPERTY_READ("Data", ".PdfLinkData", PDFPAGELINKDATA_check),
1413 GB_METHOD("MovePrevious","b",PDFINDEX_prev,0),
1414 GB_METHOD("MoveNext","b",PDFINDEX_next,0),
1415 GB_METHOD("MoveChild","b",PDFINDEX_child,0),
1416 GB_METHOD("MoveParent","b",PDFINDEX_parent,0),
1417 GB_METHOD("MoveRoot",0,PDFINDEX_root,0),
1419 GB_END_DECLARE
1420 };
1423 GB_DESC PdfPageDesc[]=
1425 GB_DECLARE(".PdfPage",0), GB_VIRTUAL_CLASS(),
1427 GB_PROPERTY_READ("W","f",PDFPAGE_width),
1428 GB_PROPERTY_READ("H","f",PDFPAGE_height),
1429 GB_PROPERTY_READ("Width","f",PDFPAGE_width),
1430 GB_PROPERTY_READ("Height","f",PDFPAGE_height),
1431 GB_PROPERTY_READ("Picture","Picture",PDFPAGE_property_picture),
1432 GB_PROPERTY_READ("Image","Image",PDFPAGE_property_image),
1433 GB_PROPERTY_SELF("Result",".PdfResult"),
1435 GB_METHOD("GetImage","Image",PDFPAGE_image,"[(X)i(Y)i(Width)i(Height)i]"),
1436 GB_METHOD("GetPicture","Picture",PDFPAGE_picture,"[(X)i(Y)i(Width)i(Height)i]"),
1437 GB_METHOD("Find","b",PDFPAGE_find,"(Text)s[(CaseSensitive)b]"),
1438 GB_METHOD("Select","s",PDFPAGE_select,"[(X)i(Y)i(W)i(H)i]"),
1440 GB_METHOD("_get",".PdfLink",PDFPAGELINKS_get,"(Index)i"),
1441 GB_PROPERTY_READ("Count","i",PDFPAGELINKS_count),
1443 GB_END_DECLARE
1444 };
1446 GB_DESC PdfDocumentInfo[] =
1448 GB_DECLARE(".PdfInfo",0), GB_VIRTUAL_CLASS(),
1450 GB_PROPERTY_READ("Title","s",PDFINFO_title),
1451 GB_PROPERTY_READ("Format","s",PDFINFO_format),
1452 GB_PROPERTY_READ("Author","s",PDFINFO_author),
1453 GB_PROPERTY_READ("Subject","s",PDFINFO_subject),
1454 GB_PROPERTY_READ("Keywords","s",PDFINFO_keywords),
1455 GB_PROPERTY_READ("Creator","s",PDFINFO_creator),
1456 GB_PROPERTY_READ("Producer","s",PDFINFO_producer),
1457 GB_PROPERTY_READ("CreationDate","d",PDFINFO_creation),
1458 GB_PROPERTY_READ("ModificationDate","d",PDFINFO_modification),
1459 GB_PROPERTY_READ("Linearized","b",PDFINFO_linearized),
1460 GB_PROPERTY_READ("Layout","i",PDFINFO_layout),
1461 GB_PROPERTY_READ("Mode","i",PDFINFO_mode),
1462 GB_PROPERTY_READ("CanCopy","b",PDFINFO_cancopy),
1463 GB_PROPERTY_READ("CanModify","b",PDFINFO_canmodify),
1464 GB_PROPERTY_READ("CanPrint","b",PDFINFO_canprint),
1465 GB_PROPERTY_READ("CanAddNotes","b",PDFINFO_canaddnotes),
1467 GB_END_DECLARE
1468 };
1470 GB_DESC PdfLayoutDesc[] =
1473 GB_DECLARE("PdfLayout", 0), GB_NOT_CREATABLE(),
1475 GB_CONSTANT("Unset","i",Catalog::pageLayoutNone),
1476 GB_CONSTANT("SinglePage","i",Catalog::pageLayoutSinglePage),
1477 GB_CONSTANT("OneColumn","i",Catalog::pageLayoutOneColumn),
1478 GB_CONSTANT("TwoColumnLeft","i",Catalog::pageLayoutTwoColumnLeft),
1479 GB_CONSTANT("TwoColumnRight","i",Catalog::pageLayoutTwoColumnRight),
1480 GB_CONSTANT("TwoPageLeft","i",Catalog::pageLayoutTwoPageLeft),
1481 GB_CONSTANT("TwoPageRight","i",Catalog::pageLayoutTwoPageRight),
1483 GB_END_DECLARE
1484 };
1487 GB_DESC PdfModeDesc[] =
1489 GB_DECLARE("PdfPageMode",0), GB_NOT_CREATABLE(),
1491 GB_CONSTANT("Unset","i",Catalog::pageModeNone),
1492 GB_CONSTANT("UseOutlines","i",Catalog::pageModeOutlines),
1493 GB_CONSTANT("UseThumbs","i",Catalog::pageModeThumbs),
1494 GB_CONSTANT("FullScreen","i",Catalog::pageModeFullScreen),
1495 GB_CONSTANT("UseOC","i",Catalog::pageModeOC),
1496 GB_CONSTANT("UseAttachments","i",Catalog::pageModeAttach),
1498 GB_END_DECLARE
1499 };
1501 GB_DESC PdfDocumentDesc[] =
1504 GB_DECLARE("PdfDocument", sizeof(CPDFDOCUMENT)),
1506 GB_CONSTANT("Unknown","i",actionUnknown), /* unknown action */
1507 GB_CONSTANT("Goto","i",actionGoTo), /* go to destination */
1508 GB_CONSTANT("GotoRemote","i",actionGoToR), /* go to destination in new file */
1509 GB_CONSTANT("Launch","i",actionLaunch), /* launch app or open doc. */
1510 GB_CONSTANT("Uri","i",actionURI), /* URI */
1511 GB_CONSTANT("Named","i",actionNamed), /* named action*/
1512 GB_CONSTANT("Movie","i",actionMovie), /* movie action */
1514 GB_CONSTANT("Normal","i",0),
1515 GB_CONSTANT("Sideways","i",90),
1516 GB_CONSTANT("Inverted","i",180),
1517 GB_CONSTANT("SidewaysInverted","i",270),
1519 GB_METHOD("_new", 0, PDFDOCUMENT_new, "[(File)s]"),
1520 GB_METHOD("_free", 0, PDFDOCUMENT_free, 0),
1522 GB_METHOD("Open",0,PDFDOCUMENT_open,"(File)s"),
1523 GB_METHOD("Close",0,PDFDOCUMENT_close,0),
1524 GB_METHOD("_get",".PdfPage",PDFDOCUMENT_get,"(Index)i"),
1526 GB_PROPERTY("Zoom", "f", PDFDOCUMENT_scale),
1527 GB_PROPERTY("Orientation", "i", PDFDOCUMENT_rotation),
1529 GB_PROPERTY_READ("Ready","b",PDFDOCUMENT_ready),
1530 GB_PROPERTY_READ("Count","i",PDFDOCUMENT_count),
1531 GB_PROPERTY_READ("HasIndex","b",PDFDOCUMENT_has_index),
1532 GB_PROPERTY_READ("Index",".PdfIndex",PDFDOCUMENT_index),
1533 GB_PROPERTY_READ("Info",".PdfInfo",PDFDOCUMENT_info),
1535 GB_END_DECLARE
1536 };