X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2Fpdf.cc;h=3f74b60b03f6f7a65057faf15111e52ed896348e;hb=6b98a8dc81b47257d03a91dbd0efa3789aa0abfd;hp=9390e4a28b214ad8119632f734c8b4749d705047;hpb=d0f9d82a8652cedc913671a2caf8d7a367beadb1;p=swftools.git diff --git a/lib/pdf/pdf.cc b/lib/pdf/pdf.cc index 9390e4a..3f74b60 100644 --- a/lib/pdf/pdf.cc +++ b/lib/pdf/pdf.cc @@ -6,6 +6,7 @@ #include "GlobalParams.h" #include "InfoOutputDev.h" #include "GFXOutputDev.h" +#include "FullBitmapOutputDev.h" #include "BitmapOutputDev.h" #include "../mem.h" #include "pdf.h" @@ -18,8 +19,7 @@ static int ppm_dpi = 0; static int multiply = 1; static char* global_page_range = 0; -static parameter_t* device_config = 0; -static parameter_t* device_config_next = 0; +static int globalparams_count=0; typedef struct _pdf_page_info { @@ -41,6 +41,8 @@ typedef struct _pdf_doc_internal CommonOutputDev*outputDev; pdf_page_info_t*pages; gfxdevice_t* middev; + char*filename; + gfxsource_t*parent; } pdf_doc_internal_t; typedef struct _pdf_page_internal @@ -52,8 +54,25 @@ typedef struct _dev_output_internal CommonOutputDev*outputDev; } dev_output_internal_t; +typedef struct _parameter +{ + struct _parameter *next; + const char*name; + const char*value; +} parameter_t; + +typedef struct _gfxsource_internal +{ + int config_bitmap_optimizing; + int config_full_bitmap_optimizing; + + parameter_t* device_config; + parameter_t* device_config_next; + +} gfxsource_internal_t; + -static char* dirseparator() +static const char* dirseparator() { #ifdef WIN32 return "\\"; @@ -97,13 +116,15 @@ void render2(gfxpage_t*page, gfxdevice_t*dev) } /* pass global parameters to output device */ - parameter_t*p = device_config; + parameter_t*p = ((gfxsource_internal_t*)pi->parent->internal)->device_config; while(p) { dev->setparameter(dev, p->name, p->value); p = p->next; } pi->doc->displayPage((OutputDev*)pi->outputDev, page->nr, zoom*multiply, zoom*multiply, /*rotate*/0, true, true, /*doLinks*/(int)1); pi->doc->processLinks((OutputDev*)pi->outputDev, page->nr); + pi->outputDev->finishPage(); + pi->outputDev->setDevice(0); if(pi->middev) { gfxdevice_rescale_setdevice(pi->middev, 0x00000000); @@ -131,8 +152,6 @@ void pdfpage_rendersection(gfxpage_t*page, gfxdevice_t*output, gfxcoord_t x, gfx render2(page, output); } -static int globalparams_count=0; - void pdf_doc_destroy(gfxdocument_t*gfx) { pdf_doc_internal_t*i= (pdf_doc_internal_t*)gfx->internal; @@ -148,6 +167,10 @@ void pdf_doc_destroy(gfxdocument_t*gfx) free(i->pages); i->pages = 0; i->docinfo.free(); + + if(i->filename) { + free(i->filename);i->filename=0; + } if(i->info) { delete i->info;i->info=0; @@ -188,10 +211,6 @@ gfxpage_t* pdf_doc_getpage(gfxdocument_t*doc, int page) if(page < 1 || page > doc->num_pages) return 0; - if(di->nocopy) { - msg(" PDF disallows copying."); - return 0; - } gfxpage_t* pdf_page = (gfxpage_t*)malloc(sizeof(gfxpage_t)); pdf_page_internal_t*pi= (pdf_page_internal_t*)malloc(sizeof(pdf_page_internal_t)); @@ -209,13 +228,13 @@ gfxpage_t* pdf_doc_getpage(gfxdocument_t*doc, int page) return pdf_page; } -static char*getInfoString(Dict *infoDict, char *key) +static char*getInfoString(Dict *infoDict, const char *key) { Object obj; GString *s1, *s2; int i; - if (infoDict && infoDict->lookup(key, &obj)->isString()) { + if (infoDict && infoDict->lookup((char*)key, &obj)->isString()) { s1 = obj.getString(); if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getChar(1) & 0xff) == 0xff) { @@ -242,12 +261,12 @@ static char*getInfoString(Dict *infoDict, char *key) return strdup(""); } -static char*getInfoDate(Dict *infoDict, char *key) +static char*getInfoDate(Dict *infoDict, const char *key) { Object obj; char *s; - if (infoDict && infoDict->lookup(key, &obj)->isString()) { + if (infoDict && infoDict->lookup((char*)key, &obj)->isString()) { s = obj.getString()->getCString(); if (s[0] == 'D' && s[1] == ':') { s += 2; @@ -286,26 +305,32 @@ char* pdf_doc_getinfo(gfxdocument_t*doc, const char*name) } -static void storeDeviceParameter(const char*name, const char*value) +static void storeDeviceParameter(gfxsource_internal_t*i, const char*name, const char*value) { + parameter_t*o = i->device_config; + while(o) { + if(!strcmp(name, o->name)) { + /* overwrite old value */ + free((void*)o->value); + o->value = strdup(value); + return; + } + o = o->next; + } parameter_t*p = new parameter_t(); p->name = strdup(name); p->value = strdup(value); p->next = 0; - if(device_config_next) { - device_config_next->next = p; - device_config_next = p; + + if(i->device_config_next) { + i->device_config_next->next = p; + i->device_config_next = p; } else { - device_config = p; - device_config_next = p; + i->device_config = p; + i->device_config_next = p; } } -typedef struct _gfxsource_internal -{ - int config_bitmap_optimizing; -} gfxsource_internal_t; - static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value) { gfxsource_internal_t*i = (gfxsource_internal_t*)src->internal; @@ -314,7 +339,7 @@ static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value addGlobalFontDir(value); } else if(!strcmp(name, "pages")) { global_page_range = strdup(value); - } else if(!strncmp(name, "font", strlen("font"))) { + } else if(!strncmp(name, "font", strlen("font")) && name[4]!='q') { addGlobalFont(value); } else if(!strncmp(name, "languagedir", strlen("languagedir"))) { addGlobalLanguageDir(value); @@ -322,31 +347,36 @@ static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value char buf[80]; zoom = atof(value); sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom); - storeDeviceParameter("jpegsubpixels", buf); + storeDeviceParameter(i, "jpegsubpixels", buf); sprintf(buf, "%f", (double)ppm_dpi/(double)zoom); - storeDeviceParameter("ppmsubpixels", buf); + storeDeviceParameter(i, "ppmsubpixels", buf); } else if(!strcmp(name, "jpegdpi")) { char buf[80]; jpeg_dpi = atoi(value); sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom); - storeDeviceParameter("jpegsubpixels", buf); + storeDeviceParameter(i, "jpegsubpixels", buf); } else if(!strcmp(name, "ppmdpi")) { char buf[80]; ppm_dpi = atoi(value); sprintf(buf, "%f", (double)ppm_dpi/(double)zoom); - storeDeviceParameter("ppmsubpixels", buf); + storeDeviceParameter(i, "ppmsubpixels", buf); } else if(!strcmp(name, "poly2bitmap")) { i->config_bitmap_optimizing = atoi(value); + } else if(!strcmp(name, "bitmapfonts") || !strcmp(name, "bitmap")) { + i->config_full_bitmap_optimizing = atoi(value); } else if(!strcmp(name, "multiply")) { multiply = atoi(value); } else if(!strcmp(name, "help")) { printf("\nPDF device global parameters:\n"); - printf("fontdir= a directory with additional fonts\n"); - printf("font= an dditional font filename\n"); - printf("pages= the range of pages to convert (example: pages=1-100,210-)\n"); - printf("zoom= the resultion (default: 72)\n"); + printf("fontdir= a directory with additional fonts\n"); + printf("font= an additional font filename\n"); + printf("pages= the range of pages to convert (example: pages=1-100,210-)\n"); + printf("zoom= the resultion (default: 72)\n"); + printf("languagedir= Add an xpdf language directory\n"); + printf("multiply= Render everything at the resolution\n"); + printf("poly2bitmap Convert graphics to bitmaps\n"); + printf("bitmap Convert everything to bitmaps\n"); } - storeDeviceParameter(name,value); } static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) @@ -356,10 +386,11 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) memset(pdf_doc, 0, sizeof(gfxdocument_t)); pdf_doc_internal_t*i= (pdf_doc_internal_t*)malloc(sizeof(pdf_doc_internal_t)); memset(i, 0, sizeof(pdf_doc_internal_t)); + i->parent = src; pdf_doc->internal = i; char*userPassword=0; - filename = strdup(filename); + i->filename = strdup(filename); char*x = 0; if((x = strchr(filename, '|'))) { @@ -419,7 +450,10 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) } } - if(isrc->config_bitmap_optimizing) { + if(isrc->config_full_bitmap_optimizing) { + FullBitmapOutputDev*outputDev = new FullBitmapOutputDev(i->info, i->doc); + i->outputDev = (CommonOutputDev*)outputDev; + } else if(isrc->config_bitmap_optimizing) { BitmapOutputDev*outputDev = new BitmapOutputDev(i->info, i->doc); i->outputDev = (CommonOutputDev*)outputDev; } else { @@ -428,7 +462,7 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) } /* pass global parameters to PDF driver*/ - parameter_t*p = device_config; + parameter_t*p = isrc->device_config; while(p) { i->outputDev->setParameter(p->name, p->value); p = p->next; @@ -450,6 +484,28 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) return pdf_doc; } + +void pdf_destroy(gfxsource_t*src) +{ + if(!src->internal) + return; + gfxsource_internal_t*i = (gfxsource_internal_t*)src->internal; + + parameter_t*p = i->device_config; + while(p) { + parameter_t*next = p->next; + if(p->name) free((void*)p->name);p->name = 0; + if(p->value) free((void*)p->value);p->value =0; + p->next = 0;delete p; + p = next; + } + i->device_config=i->device_config_next=0; + + free(src->internal);src->internal=0; + + delete globalParams;globalParams = 0; + free(src); +} gfxsource_t*gfxsource_pdf_create() { @@ -457,6 +513,7 @@ gfxsource_t*gfxsource_pdf_create() memset(src, 0, sizeof(gfxsource_t)); src->set_parameter = pdf_set_parameter; src->open = pdf_open; + src->destroy = pdf_destroy; src->internal = malloc(sizeof(gfxsource_internal_t)); memset(src->internal, 0, sizeof(gfxsource_internal_t));