+ 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;y<ynup;y++)
+ for(x=0;x<xnup;x++) {
+ int t = y*xnup + x;
+
+ if(pages[t].info->xMax-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;x<xnup;x++) {
+ width += xmax[x];
+ xmax[x] = width;
+ }
+ for(y=0;y<ynup;y++) {
+ height += ymax[y];
+ ymax[y] = height;
+ }
+ swf_output_startframe(swf, width, height);
+ for(t=0;t<pagenum;t++) {
+ int x = t%xnup;
+ int y = t/xnup;
+ int xpos = x>0?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("<verbose> 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<pagenum;t++) {
+ pdf_page_info_destroy(pages[t].info);
+ pdf_page_destroy(pages[t].page);
+ }
+ pagenum = 0;
+ }
+ }
+ if(swf_output_save(swf, outputname) < 0) {
+ exit(1);
+ }
+ msg("<notice> SWF written");
+ swf_output_destroy(swf);
+
+ pdf_destroy(pdf);
+
+ if(viewer || preloader) {
+#ifndef SYSTEM_BACKTICKS
+ msg("<warning> Not sure whether system() can handle command substitution");
+ msg("<warning> (According to config.h, it can't)");
+#endif
+ if(!system_quiet)
+ printf("\n");
+ }
+
+ char*zip = "";
+ if(zlib)
+ zip = "-z";
+
+ if(viewer && !preloader) {
+ systemf("swfcombine %s `swfdump -XY \"%s\"` \"%s\" viewport=\"%s\" -o \"%s\"",zip,
+ outputname, viewer, outputname, outputname);
+ if(!system_quiet)
+ printf("\n");
+ }
+ if(preloader && !viewer) {
+ msg("<warning> --preloader option without --viewer option doesn't make very much sense.");
+ ret = systemf("swfcombine %s `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip,
+ preloader, SWFDIR, preloader, outputname, outputname);
+ if(!system_quiet)
+ printf("\n");
+ }
+ if(preloader && viewer) {
+ systemf("swfcombine \"%s\" viewport=%s -o __tmp__.swf",
+ viewer, outputname, outputname);
+ 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);
+ systemf("rm __tmp__.swf");