fixed -b in conjunction with -z.
[swftools.git] / pdf2swf / pdf2swf.cc
index 143b867..aaf1945 100644 (file)
 #include <sys/stat.h>
 #endif
 #include "../lib/args.h"
+#include "../lib/os.h"
 #include "SWFOutputDev.h"
 #include "log.h"
 
-#ifndef WIN32
-#define FONTDIR SWFTOOLS_DATADIR "/fonts"
-#define SWFDIR SWFTOOLS_DATADIR "/swfs"
-#else
-#define FONTDIR "C:\\swftools\\fonts"
-#define SWFDIR "C:\\swftools\\swfs"
-#endif
+#define FONTDIR concatPaths(getInstallationPath(), "fonts")
+#define SWFDIR concatPaths(getInstallationPath(), "swfs")
 
 static char * outputname = 0;
 static int loglevel = 3;
 static char * pagerange = 0;
 static char * filename = 0;
 static char * password = 0;
+static int zlib = 0;
 
 static char * preloader = 0;
 static char * viewer = 0;
@@ -154,6 +151,7 @@ int args_callback_option(char*name,char*val) {
     else if (!strcmp(name, "z"))
     {
        pdfswf_setparameter("enablezlib", "1");
+       zlib = 1;
        return 0;
     }
     else if (!strcmp(name, "n"))
@@ -351,31 +349,12 @@ void args_callback_usage(char*name)
 #ifndef SYSTEM_BACKTICKS
     printf("(They might not work because your system call doesn't support command substitution)\n");
 #endif
-    printf("-b  --defaultviewer        Link default viewer to the pdf (%s/swfs/default_viewer.swf)\n", SWFTOOLS_DATADIR);
-    printf("-l  --defaultpreloader     Link default preloader the pdf (%s/swfs/default_loader.swf)\n", SWFTOOLS_DATADIR);
+    printf("-b  --defaultviewer        Link default viewer to the pdf (%s)\n", concatPaths(SWFDIR, "default_viewer.swf"));
+    printf("-l  --defaultpreloader     Link default preloader the pdf (%s)\n", concatPaths(SWFDIR, "default_loader.swf"));
     printf("-B  --viewer=filename      Link viewer \"name\" to the pdf (\"%s -B\" for list)\n", name);
     printf("-L  --preloader=filename   Link preloader \"name\" to the pdf (\"%s -L\" for list)\n",name);
 }
 
-static char* stripfilename(char*filename, char*newext)
-{
-    char*last1 = strrchr(filename, '/');
-    char*last2 = strrchr(filename, '\\');
-    char*pos = filename;
-    char*name;
-    char*dot;
-    if(last1>pos) pos = last1 + 1;
-    if(last2>pos) pos = last2 + 1;
-    name = (char*)malloc(strlen(pos)+5);
-    strcpy(name, pos);
-    dot = strrchr(name, '.');
-    if(dot) {
-       *dot = 0;
-    }
-    strcat(name, newext);
-    return name;
-}
-
 int main(int argn, char *argv[])
 {
     int ret;
@@ -389,9 +368,9 @@ int main(int argn, char *argv[])
     initLog(0,-1,0,0,-1,loglevel);
 
 #if defined(WIN32) && defined(HAVE_STAT) && defined(HAVE_SYS_STAT_H)
-    FILE*test = fopen(FONTDIR "\\d050000l.afm", "rb");
+    FILE*test = fopen(concatPaths(FONTDIR,"\\d050000l.afm"), "rb");
     if(!test) {
-       fprintf(stderr, "Couldn't find file " FONTDIR "\\d050000l.afm- pdf2swf not installed properly? OS says:\n");
+       fprintf(stderr, "Couldn't find file %s - pdf2swf not installed properly? OS says:\n", concatPaths(FONTDIR, "\\d050000l.afm"));
        perror("open");
        exit(1);
     }
@@ -416,7 +395,7 @@ int main(int argn, char *argv[])
     if(!outputname)
     {
        if(filename) {
-           outputname = stripfilename(filename, ".swf");
+           outputname = stripFilename(filename, ".swf");
            msg("<notice> Output filename not given. Writing to %s", outputname);
        } 
     }
@@ -497,15 +476,19 @@ int main(int argn, char *argv[])
            printf("\n");
     }
 
+    char*zip = "";
+    if(zlib)
+       zip = "-z";
+
     if(viewer && !preloader) {
-       systemf("swfcombine `swfdump -XY \"%s\"` \"%s\" viewport=\"%s\" -o \"%s\"",
+       systemf("swfcombine %s `swfdump -XY \"%s\"` \"%s\" viewport=\"%s\" -o \"%s\"",zip,
                outputname, viewer, outputname, outputname);
        if(!system_quiet)
            printf("\n");
     }
     if(preloader && !viewer) {
        msg("<warning> --preloader option without --viewer option doesn't make very much sense.");
-       ret = systemf("swfcombine `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",
+       ret = systemf("swfcombine %s `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip,
                preloader, SWFDIR, preloader, outputname, outputname);
        if(!system_quiet)
            printf("\n");
@@ -513,7 +496,7 @@ int main(int argn, char *argv[])
     if(preloader && viewer) {
        systemf("swfcombine \"%s\" viewport=%s -o __tmp__.swf",
                viewer, outputname, outputname);
-       systemf("swfcombine `swfdump -XY \"%s\"` `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=%s movie=__tmp__.swf -o \"%s\"",
+       systemf("swfcombine %s `swfdump -XY \"%s\"` `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=%s movie=__tmp__.swf -o \"%s\"",zip,
                outputname, preloader, SWFDIR, preloader, outputname);
        systemf("rm __tmp__.swf");
     }