X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fdevices%2Frescale.c;h=350dfd2b849bf498ba87eb070ba9d790df954bd8;hb=7fb4a4ac393f19a0b8a8998a2f1deac88c97eda0;hp=53d3623f061a1975986b62f3f81e6b1a1b7ad795;hpb=0784a8a882e7b98299fb6a90f0f9a7ebb322562b;p=swftools.git diff --git a/lib/devices/rescale.c b/lib/devices/rescale.c index 53d3623..350dfd2 100644 --- a/lib/devices/rescale.c +++ b/lib/devices/rescale.c @@ -54,7 +54,7 @@ static void dbg(char*format, ...) int l; va_list arglist; va_start(arglist, format); - vsprintf(buf, format, arglist); + vsnprintf(buf, sizeof(buf)-1, format, arglist); va_end(arglist); l = strlen(buf); while(l && buf[l-1]=='\n') { @@ -121,6 +121,12 @@ int rescale_setparameter(gfxdevice_t*dev, const char*key, const char*value) if(!strcmp(key, "keepratio")) { i->keepratio = atoi(value); return 1; + } else if(!strcmp(key, "centerx")) { + i->centerx = atoi(value); + return 1; + } else if(!strcmp(key, "centery")) { + i->centery = atoi(value); + return 1; } else { if(i->out) { return i->out->setparameter(i->out,key,value); @@ -137,31 +143,37 @@ void rescale_startpage(gfxdevice_t*dev, int width, int height) i->origwidth = width; i->origheight = height; - if(i->targetwidth && i->targetheight) { + if(i->targetwidth || i->targetheight) { + int targetwidth = i->targetwidth; + if(!targetwidth) + targetwidth = width*i->targetheight/height; + int targetheight = i->targetheight; + if(!targetheight) + targetheight = height*i->targetwidth/width; if(i->keepratio) { - double rx = (double)i->targetwidth / (double)width; - double ry = (double)i->targetheight / (double)height; + double rx = (double)targetwidth / (double)width; + double ry = (double)targetheight / (double)height; if(rxmatrix.m00 = rx; i->matrix.m11 = rx; i->matrix.tx = 0; if(i->centery) { - i->matrix.ty = (i->targetheight - height*rx) / 2; + i->matrix.ty = (targetheight - height*rx) / 2; } } else { i->matrix.m00 = ry; i->matrix.m11 = ry; if(i->centerx) { - i->matrix.tx = (i->targetwidth - width*ry) / 2; + i->matrix.tx = (targetwidth - width*ry) / 2; } i->matrix.ty = 0; } } else { - i->matrix.m00 = (double)i->targetwidth / (double)width; - i->matrix.m11 = (double)i->targetheight / (double)height; + i->matrix.m00 = (double)targetwidth / (double)width; + i->matrix.m11 = (double)targetheight / (double)height; } i->zoomwidth = sqrt(i->matrix.m00*i->matrix.m11); - i->out->startpage(i->out,i->targetwidth,i->targetheight); + i->out->startpage(i->out,targetwidth,targetheight); } else { i->out->startpage(i->out,(int)(width*i->matrix.m00),(int)(height*i->matrix.m11)); } @@ -211,7 +223,7 @@ void rescale_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradien { internal_t*i = (internal_t*)dev->internal; gfxline_t*line2 = transformgfxline(i, line); - i->out->fillgradient(i->out, line, gradient, type, matrix); + i->out->fillgradient(i->out, line2, gradient, type, matrix); gfxline_free(line2); } @@ -233,7 +245,7 @@ void rescale_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action) { internal_t*i = (internal_t*)dev->internal; gfxline_t*line2 = transformgfxline(i, line); - i->out->drawlink(i->out, line, action); + i->out->drawlink(i->out, line2, action); gfxline_free(line2); } @@ -319,3 +331,10 @@ void gfxdevice_rescale_setdevice(gfxdevice_t*dev, gfxdevice_t*out) } i->out = out; } + +gfxdevice_t* gfxdevice_rescale_new(gfxdevice_t*out, int width, int height, double scale) +{ + gfxdevice_t* d = (gfxdevice_t*)malloc(sizeof(gfxdevice_t)); + gfxdevice_rescale_init(d, out, width, height, scale); + return d; +}