X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fpdf2swf.cc;h=fc6bad18826bc8548a09e16b95cb39d55da79a0b;hb=e3568797f32e95acba1d3ba4be5b43073a8a9955;hp=98f3dce8048e08a6253e696e20f3127b3d0ed4c0;hpb=98c2aea6b4805af2151b30ddbafd9de267903e55;p=swftools.git diff --git a/pdf2swf/pdf2swf.cc b/pdf2swf/pdf2swf.cc index 98f3dce..fc6bad1 100644 --- a/pdf2swf/pdf2swf.cc +++ b/pdf2swf/pdf2swf.cc @@ -33,6 +33,7 @@ #endif #include "../lib/args.h" #include "../lib/os.h" +#include "../lib/rfxswf.h" #include "SWFOutputDev.h" #include "log.h" @@ -360,15 +361,33 @@ void args_callback_usage(char*name) //printf("-2 Put 2 pages into each frame.\n"); //printf("-4 Put 4 pages into each frame.\n"); printf("Postprocessing options:\n"); -#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)\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); } +float getRate(char*filename) +{ + int fi; + SWF swf; + fi = open(filename,O_RDONLY|O_BINARY); + if(fi<0) { + char buffer[256]; + sprintf(buffer, "Couldn't open %s", filename); + perror(buffer); + exit(1); + } + if(swf_ReadSWF(fi,&swf) < 0) + { + fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename); + close(fi); + exit(1); + } + swf_FreeTags(&swf); + return swf.frameRate / 256.0; +} + int main(int argn, char *argv[]) { int ret; @@ -536,42 +555,51 @@ int main(int argn, char *argv[]) if(swf_output_save(swf, outputname) < 0) { exit(1); } + int width = (int)swf_output_get(swf, "width"); + int height = (int)swf_output_get(swf, "height"); msg(" SWF written"); swf_output_destroy(swf); pdf_destroy(pdf); - if(viewer || preloader) { -#ifndef SYSTEM_BACKTICKS - msg(" Not sure whether system() can handle command substitution"); - msg(" (According to config.h, it can't)"); -#endif - if(!system_quiet) - printf("\n"); - } - char*zip = ""; if(zlib) zip = "-z"; - +#undef SYSTEM_BACKTICKS if(viewer && !preloader) { +#ifdef SYSTEM_BACKTICKS systemf("swfcombine %s `swfdump -XY \"%s\"` \"%s\" viewport=\"%s\" -o \"%s\"",zip, - outputname, viewer, outputname, outputname); + viewer, outputname, outputname); +#else + systemf("swfcombine %s -X %d -Y %d \"%s\" viewport=\"%s\" -o \"%s\"",zip,width,height, + viewer, outputname, outputname); +#endif if(!system_quiet) printf("\n"); } if(preloader && !viewer) { msg(" --preloader option without --viewer option doesn't make very much sense."); +#ifdef SYSTEM_BACKTICKS ret = systemf("swfcombine %s `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip, preloader, SWFDIR, preloader, outputname, outputname); +#else + ret = systemf("swfcombine %s -Y %d -X %d %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip,width,height, + SWFDIR, preloader, outputname, outputname); +#endif if(!system_quiet) printf("\n"); } if(preloader && viewer) { systemf("swfcombine \"%s\" viewport=%s -o __tmp__.swf", viewer, outputname, outputname); +#ifdef SYSTEM_BACKTICKS 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); +#else + /* TODO: read out rate */ + systemf("swfcombine %s -X %d -Y %d -r %f %s/PreLoaderTemplate.swf loader=%s movie=__tmp__.swf -o \"%s\"",zip,width,height, + getRate(preloader), preloader, SWFDIR, preloader, outputname); +#endif systemf("rm __tmp__.swf"); }