X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fpdf2swf.c;h=5422e7d5c7703b3e36eb72e82de353cde93c03e3;hb=f0f4599a8cc05f18859d2bb8d0afe447f3e00813;hp=517f0481e9d50e58e6ddcdcb0e23b7dcb8b1259b;hpb=e64b8ed118621cf212256e9bd80d43ab32795baa;p=swftools.git diff --git a/src/pdf2swf.c b/src/pdf2swf.c index 517f048..5422e7d 100644 --- a/src/pdf2swf.c +++ b/src/pdf2swf.c @@ -42,6 +42,7 @@ #include "../lib/devices/swf.h" #include "../lib/devices/polyops.h" #include "../lib/devices/record.h" +#include "../lib/devices/rescale.h" #include "../lib/pdf/pdf.h" #include "../lib/log.h" @@ -50,6 +51,8 @@ static gfxsource_t*driver = 0; static gfxdevice_t*out = 0; +static int maxwidth=0, maxheight=0; + static char * outputname = 0; static int loglevel = 3; static char * pagerange = 0; @@ -137,7 +140,7 @@ static void store_parameter(const char*name, const char*value) } o = o->next; } - parameter_t*p = malloc(sizeof(parameter_t)); + parameter_t*p = (parameter_t*)malloc(sizeof(parameter_t)); p->name = strdup(name); p->value = strdup(value); p->next = 0; @@ -181,6 +184,16 @@ int args_callback_option(char*name,char*val) { ynup = 3; return 0; } + else if (!strcmp(name, "X")) + { + maxwidth = atoi(val); + return 1; + } + else if (!strcmp(name, "Y")) + { + maxheight = atoi(val); + return 1; + } else if (!strcmp(name, "q")) { loglevel --; @@ -250,9 +263,9 @@ int args_callback_option(char*name,char*val) { *c = 0; c++; store_parameter(s,c); - } else if(strcmp(s,"help")) { + } else if(!strcmp(s,"help")) { printf("PDF Parameters:\n"); - gfxsource_t*pdf = gfxsource_pdf_create(&pdf); + gfxsource_t*pdf = gfxsource_pdf_create(); pdf->set_parameter(pdf, "help", ""); gfxdevice_t swf; gfxdevice_swf_init(&swf); @@ -266,12 +279,12 @@ int args_callback_option(char*name,char*val) { } else if (!strcmp(name, "S")) { - driver->set_parameter(driver, "drawonlyshapes", "1"); + store_parameter("drawonlyshapes", "1"); return 0; } else if (!strcmp(name, "i")) { - driver->set_parameter(driver, "ignoredraworder", "1"); + store_parameter("ignoredraworder", "1"); return 0; } #ifndef WIN32 @@ -287,13 +300,13 @@ int args_callback_option(char*name,char*val) { #endif else if (!strcmp(name, "z")) { - driver->set_parameter(driver, "enablezlib", "1"); + store_parameter("enablezlib", "1"); zlib = 1; return 0; } else if (!strcmp(name, "n")) { - driver->set_parameter(driver, "opennewwindow", "1"); + store_parameter("opennewwindow", "1"); return 0; } else if (!strcmp(name, "I")) @@ -303,27 +316,27 @@ int args_callback_option(char*name,char*val) { } else if (!strcmp(name, "t")) { - driver->set_parameter(driver, "insertstop", "1"); + store_parameter("insertstop", "1"); return 0; } else if (!strcmp(name, "T")) { if(!strcasecmp(val, "mx")) - driver->set_parameter(driver, "flashversion", "6"); + store_parameter("flashversion", "6"); else - driver->set_parameter(driver, "flashversion", val); + store_parameter("flashversion", val); return 1; } else if (!strcmp(name, "f")) { - driver->set_parameter(driver, "storeallcharacters", "1"); - driver->set_parameter(driver, "extrafontdata", "1"); + store_parameter("storeallcharacters", "1"); + store_parameter("extrafontdata", "1"); return 0; } else if (!strcmp(name, "w")) { - driver->set_parameter(driver, "linksopennewwindow", "0"); + store_parameter("linksopennewwindow", "0"); return 0; } else if (!strcmp(name, "O")) @@ -335,16 +348,16 @@ int args_callback_option(char*name,char*val) { ret=1; } if(level>=1) - driver->set_parameter(driver, "poly2bitmap", "1"); + store_parameter("poly2bitmap", "1"); if(level>=2) - driver->set_parameter(driver, "bitmapfonts", "1"); + store_parameter("bitmapfonts", "1"); if(level>=3) - driver->set_parameter(driver, "ignoredraworder", "1"); + store_parameter("ignoredraworder", "1"); return ret; } else if (!strcmp(name, "G")) { - //driver->set_parameter(driver, "optimize_polygons", "1"); + //store_parameter("optimize_polygons", "1"); flatten = 1; return 0; } @@ -406,10 +419,10 @@ int args_callback_option(char*name,char*val) { else if (!strcmp(name, "j")) { if(name[1]) { - driver->set_parameter(driver, "jpegquality", &name[1]); + store_parameter("jpegquality", &name[1]); return 0; } else { - driver->set_parameter(driver, "jpegquality", val); + store_parameter("jpegquality", val); return 1; } } @@ -468,6 +481,8 @@ static struct options_t options[] = { {"G", "flatten"}, {"I", "info"}, {"Q", "maxtime"}, +{"X", "width"}, +{"Y", "height"}, {0,0} }; @@ -572,15 +587,24 @@ void show_info(gfxsource_t*driver, char*filename) } -static gfxdevice_t swf,wrap; +static gfxdevice_t swf,wrap,rescale; gfxdevice_t*create_output_device() { gfxdevice_swf_init(&swf); - gfxdevice_removeclippings_init(&wrap, &swf); - out = &wrap; - if(!flatten) { - out = &swf; + + /* set up filter chain */ + + out = &swf; + if(flatten) { + gfxdevice_removeclippings_init(&wrap, &swf); + out = &wrap; } + + if(maxwidth || maxheight) { + gfxdevice_rescale_init(&rescale, out, maxwidth, maxheight, 0); + out = &rescale; + } + /* pass global parameters to output device */ parameter_t*p = device_config; while(p) { @@ -599,8 +623,7 @@ int main(int argn, char *argv[]) char t1searchpath[1024]; int nup_pos = 0; int x,y; - char* installPath = getInstallationPath(); - char one_file_per_page = 0; + int one_file_per_page = 0; initLog(0,-1,0,0,-1,loglevel); @@ -679,16 +702,16 @@ int main(int argn, char *argv[]) if((u = strchr(outputname, '%'))) { if(strchr(u+1, '%') || strchr(outputname, '%')!=u) { - msg(" only one %%d allowed in filename\n"); + msg(" only one %% allowed in filename\n"); return 1; } if(preloader || viewer) { - msg(" -b/-l/-B/-L not supported together with %%d in filename\n"); + msg(" -b/-l/-B/-L not supported together with %% in filename\n"); return 1; } msg(" outputting one file per page"); one_file_per_page = 1; - char*pattern = malloc(strlen(outputname)+2); + char*pattern = (char*)malloc(strlen(outputname)+2); /* convert % to %d */ int l = u-outputname+1; memcpy(pattern, outputname, l); @@ -801,7 +824,7 @@ int main(int argn, char *argv[]) if(one_file_per_page) { gfxresult_t*result = out->finish(out);out=0; char buf[1024]; - sprintf(buf, outputname, one_file_per_page++); + sprintf(buf, outputname, pagenr); if(result->save(result, buf) < 0) { return 1; } @@ -822,8 +845,8 @@ int main(int argn, char *argv[]) if(result->save(result, outputname) < 0) { exit(1); } - int width = (int)result->get(result, "width"); - int height = (int)result->get(result, "height"); + int width = (int)(ptroff_t)result->get(result, "width"); + int height = (int)(ptroff_t)result->get(result, "height"); result->destroy(result);result=0; if(preloader || viewer) {