X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fpdf2swf.cc;h=680864fc1188e68f0db4782b5d0ef53dbca5687d;hb=3b178e342242bbacc6c9d620f4129b6acb6478ed;hp=ed958d17cd72e59a2fd61a2a90050f57cc50ed75;hpb=0a72bdd2dc58cb78b07c29e8b07ecc75b7912880;p=swftools.git diff --git a/pdf2swf/pdf2swf.cc b/pdf2swf/pdf2swf.cc index ed958d1..680864f 100644 --- a/pdf2swf/pdf2swf.cc +++ b/pdf2swf/pdf2swf.cc @@ -48,7 +48,8 @@ static int zlib = 0; static char * preloader = 0; static char * viewer = 0; -static int nup = 0; +static int xnup = 1; +static int ynup = 1; char* fontpaths[256]; int fontpathpos = 0; @@ -90,12 +91,20 @@ int args_callback_option(char*name,char*val) { } else if (!strcmp(name, "2")) { - nup = 2; + xnup = 2; + ynup = 1; return 0; } else if (!strcmp(name, "4")) { - nup = 4; + xnup = 2; + ynup = 2; + return 0; + } + else if (!strcmp(name, "9")) + { + xnup = 3; + ynup = 3; return 0; } else if (!strcmp(name, "q")) @@ -178,6 +187,11 @@ int args_callback_option(char*name,char*val) { pdfswf_setparameter("storeallcharacters", "1"); return 0; } + else if (!strcmp(name, "w")) + { + pdfswf_setparameter("linksopennewwindow", "0"); + return 0; + } else if (!strcmp(name, "F")) { char *s = strdup(val); @@ -425,44 +439,87 @@ int main(int argn, char *argv[]) msg(" Couldn't open %s", filename); exit(1); } + swf_output_t* swf = swf_output_init(); - for(t = 1; t <= pdf->num_pages; t++) + struct mypage_t { + int x; + int y; + pdf_page_t*page; + pdf_page_info_t*info; + } pages[4]; + int pagenum=0; + + for(int pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { - if(is_in_range(t, pagerange)) { - /* for links: FIXME */ - pdfswf_preparepage(t); - } - if(is_in_range(t, pagerange)) { - pdf_page_t*page = pdf_getpage(pdf, t); - 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++; - } - if(!swf_output_save(swf, outputname)) + if(is_in_range(pagenr, pagerange)) { + pdf_page_t* page = pages[pagenum].page = pdf_getpage(pdf, pagenr); + pdf_page_info_t* info = pdf_page_getinfo(page); + pages[pagenum].x = 0; + pages[pagenum].y = 0; + pages[pagenum].info = info; + pages[pagenum].page = page; + pagenum++; + } + if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { + + int t; + int xmax[xnup], ymax[xnup]; + int x,y; + int width=0, height=0; + + memset(xmax, 0, xnup*sizeof(int)); + memset(ymax, 0, ynup*sizeof(int)); + + for(y=0;yxMax-pages[t].info->xMin > xmax[x]) + xmax[x] = pages[t].info->xMax-pages[t].info->xMin; + if(pages[t].info->yMax-pages[t].info->yMin > ymax[y]) + ymax[y] = pages[t].info->yMax-pages[t].info->yMin; + } + for(x=0;x0?xmax[x-1]:0; + int ypos = y>0?ymax[y-1]:0; + pdf_page_info_t*info = pages[t].info; + xpos -= info->xMin; + ypos -= info->yMin; + msg(" Render (%d,%d)-(%d,%d) move:%d/%d\n", + info->xMin + xpos, + info->yMin + 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); + } + swf_output_endframe(swf); + for(t=0;t SWF written"); swf_output_destroy(swf);