X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fpdf2swf.cc;h=5558e4d0d66e948291bf3e32b9e737369e7becca;hb=04c3312de54408aaf6afe487b6a9cdfaf707949c;hp=fc6bad18826bc8548a09e16b95cb39d55da79a0b;hpb=e3568797f32e95acba1d3ba4be5b43073a8a9955;p=swftools.git diff --git a/pdf2swf/pdf2swf.cc b/pdf2swf/pdf2swf.cc index fc6bad1..5558e4d 100644 --- a/pdf2swf/pdf2swf.cc +++ b/pdf2swf/pdf2swf.cc @@ -34,10 +34,11 @@ #include "../lib/args.h" #include "../lib/os.h" #include "../lib/rfxswf.h" +#include "../lib/devices/swf.h" +//#include "../lib/devices/render.h" #include "SWFOutputDev.h" #include "log.h" -#define FONTDIR concatPaths(getInstallationPath(), "fonts") #define SWFDIR concatPaths(getInstallationPath(), "swfs") static char * outputname = 0; @@ -55,6 +56,12 @@ static int ynup = 1; char* fontpaths[256]; int fontpathpos = 0; +int move_x=0; +int move_y=0; +int custom_move = 0; +int clip_x1=0,clip_y1=0,clip_x2=0,clip_y2=0; +int custom_clip = 0; + static int system_quiet=0; int systemf(const char* format, ...) @@ -135,6 +142,40 @@ int args_callback_option(char*name,char*val) { password = val; return 1; } + else if (!strcmp(name, "c")) + { + char*s = strdup(val); + char*x1 = strtok(s, ":"); + char*y1 = strtok(0, ":"); + char*x2 = strtok(0, ":"); + char*y2 = strtok(0, ":"); + if(!(x1 && y1 && x2 && y2)) { + fprintf(stderr, "-m option requires four arguments, :::\n"); + exit(1); + } + custom_clip = 1; + clip_x1 = atoi(x1); + clip_y1 = atoi(y1); + clip_x2 = atoi(x2); + clip_y2 = atoi(y2); + free(s); + return 1; + } + else if (!strcmp(name, "m")) + { + char*s = strdup(val); + char*c = strchr(s, ':'); + if(!c) { + fprintf(stderr, "-m option requires two arguments, :\n"); + exit(1); + } + *c = 0; + custom_move = 1; + move_x = atoi(val); + move_y = atoi(c+1); + free(s); + return 1; + } else if (!strcmp(name, "s")) { char*s = strdup(val); @@ -397,17 +438,24 @@ int main(int argn, char *argv[]) char t1searchpath[1024]; int nup_pos = 0; int x,y; + char* installPath = getInstallationPath(); + char* fontdir = 0; initLog(0,-1,0,0,-1,loglevel); #if defined(WIN32) && defined(HAVE_STAT) && defined(HAVE_SYS_STAT_H) - FILE*test = fopen(concatPaths(FONTDIR,"\\d050000l.afm"), "rb"); - if(!test) { - fprintf(stderr, "Couldn't find file %s - pdf2swf not installed properly? OS says:\n", concatPaths(FONTDIR, "\\d050000l.afm")); - perror("open"); - exit(1); + if(installPath) { + fontdir = concatPaths(installPath, "fonts"); + FILE*test = fopen(concatPaths(fontdir,"\\d050000l.afm"), "rb"); + if(!test) { + fprintf(stderr, "Couldn't find file %s - pdf2swf not installed properly? OS says:\n", concatPaths(fontdir, "\\d050000l.afm")); + perror("open"); + exit(1); + } + fclose(test); } - fclose(test); +#else + fontdir = concatPaths(installPath, "fonts"); #endif #ifdef HAVE_SRAND48 @@ -448,7 +496,9 @@ int main(int argn, char *argv[]) } /* add fonts */ - pdfswf_addfontdir(FONTDIR); + if(fontdir) { + pdfswf_addfontdir(fontdir); + } for(t=0;tnum_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { - swf_output_preparepage(swf, pagenr, frame); + dev_output_preparepage(swf, pagenr, frame); pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { @@ -523,7 +576,11 @@ int main(int argn, char *argv[]) height += ymax[y]; ymax[y] = height; } - swf_output_startframe(swf, width, height); + if(custom_clip) { + dev_output_startframe(swf, clip_x2 - clip_x1, clip_y2 - clip_y1); + } else { + dev_output_startframe(swf, width, height); + } for(t=0;tyMin + ypos, info->xMax + xpos, info->yMax + ypos, xpos, ypos); - pdf_page_rendersection(pages[t].page, swf, xpos, - ypos, - info->xMin + xpos, - info->yMin + ypos, - info->xMax + xpos, - info->yMax + ypos); + pdf_page_rendersection(pages[t].page, swf, custom_move? move_x : xpos, + custom_move? move_y : ypos, + custom_clip? clip_x1 : info->xMin + xpos, + custom_clip? clip_y1 : info->yMin + ypos, + custom_clip? clip_x2 : info->xMax + xpos, + custom_clip? clip_y2 : info->yMax + ypos); } - swf_output_endframe(swf); + dev_output_endframe(swf); for(t=0;tsave(result, outputname) < 0) { exit(1); } - int width = (int)swf_output_get(swf, "width"); - int height = (int)swf_output_get(swf, "height"); + + int width = (int)result->get(result, "width"); + int height = (int)result->get(result, "height"); msg(" SWF written"); - swf_output_destroy(swf); + + result->destroy(result); + + dev_output_destroy(swf); pdf_destroy(pdf);