From bcdeea968b4e4ec2cfdfaa21a7f6151a875fd5ce Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Thu, 28 May 2009 13:15:31 -0700 Subject: [PATCH] added '-s zoomtowidth' option to pdf2swf --- lib/pdf/pdf.cc | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/pdf/pdf.cc b/lib/pdf/pdf.cc index 4a90bf5..a0d9c6a 100644 --- a/lib/pdf/pdf.cc +++ b/lib/pdf/pdf.cc @@ -14,8 +14,7 @@ #include "../args.h" static double zoom = 72; /* xpdf: 86 */ -static int jpeg_dpi = 0; -static int ppm_dpi = 0; +static int zoomtowidth = 0; static int multiply = 1; static char* global_page_range = 0; @@ -406,23 +405,13 @@ static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value addGlobalFont(value); } else if(!strncmp(name, "languagedir", strlen("languagedir"))) { addGlobalLanguageDir(value); + } else if(!strcmp(name, "zoomtowidth")) { + zoomtowidth = atoi(value); } else if(!strcmp(name, "zoom")) { char buf[80]; zoom = atof(value); - sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom); - storeDeviceParameter(p, "jpegsubpixels", buf); - sprintf(buf, "%f", (double)ppm_dpi/(double)zoom); - storeDeviceParameter(p, "ppmsubpixels", buf); - } else if(!strcmp(name, "jpegdpi")) { - char buf[80]; - jpeg_dpi = atoi(value); - sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom); - storeDeviceParameter(p, "jpegsubpixels", buf); - } else if(!strcmp(name, "ppmdpi")) { - char buf[80]; - ppm_dpi = atoi(value); - sprintf(buf, "%f", (double)ppm_dpi/(double)zoom); - storeDeviceParameter(p, "ppmsubpixels", buf); + } else if(!strcmp(name, "jpegdpi") || !strcmp(name, "ppmdpi")) { + msg(" %s not supported anymore. Please use jpegsubpixels/ppmsubpixels"); } else if(!strcmp(name, "multiply")) { multiply = atoi(value); } else if(!strcmp(name, "help")) { @@ -496,6 +485,14 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename) if(!i->doc->okToChange() || !i->doc->okToAddNotes()) i->protect = 1; } + + if(zoomtowidth && i->doc->getNumPages()) { + Page*page = i->doc->getCatalog()->getPage(1); + PDFRectangle *r = page->getCropBox(); + double width_before = r->x2 - r->x1; + zoom = 72.0 * zoomtowidth / width_before; + msg(" Rendering at %f DPI. (Page width at 72 DPI: %f, target width: %d)", zoom, width_before, zoomtowidth); + } i->info = new InfoOutputDev(i->doc->getXRef()); int t; -- 1.7.10.4