X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fpdf2swf.cc;h=96f125b8354351ba42fd7c3462f54feb72a3b644;hb=691052d481359cfb2ae48f6336a481f5117281db;hp=c943c691848a51ccf5c8262e0037c2f0811b0274;hpb=3dab974276d6a99794e4dd33622a1dc098e4a27c;p=swftools.git diff --git a/pdf2swf/pdf2swf.cc b/pdf2swf/pdf2swf.cc index c943c69..96f125b 100644 --- a/pdf2swf/pdf2swf.cc +++ b/pdf2swf/pdf2swf.cc @@ -32,16 +32,12 @@ #include #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; @@ -51,6 +47,7 @@ static char * password = 0; static char * preloader = 0; static char * viewer = 0; +static int nup = 0; char* fontpaths[256]; int fontpathpos = 0; @@ -87,11 +84,23 @@ int args_callback_option(char*name,char*val) { else if (!strcmp(name, "v")) { loglevel ++; + setConsoleLogging(loglevel); + return 0; + } + else if (!strcmp(name, "2")) + { + nup = 2; + return 0; + } + else if (!strcmp(name, "4")) + { + nup = 4; return 0; } else if (!strcmp(name, "q")) { loglevel --; + setConsoleLogging(loglevel); system_quiet = 1; return 0; } @@ -331,85 +340,19 @@ void args_callback_usage(char*name) " graphic errors)\n"); printf("-s filloverlap Make intersecting shapes overlap, instead of canceling each\n" " other out. (Needed for some Powerpoint PDFs)\n"); + //deliberately undocumented (for now) + //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/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); } -#ifdef HAVE_DIRENT_H -static void addfontdir(char* dirname, int*numfonts) -{ - if(!numfonts) - msg(" Adding %s to search path\n", dirname); - - DIR*dir = opendir(dirname); - if(!dir) { - msg(" Couldn't open directory %s\n", dirname); - return; - } - struct 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], ".pfa", 4)) - type=1; - if(!strncasecmp(&name[l-4], ".pfb", 4)) - type=3; - if(!strncasecmp(&name[l-4], ".ttf", 4)) - type=2; - if(type) - { - char*fontname = (char*)malloc(strlen(dirname)+strlen(name)+2); - strcpy(fontname, dirname); -#ifdef WIN32 - strcat(fontname, "\\"); -#else - strcat(fontname, "/"); -#endif - strcat(fontname, name); - if(!numfonts) - msg(" Adding %s to fonts", fontname); - pdfswf_addfont(fontname); - if(numfonts) - (*numfonts)++; - } - } - closedir(dir); -} -#endif - -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; @@ -417,11 +360,15 @@ int main(int argn, char *argv[]) int numfonts = 0; int t; char t1searchpath[1024]; + int nup_pos = 0; + int x,y; + + 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); } @@ -436,7 +383,6 @@ int main(int argn, char *argv[]) #endif #endif processargs(argn, argv); - initLog(0,-1,0,0,-1,loglevel); if(!filename) { @@ -447,7 +393,7 @@ int main(int argn, char *argv[]) if(!outputname) { if(filename) { - outputname = stripfilename(filename, ".swf"); + outputname = stripFilename(filename, ".swf"); msg(" Output filename not given. Writing to %s", outputname); } } @@ -466,20 +412,11 @@ int main(int argn, char *argv[]) exit(0); } -#ifdef HAVE_DIRENT_H - // pass 1 - addfontdir(FONTDIR, &numfonts); - for(t=0;t Couldn't find any fonts!"); -#endif pdf_doc_t* pdf = pdf_init(filename, password); if(!pdf) { @@ -496,11 +433,34 @@ int main(int argn, char *argv[]) } if(is_in_range(t, pagerange)) { pdf_page_t*page = pdf_getpage(pdf, t); - pdf_page_render(page, swf); + if(nup) { + pdf_page_info_t* info = pdf_page_getinfo(page); + if(nup_pos%nup == 0) { + pdf_page_render(page, swf); + x = info->xMax; + y = info->yMax; + } else if(nup_pos%nup == 1) { + pdf_page_rendersection(page, swf, x, 0, info->xMin+x, info->yMin, info->xMax+x, info->yMax); + } else if(nup_pos%nup == 2) { + pdf_page_rendersection(page, swf, 0, y, info->xMin, info->yMin+y, info->xMax, info->yMax+y); + } else if(nup_pos%nup == 3) { + pdf_page_rendersection(page, swf, x, y, info->xMin+x, info->yMin+y, info->xMax+x, info->yMax+y); + } + if(nup_pos % nup == nup-1) + swf_output_pagefeed(swf); + + pdf_page_info_destroy(info); + } else { + pdf_page_render(page, swf); + swf_output_pagefeed(swf); + } + pdf_page_destroy(page); } + nup_pos++; } - swf_output_save(swf, outputname); + if(!swf_output_save(swf, outputname)) + exit(1); swf_output_destroy(swf); pdf_destroy(pdf);