Combined Annotation Edit and Text Select Tool

97 views
Skip to first unread message

Matt Parizeau

unread,
Jun 11, 2014, 1:42:47 PM6/11/14
to pdfnet-w...@googlegroups.com
Q:

Is it possible to have a tool that will allow selection of annotations and selection of text if the mouse isn't over any annotations?

A:

There isn't a built in tool to do this, but you can create a custom tool that combines the AnnotationEdit and TextSelect tools.

function getAnnotationByMouseEvent(pageCoordinate, annotations) {
   
for (var i = 0; i < annotations.length; i++) {
       
var annot = annotations[i];
       
if (annot.GetPageNumber() - 1 === pageCoordinate.pageIndex) {

           
var rect = {
                x1
: annot.GetLeft(),
                y1
: annot.GetTop(),
                x2
: annot.GetRight(),
                y2
: annot.GetBottom()
           
};
           
if (pageCoordinate.x >= rect.x1 && pageCoordinate.x <= rect.x2 && pageCoordinate.y >= rect.y1 && pageCoordinate.y <= rect.y2) {
               
return annot;
           
}
       
}
   
}

   
return null;
}

Tools.AnnotAndTextSelectTool = function(docViewer) {
   
Tools.TextSelectTool.call(this, docViewer);
   
this._editTool = new Tools.AnnotationEditTool(docViewer);
   
this._textSelectTool = new Tools.TextSelectTool(docViewer);
};
Tools.AnnotAndTextSelectTool.prototype = $.extend(new Tools.TextSelectTool(), {
    mouseLeftDown
: function(e) {
       
Tools.Tool.prototype.mouseLeftDown.call(this, e);
       
var am = this.docViewer.GetAnnotationManager();
       
       
if (e.originalEvent.touches && e.originalEvent.touches.length > 1) {
           
return true;
       
}

       
this._annot = getAnnotationByMouseEvent(this.pageCoordinates[0], am.GetAnnotationsList());

       
if (this._annot) {
           
this._editTool.mouseLeftDown(e);
       
} else {
            am
.DeselectAllAnnotations();
           
this._textSelectTool.mouseLeftDown(e);
       
}
   
},
    mouseLeftUp
: function(e) {
       
if (this._annot) {
           
this._editTool.mouseLeftUp(e);
       
} else {
           
this._textSelectTool.mouseLeftUp(e);
       
}
   
},
    mouseMove
: function(e) {
       
if (e.originalEvent.touches && e.originalEvent.touches.length > 1) {
           
return true;
       
}
       
if (this._annot) {
           
this._editTool.mouseMove(e);
       
} else {
           
this._textSelectTool.mouseMove(e);
       
}
   
},
    keyDown
: function(e) {
       
if (this._annot) {
           
this._editTool.keyDown(e);
       
} else {
           
this._textSelectTool.keyDown(e);
       
}
   
}
});

Reply all
Reply to author
Forward
0 new messages