diff --git a/src/Core.js b/src/Core.js index 1db2d96..73bbe6e 100644 --- a/src/Core.js +++ b/src/Core.js @@ -245,7 +245,7 @@ _html2canvas.Util.getCSS = function (el, attribute, index) { return val; }; -function resize(current_width, current_height, target_width, target_height, stretch_mode){ +_html2canvas.Util.resizeBounds = function( current_width, current_height, target_width, target_height, stretch_mode ){ var target_ratio = target_width / target_height, current_ratio = current_width / current_height, output_width, output_height; @@ -265,7 +265,7 @@ function resize(current_width, current_height, target_width, target_height, stre } return { width: output_width, height: output_height }; -} +}; function backgroundBoundsFactory( prop, el, bounds, image, imageIndex ) { // TODO add support for multi image backgrounds @@ -299,7 +299,7 @@ function backgroundBoundsFactory( prop, el, bounds, image, imageIndex ) { if(left === undefined) { if(bgposition[0].match(/contain|cover/)) { - var resized = resize( image.width, image.height, bounds.width, bounds.height, bgposition[0] ); + var resized = _html2canvas.Util.resizeBounds( image.width, image.height, bounds.width, bounds.height, bgposition[0] ); left = resized.width; topPos = resized.height; } else { @@ -336,7 +336,6 @@ _html2canvas.Util.BackgroundSize = function( el, bounds, image, imageIndex ) { var result = backgroundBoundsFactory( 'backgroundSize', el, bounds, image, imageIndex ); return { width: result[0], height: result[1] }; }; -window._html2canvas = _html2canvas; _html2canvas.Util.Extend = function (options, defaults) { for (var key in options) { diff --git a/tests/qunit/unit/utils.js b/tests/qunit/unit/utils.js index 53d73d7..019138d 100644 --- a/tests/qunit/unit/utils.js +++ b/tests/qunit/unit/utils.js @@ -14,5 +14,33 @@ $(function() { // text nodes differ QUnit.equal( _html2canvas.Util.Children(el[0]), arr, "Util.Children === jQuery.children()" ); }); + + test('resizeBounds', function(){ + + QUnit.deepEqual( + _html2canvas.Util.resizeBounds(100, 100, 100, 100), + { width: 100, height: 100 }, + 'no resize' + ); + + QUnit.deepEqual( + _html2canvas.Util.resizeBounds(100, 100, 2, 100), + { width: 20, height: 100 }, + 'stretch' + ); + + QUnit.deepEqual( + _html2canvas.Util.resizeBounds(100, 100, 2, 100, 'contain'), + { width: 2, height: 2 }, + 'contain' + ); + + QUnit.deepEqual( + _html2canvas.Util.resizeBounds(100, 100, 2, 100, 'cover'), + { width: 100, height: 100 }, + 'contain' + ); + + }); });