Center scaled image in the available target space when preserving aspect

This commit is contained in:
Manuel Reimer 2014-11-09 10:57:12 +01:00
parent 28413f7f2c
commit 0d5773cb7f

View File

@ -33,10 +33,17 @@ cImage *cImageLoader::CreateImage(int width, int height, bool preserveAspect) {
double sx = width / (double)w;
double sy = height / (double)h;
if (preserveAspect) {
if (sx < sy)
double tx = 0;
double ty = 0;
if (sx < sy) {
sy = sx;
if (sy < sx)
ty = (height - h * sy) / 2;
}
if (sy < sx) {
sx = sy;
tx = (width - w * sx) / 2;
}
cairo_translate(cr, tx, ty);
}
cairo_scale(cr, sx, sy);