X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fpdf2swf.c;h=0e9e3e5da22a342a115fb74ddf5f924759343cee;hb=aab59bee1b79b487e2a15ec57a80a857ffd623a5;hp=4bf18dfba332f6196b148006d447e294404f0b8a;hpb=c3b25d880211cbc0e57ff53243ab77ce38c3cde8;p=swftools.git diff --git a/src/pdf2swf.c b/src/pdf2swf.c index 4bf18df..0e9e3e5 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; @@ -85,7 +88,7 @@ int systemf(const char* format, ...) int ret; va_list arglist; va_start(arglist, format); - vsprintf(buf, format, arglist); + vsnprintf(buf, sizeof(buf)-1, format, arglist); va_end(arglist); if(!system_quiet) { @@ -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 --; @@ -426,23 +439,6 @@ int args_callback_option(char*name,char*val) { return 0; } -/*struct docoptions_t options[] = -{{"o","output","filename::Specify output file"}, - {"V","version","Print program version"}, - {"i","ignore","Ignore draw order (makes the SWF file smaller, but may produce graphic errors)"}, - {"z","zlib","Use Flash 6 (MX) zlib compression (Needs at least Flash 6 Plugin to play)"}, - {"s","shapes","Don't use SWF Fonts, but store everything as shape"}, - {"j","jpegquality","Set quality of embedded jpeg pictures (default: 85)"}, - {"p","pages","Convert only pages in range. (E.g. 3-85)"}, - {"w","samewindow","Don't open a new browser window for links in the SWF"}, - {"f","fonts","Stroe full fonts in SWF. (Don't reduce to used characters)"}, - {"F","fontpath","path::Add directory to font search path"}, - {"B","viewer","name::Link viewer \"name\" to the pdf"}, - {"L","preloader","file.swf::Link preloader \"file.swf\" to the pdf"}, - {"b","defaultviewer","Link default viewer to the pdf"}, - {"l","defaultpreloader","Link default preloader to the pdf"} - {0,0} -};*/ static struct options_t options[] = { {"h", "help"}, {"V", "version"}, @@ -468,6 +464,8 @@ static struct options_t options[] = { {"G", "flatten"}, {"I", "info"}, {"Q", "maxtime"}, +{"X", "width"}, +{"Y", "height"}, {0,0} }; @@ -497,7 +495,7 @@ void args_callback_usage(char *name) printf("\n"); printf("-h , --help Print short help message and exit\n"); printf("-V , --version Print version info and exit\n"); - printf("-o , --output file.swf Direct output to file.swf. If file.swf contains '%d' (file%d.swf), then each page \n"); + printf("-o , --output file.swf Direct output to file.swf. If file.swf contains '%%' (file%%.swf), then each page goes to a seperate file.\n"); printf("-p , --pages range Convert only pages in range with range e.g. 1-20 or 1,4,6,9-11 or\n"); printf("-P , --password password Use password for deciphering the pdf.\n"); printf("-v , --verbose Be verbose. Use more than one -v for greater effect.\n"); @@ -572,15 +570,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 +606,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,11 +685,11 @@ 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"); @@ -801,7 +807,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 +828,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) {