X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2Fpdf.cc;h=885ebbf5814db97adea72404a72212915e98d755;hb=6a529bfa890997a55fec9ae0e0d388cf9d5276c2;hp=ea7b3f6576fc8ddd89999d54c2774be1b855425e;hpb=b2b8805d2034f3beb7d26dbf0b49c2b110580ef0;p=swftools.git diff --git a/lib/pdf/pdf.cc b/lib/pdf/pdf.cc index ea7b3f6..885ebbf 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 { @@ -34,12 +34,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 @@ -78,7 +80,6 @@ void render2(gfxpage_t*page, gfxdevice_t*dev) pi->middev->setparameter(pi->middev, "protect", "1"); dev = pi->middev; } - dev->setparameter(dev, "protect", "1"); if(!pi) { msg(" pdf_page_render: Parent PDF this page belongs to doesn't exist yet/anymore"); @@ -96,14 +97,10 @@ void render2(gfxpage_t*page, gfxdevice_t*dev) dev->setparameter(dev, "protect", "1"); } - /* pass global parameters to output device */ - parameter_t*p = 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 +128,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 +143,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; @@ -281,25 +280,10 @@ char* pdf_doc_getinfo(gfxdocument_t*doc, const char*name) return 0; } - -static void storeDeviceParameter(const char*name, const char*value) -{ - 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; - } else { - device_config = p; - 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) @@ -310,7 +294,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); @@ -332,17 +316,26 @@ 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("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("bitmap Convert everything to bitmaps\n"); + printf("poly2bitmap Convert graphics to bitmaps\n"); + printf("languagedir= Add an xpdf language directory\n"); + printf("multiply= Render everything at the resolution\n"); + printf("breakonwarning=0/1 Abort conversion if graphic objects are found which\n"); + printf(" are not 100%% supported\n"); + printf("transparent=0/1 Make output file transparent (alpha background)\n"); + printf("extrafontdata=0/1 Store Type3 characters and capture characters\n"); + printf("fontquality=1..100 Curve approximation quality of the fonts\n"); } - storeDeviceParameter(name,value); } static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) @@ -355,7 +348,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, '|'))) { @@ -388,8 +381,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; @@ -416,7 +408,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 { @@ -424,13 +419,6 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) i->outputDev = (CommonOutputDev*)outputDev; } - /* pass global parameters to PDF driver*/ - parameter_t*p = device_config; - while(p) { - i->outputDev->setParameter(p->name, p->value); - p = p->next; - } - i->middev = 0; if(multiply>1) { i->middev = (gfxdevice_t*)malloc(sizeof(gfxdevice_t)); @@ -447,6 +435,17 @@ 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; + + delete globalParams;globalParams = 0; + free(src); +} gfxsource_t*gfxsource_pdf_create() { @@ -454,6 +453,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));