X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2Fpdf.cc;h=f06949ea5ea6794352495aba59ffad126f1b7f60;hb=072be5204983fd801b1d573f5a8efc6e0ae2bc5a;hp=13957de510f53329a1b152dd42d67997376a0e38;hpb=6c58c6033086c7ca4628e00eb0f6f010573ad6b7;p=swftools.git diff --git a/lib/pdf/pdf.cc b/lib/pdf/pdf.cc index 13957de..f06949e 100644 --- a/lib/pdf/pdf.cc +++ b/lib/pdf/pdf.cc @@ -89,7 +89,7 @@ void render2(gfxpage_t*page, gfxdevice_t*output) pi->outputDev->setXRef(pi->doc, pi->doc->getXRef()); pi->doc->displayPage((OutputDev*)pi->outputDev, page->nr, zoom, zoom, /*rotate*/0, true, true, /*doLinks*/(int)1); pi->doc->processLinks((OutputDev*)pi->outputDev, page->nr); - pi->doc->endframe(); + pi->outputDev->endframe(); } @@ -115,6 +115,8 @@ void pdfpage_rendersection(gfxpage_t*page, gfxdevice_t*output, gfxcoord_t x, gfx pi->outputDev->setDevice(0); } +static int globalparams_count=0; + void pdf_doc_destroy(gfxdocument_t*gfx) { pdf_doc_internal_t*i= (pdf_doc_internal_t*)gfx->internal; @@ -135,18 +137,25 @@ void pdf_doc_destroy(gfxdocument_t*gfx) free(global_page_range); global_page_range = 0; } + + globalparams_count--; + if(!globalparams_count) { + delete globalParams; + globalParams = 0; + globalparams_count = 0; + } } -void pdf_doc_set_parameter(gfxdocument_t*gfx, char*name, char*value) +void pdf_doc_set_parameter(gfxdocument_t*gfx, const char*name, const char*value) { pdf_doc_internal_t*i= (pdf_doc_internal_t*)gfx->internal; + GFXOutputDev*o = i->outputDev; if(!strcmp(name, "pagemap")) { - GFXOutputDev*o = i->outputDev; int pdfpage=0, outputpage=0; sscanf(value,"%d:%d", &pdfpage, &outputpage); o->preparePage(pdfpage, outputpage); } else { - msg(" Ignored parameter: %s=%s", name, value); + o->setParameter(name, value); } } @@ -179,7 +188,7 @@ static char*getInfoString(Dict *infoDict, char *key) GString *s1, *s2; int i; - if (infoDict->lookup(key, &obj)->isString()) { + if (infoDict && infoDict->lookup(key, &obj)->isString()) { s1 = obj.getString(); if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getChar(1) & 0xff) == 0xff) { @@ -211,7 +220,7 @@ static char*getInfoDate(Dict *infoDict, char *key) Object obj; char *s; - if (infoDict->lookup(key, &obj)->isString()) { + if (infoDict && infoDict->lookup(key, &obj)->isString()) { s = obj.getString()->getCString(); if (s[0] == 'D' && s[1] == ':') { s += 2; @@ -223,7 +232,7 @@ static char*getInfoDate(Dict *infoDict, char *key) return strdup(""); } -char* pdf_doc_getinfo(gfxdocument_t*doc, char*name) +char* pdf_doc_getinfo(gfxdocument_t*doc, const char*name) { pdf_doc_internal_t*i= (pdf_doc_internal_t*)doc->internal; if(!strcmp(name, "title")) return getInfoString(i->docinfo.getDict(), "Title"); @@ -235,16 +244,22 @@ char* pdf_doc_getinfo(gfxdocument_t*doc, char*name) else if(!strcmp(name, "creationdate")) return getInfoDate(i->docinfo.getDict(), "CreationDate"); else if(!strcmp(name, "moddate")) return getInfoDate(i->docinfo.getDict(), "ModDate"); else if(!strcmp(name, "linearized")) return strdup(i->doc->isLinearized() ? "yes" : "no"); + else if(!strcmp(name, "tagged")) return strdup(i->doc->getStructTreeRoot()->isDict() ? "yes" : "no"); else if(!strcmp(name, "encrypted")) return strdup(i->doc->isEncrypted() ? "yes" : "no"); else if(!strcmp(name, "oktoprint")) return strdup(i->doc->okToPrint() ? "yes" : "no"); else if(!strcmp(name, "oktocopy")) return strdup(i->doc->okToCopy() ? "yes" : "no"); else if(!strcmp(name, "oktochange")) return strdup(i->doc->okToChange() ? "yes" : "no"); else if(!strcmp(name, "oktoaddnotes")) return strdup(i->doc->okToAddNotes() ? "yes" : "no"); + else if(!strcmp(name, "version")) { + char buf[32]; + sprintf(buf, "%.1f", i->doc->getPDFVersion()); + return strdup(buf); + } return 0; } -void storeDeviceParameter(char*name, char*value) +static void storeDeviceParameter(const char*name, const char*value) { parameter_t*p = new parameter_t(); p->name = strdup(name); @@ -259,7 +274,7 @@ void storeDeviceParameter(char*name, char*value) } } -void pdf_set_parameter(char*name, char*value) +static void pdf_set_parameter(const char*name, const char*value) { msg(" setting parameter %s to \"%s\"", name, value); if(!strncmp(name, "fontdir", strlen("fontdir"))) { @@ -292,8 +307,13 @@ void pdf_set_parameter(char*name, char*value) } } -gfxdocument_t*pdf_open(char*filename) +static gfxdocument_t*pdf_open(const char*filename) { + if(!globalParams) { + globalParams = new GFXGlobalParams(); + globalparams_count++; + } + gfxdocument_t*pdf_doc = (gfxdocument_t*)malloc(sizeof(gfxdocument_t)); memset(pdf_doc, 0, sizeof(gfxdocument_t)); pdf_doc_internal_t*i= (pdf_doc_internal_t*)malloc(sizeof(pdf_doc_internal_t)); @@ -312,10 +332,6 @@ gfxdocument_t*pdf_open(char*filename) GString *fileName = new GString(filename); GString *userPW; - // read config file - if(!globalParams) - globalParams = new GlobalParams(""); - // open PDF file if (userPassword && userPassword[0]) { userPW = new GString(userPassword); @@ -345,7 +361,7 @@ gfxdocument_t*pdf_open(char*filename) i->protect = 1; } - InfoOutputDev*io = new InfoOutputDev(); + InfoOutputDev*io = new InfoOutputDev(i->doc->getXRef()); int t; i->pages = (pdf_page_info_t*)malloc(sizeof(pdf_page_info_t)*pdf_doc->num_pages); memset(i->pages,0,sizeof(pdf_page_info_t)*pdf_doc->num_pages);