+ i->info = io;
+
+ return pdf_doc;
+}
+
+class MemCheck
+{
+ public: ~MemCheck()
+ {
+ delete globalParams;globalParams=0;
+ Object::memCheck(stderr);
+ gMemReport(stderr);
+ }
+} myMemCheck;
+
+void pdf_destroy(pdf_doc_t*pdf_doc)
+{
+ pdf_doc_internal_t*i= (pdf_doc_internal_t*)pdf_doc->internal;
+
+ delete i->doc; i->doc=0;
+
+ if(i->info) {
+ delete i->info;i->info=0;
+ }
+
+ free(pdf_doc->internal);pdf_doc->internal=0;
+ free(pdf_doc);pdf_doc=0;
+}
+
+pdf_page_t* pdf_getpage(pdf_doc_t*pdf_doc, int page)
+{
+ pdf_doc_internal_t*di= (pdf_doc_internal_t*)pdf_doc->internal;
+
+ if(page < 1 || page > pdf_doc->num_pages)
+ return 0;
+
+ pdf_page_t* pdf_page = (pdf_page_t*)malloc(sizeof(pdf_page_t));
+ pdf_page_internal_t*pi= (pdf_page_internal_t*)malloc(sizeof(pdf_page_internal_t));
+ memset(pi, 0, sizeof(pdf_page_internal_t));
+ pdf_page->internal = pi;
+
+ pdf_page->parent = pdf_doc;
+ pdf_page->nr = page;
+ return pdf_page;
+}
+
+void pdf_page_destroy(pdf_page_t*pdf_page)
+{
+ pdf_page_internal_t*i= (pdf_page_internal_t*)pdf_page->internal;
+ free(pdf_page->internal);pdf_page->internal = 0;
+ free(pdf_page);pdf_page=0;
+}
+
+swf_output_t* swf_output_init()
+{
+ swf_output_t*swf_output = (swf_output_t*)malloc(sizeof(swf_output_t));
+ memset(swf_output, 0, sizeof(swf_output_t));
+ swf_output_internal_t*i= (swf_output_internal_t*)malloc(sizeof(swf_output_internal_t));
+ memset(i, 0, sizeof(swf_output_internal_t));
+ swf_output->internal = i;
+
+ i->outputDev = new SWFOutputDev();
+ return swf_output;
+}
+
+void swf_output_setparameter(swf_output_t*swf, char*name, char*value)
+{
+ pdfswf_setparameter(name, value);
+}
+
+void swf_output_startframe(swf_output_t*swf, int width, int height)
+{
+ swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
+ i->outputDev->startFrame(width, height);
+}
+
+void swf_output_endframe(swf_output_t*swf)
+{
+ swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
+ i->outputDev->endframe();
+}
+
+void swf_output_preparepage(swf_output_t*swf, int pdfpage, int outputpage)
+{
+ swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
+ SWFOutputDev*o = i->outputDev;
+
+ if(pdfpage < 0)
+ return;
+
+ if(!o->pages) {
+ o->pagebuflen = 1024;
+ o->pages = (int*)malloc(o->pagebuflen*sizeof(int));
+ memset(o->pages, -1, o->pagebuflen*sizeof(int));
+ } else {
+ while(pdfpage >= o->pagebuflen)
+ {
+ int oldlen = o->pagebuflen;
+ o->pagebuflen+=1024;
+ o->pages = (int*)realloc(o->pages, o->pagebuflen*sizeof(int));
+ memset(&o->pages[oldlen], -1, (o->pagebuflen-oldlen)*sizeof(int));
+ }
+ }
+ o->pages[pdfpage] = outputpage;
+ if(pdfpage>o->pagepos)
+ o->pagepos = pdfpage;
+}
+
+int swf_output_save(swf_output_t*swf, char*filename)
+{
+ swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
+ int ret = i->outputDev->save(filename);
+ return ret;
+}
+
+void* swf_output_get(swf_output_t*swf,char*name)
+{
+ swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
+ void* ret = i->outputDev->get(name);
+ return ret;
+}
+
+void swf_output_destroy(swf_output_t*output)
+{
+ swf_output_internal_t*i = (swf_output_internal_t*)output->internal;
+ delete i->outputDev; i->outputDev=0;
+ free(output->internal);output->internal=0;
+ free(output);
+}
+
+void pdf_page_render2(pdf_page_t*page, swf_output_t*swf)
+{
+ pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
+ swf_output_internal_t*si = (swf_output_internal_t*)swf->internal;
+
+ if(!pi) {
+ msg("<fatal> pdf_page_render: Parent PDF this page belongs to doesn't exist yet/anymore");
+ return;
+ }
+
+ if(pi->protect) {
+ gfxdevice_t*dev = si->outputDev->output;
+ dev->setparameter(dev, "protect", "1");
+ }
+ si->outputDev->setInfo(pi->info);
+ si->outputDev->setXRef(pi->doc, pi->doc->getXRef());
+#ifdef XPDF_101
+ pi->doc->displayPage((OutputDev*)si->outputDev, page->nr, /*zoom*/zoom, /*rotate*/0, /*doLinks*/(int)1);
+#else
+ pi->doc->displayPage((OutputDev*)si->outputDev, page->nr, zoom, zoom, /*rotate*/0, true, /*doLinks*/(int)1);
+#endif
+}
+
+void pdf_page_rendersection(pdf_page_t*page, swf_output_t*output, int x, int y, int x1, int y1, int x2, int y2)
+{
+ pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
+ swf_output_internal_t*si = (swf_output_internal_t*)output->internal;
+
+ si->outputDev->setMove(x,y);
+ if((x1|y1|x2|y2)==0) x2++;
+ si->outputDev->setClip(x1,y1,x2,y2);
+
+ pdf_page_render2(page, output);