X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fpdf2swf.cc;h=85c72019a05fa5979e2e1a6e60de4cffb71980fc;hb=785f09eb70213f929e77c8729cd0212c24e2826e;hp=739e421c16c79b63ba14d5b4425fb204d9b84d10;hpb=5476293b41224aa36313ba57db5b4b6ae2db31ef;p=swftools.git diff --git a/pdf2swf/pdf2swf.cc b/pdf2swf/pdf2swf.cc index 739e421..85c7201 100644 --- a/pdf2swf/pdf2swf.cc +++ b/pdf2swf/pdf2swf.cc @@ -13,8 +13,11 @@ #include #include #include "../config.h" +#ifdef HAVE_DIRENT_H +#include +#endif #include "../lib/args.h" -#include "pdfswf.h" +#include "SWFOutputDev.h" #include "t1lib.h" extern "C" { #include "log.h" @@ -29,6 +32,11 @@ static char * password = 0; static char * preloader = 0; static char * viewer = 0; +char* fontpaths[256]; +int fontpathpos = 0; + +static int system_quiet=0; + int systemf(const char* format, ...) { char buf[1024]; @@ -38,8 +46,10 @@ int systemf(const char* format, ...) vsprintf(buf, format, arglist); va_end(arglist); - printf("%s\n", buf); - fflush(stdout); + if(!system_quiet) { + printf("%s\n", buf); + fflush(stdout); + } ret = system(buf); if(ret) { fprintf(stderr, "system() returned %d\n", ret); @@ -59,6 +69,12 @@ int args_callback_option(char*name,char*val) { loglevel ++; return 0; } + else if (!strcmp(name, "q")) + { + loglevel --; + system_quiet = 1; + return 0; + } else if (name[0]=='p') { /* check whether the page range follows the p directly, like @@ -89,16 +105,45 @@ int args_callback_option(char*name,char*val) { pdfswf_ignoredraworder(); return 0; } + else if (!strcmp(name, "z")) + { + pdfswf_enablezlib(); + return 0; + } else if (!strcmp(name, "n")) { pdfswf_linksopennewwindow(); return 0; } + else if (!strcmp(name, "t")) + { + pdfswf_insertstop(); + return 0; + } + else if (!strcmp(name, "T")) + { + int i = atoi(val); + if(!strcasecmp(val, "mx")) + i = 6; + pdfswf_setversion(i); + return 1; + } else if (!strcmp(name, "f")) { pdfswf_storeallcharacters(); return 0; } + else if (!strcmp(name, "F")) + { + char *s = strdup(val); + int l = strlen(s); + while(l && s[l-1]=='/') { + s[l-1] = 0; + l--; + } + fontpaths[fontpathpos++] = s; + return 1; + } else if (!strcmp(name, "l")) { char buf[256]; @@ -122,7 +167,8 @@ int args_callback_option(char*name,char*val) { else { systemf("ls %s/swfs/*_loader.swf", DATADIR); - printf("\n"); + if(!system_quiet) + printf("\n"); exit(1); } return 1; @@ -136,12 +182,13 @@ int args_callback_option(char*name,char*val) { else { systemf("ls %s/swfs/*_viewer.swf", DATADIR); - printf("\n"); + if(!system_quiet) + printf("\n"); exit(1); } return 1; } - else if (name[0]=='j') + else if (!strcmp(name, "j")) { if(name[1]) { pdfswf_jpegquality(atoi(&name[1])); @@ -164,19 +211,41 @@ 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} +};*/ struct options_t options[] = {{"o","output"}, + {"q","quiet"}, {"V","version"}, {"i","ignore"}, + {"z","zlib"}, {"s","shapes"}, {"j","jpegquality"}, {"p","pages"}, {"w","samewindow"}, {"f","fonts"}, + {"F","fontdir"}, {"B","viewer"}, {"L","preloader"}, {"b","defaultviewer"}, {"l","defaultpreloader"}, + {"t","stop"}, + {"T","flashversion"}, {0,0} }; @@ -201,29 +270,93 @@ int args_callback_command(char*name, char*val) { void args_callback_usage(char*name) { - printf("Usage: %s [-si] [-j quality] [-p range] [-P password] input.pdf [output.swf]\n", name); + printf("Usage: %s [-si] [-j quality] [-p range] [-P password] input.pdf -o output.swf\n", name); printf("\n"); printf("-p --pages=range Convert only pages in range\n"); printf("-P --password=password Use password for deciphering the pdf\n"); printf("-s --shapes Don't use SWF Fonts, but store everything as shape\n"); - printf("-i --ignore Ignore draw order (makes the SWF file smaller)\n"); + printf("-i --ignore Ignore draw order (makes the SWF file smaller, but may produce\n"); + printf(" graphic errors)\n"); + printf("-z --zlib Use Flash 6 (MX) zlib compression (Needs at least Flash 6 Plugin to play)\n"); printf("-j --jpegquality=quality Set quality of embedded jpeg pictures (default:85)\n"); printf("-v --verbose Be verbose. Use more than one -v for greater effect\n"); + printf("-q --quiet Suppress normal messages. Use -qq to suppress warnings, also.\n"); printf("-w --samewindow Don't open a new Browser Window for Links in the SWF\n"); +#ifdef HAVE_DIRENT_H + printf("-F --fontdir directory Add directory to font search path\n"); +#endif printf("-f --fonts Store full fonts in SWF. (Don't reduce to used characters)\n"); printf("-V --version Print program version\n"); + printf("-t --stop Insert a \"Stop\" Tag in every frame (don't turn pages automatically)\n"); + printf("-T --flashversion=num Set the flash version in the header to num (default: 4)\n"); #ifndef SYSTEM_BACKTICKS printf("The following 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", DATADIR); - printf("-l --defaultpreloader Link preloader \"name\" to the pdf (%s/swfs/default_loader.swf)\n", DATADIR); + printf("-l --defaultpreloader Link default preloader the pdf (%s/swfs/default_loader.swf)\n", DATADIR); 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); } +#ifdef HAVE_DIRENT_H +void addfontdir(FILE*database, char* dirname, int*numfonts, char*searchpath) +{ + if(searchpath) { + if(searchpath[0]) + strcat(searchpath, ":"); + strcat(searchpath, dirname); + } + logf(" Adding %s to search path\n", dirname); + + DIR*dir = opendir(dirname); + if(!dir) { + logf(" Couldn't open directory %s\n", dirname); + return; + } + dirent*ent; + while(1) { + ent = readdir (dir); + if (!ent) + break; + int l; + char*name = ent->d_name; + char type = 0; + if(!name) continue; + l=strlen(name); + if(l<4) + continue; + if(!strncasecmp(&name[l-4], ".afm", 4)) + type=1; + if(!strncasecmp(&name[l-4], ".ttf", 4)) + type=2; + if(type) + { + if(database && type==1) { + char buf[256],a; + FILE*fi; + sprintf(buf, "%s/%s", dirname,name); + fi = fopen(buf, "rb"); + if(!fi || !fread(&a,1,1,fi)) { + logf(" Couldn't read from %s", buf); + } + fprintf(database, "%s\n", buf); + logf(" Found font %s\n", buf); + } + if(numfonts) + (*numfonts)++; + } + } + closedir(dir); +} +#endif + int main(int argn, char *argv[]) { int ret; + char buf[256]; + int numfonts = 0; + int t; + char t1searchpath[1024]; #ifdef HAVE_SRAND48 srand48(time(0)); #else @@ -251,12 +384,55 @@ int main(int argn, char *argv[]) //TODO: use tempnam here. Check if environment already contains a //T1LIB_CONFIG. putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp"); + FILE*db = fopen("/tmp/FontDataBase", "wb"); FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb"); - fprintf(fi, "FONTDATABASE=%s/fonts/FontDataBase\n", DATADIR); - fprintf(fi, "ENCODING=%s/fonts:.\n", DATADIR); - fprintf(fi, "AFM=%s/fonts:.\n", DATADIR); - fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR); + if(!db || !fi) { + fprintf(stderr, "Couldn't create temporary file in /tmp/\n"); + exit(1); + } + t1searchpath[0] = 0; +#ifdef HAVE_DIRENT_H + sprintf(buf, "%s/fonts",DATADIR); + // pass 1 + addfontdir(0, buf, &numfonts, 0); + for(t=0;t Not sure whether system() can handle command substitution"); logf(" (According to config.h, it can't)"); #endif - printf("\n"); + if(!system_quiet) + printf("\n"); } if(viewer && !preloader) { systemf("swfcombine `swfdump -XY %s` %s viewport=%s -o %s", outputname, viewer, outputname, outputname); - printf("\n"); + if(!system_quiet) + printf("\n"); } if(preloader && !viewer) { logf(" --preloader option without --viewer option doesn't make very much sense."); ret = systemf("swfcombine `swfdump -r %s` %s/swfs/PreLoaderTemplate.swf loader=%s movie=%s -o %s", preloader, DATADIR, preloader, outputname, outputname); - printf("\n"); + if(!system_quiet) + printf("\n"); } if(preloader && viewer) { - systemf("swfcombine %s viewport=%s -o %s", + systemf("swfcombine %s viewport=%s -o __tmp__.swf", viewer, outputname, outputname); - systemf("swfcombine `swfdump -XY %s` `swfdump -r %s` %s/swfs/PreLoaderTemplate.swf loader=%s movie=%s -o %s", - outputname, preloader, DATADIR, preloader, outputname, outputname); + systemf("swfcombine `swfdump -XY %s` `swfdump -r %s` %s/swfs/PreLoaderTemplate.swf loader=%s movie=__tmp__.swf -o %s", + outputname, preloader, DATADIR, preloader, outputname); + systemf("rm __tmp__.swf"); } + unlink("/tmp/FontDataBase"); return 0; }