@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
873 lines (872 loc) • 184 kB
JavaScript
import { PdfViewerBase } from '../index';
import { createElement, Browser, isNullOrUndefined, isBlazor } from '@syncfusion/ej2-base';
/**
* The `TextMarkupAnnotation` module is used to handle text markup annotation actions of PDF viewer.
*
* @hidden
* @param {Event} event - It describes about the event
* @returns {void}
*/
var TextMarkupAnnotation = /** @class */ (function () {
/**
* @param {PdfViewer} pdfViewer - It describes about the pdfViewer
* @param {PdfViewerBase} viewerBase - It describes about the viewerBase
* @private
* @returns {void}
*/
function TextMarkupAnnotation(pdfViewer, viewerBase) {
var _this = this;
/**
* @private
*/
this.currentTextMarkupAddMode = '';
/**
* @private
*/
this.selectTextMarkupCurrentPage = null;
/**
* @private
*/
this.currentTextMarkupAnnotation = null;
/**
* @private
*/
this.isAddAnnotationProgramatically = false;
this.currentAnnotationIndex = null;
this.isAnnotationSelect = false;
/**
* @private
*/
this.isDropletClicked = false;
/**
* @private
*/
this.isRightDropletClicked = false;
/**
* @private
*/
this.isLeftDropletClicked = false;
/**
* @private
*/
this.isSelectionMaintained = false;
this.isExtended = false;
this.isNewAnnotation = false;
this.selectedTextMarkup = null;
this.multiPageCollection = [];
this.triggerAddEvent = false;
/**
* @private
*/
this.isSelectedAnnotation = false;
this.dropletHeight = 20;
// To update the height value of strikethrough and underline annotations for Chinese language (Task ID: 861029).
this.strikeoutDifference = -3;
this.underlineDifference = 2;
/**
* @private
*/
this.annotationClickPosition = {};
this.maintainSelection = function () {
_this.isDropletClicked = true;
_this.pdfViewer.textSelectionModule.initiateSelectionByTouch();
_this.isExtended = true;
_this.pdfViewer.textSelectionModule.selectionRangeArray = [];
};
this.selectionEnd = function () {
if (_this.isDropletClicked) {
_this.isDropletClicked = false;
}
};
this.annotationLeftMove = function () {
if (_this.isDropletClicked) {
_this.isLeftDropletClicked = true;
}
};
this.annotationRightMove = function () {
if (_this.isDropletClicked) {
_this.isRightDropletClicked = true;
}
};
this.pdfViewer = pdfViewer;
this.pdfViewerBase = viewerBase;
}
/**
* @private
* @returns {void}
*/
TextMarkupAnnotation.prototype.createAnnotationSelectElement = function () {
this.dropDivAnnotationLeft = createElement('div', { id: this.pdfViewer.element.id + '_droplet_left', className: 'e-pv-drop' });
this.dropDivAnnotationLeft.style.borderRight = '2px solid';
this.dropDivAnnotationRight = createElement('div', { id: this.pdfViewer.element.id + '_droplet_right', className: 'e-pv-drop' });
this.dropDivAnnotationRight.style.borderLeft = '2px solid';
this.dropElementLeft = createElement('div', { className: 'e-pv-droplet', id: this.pdfViewer.element.id + '_dropletspan_left' });
this.dropElementLeft.style.transform = 'rotate(0deg)';
this.dropDivAnnotationLeft.appendChild(this.dropElementLeft);
this.dropElementRight = createElement('div', { className: 'e-pv-droplet', id: this.pdfViewer.element.id + '_dropletspan_right' });
this.dropElementRight.style.transform = 'rotate(-90deg)';
this.dropDivAnnotationRight.appendChild(this.dropElementRight);
this.pdfViewerBase.pageContainer.appendChild(this.dropDivAnnotationLeft);
this.pdfViewerBase.pageContainer.appendChild(this.dropDivAnnotationRight);
this.dropElementLeft.style.top = '20px';
this.dropElementRight.style.top = '20px';
this.dropElementRight.style.left = '-8px';
this.dropElementLeft.style.left = '-8px';
this.dropDivAnnotationLeft.style.display = 'none';
this.dropDivAnnotationRight.style.display = 'none';
this.dropDivAnnotationLeft.addEventListener('mousedown', this.maintainSelection);
this.dropDivAnnotationLeft.addEventListener('mousemove', this.annotationLeftMove);
this.dropDivAnnotationLeft.addEventListener('mouseup', this.selectionEnd);
this.dropDivAnnotationRight.addEventListener('mousedown', this.maintainSelection);
this.dropDivAnnotationRight.addEventListener('mousemove', this.annotationRightMove);
this.dropDivAnnotationRight.addEventListener('mouseup', this.selectionEnd);
};
/**
* @param {any} target - It describes about the target
* @param {any} x - It describes about the X
* @param {any} y - It describes about the Y
* @private
* @returns {void}
*/
TextMarkupAnnotation.prototype.textSelect = function (target, x, y) {
if (this.isLeftDropletClicked) {
var leftElement = this.dropDivAnnotationRight.getBoundingClientRect();
var rightElement = this.dropDivAnnotationLeft.getBoundingClientRect();
var clientX = x;
var clientY = y;
if (target.classList.contains('e-pv-text')) {
if ((rightElement.top - 25) > leftElement.top) {
this.pdfViewer.textSelectionModule.textSelectionOnDrag(target, clientX, clientY, true);
}
else {
this.pdfViewer.textSelectionModule.textSelectionOnDrag(target, clientX, clientY, false);
}
this.updateLeftposition(clientX, clientY);
}
}
else if (this.isRightDropletClicked) {
var leftElement = this.dropDivAnnotationLeft.getBoundingClientRect();
var clientX = x;
var clientY = y;
if (target.classList.contains('e-pv-text')) {
if ((clientY) >= leftElement.top) {
this.pdfViewer.textSelectionModule.textSelectionOnDrag(target, clientX, clientY, true);
}
else {
this.pdfViewer.textSelectionModule.textSelectionOnDrag(target, clientX, clientY, false);
}
this.updatePosition(clientX, clientY);
}
}
};
/**
* @param {boolean} hide - It describes about the hide
* @private
* @returns {void}
*/
TextMarkupAnnotation.prototype.showHideDropletDiv = function (hide) {
var type = this.pdfViewer.annotationModule.textMarkupAnnotationModule.currentTextMarkupAddMode;
var isEnableResizer = this.isEnableTextMarkupResizer(type);
if (isEnableResizer && this.dropDivAnnotationLeft && this.dropDivAnnotationRight) {
if (hide) {
this.dropDivAnnotationLeft.style.display = 'none';
this.dropDivAnnotationRight.style.display = 'none';
}
else {
this.dropDivAnnotationLeft.style.display = '';
this.dropDivAnnotationRight.style.display = '';
this.updateDropletStyles(type);
}
}
};
/**
* @param {string} type - It describes about the type
* @private
* @returns {boolean} - boolean
*/
TextMarkupAnnotation.prototype.isEnableTextMarkupResizer = function (type) {
var isEnableResizer = false;
if (type) {
if (type === 'Highlight' && this.pdfViewer.highlightSettings.enableTextMarkupResizer) {
isEnableResizer = true;
}
else if (type === 'Underline' && this.pdfViewer.underlineSettings.enableTextMarkupResizer) {
isEnableResizer = true;
}
else if (type === 'Strikethrough' && this.pdfViewer.strikethroughSettings.enableTextMarkupResizer) {
isEnableResizer = true;
}
else if (this.pdfViewer.enableTextMarkupResizer) {
isEnableResizer = true;
}
}
else {
if (this.pdfViewer.enableTextMarkupResizer) {
isEnableResizer = true;
}
else if (this.pdfViewer.highlightSettings.enableTextMarkupResizer) {
isEnableResizer = true;
}
else if (this.pdfViewer.underlineSettings.enableTextMarkupResizer) {
isEnableResizer = true;
}
else if (this.pdfViewer.strikethroughSettings.enableTextMarkupResizer) {
isEnableResizer = true;
}
}
return isEnableResizer;
};
TextMarkupAnnotation.prototype.updateDropletStyles = function (type) {
if (this.isEnableTextMarkupResizer(type) && this.dropDivAnnotationLeft && this.dropDivAnnotationLeft.offsetWidth > 0) {
this.dropDivAnnotationLeft.style.width = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropDivAnnotationRight.style.width = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropElementLeft.style.width = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropElementRight.style.width = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropDivAnnotationLeft.style.height = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropDivAnnotationRight.style.height = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropElementLeft.style.height = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropElementRight.style.height = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropElementLeft.style.top = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
this.dropElementRight.style.top = this.dropletHeight * this.pdfViewerBase.getZoomFactor() + 'px';
}
};
TextMarkupAnnotation.prototype.updateAnnotationBounds = function () {
this.isSelectionMaintained = false;
var annotation = this.currentTextMarkupAnnotation;
if (annotation && annotation.isMultiSelect) {
this.showHideDropletDiv(true);
this.updateMultiAnnotBounds(annotation);
}
else if (annotation && annotation.bounds) {
this.retreieveSelection(annotation, null);
this.pdfViewer.textSelectionModule.maintainSelection(this.selectTextMarkupCurrentPage, false);
this.isSelectionMaintained = true;
window.getSelection().removeAllRanges();
}
};
TextMarkupAnnotation.prototype.updateMultiAnnotBounds = function (annotation) {
if (!annotation.annotpageNumbers) {
var annotationList = this.getAnnotations(annotation.pageNumber, null);
if (annotationList) {
for (var z = 0; z < annotationList.length; z++) {
if (annotationList[parseInt(z.toString(), 10)].annotName === annotation.annotName) {
annotation = annotationList[parseInt(z.toString(), 10)];
break;
}
}
}
}
var lowestNumber = annotation.annotpageNumbers[0];
var highestNumber = annotation.annotpageNumbers[0];
for (var p = 0; p < annotation.annotpageNumbers.length; p++) {
var currentPage = annotation.annotpageNumbers[parseInt(p.toString(), 10)];
if (currentPage >= highestNumber) {
highestNumber = currentPage;
}
if (currentPage <= lowestNumber) {
lowestNumber = currentPage;
}
}
for (var k = lowestNumber; k <= highestNumber; k++) {
var annotationList = this.getAnnotations(k, null);
if (annotationList) {
for (var j = 0; j < annotation.annotNameCollection.length; j++) {
var currentAnnot = annotation.annotNameCollection[parseInt(j.toString(), 10)];
for (var z = 0; z < annotationList.length; z++) {
if (annotationList[parseInt(z.toString(), 10)].annotName === currentAnnot) {
var newAnnotation = annotationList[parseInt(z.toString(), 10)];
this.retreieveSelection(newAnnotation, null);
this.pdfViewer.textSelectionModule.maintainSelection(newAnnotation.pageNumber, false);
}
}
}
}
}
this.isSelectionMaintained = true;
window.getSelection().removeAllRanges();
};
TextMarkupAnnotation.prototype.retreieveSelection = function (annotation, element) {
for (var k = 0; k < annotation.bounds.length; k++) {
var bound = annotation.bounds[parseInt(k.toString(), 10)];
var x = (bound.left ? bound.left : bound.Left) * this.pdfViewerBase.getZoomFactor();
var y = (bound.top ? bound.top : bound.Top) * this.pdfViewerBase.getZoomFactor();
var width = (bound.width ? bound.width : bound.Width) * this.pdfViewerBase.getZoomFactor();
var textLayer = this.pdfViewerBase.getElement('_textLayer_' + annotation.pageNumber);
if (textLayer) {
var textDivs = textLayer.childNodes;
for (var n = 0; n < textDivs.length; n++) {
if (textDivs[parseInt(n.toString(), 10)]) {
var rangebounds = textDivs[parseInt(n.toString(), 10)].getBoundingClientRect();
var top_1 = this.getClientValueTop(rangebounds.top, annotation.pageNumber);
var currentLeft = rangebounds.left - this.pdfViewerBase.getElement('_pageDiv_' + annotation.pageNumber).getBoundingClientRect().left;
var totalLeft = currentLeft + rangebounds.width;
var textDiVLeft = parseInt(textDivs[parseInt(n.toString(), 10)].style.left, 10);
var currentTop = parseInt(textDivs[parseInt(n.toString(), 10)].style.top, 10);
var isLeftBounds = this.pdfViewer.textSelectionModule.
checkLeftBounds(currentLeft, textDiVLeft, totalLeft, x);
var isTopBounds = this.pdfViewer.textSelectionModule.checkTopBounds(top_1, currentTop, y);
if (isLeftBounds && isTopBounds) {
element = textDivs[parseInt(n.toString(), 10)];
break;
}
}
}
if (element != null) {
var boundingRect = this.pdfViewerBase.getElement('_textLayer_' + annotation.pageNumber).getBoundingClientRect();
this.pdfViewer.textSelectionModule.textSelectionOnMouseMove(element, x + boundingRect.left, y + boundingRect.top, false);
if ((annotation.bounds.length - 1) === k) {
this.pdfViewer.textSelectionModule.textSelectionOnMouseMove(element, x + boundingRect.left + width, y + boundingRect.top, false);
}
}
}
}
};
/**
* @param {number} x - It describes about the X
* @param {number} y - It describes about the Y
* @param {boolean} isSelected - It describes about the isSelected
* @private
* @returns {void}
*/
TextMarkupAnnotation.prototype.updatePosition = function (x, y, isSelected) {
this.showHideDropletDiv(false);
var pageTopValue = this.pdfViewerBase.pageSize[this.pdfViewerBase.currentPageNumber - 1].top;
var topClientValue = this.getClientValueTop(y, this.pdfViewerBase.currentPageNumber - 1);
var rightDivElement = document.getElementById(this.pdfViewer.element.id + '_droplet_right');
if (isSelected) {
rightDivElement.style.top = topClientValue * this.pdfViewerBase.getZoomFactor() + pageTopValue * this.pdfViewerBase.getZoomFactor() + 'px';
}
else {
rightDivElement.style.top = topClientValue + pageTopValue * this.pdfViewerBase.getZoomFactor() + 'px';
}
rightDivElement.style.left = x + this.pdfViewerBase.viewerContainer.scrollLeft - this.pdfViewerBase.viewerContainer.getBoundingClientRect().left + 'px';
};
/**
* @param {number} x - It describes about the X
* @param {number} y - It describes about the Y
* @param {boolean} isSelected - It describes about the isSelected
* @private
* @returns {void}
*/
TextMarkupAnnotation.prototype.updateLeftposition = function (x, y, isSelected) {
this.showHideDropletDiv(false);
var pageTopValue = this.pdfViewerBase.pageSize[this.pdfViewerBase.currentPageNumber - 1].top;
var topClientValue = this.getClientValueTop(y, this.pdfViewerBase.currentPageNumber - 1);
var leftDivElement = document.getElementById(this.pdfViewer.element.id + '_droplet_left');
leftDivElement.style.display = '';
if (isSelected) {
leftDivElement.style.top = topClientValue * this.pdfViewerBase.getZoomFactor() + pageTopValue * this.pdfViewerBase.getZoomFactor() + 'px';
}
else {
leftDivElement.style.top = topClientValue + pageTopValue * this.pdfViewerBase.getZoomFactor() + 'px';
}
leftDivElement.style.left = x + this.pdfViewerBase.viewerContainer.scrollLeft - this.pdfViewerBase.viewerContainer.getBoundingClientRect().left - (this.dropletHeight * this.pdfViewerBase.getZoomFactor()) + 'px';
};
TextMarkupAnnotation.prototype.getClientValueTop = function (clientValue, pageNumber) {
if (this.pdfViewerBase.getElement('_pageDiv_' + pageNumber)) {
return clientValue - this.pdfViewerBase.getElement('_pageDiv_' + pageNumber).getBoundingClientRect().top;
}
else {
return clientValue;
}
};
/**
* @param {any} textMarkupAnnotations - It describes about the text markup annotations
* @param {number} pageNumber - It describes about the page number
* @param {boolean} isImportTextMarkup - It describes about the isImportTextMarkup
* @param {boolean} isAnnotOrderAction - It describes about the isAnnotOrderAction
* @private
* @returns {void}
*/
TextMarkupAnnotation.prototype.renderTextMarkupAnnotationsInPage = function (textMarkupAnnotations, pageNumber, isImportTextMarkup, isAnnotOrderAction) {
var canvasId = textMarkupAnnotations && textMarkupAnnotations.textMarkupAnnotationType === 'Highlight' ? '_blendAnnotationsIntoCanvas_' : '_annotationCanvas_';
var canvas = (canvasId === '_blendAnnotationsIntoCanvas_') ? this.pdfViewerBase.getElement(canvasId + pageNumber) :
this.pdfViewerBase.getAnnotationCanvas(canvasId, pageNumber);
if (isImportTextMarkup) {
this.renderTextMarkupAnnotations(null, pageNumber, canvas, this.pdfViewerBase.getZoomFactor());
this.renderTextMarkupAnnotations(textMarkupAnnotations, pageNumber, canvas, this.pdfViewerBase.getZoomFactor(), true);
}
else {
this.renderTextMarkupAnnotations(textMarkupAnnotations, pageNumber, canvas, this.pdfViewerBase.getZoomFactor(), null, isAnnotOrderAction);
}
};
TextMarkupAnnotation.prototype.renderTextMarkupAnnotations = function (textMarkupAnnotations, pageNumber, canvas, factor, isImportAction, isAnnotOrderAction) {
var highlightCanvasContext = null;
if (canvas) {
var context = canvas.getContext('2d');
context.setTransform(1, 0, 0, 1, 0, 0);
context.setLineDash([]);
var annotations_1;
if (!isImportAction && !isAnnotOrderAction) {
annotations_1 = this.getAnnotations(pageNumber, textMarkupAnnotations);
}
else {
annotations_1 = textMarkupAnnotations;
}
if (textMarkupAnnotations) {
textMarkupAnnotations.forEach(function (textMarkupAnnotation) {
var exists = annotations_1.some(function (existingAnnotation) {
return existingAnnotation.annotName === textMarkupAnnotation.AnnotName;
});
if (!exists) {
annotations_1.push(textMarkupAnnotation);
}
});
}
if (annotations_1) {
var distinctAnnotations = [];
for (var i = 0; i < annotations_1.length; i++) {
var duplicateFound = false;
for (var j = 0; j < distinctAnnotations.length; j++) {
if (annotations_1[parseInt(i.toString(), 10)].AnnotName ===
distinctAnnotations[parseInt(j.toString(), 10)].AnnotName &&
annotations_1[parseInt(i.toString(), 10)].annotName === distinctAnnotations[parseInt(j.toString(), 10)].annotName) {
duplicateFound = true;
break;
}
}
if (!duplicateFound) {
distinctAnnotations.push(annotations_1[parseInt(i.toString(), 10)]);
}
}
annotations_1 = distinctAnnotations;
}
if (annotations_1) {
for (var i = 0; i < annotations_1.length; i++) {
var annotation = annotations_1[parseInt(i.toString(), 10)];
var annotationObject = null;
var isAnnotationRotated = void 0;
if (annotation.TextMarkupAnnotationType) {
if (isImportAction) {
if (this.pdfViewerBase.isJsonImported) {
var newArray = [];
for (var i_1 = 0; i_1 < annotation.Bounds.length; i_1++) {
annotation.Bounds[parseInt(i_1.toString(), 10)] = this.pdfViewerBase.
importJsonForRotatedDocuments(annotation.Rotate, pageNumber, annotation.Bounds[parseInt(i_1.toString(), 10)], annotation.AnnotationRotation);
annotation.Bounds[parseInt(i_1.toString(), 10)].left = annotation.Bounds[parseInt(i_1.toString(), 10)].X;
annotation.Bounds[parseInt(i_1.toString(), 10)].top = annotation.Bounds[parseInt(i_1.toString(), 10)].Y;
newArray.push(annotation.Bounds[parseInt(i_1.toString(), 10)]);
}
annotation.Bounds = newArray;
isAnnotationRotated = this.pdfViewerBase.isPageRotated;
}
}
annotation.annotationAddMode = this.pdfViewer.annotationModule.
findAnnotationMode(annotation, pageNumber, annotation.AnnotType);
annotation.allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions :
this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
annotation.AnnotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings :
this.pdfViewer.annotationModule.updateAnnotationSettings(annotation);
if (annotation.IsLocked) {
annotation.AnnotationSettings.isLock = annotation.IsLocked;
}
annotationObject = {
textMarkupAnnotationType: annotation.TextMarkupAnnotationType, color: annotation.Color,
allowedInteractions: annotation.allowedInteractions, opacity: annotation.Opacity,
bounds: annotation.Bounds, author: annotation.Author, subject: annotation.Subject,
modifiedDate: annotation.ModifiedDate, note: annotation.Note, rect: annotation.Rect,
annotName: annotation.AnnotName, comments: this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author), review: { state: annotation.State, stateModel: annotation.StateModel, modifiedDate: annotation.ModifiedDate, author: annotation.Author }, shapeAnnotationType: 'textMarkup', pageNumber: pageNumber,
textMarkupContent: annotation.TextMarkupContent, textMarkupStartIndex: 0, textMarkupEndIndex: 0,
annotationSelectorSettings: this.getSettings(annotation),
customData: this.pdfViewer.annotation.getCustomData(annotation), annotationAddMode: annotation.annotationAddMode, annotationSettings: annotation.AnnotationSettings,
isLocked: annotation.IsLocked, isPrint: annotation.IsPrint, isCommentLock: annotation.IsCommentLock,
isAnnotationRotated: isAnnotationRotated, annotationRotation: annotation.AnnotationRotation
};
if (annotation.IsMultiSelect) {
annotationObject.annotNameCollection = annotation.AnnotNameCollection;
annotationObject.annotpageNumbers = annotation.AnnotpageNumbers;
annotationObject.isMultiSelect = annotation.IsMultiSelect;
}
if (annotation.textMarkupContent && annotation.textMarkupContent !== '') {
annotationObject.textMarkupContent = annotation.textMarkupContent;
annotationObject.textMarkupStartIndex = annotation.textMarkupStartIndex;
annotationObject.textMarkupEndIndex = annotation.textMarkupEndIndex;
}
if (isNullOrUndefined(annotation.TextMarkupContent) && isNullOrUndefined(annotation.textMarkupContent)) {
var markedBounds = annotation.Bounds;
var storedData = this.pdfViewerBase.getStoredData(pageNumber, true);
if (isNullOrUndefined(storedData)) {
this.pdfViewerBase.requestForTextExtraction(pageNumber, annotationObject);
}
else {
var pageCharText = storedData.pageText.split('');
var characterBounds = this.pdfViewerBase.textLayer.
characterBound[parseInt(pageNumber.toString(), 10)];
var textMarkupContent = this.pdfViewerBase.
textMarkUpContent(markedBounds, pageCharText, characterBounds);
annotationObject.textMarkupContent = textMarkupContent;
}
}
this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annotationObject, '_annotations_textMarkup');
if (this.isAddAnnotationProgramatically) {
var settings = {
opacity: annotationObject.opacity, author: annotation.author, subject: annotation.subject,
modifiedDate: annotation.modifiedDate,
width: annotationObject.bounds.width, height: annotationObject.bounds.height
};
this.pdfViewer.fireAnnotationAdd(annotationObject.pageNumber, annotationObject.annotName, annotation.TextMarkupAnnotationType, annotationObject.bounds, settings);
}
}
var type = annotation.TextMarkupAnnotationType ? annotation.TextMarkupAnnotationType :
annotation.textMarkupAnnotationType;
var annotBounds = annotation.Bounds ? annotation.Bounds : annotation.bounds;
var opacity = annotation.Opacity ? annotation.Opacity : annotation.opacity;
var color = annotation.Color ? annotation.Color : annotation.color;
var annotationRotation = annotation.AnnotationRotation ? annotation.AnnotationRotation :
annotation.annotationRotation;
var isPrint = true;
if (annotation.TextMarkupAnnotationType) {
isPrint = annotation.IsPrint;
}
if (annotation.textMarkupAnnotationType) {
isPrint = annotation.isPrint;
}
if (type === 'Highlight' && isNullOrUndefined(highlightCanvasContext)) {
highlightCanvasContext = this.getHighlightCanvasContext(this.isPrintCanvas(canvas), pageNumber);
}
switch (type) {
case 'Highlight':
this.renderHighlightAnnotation(annotBounds, opacity, color, highlightCanvasContext.context, factor, isPrint, pageNumber);
break;
case 'Strikethrough':
this.renderStrikeoutAnnotation(annotBounds, opacity, color, context, factor, pageNumber, isPrint, annotationRotation, annotation.textMarkupContent);
break;
case 'Underline':
this.renderUnderlineAnnotation(annotBounds, opacity, color, context, factor, pageNumber, isPrint, annotationRotation);
break;
}
}
}
var isMaintainedSelector = false;
if (this.currentTextMarkupAnnotation && this.currentTextMarkupAnnotation.annotpageNumbers) {
for (var m = 0; m < this.currentTextMarkupAnnotation.annotpageNumbers.length; m++) {
if (pageNumber === this.currentTextMarkupAnnotation.annotpageNumbers[parseInt(m.toString(), 10)]) {
isMaintainedSelector = true;
this.isAnnotationSelect = false;
break;
}
}
}
if ((pageNumber === this.selectTextMarkupCurrentPage) || isMaintainedSelector) {
if (!this.isAnnotationSelect) {
this.maintainAnnotationSelection();
}
else {
this.isAnnotationSelect = false;
}
}
var annotImg = canvas.toDataURL();
var highlightImg = void 0;
if (highlightCanvasContext) {
highlightImg = highlightCanvasContext.canvas.toDataURL();
}
return { annotImg: annotImg, highlightImg: highlightImg };
}
};
TextMarkupAnnotation.prototype.getHighlightCanvasContext = function (isPrintCanvas, pageNumber) {
var canvas;
if (!isPrintCanvas) {
canvas = this.pdfViewerBase.getElement('_blendAnnotationsIntoCanvas_' + pageNumber);
if (isNullOrUndefined(canvas)) {
var pageDiv = document.getElementById(this.pdfViewer.element.id + '_pageDiv_' + pageNumber);
canvas = this.pdfViewer.annotationModule.createBlendAnnotationsIntoCanvas(pageDiv, parseFloat(pageDiv.style.width), parseFloat(pageDiv.style.height), pageNumber);
}
}
else {
canvas = this.pdfViewerBase.getElement(this.pdfViewer.element.id + '_print_blendAnnotations_canvas_' + pageNumber);
if (isNullOrUndefined(canvas)) {
canvas = createElement('canvas', { id: this.pdfViewer.element.id + '_print_blendAnnotations_canvas_' + pageNumber });
canvas.style.width = 816 + 'px';
canvas.style.height = 1056 + 'px';
var pageWidth = this.pdfViewerBase.pageSize[parseInt(pageNumber.toString(), 10)].width;
var pageHeight = this.pdfViewerBase.pageSize[parseInt(pageNumber.toString(), 10)].height;
var zoom = void 0;
if (isPrintCanvas) {
zoom = 1;
}
else {
zoom = this.pdfViewerBase.getZoomFactor();
}
var zoomRatio = this.pdfViewerBase.getZoomRatio(zoom);
canvas.height = pageHeight * zoomRatio;
canvas.width = pageWidth * zoomRatio;
}
}
var context = canvas.getContext('2d');
context.setTransform(1, 0, 0, 1, 0, 0);
context.setLineDash([]);
return { context: context, canvas: canvas };
};
TextMarkupAnnotation.prototype.isPrintCanvas = function (canvas) {
return canvas && canvas.id.indexOf('_print_annotation_layer_') !== -1 ? true : false;
};
/**
* @param {any} annotation - It describes about the annotation
* @private
* @returns {any} - any
*/
TextMarkupAnnotation.prototype.getSettings = function (annotation) {
var selector;
if (annotation.AnnotationSelectorSettings) {
selector = typeof (annotation.AnnotationSelectorSettings) === 'string' ? JSON.parse(annotation.AnnotationSelectorSettings) : annotation.AnnotationSelectorSettings;
}
else {
selector = this.getSelector(annotation.TextMarkupAnnotationType);
}
return selector;
};
/**
* @param {string} type - It describes about the type
* @private
* @returns {void}
*/
TextMarkupAnnotation.prototype.drawTextMarkupAnnotations = function (type) {
var isDrawn = false;
this.isTextMarkupAnnotationMode = true;
this.pdfViewer.annotationModule.isFormFieldShape = false;
this.currentTextMarkupAddMode = type;
var isCleared = true;
this.multiPageCollection = [];
var selectionObject = this.pdfViewer.textSelectionModule ?
this.pdfViewer.textSelectionModule.selectionRangeArray : [];
if (selectionObject.length > 0 && !this.isSelectionMaintained) {
isDrawn = true;
this.convertSelectionToTextMarkup(type, selectionObject, this.pdfViewerBase.getZoomFactor());
}
var selection = window.getSelection();
var targetElement;
if (selection && selection.anchorNode) {
targetElement = selection.anchorNode.parentElement;
}
if (this.isEnableTextMarkupResizer(type) && this.isExtended && window.getSelection().toString()) {
var pageBounds = this.getDrawnBounds();
if (pageBounds[0] && pageBounds[0].bounds) {
var currentAnnot = this.currentTextMarkupAnnotation;
for (var k = 0; k < pageBounds.length; k++) {
if (currentAnnot && currentAnnot.pageNumber === pageBounds[parseInt(k.toString(), 10)].pageIndex) {
this.currentTextMarkupAnnotation = currentAnnot;
this.selectTextMarkupCurrentPage = pageBounds[parseInt(k.toString(), 10)].pageIndex;
this.updateTextMarkupAnnotationBounds(pageBounds, k);
}
else {
if (currentAnnot) {
if (type === '') {
type = currentAnnot.textMarkupAnnotationType;
}
}
if (!currentAnnot.isMultiSelect) {
var isMultiSelect = false;
if (this.isMultiAnnotation(type)) {
this.multiPageCollection.push(currentAnnot);
isMultiSelect = true;
}
this.drawTextMarkups(type, pageBounds[parseInt(k.toString(), 10)].bounds, pageBounds[parseInt(k.toString(), 10)].pageIndex, pageBounds[parseInt(k.toString(), 10)].rect, this.pdfViewerBase.getZoomFactor(), pageBounds[parseInt(k.toString(), 10)].textContent, pageBounds[parseInt(k.toString(), 10)].startIndex, pageBounds[parseInt(k.toString(), 10)].endIndex, isMultiSelect, targetElement);
}
else {
if (currentAnnot.isMultiSelect && currentAnnot.annotNameCollection) {
this.modifyCurrentAnnotation(currentAnnot, pageBounds, k);
}
}
}
}
}
}
else if (window.getSelection().toString() && !isDrawn) {
var pageBounds = this.getDrawnBounds();
var isMultiSelect = this.isMultiPageAnnotations(pageBounds, type);
if (pageBounds.length > 0) {
for (var i = 0; i < pageBounds.length; i++) {
if (type === '') {
isCleared = false;
}
this.drawTextMarkups(type, pageBounds[parseInt(i.toString(), 10)].bounds, pageBounds[parseInt(i.toString(), 10)].pageIndex, pageBounds[parseInt(i.toString(), 10)].rect, this.pdfViewerBase.getZoomFactor(), pageBounds[parseInt(i.toString(), 10)].textContent, pageBounds[parseInt(i.toString(), 10)].startIndex, pageBounds[parseInt(i.toString(), 10)].endIndex, isMultiSelect, targetElement);
}
}
}
if (this.multiPageCollection) {
for (var j = 0; j < this.multiPageCollection.length; j++) {
this.updateAnnotationNames(this.multiPageCollection[parseInt(j.toString(), 10)], this.multiPageCollection[parseInt(j.toString(), 10)].pageNumber);
}
}
this.isExtended = false;
this.isSelectionMaintained = false;
// this.pdfViewerBase.annotationHelper.redoCollection = [];
if (isCleared && this.pdfViewer.textSelectionModule) {
this.pdfViewer.textSelectionModule.clearTextSelection();
}
if (this.isEnableTextMarkupResizer(type)) {
this.updateAnnotationBounds();
}
};
TextMarkupAnnotation.prototype.isMultiPageAnnotations = function (pageBounds, type) {
var isMultiSelect = false;
for (var n = 0; n < pageBounds.length; n++) {
if (pageBounds[parseInt(n.toString(), 10)].pageIndex !== pageBounds[0].pageIndex && this.isMultiAnnotation(type)) {
isMultiSelect = true;
break;
}
}
return isMultiSelect;
};
TextMarkupAnnotation.prototype.isMultiAnnotation = function (type) {
var isSelection = false;
if (type === 'Highlight' && this.pdfViewer.highlightSettings.enableMultiPageAnnotation) {
isSelection = true;
}
else if (type === 'Underline' && this.pdfViewer.underlineSettings.enableMultiPageAnnotation) {
isSelection = true;
}
else if (type === 'Strikethrough' && this.pdfViewer.strikethroughSettings.enableMultiPageAnnotation) {
isSelection = true;
}
else if (this.pdfViewer.enableMultiPageAnnotation) {
isSelection = true;
}
return isSelection;
};
TextMarkupAnnotation.prototype.modifyCurrentAnnotation = function (currentAnnot, pageBounds, index) {
for (var c = 0; c < currentAnnot.annotNameCollection.length; c++) {
var currentAnnots = currentAnnot.annotNameCollection[parseInt(c.toString(), 10)];
var annotationList = this.getAnnotations(pageBounds[parseInt(index.toString(), 10)].pageIndex, null);
if (annotationList) {
for (var z = 0; z < annotationList.length; z++) {
if (annotationList[parseInt(z.toString(), 10)].annotName === currentAnnots) {
this.currentTextMarkupAnnotation = annotationList[parseInt(z.toString(), 10)];
this.selectTextMarkupCurrentPage = pageBounds[parseInt(index.toString(), 10)].pageIndex;
this.updateTextMarkupAnnotationBounds(pageBounds, index);
break;
}
}
}
}
};
TextMarkupAnnotation.prototype.drawAnnotationSelector = function (newAnnotation, annotation, newcanvas) {
var newBounds = [];
var x = 0;
var y = 0;
var width = 0;
var height = 0;
var currentTop = 0;
var nextTop = 0;
var currentLeft = 0;
var nextLeft = 0;
var currentRotation = 0;
var nextRotation = 0;
for (var i = 0; i < newAnnotation.bounds.length; i++) {
currentTop = newAnnotation.bounds[parseInt(i.toString(), 10)].top ?
newAnnotation.bounds[parseInt(i.toString(), 10)].top : newAnnotation.bounds[parseInt(i.toString(), 10)].Top;
nextTop = !isNullOrUndefined(newAnnotation.bounds[i + 1]) ? newAnnotation.bounds[i + 1].top ?
newAnnotation.bounds[i + 1].top : newAnnotation.bounds[i + 1].Top : 0;
var rotation180Exists = void 0;
if (this.pdfViewerBase.clientSideRendering) {
currentLeft = newAnnotation.bounds[parseInt(i.toString(), 10)].left ?
newAnnotation.bounds[parseInt(i.toString(), 10)].left : newAnnotation.bounds[parseInt(i.toString(), 10)].Left;
nextLeft = !isNullOrUndefined(newAnnotation.bounds[i + 1]) ? newAnnotation.bounds[i + 1].left ?
newAnnotation.bounds[i + 1].left : newAnnotation.bounds[i + 1].Left : 0;
currentRotation = newAnnotation.bounds[parseInt(i.toString(), 10)].rotation;
nextRotation = !isNullOrUndefined(newAnnotation.bounds[i + 1]) ? newAnnotation.bounds[i + 1].rotation : 0;
rotation180Exists = (currentRotation === 0) || (currentRotation === 180);
}
if (newAnnotation.bounds.length > 1 && i < newAnnotation.bounds.length - 1 && currentTop === nextTop) {
newBounds.push(newAnnotation.bounds[parseInt(i.toString(), 10)]);
}
else {
if (i === newAnnotation.bounds.length - 1 || newAnnotation.bounds.length >= 1) {
newBounds.push(newAnnotation.bounds[parseInt(i.toString(), 10)]);
}
if (newBounds.length >= 1) {
x = newBounds[0].left ? newBounds[0].left : newBounds[0].Left;
y = newBounds[0].top ? newBounds[0].top : newBounds[0].Top;
height = newBounds[0].height ? newBounds[0].height : newBounds[0].Height;
for (var j = 0; j < newBounds.length; j++) {
if ((!isNaN(newBounds[parseInt(j.toString(), 10)].width) &&
newBounds[parseInt(j.toString(), 10)].width > 0) || (!isNaN(newBounds[parseInt(j.toString(), 10)].Width) &&
newBounds[parseInt(j.toString(), 10)].Width > 0)) {
width += newBounds[parseInt(j.toString(), 10)].width ?
newBounds[parseInt(j.toString(), 10)].width : newBounds[parseInt(j.toString(), 10)].Width;
}
}
if (!newcanvas) {
var canvasId = newAnnotation.textMarkupAnnotationType === 'Highlight' ? '_blendAnnotationsIntoCanvas_' : '_annotationCanvas_';
newcanvas = (canvasId === '_blendAnnotationsIntoCanvas_') ? this.pdfViewerBase.getElement(canvasId + newAnnotation.pageNumber) :
this.pdfViewerBase.getAnnotationCanvas(canvasId, newAnnotation.pageNumber);
}
this.drawAnnotationSelectRect(newcanvas, this.getMagnifiedValue(x - 0.5, this.pdfViewerBase.getZoomFactor()), this.getMagnifiedValue(y - 0.5, this.pdfViewerBase.getZoomFactor()), this.getMagnifiedValue(width + 0.5, this.pdfViewerBase.getZoomFactor()), this.getMagnifiedValue(height + 0.5, this.pdfViewerBase.getZoomFactor()), annotation);
newBounds = [];
width = 0;
}
}
}
};
TextMarkupAnnotation.prototype.selectMultiPageAnnotations = function (annotation) {
for (var k = 0; k < annotation.annotNameCollection.length; k++) {
var currentAnnot = annotation.annotNameCollection[parseInt(k.toString(), 10)];
if (currentAnnot !== annotation.annotName) {
for (var p = 0; p < annotation.annotpageNumbers.length; p++) {
var currentPage = annotation.annotpageNumbers[parseInt(p.toString(), 10)];
var annotationList = this.getAnnotations(currentPage, null);
if (annotationList) {
for (var z = 0; z < annotationList.length; z++) {
if (annotationList[parseInt(z.toString(), 10)].annotName === currentAnnot) {
var newAnnotation = annotationList[parseInt(z.toString(), 10)];
this.drawAnnotationSelector(newAnnotation, annotation);
}
}
}
}
}
}
};
TextMarkupAnnotation.prototype.deletMultiPageAnnotation = function (annotation) {
for (var k = 0; k < annotation.annotNameCollection.length; k++) {
var currentAnnot = annotation.annotNameCollection[parseInt(k.toString(), 10)];
if (currentAnnot !== annotation.annotName) {
for (var p = 0; p < annotation.annotpageNumbers.length; p++) {
var currentPage = annotation.annotpageNumbers[parseInt(p.toString(), 10)];
var annotationList = this.getAnnotations(currentPage, null);
if (annotationList) {
for (var z = 0; z < annotationList.length; z++) {
if (annotationList[parseInt(z.toString(), 10)].annotName === currentAnnot) {
var newAnnotation = annotationList[parseInt(z.toString(), 10)];
var deletedAnnotation = null;
deletedAnnotation = annotationList.splice(z, 1)[0];
this.pdfViewer.annotationModule.addAction(currentPage, z, deletedAnnotation, 'Text Markup Deleted', null);
this.currentAnnotationIndex = z;
this.pdfViewer.annotation.stickyNotesAnnotationModule.findPosition(deletedAnnotation, 'textMarkup');
var removeDiv = document.getElementById(deletedAnnotation.annotName);
if (removeDiv) {
if (removeDiv.parentElement.childElementCount === 1) {
this.pdfViewer.annotationModule.stickyNotesAnnotationModule.updateAccordionContainer(removeDiv);
}
else {
removeDiv.remove();
}
}
this.pdfViewer.annotationModule.updateAnnotationCollection(newAnnotation);
this.manageAnnotations(annotationList, currentPage);
this.pdfViewer.annotationModule.updateImportAnnotationCollection(newAnnotation, newAnnotation.pageNumber, 'textMarkupAnnotation');
this.pdfViewer.annotationModule.renderAnnotations(currentPage, null, null, null);
}
}
}
}
}
}
};
TextMarkupAnnotation.prototype.modifyMultiPageAnnotations = function (annotation, property, value) {
for (var k = 0; k < annotation.annotNameCollection.length; k++) {
var currentAnnot = annotation.annotNameCollection[parseInt(k.toString(), 10)];
if (currentAnnot !== annotation.annotName) {
for (var p = 0; p < annotation.annotpageNumbers.length; p++) {
var currentPage = annotation.annotpageNumbers[parseInt(p.toString(), 10)];
var annotationList = this.getAnnotations(currentPage, null);
if (annotationList) {
for (var z = 0; z < annotationList.length; z++) {
if (annotationList[parseInt(z.toString(), 10)].annotName === currentAnnot) {
if (property === 'Color') {
annotationList[parseInt(z.toString(), 10)].color = value;
}
else {
annotationList[parseInt(z.toString(), 10)].opacity = value;
}
annotationList[parseInt(z.toString(), 10)].modifiedDate =