From e433863f096fb0fdca2fd6915b7bad4f48869edb Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Fri, 20 Mar 2015 10:09:33 -0700 Subject: [PATCH] Test for clip feature --- src/tiledimage.js | 8 ++++---- test/modules/tiledimage.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index 48e2773b..405989b7 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -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; } diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js index 44dc9327..704f4773 100644 --- a/test/modules/tiledimage.js +++ b/test/modules/tiledimage.js @@ -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 + }); + }); + })();