X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fpdf2swf.c;h=ea61645fc0c0ba03bf9ee5520ca108768d9d5cec;hb=ba5dfbfffd6000fa05bf191858d3b2c4fa854070;hp=cbf54547ba12b0fcb8c45280efcb5cd678f6b08b;hpb=1bfd6af7086bc546cb01bc8f01ef3ff4f0c0cf61;p=swftools.git diff --git a/src/pdf2swf.c b/src/pdf2swf.c index cbf5454..ea61645 100644 --- a/src/pdf2swf.c +++ b/src/pdf2swf.c @@ -25,9 +25,16 @@ #include #include #include "../config.h" +#ifdef HAVE_SIGNAL_H +#include +#endif #ifdef HAVE_DIRENT_H #include #endif +#ifdef HAVE_MALLOC_H +#include +#endif + #include "../lib/args.h" #include "../lib/os.h" #include "../lib/rfxswf.h" @@ -39,7 +46,8 @@ #define SWFDIR concatPaths(getInstallationPath(), "swfs") -gfxsource_t*driver; +static gfxsource_t*driver = 0; +static gfxdevice_t*out = 0; static char * outputname = 0; static int loglevel = 3; @@ -55,6 +63,8 @@ static int ynup = 1; static int info_only = 0; +static int max_time = 0; + static int flatten = 0; char* fontpaths[256]; @@ -89,6 +99,23 @@ int systemf(const char* format, ...) return ret; } +#ifdef HAVE_SIGNAL_H +void sigalarm(int signal) +{ + msg(" Aborting rendering after %d seconds", max_time); +#if 0 && defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRUSAGE) + struct rusage usage; + getrusage(RUSAGE_CHILDREN, &usage); + msg(" Memory used: %d,%d,%d", usage.ru_maxrss, usage.ru_idrss, usage.ru_isrss); +#endif +#if defined(HAVE_MALLINFO) && defined(HAVE_MALLOC_H) + struct mallinfo info = mallinfo(); + msg(" Memory used: %d Mb (%d bytes)", info.uordblks/1048576, info.uordblks); +#endif + exit(1); +} +#endif + int args_callback_option(char*name,char*val) { if (!strcmp(name, "o")) { @@ -154,7 +181,7 @@ int args_callback_option(char*name,char*val) { char*x2 = strtok(0, ":"); char*y2 = strtok(0, ":"); if(!(x1 && y1 && x2 && y2)) { - fprintf(stderr, "-m option requires four arguments, :::\n"); + fprintf(stderr, "-c option requires four arguments, :::\n"); exit(1); } custom_clip = 1; @@ -188,9 +215,11 @@ int args_callback_option(char*name,char*val) { *c = 0; c++; driver->set_parameter(driver, s,c); - } - else + out->setparameter(out, s,c); + } else { driver->set_parameter(driver, s,"1"); + out->setparameter(out, s,"1"); + } return 1; } else if (!strcmp(name, "S")) @@ -206,8 +235,11 @@ int args_callback_option(char*name,char*val) { #ifndef WIN32 else if (!strcmp(name, "Q")) { - int seconds = atoi(val); - alarm(seconds); + max_time = atoi(val); + alarm(max_time); +# ifdef HAVE_SIGNAL_H + signal(SIGALRM, sigalarm); +# endif return 1; } #endif @@ -270,7 +302,7 @@ int args_callback_option(char*name,char*val) { } else if (!strcmp(name, "G")) { - driver->set_parameter(driver, "optimize_polygons", "1"); + //driver->set_parameter(driver, "optimize_polygons", "1"); flatten = 1; return 0; } @@ -528,8 +560,18 @@ int main(int argn, char *argv[]) #endif driver = gfxsource_pdf_create(); + gfxdevice_t swf,wrap; + gfxdevice_swf_init(&swf); + + gfxdevice_removeclippings_init(&wrap, &swf); + + out = &wrap; processargs(argn, argv); + if(!flatten) { + out = &swf; + } + if(!filename) { fprintf(stderr, "Please specify an input file\n"); @@ -583,17 +625,6 @@ int main(int argn, char *argv[]) exit(1); } - gfxdevice_t swf,wrap; - gfxdevice_swf_init(&swf); - gfxdevice_t*out; - - if(flatten) { - gfxdevice_removeclippings_init(&wrap, &swf); - out = &wrap; - } else { - out = &swf; - } - struct mypage_t { int x; int y;