From d476c08237990b0ef8af3e32fd109c3ac9253fc6 Mon Sep 17 00:00:00 2001 From: timw Date: Mon, 6 Aug 2012 11:17:48 +1200 Subject: [PATCH] Add resolution base scaling to swfrender using a -r parameter to specify the desired output DPI. This relies on assuming that production of swf via pdf2swf uses a 72dpi resolution (e.g. it maps one pt in the input document to one px in the swf), and so a DPI based resolution for the output image can be translated to a scaling factor. --- src/swfrender.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/swfrender.c b/src/swfrender.c index ff1e063..dafb6de 100644 --- a/src/swfrender.c +++ b/src/swfrender.c @@ -16,6 +16,7 @@ static struct options_t options[] = { {"h", "help"}, {"o", "output"}, {"p", "pages"}, +{"r", "resolution"}, {"l", "legacy"}, {"V", "version"}, {"X", "width"}, @@ -31,6 +32,7 @@ static char*pagerange = 0; static int width = 0; static int height = 0; +static int resolution = 0; typedef struct _parameter { const char*name; @@ -57,6 +59,9 @@ int args_callback_option(char*name,char*val) } else if(!strcmp(name, "p")) { pagerange = val; return 1; + } else if(!strcmp(name, "r")) { + resolution = atoi(val); + return 1; } else if(!strcmp(name, "s")) { char*s = strdup(val); char*c = strchr(s, '='); @@ -99,6 +104,7 @@ void args_callback_usage(char *name) printf("-l , --legacy Use old rendering framework\n"); printf("-o , --output Output file, suffixed for multiple pages (default: output.png)\n"); printf("-p , --pages range Render pages in specified range e.g. 9 or 1-20 or 1,4-6,9-11 (default: all pages)\n"); + printf("-r , --resolution dpi Scale width and height to a specific DPI resolution, assuming input is 1px per pt (default: 72)\n"); printf("-X , --width width Scale output to specific width (proportional unless height specified)\n"); printf("-Y , --height height Scale output to specific height (proportional unless width specified)\n"); printf("\n"); @@ -126,6 +132,11 @@ int main(int argn, char*argv[]) fprintf(stderr, "You must supply a filename.\n"); return 1; } + + if (resolution && (width || height)) { + fprintf(stderr, "Height/width cannot be specified with resolution.\n"); + return 1; + } if(!ng) { fi = open(filename, O_RDONLY|O_BINARY); @@ -186,8 +197,13 @@ int main(int argn, char*argv[]) if(quantize) { dev->setparameter(dev, "palette", "1"); } - if(width || height) { - dev = gfxdevice_rescale_new(dev, width, height, 0); + if(width || height || resolution) { + double scale = 0.0; + if (resolution) { + /* Assume input is generated by pdf2swf at 72dpi (1px == 1pt) */ + scale = resolution / 72.0; + } + dev = gfxdevice_rescale_new(dev, width, height, scale); } for(p=params;p;p=p->next) { dev->setparameter(dev, p->name, p->value); -- 1.7.9