X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2Fpdf.cc;h=368416e1a9ab11764e248b182b8d317909b2eaff;hb=b0d6b177b15ec7aff4c132353366b946aa382a89;hp=f7fb640e729bd589d87f6df081f4f80879205f1f;hpb=21a3f7b017e8bc721f55c9f3365005b57b19816a;p=swftools.git diff --git a/lib/pdf/pdf.cc b/lib/pdf/pdf.cc index f7fb640..368416e 100644 --- a/lib/pdf/pdf.cc +++ b/lib/pdf/pdf.cc @@ -8,7 +8,6 @@ #include "GFXOutputDev.h" #include "FullBitmapOutputDev.h" #include "BitmapOutputDev.h" -#include "DummyOutputDev.h" #include "../mem.h" #include "pdf.h" #define NO_ARGPARSER @@ -20,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 { @@ -44,6 +42,7 @@ typedef struct _pdf_doc_internal pdf_page_info_t*pages; gfxdevice_t* middev; char*filename; + gfxsource_t*parent; } pdf_doc_internal_t; typedef struct _pdf_page_internal @@ -55,6 +54,23 @@ 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() { @@ -100,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); @@ -134,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; @@ -195,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)); @@ -293,13 +305,13 @@ 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 = device_config; + parameter_t*o = i->device_config; while(o) { if(!strcmp(name, o->name)) { /* overwrite old value */ - free(o->value); + free((void*)o->value); o->value = strdup(value); return; } @@ -310,21 +322,15 @@ static void storeDeviceParameter(const char*name, const char*value) 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; - int config_full_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; @@ -333,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); @@ -341,19 +347,19 @@ 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")) { @@ -362,12 +368,15 @@ static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value 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) @@ -377,6 +386,7 @@ 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; @@ -452,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; @@ -480,7 +490,21 @@ 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()