Test for clip feature

This commit is contained in:
Ian Gilman 2015-03-20 10:09:33 -07:00
parent c27f68640f
commit e433863f09
2 changed files with 33 additions and 4 deletions

View File

@ -1163,10 +1163,10 @@ function drawTiles( tiledImage, lastDrawn ){
var box = tiledImage.imageToViewportRectangle(tiledImage._clip, true);
var topLeft = tiledImage.viewport.pixelFromPoint(box.getTopLeft(), true);
var size = tiledImage.viewport.deltaPixelsFromPoints(box.getSize(), true);
box = new OpenSeadragon.Rect(Math.round(topLeft.x * $.pixelDensityRatio),
Math.round(topLeft.y * $.pixelDensityRatio),
Math.round(size.x * $.pixelDensityRatio),
Math.round(size.y * $.pixelDensityRatio));
box = new OpenSeadragon.Rect(topLeft.x * $.pixelDensityRatio,
topLeft.y * $.pixelDensityRatio,
size.x * $.pixelDensityRatio,
size.y * $.pixelDensityRatio);
tiledImage._drawer.setClip(box);
usedClip = true;
}

View File

@ -191,4 +191,33 @@
viewer.open('/test/data/testpattern.dzi');
});
// ----------
asyncTest('clip', function() {
var clip = new OpenSeadragon.Rect(100, 100, 800, 800);
viewer.addHandler('open', function() {
var image = viewer.world.getItemAt(0);
propEqual(image.getClip(), clip, 'image has correct clip');
image.setClip(null);
equal(image.getClip(), null, 'clip is cleared');
image.setClip(clip);
propEqual(image.getClip(), clip, 'clip is set correctly');
Util.spyOnce(viewer.drawer, 'setClip', function(rect) {
ok(true, 'drawer.setClip is called');
var pixelRatio = viewer.viewport.getContainerSize().x / image.getContentSize().x;
var canvasClip = clip.times(pixelRatio * OpenSeadragon.pixelDensityRatio);
propEqual(rect, canvasClip, 'clipping to correct rect');
start();
});
});
viewer.open({
tileSource: '/test/data/testpattern.dzi',
clip: clip
});
});
})();