mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
add tests for resizeBounds
This commit is contained in:
parent
85706166cc
commit
67ccb33dd5
@ -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) {
|
||||
|
@ -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'
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user