Created
April 23, 2012 19:41
-
-
Save monteslu/2473328 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
], function(){ | |
return function(gfxSurfaceW, gfxSurfaceH, canvasW, canvasH, borderThickness, textOffset){ | |
var surfaceRatio = (gfxSurfaceW * 1.0) / (gfxSurfaceH * 1.0); | |
var canvasRatio = (canvasW * 1.0) / (canvasH * 1.0); | |
if(canvasRatio > surfaceRatio){ | |
//stick box to left | |
var xRemaining = gfxSurfaceW - (textOffset * 2); | |
var pxPerInch = xRemaining / (canvasW + (borderThickness * 2)); | |
var x = (borderThickness * pxPerInch) + textOffset; | |
var y = (gfxSurfaceH / 2 ) - ((canvasH * pxPerInch) / 2); | |
return { | |
x: x, | |
y: y, | |
width: pxPerInch * canvasW, | |
height: pxPerInch * canvasH, | |
pxPerInch: pxPerInch | |
}; | |
}else{ | |
//stick box to top | |
var yRemaining = gfxSurfaceH - (textOffset * 2); | |
var pxPerInch = yRemaining / (canvasH + (borderThickness * 2)); | |
var y = (borderThickness * pxPerInch) + textOffset; | |
var x = (gfxSurfaceW / 2 ) - ((canvasW * pxPerInch) / 2); | |
return { | |
x: x, | |
y: y, | |
width: pxPerInch * canvasW, | |
height: pxPerInch * canvasH, | |
pxPerInch: pxPerInch | |
}; | |
} | |
} | |
}); | |
console.log('canvasSizing Portrait', canvasSizing(620,620,8,10,1,20)); | |
console.log('canvasSizing portait big', canvasSizing(620,620,16,20,1,20)); | |
console.log('canvasSizing landscape', canvasSizing(620,620,10,8,1,20)); | |
console.log('canvasSizing landscape big', canvasSizing(620,620,20,16,1,20)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment