+ if(abs(size[0])<abs(size[1])) // if canvas is tall and thin
+ {
+ x[0]=size[0]; // use full width
+ x[1]=size[0]/w*h; // and scale for height
+ if((size[0]<0) ^ (size[1]<0))
+ x[1]=-x[1];
+ }
+ else // else canvas is short and fat (or maybe square)
+ {
+ x[1]=size[1]; // use full height
+ x[0]=size[1]/h*w; // and scale for width
+ if((size[0]<0) ^ (size[1]<0))
+ x[0]=-x[0];
+ }