drop parameters into output device as well as input device
[swftools.git] / src / pdf2swf.c
index 44c3457..39680cf 100644 (file)
 #include "../lib/os.h"
 #include "../lib/rfxswf.h"
 #include "../lib/devices/swf.h"
-#include "../lib/devices/arts.h"
+#include "../lib/devices/polyops.h"
 #include "../lib/devices/record.h"
 #include "../lib/pdf/pdf.h"
 #include "../lib/log.h"
 
 #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;
@@ -154,7 +155,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, <x1>:<y1>:<x2>:<y2>\n");
+           fprintf(stderr, "-c option requires four arguments, <x1>:<y1>:<x2>:<y2>\n");
            exit(1);
        }
        custom_clip = 1;
@@ -188,9 +189,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"))
@@ -203,6 +206,14 @@ int args_callback_option(char*name,char*val) {
        driver->set_parameter(driver, "ignoredraworder", "1");
        return 0;
     }
+#ifndef WIN32
+    else if (!strcmp(name, "Q"))
+    {
+       int seconds = atoi(val);
+       alarm(seconds);
+       return 1;
+    }
+#endif
     else if (!strcmp(name, "z"))
     {
        driver->set_parameter(driver, "enablezlib", "1");
@@ -244,8 +255,25 @@ int args_callback_option(char*name,char*val) {
        driver->set_parameter(driver, "linksopennewwindow", "0");
        return 0;
     }
+    else if (!strcmp(name, "O"))
+    {
+       int level = 1;
+       int ret=0;
+       if(val&& val[0] && val[1]==0 && isdigit(val[0])) {
+           level = atoi(val);
+           ret=1;
+       }
+       if(level>=1)
+           driver->set_parameter(driver, "poly2bitmap", "1");
+       if(level>=2)
+           driver->set_parameter(driver, "bitmapfonts", "1");
+       if(level>=3)
+           driver->set_parameter(driver, "ignoredraworder", "1");
+       return ret;
+    }
     else if (!strcmp(name, "G"))
     {
+       driver->set_parameter(driver, "optimize_polygons", "1");
        flatten = 1;
        return 0;
     }
@@ -353,6 +381,7 @@ struct options_t options[] =
  {"z","zlib"},
  {"s","set"},
  {"S","shapes"},
+ {"Q","maxtime"},
  {"j","jpegquality"},
  {"p","pages"},
  {"w","samewindow"},
@@ -502,8 +531,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");
@@ -557,17 +596,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;
@@ -671,6 +699,7 @@ int main(int argn, char *argv[])
     result->destroy(result);
 
     pdf->destroy(pdf);
+    driver->destroy(driver);
 
     const char*zip = "";
     if(zlib) {
@@ -690,15 +719,20 @@ int main(int argn, char *argv[])
            printf("\n");
     }
     if(preloader && viewer) {
+#ifdef HAVE_MKSTEMP
         char tmpname[] = "__swf__XXXXXX";
-        mkstemp(tmpname); /* could fail */
-       systemf("swfcombine \"%s\" viewport=%s -o __tmp__.swf",
-               viewer, outputname);
+        mkstemp(tmpname);
+#else 
+       char*tmpname = "__tmp__.swf";
+#endif
+       systemf("swfcombine \"%s\" viewport=%s -o %s",
+               viewer, outputname, tmpname);
         systemf("swfcombine %s -X %d -Y %d -r %f %s/PreLoaderTemplate.swf loader=%s movie=%s -o \"%s\"",zip,width,height,
                 getRate(preloader), SWFDIR, preloader, tmpname, outputname);
         systemf("rm %s", tmpname);
     }
 
+
     return 0;
 }