all files / pdfviewer/annotation/ ink-annotation.js

7.13% Statements 31/435
0% Branches 0/321
7.14% Functions 2/28
7.13% Lines 31/435
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 7051×   1× 1× 1×                     1×       1×                                                       1×                             1×                     1×       1×                                                                 1×             1×         1×         1×                                                                                                                                     1×                 1×                                                               1×                 1×                                                                         1×                                                                                                                                                                                                                                                               1×                                                                 1×                   1×                                                                                       1×               1×                                 1×                                                                                                     1×                     1×                     1×                                                                     1×                                                                                                                                             1×   1×    
define(["require", "exports", "@syncfusion/ej2-drawings", "@syncfusion/ej2-base"], function (require, exports, ej2_drawings_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var InkAnnotation = (function () {
        function InkAnnotation(pdfViewer, pdfViewerBase) {
            this.newObject = [];
            this.outputString = '';
            this.inkAnnotationindex = [];
            this.isAddAnnotationProgramatically = false;
            this.currentPageNumber = '';
            this.inkAnnotationInitialZoom = 1;
            this.inkPathDataCollection = [];
            this.pdfViewer = pdfViewer;
            this.pdfViewerBase = pdfViewerBase;
        }
        InkAnnotation.prototype.drawInk = function () {
            this.pdfViewerBase.disableTextSelectionMode();
            this.pdfViewer.tool = 'Ink';
        };
        InkAnnotation.prototype.drawInkAnnotation = function (pageNumber) {
            if (this.pdfViewerBase.isToolbarInkClicked) {
                this.pdfViewerBase.isInkAdded = true;
                this.pdfViewer.annotationModule.isFormFieldShape = false;
                var pageIndex = !isNaN(pageNumber) ? pageNumber : this.pdfViewerBase.currentPageNumber - 1;
                if ((this.outputString && this.outputString !== '') || this.inkPathDataCollection.length > 0) {
                    var currentAnnot = this.addInk(pageIndex);
                    this.pdfViewer.renderDrawing(undefined, pageIndex);
                    this.pdfViewer.clearSelection(pageIndex);
                    this.pdfViewer.select([currentAnnot.id], currentAnnot.annotationSelectorSettings);
                    if (this.pdfViewer.toolbar && this.pdfViewer.toolbar.annotationToolbarModule) {
                        this.pdfViewer.toolbar.annotationToolbarModule.enableSignaturePropertiesTools(true);
                    }
                    if (ej2_base_1.Browser.isDevice && !this.pdfViewer.enableDesktopMode &&
                        this.pdfViewer.enableToolbar && this.pdfViewer.enableAnnotationToolbar) {
                        this.pdfViewer.toolbarModule.annotationToolbarModule.createPropertyTools('Ink');
                    }
                }
                else {
                    this.outputString = '';
                    this.newObject = [];
                    this.pdfViewerBase.isToolbarInkClicked = false;
                    this.pdfViewer.tool = '';
                    this.inkPathDataCollection = [];
                }
                this.pdfViewerBase.isInkAdded = false;
            }
        };
        InkAnnotation.prototype.updateInkDataWithZoom = function () {
            var updatedPathData = '';
            if (this.outputString !== '') {
                this.inkPathDataCollection.push({ pathData: this.outputString, zoomFactor: this.inkAnnotationInitialZoom });
            }
            if (this.inkPathDataCollection.length > 0) {
                for (var i = 0; i < this.inkPathDataCollection.length; i++) {
                    updatedPathData += this.updatePathDataWithZoom(this.inkPathDataCollection[parseInt(i.toString(), 10)].pathData, this.inkPathDataCollection[parseInt(i.toString(), 10)].zoomFactor);
                }
            }
            else {
                updatedPathData += this.updatePathDataWithZoom(this.outputString, this.inkAnnotationInitialZoom);
            }
            return updatedPathData;
        };
        InkAnnotation.prototype.updatePathDataWithZoom = function (pathData, pathZoomFactor) {
            var pathString = '';
            var zoom = this.pdfViewerBase.getZoomFactor();
            var collectionData = ej2_drawings_1.processPathData(pathData);
            var csData = ej2_drawings_1.splitArrayCollection(collectionData);
            for (var j = 0; j < csData.length; j++) {
                var pathValue = csData[parseInt(j.toString(), 10)];
                pathString += pathValue.command + pathValue.x * (zoom / pathZoomFactor) + ',' + pathValue.y * (zoom / pathZoomFactor) + ' ';
            }
            return pathString;
        };
        InkAnnotation.prototype.storePathData = function () {
            this.convertToPath(this.newObject);
            this.newObject = [];
        };
        InkAnnotation.prototype.drawInkInCanvas = function (position, pageIndex) {
            if (this.currentPageNumber !== '' && parseInt(this.currentPageNumber, 10) !== pageIndex) {
                this.drawInkAnnotation(parseInt(this.currentPageNumber, 10));
                this.pdfViewerBase.isToolbarInkClicked = true;
                this.pdfViewer.tool = 'Ink';
            }
            var zoom = this.pdfViewerBase.getZoomFactor();
            this.inkAnnotationInitialZoom = zoom;
            var ratio = this.pdfViewerBase.getWindowDevicePixelRatio();
            var canvas = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageIndex);
            var context = canvas.getContext('2d');
            var thickness = this.pdfViewer.inkAnnotationSettings.thickness ? this.pdfViewer.inkAnnotationSettings.thickness : 1;
            var opacity = this.pdfViewer.inkAnnotationSettings.opacity ? this.pdfViewer.inkAnnotationSettings.opacity : 1;
            var strokeColor = this.pdfViewer.inkAnnotationSettings.strokeColor ? this.pdfViewer.inkAnnotationSettings.strokeColor : '#ff0000';
            if (!ej2_base_1.Browser.isDevice || (ej2_base_1.Browser.isDevice && zoom <= 0.7)) {
                context.setTransform(ratio, 0, 0, ratio, 0, 0);
            }
            context.beginPath();
            context.lineJoin = 'round';
            context.lineCap = 'round';
            context.moveTo(position.prevPosition.x, position.prevPosition.y);
            context.lineTo(position.currentPosition.x, position.currentPosition.y);
            context.lineWidth = thickness * zoom > 1 ? thickness * zoom : thickness;
            context.strokeStyle = strokeColor;
            context.globalAlpha = opacity;
            context.setLineDash([]);
            context.stroke();
            context.arc(position.prevPosition.x, position.prevPosition.y, 2 / 2, 0, Math.PI * 2, true);
            context.closePath();
            this.pdfViewerBase.prevPosition = position.currentPosition;
            this.newObject.push(position.currentPosition.x, position.currentPosition.y);
            this.currentPageNumber = pageIndex.toString();
        };
        InkAnnotation.prototype.convertToPath = function (newObject) {
            this.movePath(newObject[0], newObject[1]);
            this.linePath(newObject[0], newObject[1]);
            for (var n = 2; n < newObject.length; n = n + 2) {
                this.linePath(newObject[parseInt(n.toString(), 10)], newObject[n + 1]);
            }
        };
        InkAnnotation.prototype.linePath = function (x, y) {
            if (!ej2_base_1.isNullOrUndefined(x) && !ej2_base_1.isNullOrUndefined(y)) {
                this.outputString += 'L' + x + ',' + y + ' ';
            }
        };
        InkAnnotation.prototype.movePath = function (x, y) {
            if (!ej2_base_1.isNullOrUndefined(x) && !ej2_base_1.isNullOrUndefined(y)) {
                this.outputString += 'M' + x + ',' + y + ' ';
            }
        };
        InkAnnotation.prototype.addInk = function (pageNumber) {
            this.outputString = this.updateInkDataWithZoom();
            var currentBounds = this.calculateInkSize(this.outputString);
            var annot;
            if (this.pdfViewerBase.isToolbarInkClicked) {
                var annotationName = this.pdfViewer.annotation.createGUID();
                var modifiedDate = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
                var pageIndex = !isNaN(pageNumber) ? pageNumber : this.pdfViewerBase.currentPageNumber - 1;
                var thickness = this.pdfViewer.inkAnnotationSettings.thickness ? this.pdfViewer.inkAnnotationSettings.thickness : 1;
                var opacity = this.pdfViewer.inkAnnotationSettings.opacity ? this.pdfViewer.inkAnnotationSettings.opacity : 1;
                var strokeColor = this.pdfViewer.inkAnnotationSettings.strokeColor ? this.pdfViewer.inkAnnotationSettings.strokeColor : '#ff0000';
                var isLock = this.pdfViewer.inkAnnotationSettings.isLock ?
                    this.pdfViewer.inkAnnotationSettings.isLock : this.pdfViewer.annotationSettings.isLock;
                var author = (this.pdfViewer.annotationSettings.author !== 'Guest') ? this.pdfViewer.annotationSettings.author : this.pdfViewer.inkAnnotationSettings.author ? this.pdfViewer.inkAnnotationSettings.author : 'Guest';
                var subject = (this.pdfViewer.annotationSettings.subject !== '' && !ej2_base_1.isNullOrUndefined(this.pdfViewer.annotationSettings.subject)) ? this.pdfViewer.annotationSettings.subject : this.pdfViewer.inkAnnotationSettings.subject ? this.pdfViewer.inkAnnotationSettings.subject : 'Ink';
                var customData = !ej2_base_1.isNullOrUndefined(this.pdfViewer.annotationSettings.customData) ?
                    this.pdfViewer.annotationSettings.customData : this.pdfViewer.inkAnnotationSettings.customData ?
                    this.pdfViewer.inkAnnotationSettings.customData : null;
                var isPrint = this.pdfViewer.inkAnnotationSettings.isPrint;
                var allowedInteractions = this.pdfViewer.inkAnnotationSettings.allowedInteractions ?
                    this.pdfViewer.inkAnnotationSettings.allowedInteractions : this.pdfViewer.annotationSettings.allowedInteractions;
                var annotationSettings = this.pdfViewer.annotationSettings ? this.pdfViewer.annotationSettings :
                    this.pdfViewer.annotationModule.updateAnnotationSettings(this.pdfViewer.inkAnnotationSettings);
                if (isLock) {
                    annotationSettings.isLock = true;
                }
                annot = {
                    id: 'ink' + this.pdfViewerBase.inkCount, bounds: { x: currentBounds.x, y: currentBounds.y, width: currentBounds.width, height: currentBounds.height }, pageIndex: pageIndex, data: this.outputString, customData: customData,
                    shapeAnnotationType: 'Ink', opacity: opacity, strokeColor: strokeColor, thickness: thickness, annotName: annotationName, comments: [],
                    author: author, subject: subject, notes: '',
                    review: { state: '', stateModel: '', modifiedDate: modifiedDate, author: author },
                    annotationSelectorSettings: this.getSelector('Ink', ''), modifiedDate: modifiedDate, annotationSettings: annotationSettings,
                    isPrint: isPrint, allowedInteractions: allowedInteractions, isCommentLock: false, isLocked: isLock
                };
                var annotObject = {
                    id: 'ink' + this.pdfViewerBase.inkCount, bounds: { x: currentBounds.x, y: currentBounds.y, width: currentBounds.width, height: currentBounds.height }, pageIndex: pageIndex, data: this.outputString, customData: customData,
                    shapeAnnotationType: 'Ink', opacity: opacity, strokeColor: strokeColor, thickness: thickness, annotName: annotationName, comments: [],
                    author: author, subject: subject, notes: '',
                    review: { state: '', stateModel: '', modifiedDate: modifiedDate, author: author },
                    annotationSelectorSettings: this.getSelector('Ink', ''), modifiedDate: modifiedDate, annotationSettings: annotationSettings,
                    isPrint: isPrint, allowedInteractions: allowedInteractions, isCommentLock: false, isLocked: isLock
                };
                var annotation = this.pdfViewer.add(annot);
                var bounds = { left: annot.bounds.x, top: annot.bounds.y, width: annot.bounds.width, height: annot.bounds.height };
                var settings = {
                    opacity: annot.opacity, strokeColor: annot.strokeColor, thickness: annot.thickness, modifiedDate: annot.modifiedDate,
                    width: annot.bounds.width, height: annot.bounds.height, data: this.outputString
                };
                this.pdfViewerBase.inkCount++;
                var commentsDivid = this.pdfViewer.annotation.stickyNotesAnnotationModule.addComments('ink', (annot.pageIndex + 1), annot.shapeAnnotationType);
                if (commentsDivid) {
                    document.getElementById(commentsDivid).id = annotationName;
                }
                annot.annotName = annotationName;
                this.pdfViewer.annotation.addAction(pageIndex, null, annotation, 'Addition', '', annotation, annotation);
                this.pdfViewer.annotationModule.storeAnnotations(pageIndex, annotObject, '_annotations_ink');
                this.pdfViewer.fireAnnotationAdd(annot.pageIndex, annot.annotName, 'Ink', bounds, settings);
                if (this.pdfViewerBase.isInkAdded) {
                    this.outputString = '';
                    this.newObject = [];
                    this.inkPathDataCollection = [];
                }
                this.pdfViewerBase.isToolbarInkClicked = false;
                this.pdfViewer.tool = '';
            }
            return annot;
        };
        InkAnnotation.prototype.setAnnotationMode = function () {
            if (this.pdfViewerBase.isToolbarInkClicked) {
                this.drawInkAnnotation();
            }
            else {
                this.pdfViewerBase.isToolbarInkClicked = true;
                this.drawInk();
            }
        };
        InkAnnotation.prototype.saveInkSignature = function () {
            var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_ink');
            var annotations = [];
            for (var j = 0; j < this.pdfViewerBase.pageCount; j++) {
                annotations[parseInt(j.toString(), 10)] = [];
            }
            if (storeObject && !this.pdfViewer.annotationSettings.skipDownload) {
                var annotationCollection = JSON.parse(JSON.stringify(storeObject));
                for (var i = 0; i < annotationCollection.length; i++) {
                    var newArray = [];
                    var pageAnnotationObject = annotationCollection[parseInt(i.toString(), 10)];
                    if (pageAnnotationObject) {
                        for (var z = 0; pageAnnotationObject.annotations.length > z; z++) {
                            this.pdfViewer.annotationModule.updateModifiedDate(pageAnnotationObject.annotations[parseInt(z.toString(), 10)]);
                            var strokeColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].strokeColor;
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].strokeColor =
                                JSON.stringify(this.pdfViewerBase.signatureModule.getRgbCode(strokeColorString));
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds =
                                JSON.stringify(this.pdfViewer.annotation.
                                    getInkBounds(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds, pageAnnotationObject.pageIndex));
                            var collectionData = ej2_drawings_1.processPathData(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].data);
                            var csData = ej2_drawings_1.splitArrayCollection(collectionData);
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].data = JSON.stringify(csData);
                        }
                        newArray = pageAnnotationObject.annotations;
                    }
                    annotations[pageAnnotationObject.pageIndex] = newArray;
                }
                annotationCollection = null;
            }
            return JSON.stringify(annotations);
        };
        InkAnnotation.prototype.addInCollection = function (pageNumber, annotationBase) {
            if (annotationBase) {
                var pageAnnotations = this.getAnnotations(pageNumber, null);
                if (pageAnnotations) {
                    pageAnnotations.push(annotationBase);
                }
                this.manageInkAnnotations(pageAnnotations, pageNumber);
            }
        };
        InkAnnotation.prototype.calculateInkSize = function (data) {
            var minimumX = -1;
            var minimumY = -1;
            var maximumX = -1;
            var maximumY = -1;
            var collectionData = ej2_drawings_1.processPathData(data);
            var zoomvalue = this.pdfViewerBase.getZoomFactor();
            for (var k = 0; k < collectionData.length; k++) {
                var val = collectionData[parseInt(k.toString(), 10)];
                if (minimumX === -1) {
                    minimumX = (val['x']);
                    maximumX = (val['x']);
                    minimumY = (val['y']);
                    maximumY = (val['y']);
                }
                else {
                    var point1 = (val['x']);
                    var point2 = (val['y']);
                    if (minimumX >= point1) {
                        minimumX = point1;
                    }
                    if (minimumY >= point2) {
                        minimumY = point2;
                    }
                    if (maximumX <= point1) {
                        maximumX = point1;
                    }
                    if (maximumY <= point2) {
                        maximumY = point2;
                    }
                }
            }
            var newdifferenceX = maximumX - minimumX;
            var newdifferenceY = maximumY - minimumY;
            return { x: (minimumX / zoomvalue), y: (minimumY / zoomvalue),
                width: (newdifferenceX / zoomvalue), height: (newdifferenceY / zoomvalue) };
        };
        InkAnnotation.prototype.renderExistingInkSignature = function (annotationCollection, pageIndex, isImport, isAnnotOrderAction, isLastAnnot) {
            var annot;
            var isinkAnnotationAdded = false;
            if (!isImport) {
                for (var p = 0; p < this.inkAnnotationindex.length; p++) {
                    if (this.inkAnnotationindex[parseInt(p.toString(), 10)] === pageIndex) {
                        isinkAnnotationAdded = true;
                        break;
                    }
                }
            }
            if (annotationCollection && (!isinkAnnotationAdded || isAnnotOrderAction)) {
                if (annotationCollection.length > 0 && this.inkAnnotationindex.indexOf(pageIndex) === -1) {
                    this.inkAnnotationindex.push(pageIndex);
                }
                for (var n = 0; n < annotationCollection.length; n++) {
                    var currentAnnotation = annotationCollection[parseInt(n.toString(), 10)];
                    if (currentAnnotation) {
                        var data = currentAnnotation.PathData;
                        if (isImport && data) {
                            if (typeof (data) === 'object' && data.length > 1) {
                                data = ej2_drawings_1.getPathString(data);
                            }
                            else {
                                if (!(currentAnnotation.IsPathData || (data.split('command').length <= 1))) {
                                    data = ej2_drawings_1.getPathString(JSON.parse(data));
                                }
                            }
                        }
                        this.outputString = data;
                        var calculateInkPosition = this.calculateInkSize(this.outputString);
                        this.outputString = '';
                        var rectDiff = 0;
                        var rectDifference = 1;
                        var bounds = currentAnnotation.Bounds;
                        if (calculateInkPosition) {
                            if (calculateInkPosition.height < 1) {
                                rectDiff = bounds.Height ? bounds.Height : bounds.height;
                                rectDifference = bounds.Height ? bounds.Height : bounds.height;
                            }
                            else if (calculateInkPosition.width < 1) {
                                rectDiff = bounds.Width ? bounds.Width : bounds.width;
                                rectDifference = bounds.Width ? bounds.Width : bounds.width;
                            }
                        }
                        var currentLeft = !ej2_base_1.isNullOrUndefined(bounds.X) ? bounds.X + (rectDiff / 2) : bounds.x + (rectDiff / 2);
                        var currentTop = !ej2_base_1.isNullOrUndefined(bounds.Y) ? bounds.Y + (rectDiff / 2) : bounds.y + (rectDiff / 2);
                        var currentWidth = bounds.Width ? bounds.Width - (rectDifference - 1) : bounds.width - (rectDifference - 1);
                        var currentHeight = bounds.Height ? bounds.Height - (rectDifference - 1) :
                            bounds.height - (rectDifference - 1);
                        var isLock = currentAnnotation.AnnotationSettings ? currentAnnotation.AnnotationSettings.isLock : false;
                        var selectorSettings = currentAnnotation.AnnotationSelectorSettings ? typeof (currentAnnotation.AnnotationSelectorSettings) === 'string' ? JSON.parse(currentAnnotation.AnnotationSelectorSettings) : currentAnnotation.AnnotationSelectorSettings : this.getSelector(currentAnnotation, 'Ink');
                        var customData = this.pdfViewer.annotation.getCustomData(currentAnnotation);
                        var isPrint = true;
                        if (currentAnnotation.AnnotationSettings) {
                            isPrint = currentAnnotation.AnnotationSettings.isPrint;
                        }
                        else {
                            isPrint = this.pdfViewer.inkAnnotationSettings.isPrint;
                        }
                        isPrint = !ej2_base_1.isNullOrUndefined(currentAnnotation.IsPrint) ? currentAnnotation.IsPrint : true;
                        if (currentAnnotation.IsLocked) {
                            isLock = currentAnnotation.IsLocked;
                        }
                        if (currentAnnotation.Subject === 'Highlight' && currentAnnotation.Opacity === 1) {
                            currentAnnotation.Opacity = currentAnnotation.Opacity / 2;
                        }
                        currentAnnotation.allowedInteractions = currentAnnotation.AllowedInteractions ?
                            currentAnnotation.AllowedInteractions : this.pdfViewer.annotationModule.
                            updateAnnotationAllowedInteractions(currentAnnotation);
                        currentAnnotation.AnnotationSettings = currentAnnotation.AnnotationSettings ?
                            currentAnnotation.AnnotationSettings : this.pdfViewer.annotationModule.updateAnnotationSettings(currentAnnotation);
                        currentAnnotation.State = currentAnnotation.State ? currentAnnotation.State : '';
                        currentAnnotation.StateModel = currentAnnotation.StateModel ? currentAnnotation.StateModel : '';
                        annot = {
                            id: 'ink' + this.pdfViewerBase.inkCount, bounds: { x: currentLeft, y: currentTop, width: currentWidth, height: currentHeight }, pageIndex: pageIndex, data: data,
                            shapeAnnotationType: 'Ink', opacity: currentAnnotation.Opacity, strokeColor: currentAnnotation.StrokeColor, thickness: currentAnnotation.Thickness, annotName: currentAnnotation.AnnotName,
                            comments: this.pdfViewer.annotationModule.
                                getAnnotationComments(currentAnnotation.Comments, currentAnnotation, currentAnnotation.Author),
                            author: currentAnnotation.Author, allowedInteractions: currentAnnotation.allowedInteractions,
                            subject: currentAnnotation.Subject, modifiedDate: currentAnnotation.ModifiedDate,
                            review: { state: currentAnnotation.State, stateModel: currentAnnotation.StateModel,
                                modifiedDate: currentAnnotation.ModifiedDate, author: currentAnnotation.Author }, notes: currentAnnotation.Note, annotationSettings: currentAnnotation.AnnotationSettings,
                            annotationSelectorSettings: selectorSettings, customData: customData, isPrint: isPrint,
                            isCommentLock: currentAnnotation.IsCommentLock
                        };
                        var annotObject = {
                            id: 'ink' + this.pdfViewerBase.inkCount, bounds: { x: currentLeft, y: currentTop, width: currentWidth, height: currentHeight }, pageIndex: pageIndex, data: data,
                            shapeAnnotationType: 'Ink', opacity: currentAnnotation.Opacity, strokeColor: currentAnnotation.StrokeColor, thickness: currentAnnotation.Thickness, annotName: currentAnnotation.AnnotName,
                            comments: this.pdfViewer.annotationModule.
                                getAnnotationComments(currentAnnotation.Comments, currentAnnotation, currentAnnotation.Author),
                            author: currentAnnotation.Author, allowedInteractions: currentAnnotation.allowedInteractions,
                            subject: currentAnnotation.Subject, modifiedDate: currentAnnotation.ModifiedDate,
                            review: { state: currentAnnotation.State, stateModel: currentAnnotation.StateModel,
                                modifiedDate: currentAnnotation.ModifiedDate, author: currentAnnotation.Author }, notes: currentAnnotation.Note, annotationSettings: currentAnnotation.AnnotationSettings,
                            annotationSelectorSettings: selectorSettings, customData: customData, isPrint: isPrint,
                            isCommentLock: currentAnnotation.IsCommentLock,
                            originalName: currentAnnotation.OriginalName ? currentAnnotation.OriginalName : null
                        };
                        this.pdfViewer.add(annot);
                        var canvasPageIndex = currentAnnotation.pageIndex ? currentAnnotation.pageIndex : currentAnnotation.PageNumber;
                        var canvass = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', canvasPageIndex);
                        var isNeedToRender = ((isImport && isLastAnnot) || ej2_base_1.isNullOrUndefined(isImport) ||
                            !isImport) ? true : false;
                        if (isNeedToRender) {
                            this.pdfViewer.renderDrawing(canvass, annot.pageIndex);
                        }
                        this.pdfViewer.annotationModule.storeAnnotations(annot.pageIndex, annotObject, '_annotations_ink');
                        if (this.isAddAnnotationProgramatically) {
                            var settings = {
                                opacity: annot.opacity, strokeColor: annot.strokeColor, thickness: annot.thickness,
                                modifiedDate: annot.modifiedDate,
                                width: annot.bounds.width, height: annot.bounds.height, data: this.outputString
                            };
                            this.pdfViewer.fireAnnotationAdd(annot.pageIndex, annot.annotName, 'Ink', bounds, settings);
                        }
                        this.pdfViewerBase.currentSignatureAnnot = null;
                        this.pdfViewerBase.signatureCount++;
                        this.pdfViewerBase.inkCount++;
                        if (this.pdfViewerBase.navigationPane && this.pdfViewerBase.navigationPane.annotationMenuObj &&
                            this.pdfViewer.isSignatureEditable) {
                            this.pdfViewerBase.navigationPane.annotationMenuObj.enableItems([this.pdfViewer.localeObj.getConstant('Export Annotations')], true);
                            this.pdfViewerBase.navigationPane.annotationMenuObj.enableItems([this.pdfViewer.localeObj.getConstant('Export XFDF')], true);
                        }
                    }
                }
            }
        };
        InkAnnotation.prototype.saveImportedInkAnnotation = function (annotation, pageNumber) {
            var annotationObject = null;
            var currentBounds = annotation.Bounds;
            var bounds = { x: currentBounds.X, y: currentBounds.Y, width: currentBounds.Width, height: currentBounds.Height };
            var allowedInteractions = this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
            var customData = this.pdfViewer.annotation.getCustomData(annotation);
            var comments = this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author);
            var review = { state: annotation.State, stateModel: annotation.StateModel,
                modifiedDate: annotation.ModifiedDate, author: annotation.Author };
            var annotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings :
                this.pdfViewer.annotationModule.updateAnnotationSettings(annotation);
            var annotationSelectorSettings = this.getSettings(annotation);
            var data = annotation.PathData;
            if (typeof (data) === 'object' && data.length > 1) {
                data = ej2_drawings_1.getPathString(data);
            }
            else {
                if (!annotation.IsPathData && data.split('command').length > 1) {
                    data = ej2_drawings_1.getPathString(JSON.parse(data));
                }
            }
            annotationObject = {
                allowedInteractions: allowedInteractions, annotName: annotation.AnnotName,
                annotationSelectorSettings: annotationSelectorSettings,
                annotationSettings: annotationSettings, author: annotation.Author, bounds: bounds,
                customData: customData, comments: comments, data: data,
                id: 'Ink', isCommentLock: annotation.IsCommentLock, isLocked: annotation.IsLocked, isPrint: annotation.IsPrint, modifiedDate: annotation.ModifiedDate,
                note: annotation.Note, opacity: annotation.Opacity, pageIndex: pageNumber, review: review,
                shapeAnnotationType: annotation.AnnotationType,
                strokeColor: annotation.StrokeColor, subject: annotation.Subject, thickness: annotation.Thickness
            };
            this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annotationObject, '_annotations_ink');
        };
        InkAnnotation.prototype.getSettings = function (annotation) {
            var selector = this.pdfViewer.annotationSelectorSettings;
            if (annotation.AnnotationSelectorSettings) {
                selector = annotation.AnnotationSelectorSettings;
            }
            else {
                selector = this.getSelector(annotation.ShapeAnnotationType, annotation.Subject);
            }
            return selector;
        };
        InkAnnotation.prototype.storeInkSignatureData = function (pageNumber, annotations) {
            this.pdfViewer.annotation.addAction(annotations.pageIndex, null, annotations, 'Addition', '', annotations, annotations);
            var annotation = null;
            var left = annotations.bounds.left ? annotations.bounds.left : annotations.bounds.x;
            var top = annotations.bounds.top ? annotations.bounds.top : annotations.bounds.y;
            if (annotations.wrapper && annotations.wrapper.bounds) {
                left = annotations.wrapper.bounds.left;
                top = annotations.wrapper.bounds.top;
            }
            annotation = {
                id: annotations.id, bounds: { x: left, y: top, width: annotations.bounds.width, height: annotations.bounds.height },
                shapeAnnotationType: 'Ink', opacity: annotations.opacity, thickness: annotations.thickness, strokeColor: annotations.strokeColor, pageIndex: annotations.pageIndex, data: annotations.data,
                annotName: annotations.annotName,
                comments: annotations.comments, author: annotations.author, subject: annotations.subject,
                modifiedDate: annotations.modifiedDate,
                review: { state: '', stateModel: '', modifiedDate: annotations.modifiedDate, author: annotations.author }, notes: annotations.notes,
                annotationSelectorSettings: this.getSelector(annotations, 'Ink'), isCommentLock: annotations.isCommentLock
            };
            var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_ink');
            var index = 0;
            if (!storeObject) {
                var shapeAnnotation = { pageIndex: pageNumber, annotations: [] };
                shapeAnnotation.annotations.push(annotation);
                index = shapeAnnotation.annotations.indexOf(annotation);
                var annotationCollection = [];
                annotationCollection.push(shapeAnnotation);
                this.pdfViewer.annotationsCollection.set(this.pdfViewerBase.documentId + '_annotations_ink', annotationCollection);
            }
            else {
                this.pdfViewer.annotationsCollection.delete(this.pdfViewerBase.documentId + '_annotations_ink');
                var pageIndex = this.pdfViewer.annotationModule.getPageCollection(storeObject, pageNumber);
                if (pageIndex != null && storeObject[parseInt(pageIndex.toString(), 10)]) {
                    storeObject[parseInt(pageIndex.toString(), 10)].annotations.push(annotation);
                    index = storeObject[parseInt(pageIndex.toString(), 10)].annotations.indexOf(annotation);
                }
                else {
                    var markupAnnotation = { pageIndex: pageNumber, annotations: [] };
                    markupAnnotation.annotations.push(annotation);
                    index = markupAnnotation.annotations.indexOf(annotation);
                    storeObject.push(markupAnnotation);
                }
                this.pdfViewer.annotationsCollection.set(this.pdfViewerBase.documentId + '_annotations_ink', storeObject);
            }
        };
        InkAnnotation.prototype.getSelector = function (type, subject) {
            var selector = this.pdfViewer.annotationSelectorSettings;
            if ((type === 'Ink' || subject === 'Ink') && this.pdfViewer.inkAnnotationSettings.annotationSelectorSettings) {
                selector = this.pdfViewer.inkAnnotationSettings.annotationSelectorSettings;
                this.pdfViewerBase.updateSelectorSettings(selector);
            }
            return selector;
        };
        InkAnnotation.prototype.getAnnotations = function (pageIndex, shapeAnnotations) {
            var annotationCollection;
            var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_ink');
            if (storeObject) {
                var index = this.pdfViewer.annotationModule.getPageCollection(storeObject, pageIndex);
                if (index != null && storeObject[parseInt(index.toString(), 10)]) {
                    annotationCollection = storeObject[parseInt(index.toString(), 10)].annotations;
                }
                else {
                    annotationCollection = shapeAnnotations;
                }
            }
            else {
                annotationCollection = shapeAnnotations;
            }
            return annotationCollection;
        };
        InkAnnotation.prototype.modifySignatureInkCollection = function (property, pageNumber, annotationBase) {
            if (!ej2_base_1.isNullOrUndefined(annotationBase.formFieldAnnotationType) && annotationBase.formFieldAnnotationType !== '') {
                this.pdfViewer.annotationModule.isFormFieldShape = true;
            }
            else {
                this.pdfViewer.annotationModule.isFormFieldShape = false;
            }
            this.pdfViewerBase.updateDocumentEditedProperty(true);
            var currentAnnotObject = null;
            var pageAnnotations = this.getAnnotations(pageNumber, null);
            if (pageAnnotations != null && annotationBase) {
                for (var i = 0; i < pageAnnotations.length; i++) {
                    if (annotationBase.id === pageAnnotations[parseInt(i.toString(), 10)].id) {
                        if (property === 'bounds') {
                            this.pdfViewerBase.isBounds =
                                this.pdfViewerBase.boundsCalculation(pageAnnotations[parseInt(i.toString(), 10)].bounds, annotationBase.wrapper.bounds);
                            if (this.pdfViewerBase.isBounds) {
                                pageAnnotations[parseInt(i.toString(), 10)].bounds = {
                                    x: annotationBase.wrapper.bounds.left,
                                    y: annotationBase.wrapper.bounds.top, width: annotationBase.bounds.width,
                                    height: annotationBase.bounds.height
                                };
                            }
                        }
                        else if (property === 'stroke') {
                            pageAnnotations[parseInt(i.toString(), 10)].strokeColor = annotationBase.wrapper.children[0].style.strokeColor;
                        }
                        else if (property === 'opacity') {
                            pageAnnotations[parseInt(i.toString(), 10)].opacity = annotationBase.wrapper.children[0].style.opacity;
                        }
                        else if (property === 'thickness') {
                            pageAnnotations[parseInt(i.toString(), 10)].thickness = annotationBase.wrapper.children[0].style.strokeWidth;
                        }
                        else if (property === 'notes') {
                            pageAnnotations[parseInt(i.toString(), 10)].notes = annotationBase.notes;
                        }
                        else if (property === 'delete') {
                            currentAnnotObject = pageAnnotations.splice(i, 1)[0];
                            break;
                        }
                        if (this.pdfViewerBase.isBounds) {
                            pageAnnotations[parseInt(i.toString(), 10)].modifiedDate =
                                this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
                        }
                        this.pdfViewer.annotationModule.storeAnnotationCollections(pageAnnotations[parseInt(i.toString(), 10)], pageNumber);
                    }
                }
                this.manageInkAnnotations(pageAnnotations, pageNumber);
            }
            return currentAnnotObject;
        };
        InkAnnotation.prototype.manageInkAnnotations = function (pageAnnotations, pageNumber) {
            var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_ink');
            if (storeObject) {
                this.pdfViewer.annotationsCollection.delete(this.pdfViewerBase.documentId + '_annotations_ink');
                var index = this.pdfViewer.annotationModule.getPageCollection(storeObject, pageNumber);
                if (index != null && storeObject[parseInt(index.toString(), 10)]) {
                    storeObject[parseInt(index.toString(), 10)].annotations = pageAnnotations;
                }
                this.pdfViewer.annotationsCollection.set(this.pdfViewerBase.documentId + '_annotations_ink', storeObject);
            }
        };
        InkAnnotation.prototype.destroy = function () {
            this.newObject = null;
            this.outputString = null;
            this.mouseX = null;
            this.mouseY = null;
            this.inkAnnotationindex = null;
            this.isAddAnnotationProgramatically = null;
            this.currentPageNumber = null;
            this.inkAnnotationInitialZoom = null;
            this.inkPathDataCollection = null;
        };
        InkAnnotation.prototype.updateInkCollections = function (currentAnnotation, pageIndex, isImport) {
            var annot;
            if (currentAnnotation) {
                var bounds = currentAnnotation.Bounds;
                var currentLeft = (bounds.X);
                var currentTop = (bounds.Y);
                var currentWidth = (bounds.Width);
                var currentHeight = (bounds.Height);
                var customData = currentAnnotation.customData;
                var isPrint = currentAnnotation.isPrint;
                currentAnnotation.AllowedInteractions = currentAnnotation.AllowedInteractions ?
                    currentAnnotation.AllowedInteractions : this.pdfViewer.annotationModule.
                    updateAnnotationAllowedInteractions(currentAnnotation);
                currentAnnotation.AnnotationSettings = currentAnnotation.AnnotationSettings ?
                    currentAnnotation.AnnotationSettings : this.pdfViewer.inkAnnotationSettings ?
                    this.pdfViewer.inkAnnotationSettings : this.pdfViewer.annotationSettings;
                if (currentAnnotation.IsLocked) {
                    currentAnnotation.AnnotationSettings.isLock = currentAnnotation.IsLocked;
                }
                var data = currentAnnotation.PathData;
                if (isImport) {
                    data = ej2_drawings_1.getPathString(JSON.parse(currentAnnotation.PathData));
                }
                annot = {
                    id: 'ink' + this.pdfViewerBase.signatureCount, bounds: { x: currentLeft, y: currentTop, width: currentWidth, height: currentHeight }, pageIndex: pageIndex, data: data,
                    shapeAnnotationType: 'Ink', opacity: currentAnnotation.Opacity, strokeColor: currentAnnotation.StrokeColor, thickness: currentAnnotation.Thickness, annotationId: currentAnnotation.AnnotName,
                    customData: customData, comments: this.pdfViewer.annotationModule.
                        getAnnotationComments(currentAnnotation.Comments, currentAnnotation, currentAnnotation.Author),
                    author: currentAnnotation.Author, allowedInteractions: currentAnnotation.AllowedInteractions,
                    subject: currentAnnotation.Subject, modifiedDate: currentAnnotation.ModifiedDate,
                    review: { state: '', stateModel: '', modifiedDate: currentAnnotation.ModifiedDate, author: currentAnnotation.Author }, notes: currentAnnotation.Note, isPrint: isPrint, isCommentLock: currentAnnotation.IsCommentLock, annotationSettings: currentAnnotation.AnnotationSettings, isLocked: currentAnnotation.AnnotationSettings.isLock
                };
                return annot;
            }
        };
        InkAnnotation.prototype.updateAddAnnotationDetails = function (annotationObject, offset, pageNumber) {
            if (!annotationObject) {
                annotationObject = { offset: { x: 10, y: 10 }, pageNumber: 0, width: undefined, height: undefined };
                offset = annotationObject.offset;
            }
            else if (!annotationObject.offset) {
                offset = { x: 10, y: 10 };
            }
            else {
                offset = annotationObject.offset;
            }
            var currentDateString = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
            var annotationName = this.pdfViewer.annotation.createGUID();
            var annotationSelectorSettings = this.pdfViewer.inkAnnotationSettings.annotationSelectorSettings;
            this.pdfViewerBase.updateSelectorSettings(annotationSelectorSettings);
            var annotationSettings = this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.inkAnnotationSettings);
            annotationObject.author = annotationObject.author ? annotationObject.author : this.pdfViewer.annotationModule.updateAnnotationAuthor('ink', annotationSettings.AnnotationType);
            var allowedInteractions = this.pdfViewer.inkAnnotationSettings.allowedInteractions ?
                this.pdfViewer.inkAnnotationSettings.allowedInteractions : this.pdfViewer.annotationSettings.allowedInteractions;
            annotationSettings.isLock = annotationObject.isLock ? annotationObject.isLock : annotationSettings.isLock;
            annotationObject.width = annotationObject.width ? annotationObject.width : 150;
            annotationObject.height = annotationObject.height ? annotationObject.height : 60;
            var pathData = annotationObject.path ? annotationObject.path : '';
            if (!ej2_base_1.isNullOrUndefined(pathData)) {
                if (pathData[0] === 'M' || pathData[0] === 'L') {
                    var collectionData = ej2_drawings_1.processPathData(pathData);
                    var csData = ej2_drawings_1.splitArrayCollection(collectionData);
                    pathData = JSON.stringify(csData);
                }
                else {
                    pathData = ej2_drawings_1.getPathString(JSON.parse(pathData));
                }
            }
            annotationObject.path = pathData;
            var signatureInkAnnotation = [];
            var ink = {
                AllowedInteractions: annotationObject.allowedInteractions ? annotationObject.allowedInteractions : allowedInteractions,
                AnnotName: annotationName,
                AnnotType: 'ink',
                AnnotationFlags: null,
                AnnotationSelectorSettings: annotationObject.annotationSelectorSettings ?
                    annotationObject.annotationSelectorSettings : annotationSelectorSettings,
                AnnotationSettings: annotationSettings,
                AnnotationType: 'Ink',
                Author: annotationObject.author ? annotationObject.author : 'Guest',
                Bounds: { X: offset.x, Y: offset.y, Width: annotationObject.width, Height: annotationObject.height,
                    Left: offset.x, Top: offset.y, Location: { X: offset.x, Y: offset.y },
                    Size: { Height: annotationObject.height, IsEmpty: false, Width: annotationObject.width } },
                Comments: null,
                CreatedDate: currentDateString,
                CustomData: annotationObject.customData ? annotationObject.customData : null,
                ExistingCustomData: null,
                IsCommentLock: false,
                IsLock: annotationObject.isLock ? annotationObject.isLock : false,
                IsPrint: !ej2_base_1.isNullOrUndefined(annotationObject.isPrint) ? annotationObject.isPrint : true,
                ModifiedDate: '',
                Note: '',
                Opacity: annotationObject.opacity ? annotationObject.opacity : 1,
                PathData: annotationObject.path,
                PageNumber: pageNumber,
                State: '',
                StateModel: '',
                StrokeColor: annotationObject.strokeColor ? annotationObject.strokeColor : 'rgba(255,0,0,1)',
                SubType: null,
                Subject: annotationObject.subject ? annotationObject.subject : 'Ink',
                Type: null,
                Thickness: annotationObject.thickness ? annotationObject.thickness : 1
            };
            signatureInkAnnotation[0] = ink;
            return { signatureInkAnnotation: signatureInkAnnotation };
        };
        return InkAnnotation;
    }());
    exports.InkAnnotation = InkAnnotation;
});