var boundingAnnot;
$(document).on('documentLoaded', function() {
boundingAnnot = new Annotations.RectangleAnnotation();
boundingAnnot.PageNumber = 1;
boundingAnnot.X = 200;
boundingAnnot.Y = 200;
boundingAnnot.Width = 200;
boundingAnnot.Height = 200;
readerControl.docViewer.getAnnotationManager().addAnnotation(boundingAnnot);
readerControl.docViewer.getAnnotationManager().redrawAnnotation(boundingAnnot);
});
var mouseLeftDown = Tools.RectangleCreateTool.prototype.mouseLeftDown;
Tools.RectangleCreateTool.prototype.mouseLeftDown = function(e) {
mouseLeftDown.apply(this, arguments);
if (!isPointInBound(e.data.pageCoordinate, boundingAnnot)) {
this.annotation = null;
}
}
var mouseMove = Tools.RectangleCreateTool.prototype.mouseMove;
Tools.RectangleCreateTool.prototype.mouseMove = function(e) {
mouseMove.apply(this, arguments);
if (this.annotation) {
if (!isPointInBound(e.data.pageCoordinate, boundingAnnot)) {
var annotRect = this.annotation.getRect();
var boundingRect = boundingAnnot.getRect();
if (annotRect.x1 < boundingRect.x1) {
annotRect.x1 = boundingRect.x1;
}
if (annotRect.y1 < boundingRect.y1) {
annotRect.y1 = boundingRect.y1;
}
if (annotRect.x2 > boundingRect.x2) {
annotRect.x2 = boundingRect.x2;
}
if (annotRect.y2 > boundingRect.y2) {
annotRect.y2 = boundingRect.y2;
}
this.annotation.setRect(annotRect);
readerControl.docViewer.getAnnotationManager().redrawAnnotation(this.annotation);
}
}
}
var isPointInBound = function(pageCoordinate, boundingAnnot) {
if (!pageCoordinate) {
return;
}
var mouseX = pageCoordinate.x;
var mouseY = pageCoordinate.y;
return (mouseX >= boundingAnnot.X && mouseX <= boundingAnnot.X + boundingAnnot.Width &&
mouseY >= boundingAnnot.Y && mouseY <= boundingAnnot.Y + boundingAnnot.Height);
}