X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2Fpdf.cc;h=1d56679026bc19256d74e6d5db1334b1e207c342;hb=bac8d2e4da298000c30c6f63031542b3b8cee7c5;hp=10cc1906d18c3e599756b4188e6b5fff2b93f51f;hpb=bcd63646450a9548aede2025b9c67c0da6a1e05c;p=swftools.git diff --git a/lib/pdf/pdf.cc b/lib/pdf/pdf.cc index 10cc190..1d56679 100644 --- a/lib/pdf/pdf.cc +++ b/lib/pdf/pdf.cc @@ -1,25 +1,28 @@ #include "../gfxdevice.h" #include "../gfxsource.h" +#include "../devices/rescale.h" #include "../log.h" #include "config.h" #include "GlobalParams.h" #include "InfoOutputDev.h" #include "GFXOutputDev.h" +#include "FullBitmapOutputDev.h" #include "BitmapOutputDev.h" #include "../mem.h" #include "pdf.h" #define NO_ARGPARSER #include "../args.h" +static double zoom = 72; /* xpdf: 86 */ +static int jpeg_dpi = 0; +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; -int jpeg_dpi = 0; -int ppm_dpi = 0; - -static double zoom = 72; /* xpdf: 86 */ - -static char* global_page_range = 0; +static int globalparams_count=0; typedef struct _pdf_page_info { @@ -34,11 +37,14 @@ typedef struct _pdf_page_info typedef struct _pdf_doc_internal { int protect; + int nocopy; PDFDoc*doc; Object docinfo; InfoOutputDev*info; CommonOutputDev*outputDev; pdf_page_info_t*pages; + gfxdevice_t* middev; + char*filename; } pdf_doc_internal_t; typedef struct _pdf_page_internal @@ -71,7 +77,13 @@ void pdfpage_destroy(gfxpage_t*pdf_page) void render2(gfxpage_t*page, gfxdevice_t*dev) { pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal; - + + if(pi->middev) { + gfxdevice_rescale_setdevice(pi->middev, dev); + pi->middev->setparameter(pi->middev, "protect", "1"); + dev = pi->middev; + } + if(!pi) { msg(" pdf_page_render: Parent PDF this page belongs to doesn't exist yet/anymore"); return; @@ -83,6 +95,7 @@ void render2(gfxpage_t*page, gfxdevice_t*dev) } pi->outputDev->setDevice(dev); + if(pi->protect) { dev->setparameter(dev, "protect", "1"); } @@ -93,9 +106,12 @@ void render2(gfxpage_t*page, gfxdevice_t*dev) dev->setparameter(dev, p->name, p->value); p = p->next; } - pi->doc->displayPage((OutputDev*)pi->outputDev, page->nr, zoom, zoom, /*rotate*/0, true, true, /*doLinks*/(int)1); + 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->setDevice(0); + if(pi->middev) { + gfxdevice_rescale_setdevice(pi->middev, 0x00000000); + } } @@ -114,13 +130,11 @@ void pdfpage_rendersection(gfxpage_t*page, gfxdevice_t*output, gfxcoord_t x, gfx int x1=(int)_x1,y1=(int)_y1,x2=(int)_x2,y2=(int)_y2; if((x1|y1|x2|y2)==0) x2++; - pi->outputDev->setMove((int)x,(int)y); - pi->outputDev->setClip((int)x1,(int)y1,(int)x2,(int)y2); + pi->outputDev->setMove((int)x*multiply,(int)y*multiply); + pi->outputDev->setClip((int)x1*multiply,(int)y1*multiply,(int)x2*multiply,(int)y2*multiply); 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; @@ -128,10 +142,18 @@ void pdf_doc_destroy(gfxdocument_t*gfx) if(i->outputDev) { delete i->outputDev;i->outputDev=0; } + if(i->middev) { + gfxdevice_rescale_setdevice(i->middev, 0x00000000); + i->middev->finish(i->middev); + } delete i->doc; i->doc=0; 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; @@ -172,6 +194,10 @@ 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)); @@ -268,10 +294,21 @@ char* pdf_doc_getinfo(gfxdocument_t*doc, const char*name) static void storeDeviceParameter(const char*name, const char*value) { + parameter_t*o = device_config; + while(o) { + if(!strcmp(name, o->name)) { + /* overwrite old value */ + free(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; @@ -284,6 +321,7 @@ static void storeDeviceParameter(const char*name, const char*value) 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) @@ -316,16 +354,19 @@ static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value sprintf(buf, "%f", (double)ppm_dpi/(double)zoom); storeDeviceParameter("ppmsubpixels", buf); } else if(!strcmp(name, "poly2bitmap")) { - i->config_bitmap_optimizing = 1; + 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("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"); - } else { - storeDeviceParameter(name,value); - } + } + storeDeviceParameter(name,value); } static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) @@ -338,7 +379,7 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) pdf_doc->internal = i; char*userPassword=0; - filename = strdup(filename); + i->filename = strdup(filename); char*x = 0; if((x = strchr(filename, '|'))) { @@ -371,8 +412,7 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) i->protect = 0; if (i->doc->isEncrypted()) { if(!i->doc->okToCopy()) { - printf("PDF disallows copying.\n"); - return 0; + i->nocopy = 1; } if(!i->doc->okToChange() || !i->doc->okToAddNotes()) i->protect = 1; @@ -399,7 +439,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 { @@ -414,6 +457,12 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) p = p->next; } + i->middev = 0; + if(multiply>1) { + i->middev = (gfxdevice_t*)malloc(sizeof(gfxdevice_t)); + gfxdevice_rescale_init(i->middev, 0x00000000, 0, 0, 1.0 / multiply); + } + pdf_doc->get = 0; pdf_doc->destroy = pdf_doc_destroy; pdf_doc->set_parameter = pdf_doc_set_parameter; @@ -424,6 +473,23 @@ 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; + free(src->internal);src->internal=0; + + parameter_t*p = device_config; + while(p) { + parameter_t*next = p->next; + p->next = 0;delete p; + p = next; + } + delete globalParams;globalParams = 0; + free(src); +} gfxsource_t*gfxsource_pdf_create() { @@ -431,6 +497,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));