all files / pdfviewer/annotation/ free-text-annotation.js

3.3% Statements 35/1060
0% Branches 0/784
6.06% Functions 2/33
3.31% Lines 35/1059
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 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 16731×   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×         1×                 1×                                                                                                     1×   1×    
define(["require", "exports", "./../base/types", "@syncfusion/ej2-base"], function (require, exports, types_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var FreeTextAnnotation = (function () {
        function FreeTextAnnotation(pdfviewer, pdfViewerBase) {
            this.inputBoxCount = 0;
            this.isFreeTextValueChange = false;
            this.isAddAnnotationProgramatically = false;
            this.isInuptBoxInFocus = false;
            this.freeTextPageNumbers = [];
            this.selectedText = '';
            this.isTextSelected = false;
            this.selectionStart = 0;
            this.selectionEnd = 0;
            this.isBold = false;
            this.isItalic = false;
            this.isUnderline = false;
            this.isStrikethrough = false;
            this.isReadonly = false;
            this.isMaximumWidthReached = false;
            this.freeTextPaddingLeft = 4;
            this.freeTextPaddingTop = 5;
            this.defaultFontSize = 16;
            this.freetextHeight = 0;
            this.freetextWidth = 0;
            this.inputBoxHeight = 0;
            this.inputBoxWidth = 0;
            this.wrapperOffsetX = 0;
            this.wrapperOffsetY = 0;
            this.prevFontsize = 16;
            this.lineGap = 1.8;
            this.initialStrokeWidth = 0;
            this.initialStrokeThickness = 0;
            this.previousText = 'Type Here';
            this.currentPosition = [];
            this.pdfViewer = pdfviewer;
            this.pdfViewerBase = pdfViewerBase;
            this.updateTextProperties();
            this.inputBoxElement = document.createElement('textarea');
            this.inputBoxElement.style.position = 'absolute';
            this.inputBoxElement.style.Width = this.defautWidth;
            this.inputBoxElement.style.Height = this.defaultHeight;
            this.inputBoxElement.style.zIndex = '5';
            this.inputBoxElement.style.fontSize = this.fontSize + 'px';
            this.inputBoxElement.className = 'free-text-input';
            this.inputBoxElement.style.resize = 'none';
            this.inputBoxElement.style.borderColor = this.borderColor;
            this.inputBoxElement.style.background = this.fillColor;
            this.inputBoxElement.style.borderStyle = this.borderStyle;
            this.inputBoxElement.style.borderWidth = this.borderWidth + 'px';
            this.inputBoxElement.style.padding = this.padding;
            this.inputBoxElement.style.lineHeight = 'normal';
            this.inputBoxElement.style.paddingLeft = this.freeTextPaddingLeft + 'px';
            this.inputBoxElement.style.paddingTop = this.freeTextPaddingTop * (parseFloat(this.inputBoxElement.style.fontSize) / this.defaultFontSize) + 'px';
            this.inputBoxElement.style.borderRadius = '2px';
            this.inputBoxElement.style.verticalAlign = 'middle';
            this.inputBoxElement.style.fontFamily = this.fontFamily;
            this.inputBoxElement.style.color = this.pdfViewer.freeTextSettings.fontColor ?
                this.pdfViewer.freeTextSettings.fontColor : '#000';
            this.inputBoxElement.style.overflow = 'hidden';
            this.inputBoxElement.style.wordBreak = this.wordBreak;
            this.inputBoxElement.readOnly = this.isReadonly;
            this.inputBoxElement.addEventListener('focusout', this.onFocusOutInputBox.bind(this));
            this.inputBoxElement.addEventListener('keydown', this.onKeyDownInputBox.bind(this));
            this.inputBoxElement.addEventListener('mouseup', this.onMouseUpInputBox.bind(this));
            this.freeTextPageNumbers = [];
        }
        FreeTextAnnotation.prototype.updateTextProperties = function (fontStyle) {
            this.defautWidth = this.pdfViewer.freeTextSettings.width ? this.pdfViewer.freeTextSettings.width : 151;
            this.defaultHeight = this.pdfViewer.freeTextSettings.height ? this.pdfViewer.freeTextSettings.height : 24.6;
            this.borderColor = this.pdfViewer.freeTextSettings.borderColor ? this.pdfViewer.freeTextSettings.borderColor : '#ffffff00';
            this.fillColor = this.pdfViewer.freeTextSettings.fillColor ? this.pdfViewer.freeTextSettings.fillColor : '#fff';
            this.borderStyle = this.pdfViewer.freeTextSettings.borderStyle ? this.pdfViewer.freeTextSettings.borderStyle : 'solid';
            this.borderWidth = !ej2_base_1.isNullOrUndefined(this.pdfViewer.freeTextSettings.borderWidth) ?
                this.pdfViewer.freeTextSettings.borderWidth : 0;
            this.fontSize = this.pdfViewer.freeTextSettings.fontSize ? this.pdfViewer.freeTextSettings.fontSize : 16;
            this.opacity = this.pdfViewer.freeTextSettings.opacity ? this.pdfViewer.freeTextSettings.opacity : 1;
            this.fontColor = this.pdfViewer.freeTextSettings.fontColor ? this.pdfViewer.freeTextSettings.fontColor : '#000';
            this.author = (this.pdfViewer.freeTextSettings.author && this.pdfViewer.freeTextSettings.author !== 'Guest') ? this.pdfViewer.freeTextSettings.author : this.pdfViewer.annotationSettings.author ? this.pdfViewer.annotationSettings.author : 'Guest';
            if (!ej2_base_1.isNullOrUndefined(this.pdfViewer.annotationModule)) {
                if (this.getRgbCode(this.borderColor).a === 0) {
                    this.borderWidth = 0;
                }
            }
            if (this.pdfViewer.freeTextSettings.fontFamily) {
                this.fontFamily = this.pdfViewer.freeTextSettings.fontFamily;
            }
            else {
                this.fontFamily = 'Helvetica';
            }
            this.textAlign = this.pdfViewer.freeTextSettings.textAlignment ? this.pdfViewer.freeTextSettings.textAlignment : 'Left';
            this.defaultText = this.pdfViewer.freeTextSettings.defaultText ? this.pdfViewer.freeTextSettings.defaultText : 'Type here';
            this.isReadonly = false;
            if (this.pdfViewer.freeTextSettings.enableAutoFit) {
                this.wordBreak = 'break-all';
                this.padding = '2px';
            }
            else {
                this.padding = '0px';
                this.wordBreak = 'break-word';
            }
            if (this.pdfViewer.freeTextSettings.isLock || this.pdfViewer.annotationSettings.isLock
                || this.pdfViewer.freeTextSettings.isReadonly) {
                this.isReadonly = true;
            }
            this.isBold = (this.pdfViewer.freeTextSettings.fontStyle & types_1.FontStyle.Bold) === types_1.FontStyle.Bold;
            this.isItalic = (this.pdfViewer.freeTextSettings.fontStyle & types_1.FontStyle.Italic) === types_1.FontStyle.Italic;
            this.isUnderline = (this.pdfViewer.freeTextSettings.fontStyle & types_1.FontStyle.Underline) === types_1.FontStyle.Underline;
            this.isStrikethrough = (this.pdfViewer.freeTextSettings.fontStyle & types_1.FontStyle.Strikethrough) === types_1.FontStyle.Strikethrough;
            if (fontStyle) {
                for (var i = 0; i < fontStyle.length; i++) {
                    this.pdfViewer.freeTextSettings.fontStyle = fontStyle[parseInt(i.toString(), 10)];
                    if ((this.pdfViewer.freeTextSettings.fontStyle & types_1.FontStyle.Underline)) {
                        this.isUnderline = (this.pdfViewer.freeTextSettings.fontStyle &
                            types_1.FontStyle.Underline) === types_1.FontStyle.Underline;
                    }
                    else if ((this.pdfViewer.freeTextSettings.fontStyle & types_1.FontStyle.Strikethrough)) {
                        this.isStrikethrough = (this.pdfViewer.freeTextSettings.fontStyle &
                            types_1.FontStyle.Strikethrough) === types_1.FontStyle.Strikethrough;
                    }
                }
            }
        };
        FreeTextAnnotation.prototype.renderFreeTextAnnotations = function (shapeAnnotations, pageNumber, isImportAction, isAnnotOrderAction, isLastAnnot) {
            var isFreeTextAdded = false;
            if (!isImportAction) {
                for (var p = 0; p < this.freeTextPageNumbers.length; p++) {
                    if (this.freeTextPageNumbers[parseInt(p.toString(), 10)] === pageNumber) {
                        isFreeTextAdded = true;
                        break;
                    }
                }
            }
            if (shapeAnnotations && (!isFreeTextAdded || isAnnotOrderAction)) {
                if (shapeAnnotations.length >= 1) {
                    this.freeTextPageNumbers.push(pageNumber);
                    for (var i = 0; i < shapeAnnotations.length; i++) {
                        var annotation = shapeAnnotations[parseInt(i.toString(), 10)];
                        annotation.annotationAddMode = this.pdfViewer.annotationModule.
                            findAnnotationMode(annotation, pageNumber, annotation.AnnotType);
                        if (annotation.AnnotType) {
                            var vertexPoints = null;
                            if (annotation.VertexPoints) {
                                vertexPoints = [];
                                for (var j = 0; j < annotation.VertexPoints.length; j++) {
                                    var point = { x: annotation.VertexPoints[parseInt(j.toString(), 10)].X,
                                        y: annotation.VertexPoints[parseInt(j.toString(), 10)].Y };
                                    vertexPoints.push(point);
                                }
                            }
                            annotation.AnnotationSettings = annotation.AnnotationSettings ?
                                annotation.AnnotationSettings : this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.freeTextSettings);
                            if (annotation.IsLocked) {
                                annotation.AnnotationSettings.isLock = annotation.IsLocked;
                            }
                            var paddingValue = void 0;
                            if (annotation.AnnotationIntent && annotation.AnnotationIntent === 'None') {
                                paddingValue = 0.5;
                            }
                            else {
                                paddingValue = 0;
                            }
                            var annotationBoundsX = !ej2_base_1.isNullOrUndefined(annotation.Bounds.X) ?
                                annotation.Bounds.X - paddingValue : annotation.Bounds.x;
                            var annotationBoundsY = !ej2_base_1.isNullOrUndefined(annotation.Bounds.Y) ?
                                annotation.Bounds.Y - paddingValue : annotation.Bounds.y;
                            var width = annotation.Bounds.Width ?
                                annotation.Bounds.Width : annotation.Bounds.width;
                            var height = annotation.Bounds.Height ?
                                annotation.Bounds.Height : annotation.Bounds.height;
                            var isAddedProgramatically = annotation.isAddAnnotationProgramatically ?
                                annotation.isAddAnnotationProgramatically : false;
                            var rotateValue = this.getRotationValue(pageNumber, isAddedProgramatically);
                            var pageRotate = annotation.PageRotation;
                            if (Math.sign(annotation.Rotate) === 1) {
                                annotation.Rotate = -annotation.Rotate + rotateValue;
                            }
                            else {
                                annotation.Rotate = annotation.Rotate + rotateValue;
                            }
                            var rotateAngle = Math.abs(annotation.Rotate);
                            if (isImportAction && rotateValue !== pageRotate) {
                                if (this.pdfViewerBase.isJsonImported) {
                                    var pageDetails = this.pdfViewerBase.pageSize[parseInt(pageNumber.toString(), 10)];
                                    var boundsX = annotation.Bounds.X;
                                    var boundsY = annotation.Bounds.Y;
                                    var annotationWidth = width;
                                    var annotationHeight = height;
                                    if (pageRotate > 0) {
                                        var rotatation = pageRotate / 90;
                                        if (rotatation === 1) {
                                            height = width;
                                            width = annotation.Bounds.Height;
                                            annotationBoundsX = annotation.Bounds.Y;
                                            if (rotateValue !== 270) {
                                                annotationBoundsY = pageDetails.height - annotation.Bounds.X -
                                                    annotation.Bounds.Width;
                                            }
                                            else {
                                                annotationBoundsY = pageDetails.width - annotation.Bounds.X -
                                                    annotation.Bounds.Width;
                                            }
                                        }
                                        else if (rotatation === 2) {
                                            if (rotateValue !== 270 && rotateValue !== 90) {
                                                annotationBoundsX = pageDetails.width - annotation.Bounds.X -
                                                    annotation.Bounds.Width;
                                                annotationBoundsY = pageDetails.height - annotation.Bounds.Y -
                                                    annotation.Bounds.Height;
                                            }
                                            else {
                                                annotationBoundsX = pageDetails.height - annotation.Bounds.X -
                                                    annotation.Bounds.Width;
                                                annotationBoundsY = pageDetails.width - annotation.Bounds.Y -
                                                    annotation.Bounds.Height;
                                            }
                                        }
                                        else if (rotatation === 3) {
                                            height = width;
                                            width = annotation.Bounds.Height;
                                            if (rotateValue !== 90) {
                                                annotationBoundsX = pageDetails.width - annotation.Bounds.Y - width;
                                            }
                                            else {
                                                annotationBoundsX = pageDetails.height - annotation.Bounds.Y - width;
                                            }
                                            annotationBoundsY = annotation.Bounds.X;
                                        }
                                        boundsX = annotationBoundsX;
                                        boundsY = annotationBoundsY;
                                        annotationWidth = width;
                                        annotationHeight = height;
                                    }
                                    rotateAngle = (rotateValue / 90) % 4;
                                    if (rotateAngle === 1) {
                                        height = width;
                                        width = annotationHeight;
                                        annotationBoundsX = pageDetails.width - boundsY - annotationHeight - paddingValue;
                                        annotationBoundsY = boundsX - paddingValue;
                                        rotateAngle = 90;
                                    }
                                    else if (rotateAngle === 2) {
                                        annotationBoundsX = pageDetails.width - boundsX - annotationWidth - paddingValue;
                                        annotationBoundsY = pageDetails.height - boundsY - annotationHeight - paddingValue;
                                        rotateAngle = 180;
                                    }
                                    else if (rotateAngle === 3) {
                                        height = width;
                                        width = annotationHeight;
                                        annotationBoundsX = boundsY - paddingValue;
                                        annotationBoundsY = pageDetails.height - boundsX - height - paddingValue;
                                        rotateAngle = 270;
                                    }
                                    else if (rotateAngle === 0) {
                                        annotationBoundsX = boundsX - paddingValue;
                                        annotationBoundsY = boundsY - paddingValue;
                                    }
                                }
                            }
                            if (rotateAngle === 90 || rotateAngle === 270) {
                                var rotationHeight = height;
                                var rotationWidth = width;
                                height = rotationWidth;
                                width = rotationHeight;
                                annotationBoundsX = (annotationBoundsX - (width / 2)) + (height / 2);
                                annotationBoundsY = (annotationBoundsY) + (width / 2 - height / 2);
                            }
                            annotation.allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions :
                                this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
                            if (!ej2_base_1.isNullOrUndefined(annotation) && annotation.MarkupText && annotation.MarkupText.includes('\n')) {
                                var noOfLines = annotation.MarkupText.split('\n').length;
                                var newHeight = noOfLines * annotation.FontSize * this.lineGap;
                                var pageHeight = this.pdfViewerBase.pageSize[parseInt(pageNumber.toString(), 10)].height
                                    - annotation.Bounds.Y;
                                if (height < newHeight) {
                                    height = newHeight;
                                }
                                if (height > pageHeight) {
                                    height = pageHeight;
                                }
                            }
                            var annot = {
                                author: annotation.Author, modifiedDate: annotation.ModifiedDate, subject: annotation.Subject, id: 'freetext' + this.inputBoxCount,
                                rotateAngle: annotation.Rotate, dynamicText: annotation.MarkupText, strokeColor: annotation.StrokeColor,
                                thickness: annotation.Thickness, fillColor: annotation.FillColor,
                                bounds: {
                                    x: annotationBoundsX, y: annotationBoundsY, left: annotationBoundsX, top: annotationBoundsY,
                                    width: width, height: height, right: annotation.Bounds.Right,
                                    bottom: annotation.Bounds.Bottom
                                }, annotName: annotation.AnnotName, shapeAnnotationType: 'FreeText',
                                pageIndex: pageNumber, opacity: annotation.Opacity, fontColor: annotation.FontColor,
                                fontSize: annotation.FontSize, pageRotation: rotateValue,
                                fontFamily: annotation.FontFamily, notes: annotation.MarkupText, textAlign: annotation.TextAlign,
                                comments: this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author),
                                review: { state: annotation.State, stateModel: annotation.StateModel,
                                    modifiedDate: annotation.ModifiedDate, author: annotation.Author },
                                font: { isBold: annotation.Font.Bold, isItalic: annotation.Font.Italic,
                                    isStrikeout: annotation.Font.Strikeout, isUnderline: annotation.Font.Underline },
                                annotationSelectorSettings: this.getSettings(annotation), annotationSettings: annotation.AnnotationSettings,
                                customData: this.pdfViewer.annotation.getCustomData(annotation),
                                annotationAddMode: annotation.annotationAddMode, allowedInteractions: annotation.allowedInteractions,
                                isPrint: annotation.IsPrint, isCommentLock: annotation.IsCommentLock, isReadonly: annotation.IsReadonly,
                                isAddAnnotationProgrammatically: isAddedProgramatically, isTransparentSet: annotation.IsTransparentSet
                            };
                            var annotObject = {
                                author: annotation.Author, modifiedDate: annotation.ModifiedDate, subject: annotation.Subject, id: 'freetext' + this.inputBoxCount,
                                rotateAngle: annotation.Rotate, dynamicText: annotation.MarkupText, strokeColor: annotation.StrokeColor,
                                thickness: annotation.Thickness, fillColor: annotation.FillColor,
                                bounds: {
                                    x: annotationBoundsX, y: annotationBoundsY, left: annotationBoundsX, top: annotationBoundsY,
                                    width: width, height: height, right: annotation.Bounds.Right,
                                    bottom: annotation.Bounds.Bottom
                                }, annotName: annotation.AnnotName, shapeAnnotationType: 'FreeText',
                                pageIndex: pageNumber, opacity: annotation.Opacity, fontColor: annotation.FontColor,
                                fontSize: annotation.FontSize, pageRotation: rotateValue,
                                fontFamily: annotation.FontFamily, notes: annotation.MarkupText, textAlign: annotation.TextAlign,
                                comments: this.pdfViewer.annotationModule.getAnnotationComments(annotation.Comments, annotation, annotation.Author),
                                review: { state: annotation.State, stateModel: annotation.StateModel,
                                    modifiedDate: annotation.ModifiedDate, author: annotation.Author },
                                font: { isBold: annotation.Font.Bold, isItalic: annotation.Font.Italic,
                                    isStrikeout: annotation.Font.Strikeout, isUnderline: annotation.Font.Underline },
                                annotationSelectorSettings: this.getSettings(annotation), annotationSettings: annotation.AnnotationSettings,
                                customData: this.pdfViewer.annotation.getCustomData(annotation),
                                annotationAddMode: annotation.annotationAddMode, allowedInteractions: annotation.allowedInteractions,
                                isPrint: annotation.IsPrint, isCommentLock: annotation.IsCommentLock, isReadonly: annotation.IsReadonly,
                                isAddAnnotationProgrammatically: isAddedProgramatically, isTransparentSet: annotation.IsTransparentSet,
                                originalName: annotation.OriginalName ? annotation.OriginalName : null
                            };
                            if (isImportAction) {
                                annot.id = annotation.AnnotName;
                                annot.previousFontSize = annotation.FontSize ? annotation.FontSize : this.fontSize;
                                annotObject.id = annotation.AnnotName;
                                annotObject.previousFontSize = annotation.FontSize ? annotation.FontSize : this.fontSize;
                            }
                            if (annotation.AnnotationIntent && annotation.AnnotationIntent === 'None') {
                                annot.isSignatureText = true;
                            }
                            var addedAnnot = this.pdfViewer.add(annot);
                            if (annotObject.textAlign !== null) {
                                if (annotObject.textAlign === 'Justify') {
                                    addedAnnot.wrapper.children[1].horizontalAlignment = 'Left';
                                    addedAnnot.wrapper.children[1].setOffsetWithRespectToBounds(0, 0, null);
                                }
                                else if (annotObject.textAlign === 'Right') {
                                    addedAnnot.wrapper.children[1].horizontalAlignment = 'Right';
                                    addedAnnot.wrapper.children[1].setOffsetWithRespectToBounds(1, 0, null);
                                }
                                else if (annotObject.textAlign === 'Left') {
                                    addedAnnot.wrapper.children[1].horizontalAlignment = 'Left';
                                    addedAnnot.wrapper.children[1].setOffsetWithRespectToBounds(0, 0, null);
                                }
                                else if (annotObject.textAlign === 'Center') {
                                    addedAnnot.wrapper.children[1].horizontalAlignment = 'Center';
                                    addedAnnot.wrapper.children[1].setOffsetWithRespectToBounds(0.51, 0, null);
                                }
                            }
                            else {
                                addedAnnot.wrapper.children[1].horizontalAlignment = 'Auto';
                            }
                            this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annotObject, '_annotations_freetext');
                            if (this.isAddAnnotationProgramatically) {
                                var settings = {
                                    opacity: annot.opacity, borderColor: annot.strokeColor, borderWidth: annot.thickness,
                                    author: annotation.author, subject: annotation.subject, modifiedDate: annotation.modifiedDate,
                                    fillColor: annot.fillColor, fontSize: annot.fontSize, width: annot.bounds.width,
                                    height: annot.bounds.height, fontColor: annot.fontColor, fontFamily: annot.fontFamily,
                                    defaultText: annot.dynamicText, fontStyle: annot.font, textAlignment: annot.textAlign
                                };
                                this.pdfViewer.fireAnnotationAdd(annot.pageIndex, annot.annotName, 'FreeText', annot.bounds, settings);
                            }
                            this.inputBoxCount += 1;
                            this.pdfViewer.annotation.freeTextAnnotationModule.isFreeTextValueChange = true;
                            var isNeedToRender = ((isImportAction && isLastAnnot) || ej2_base_1.isNullOrUndefined(isImportAction) ||
                                !isImportAction) ? true : false;
                            var zoomFactor = this.pdfViewerBase.getZoomFactor();
                            if (annotation.AnnotationIntent && annotation.AnnotationIntent !== 'None') {
                                var computedPad = 0;
                                if (addedAnnot && addedAnnot.wrapper && addedAnnot.wrapper.children[0]) {
                                    var strokeWidth = addedAnnot.wrapper.children[0].style.strokeWidth || 0;
                                    computedPad = Math.ceil(strokeWidth);
                                }
                                else if (!ej2_base_1.isNullOrUndefined(this.borderWidth)) {
                                    computedPad = Math.ceil(this.borderWidth);
                                }
                                var padPx = (computedPad * zoomFactor) + 'px';
                                this.inputBoxElement.style.paddingTop = padPx;
                                var align = (addedAnnot && addedAnnot.textAlign)
                                    ? addedAnnot.textAlign.toLowerCase()
                                    : this.textAlign ? this.textAlign.toLowerCase() : 'left';
                                this.inputBoxElement.style.paddingLeft = (align === 'left' || align === 'justify') ? padPx : (computedPad * zoomFactor) + 'px';
                                this.inputBoxElement.style.paddingRight = (align === 'right') ? padPx : (computedPad * zoomFactor) + 'px';
                                this.inputBoxElement.style.fontSize = (addedAnnot.fontSize * this.pdfViewerBase.getZoomFactor()) + 'px';
                                addedAnnot.wrapper.children[1].margin.left = 0;
                                addedAnnot.wrapper.children[1].margin.top = 0;
                            }
                            this.pdfViewer.nodePropertyChange(addedAnnot, {}, isNeedToRender);
                            this.pdfViewer.annotation.freeTextAnnotationModule.isFreeTextValueChange = false;
                        }
                    }
                }
            }
        };
        FreeTextAnnotation.prototype.getSettings = function (annotation) {
            var selector = this.pdfViewer.annotationSelectorSettings;
            if (annotation.AnnotationSelectorSettings) {
                selector = typeof (annotation.AnnotationSelectorSettings) === 'string' ? JSON.parse(annotation.AnnotationSelectorSettings) : annotation.AnnotationSelectorSettings;
            }
            else if (this.pdfViewer.freeTextSettings.annotationSelectorSettings) {
                selector = this.pdfViewer.freeTextSettings.annotationSelectorSettings;
                this.pdfViewerBase.updateSelectorSettings(selector);
            }
            return selector;
        };
        FreeTextAnnotation.prototype.setAnnotationType = function (type) {
            this.pdfViewerBase.disableTextSelectionMode();
            this.pdfViewer.annotationModule.isFormFieldShape = false;
            switch (type) {
                case 'FreeText': {
                    this.currentAnnotationMode = 'FreeText';
                    this.updateTextProperties();
                    var modifiedDateRect = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
                    this.pdfViewer.drawingObject = {
                        shapeAnnotationType: 'FreeText', strokeColor: this.borderColor,
                        fillColor: this.fillColor, opacity: this.opacity, notes: '', isCommentLock: false,
                        thickness: this.borderWidth, borderDashArray: '0', modifiedDate: modifiedDateRect,
                        author: this.author, subject: this.pdfViewer.freeTextSettings.subject,
                        font: {
                            isBold: this.isBold, isItalic: this.isItalic, isStrikeout: this.isStrikethrough,
                            isUnderline: this.isUnderline
                        }, textAlign: this.textAlign
                    };
                    this.pdfViewer.tool = 'Select';
                    break;
                }
            }
        };
        FreeTextAnnotation.prototype.modifyInCollection = function (property, pageNumber, annotationBase, isNewAdded) {
            if (!ej2_base_1.isNullOrUndefined(annotationBase.formFieldAnnotationType) && annotationBase.formFieldAnnotationType !== '') {
                this.pdfViewer.annotationModule.isFormFieldShape = true;
            }
            else {
                this.pdfViewer.annotationModule.isFormFieldShape = false;
            }
            var currentAnnotObject = null;
            var isEdited = false;
            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 = {
                                    left: annotationBase.bounds.x, top: annotationBase.bounds.y,
                                    width: annotationBase.bounds.width, height: annotationBase.bounds.height,
                                    right: annotationBase.bounds.right,
                                    bottom: annotationBase.bounds.bottom
                                };
                            }
                        }
                        else if (property === 'fill') {
                            pageAnnotations[parseInt(i.toString(), 10)].fillColor = annotationBase.wrapper.children[0].style.fill;
                        }
                        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;
                            this.initialStrokeWidth = annotationBase.wrapper.children[0].style.strokeWidth;
                            this.initialStrokeThickness = annotationBase.wrapper.children[0].style.strokeWidth;
                        }
                        else if (property === 'notes') {
                            pageAnnotations[parseInt(i.toString(), 10)].note = annotationBase.notes;
                        }
                        else if (property === 'delete') {
                            currentAnnotObject = pageAnnotations.splice(i, 1)[0];
                            break;
                        }
                        else if (property === 'dynamicText') {
                            if (pageAnnotations[parseInt(i.toString(), 10)].dynamicText !== annotationBase.dynamicText) {
                                isEdited = true;
                                this.pdfViewer.fireCommentEdit(pageAnnotations[parseInt(i.toString(), 10)].annotName, annotationBase.dynamicText, pageAnnotations[parseInt(i.toString(), 10)]);
                            }
                            pageAnnotations[parseInt(i.toString(), 10)].dynamicText = annotationBase.dynamicText;
                        }
                        else if (property === 'fontColor') {
                            pageAnnotations[parseInt(i.toString(), 10)].fontColor = annotationBase.fontColor;
                        }
                        else if (property === 'fontSize') {
                            pageAnnotations[parseInt(i.toString(), 10)].fontSize = annotationBase.fontSize;
                        }
                        else if (property === 'fontFamily') {
                            pageAnnotations[parseInt(i.toString(), 10)].fontFamily = annotationBase.fontFamily;
                        }
                        else if (property === 'textPropertiesChange') {
                            pageAnnotations[parseInt(i.toString(), 10)].font = { isBold: annotationBase.font.isBold,
                                isItalic: annotationBase.font.isItalic, isStrikeout: annotationBase.font.isStrikeout,
                                isUnderline: annotationBase.font.isUnderline };
                        }
                        else if (property === 'textAlign') {
                            pageAnnotations[parseInt(i.toString(), 10)].textAlign = annotationBase.textAlign;
                        }
                        if (this.pdfViewerBase.isBounds) {
                            pageAnnotations[parseInt(i.toString(), 10)].modifiedDate =
                                this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
                        }
                        if (isEdited) {
                            pageAnnotations[parseInt(i.toString(), 10)].author = annotationBase.author;
                            pageAnnotations[parseInt(i.toString(), 10)].modifiedDate =
                                this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
                        }
                        this.pdfViewer.annotationModule.storeAnnotationCollections(pageAnnotations[parseInt(i.toString(), 10)], pageNumber);
                    }
                }
                this.manageAnnotations(pageAnnotations, pageNumber);
            }
            if (!isNewAdded && isEdited) {
                this.pdfViewerBase.updateDocumentEditedProperty(true);
            }
            return currentAnnotObject;
        };
        FreeTextAnnotation.prototype.addInCollection = function (pageNumber, annotationBase) {
            if (annotationBase) {
                var pageAnnotations = this.getAnnotations(pageNumber, null);
                if (pageAnnotations) {
                    pageAnnotations.push(annotationBase);
                }
                this.manageAnnotations(pageAnnotations, pageNumber);
            }
        };
        FreeTextAnnotation.prototype.saveFreeTextAnnotations = function () {
            var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_freetext');
            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)]);
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds =
                                this.getBoundsBasedOnRotation(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds, pageAnnotationObject.annotations[parseInt(z.toString(), 10)].rotateAngle, pageAnnotationObject.pageIndex, pageAnnotationObject.annotations[parseInt(z.toString(), 10)]);
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].bounds =
                                JSON.stringify(this.pdfViewer.annotation.getBounds(pageAnnotationObject.
                                    annotations[parseInt(z.toString(), 10)].bounds, pageAnnotationObject.pageIndex));
                            var strokeColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].strokeColor;
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].strokeColor =
                                JSON.stringify(this.getRgbCode(strokeColorString));
                            var fillColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].fillColor;
                            if (typeof fillColorString === 'string' && fillColorString.trim().toLowerCase() === 'transparent') {
                                fillColorString = 'rgba(0,0,0,0)';
                            }
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].fillColor =
                                JSON.stringify(this.getRgbCode(fillColorString));
                            var fontColorString = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].fontColor;
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].fontColor =
                                JSON.stringify(this.getRgbCode(fontColorString));
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].vertexPoints =
                                JSON.stringify(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].vertexPoints);
                            if (pageAnnotationObject.annotations[parseInt(z.toString(), 10)].rectangleDifference !== null) {
                                pageAnnotationObject.annotations[parseInt(z.toString(), 10)].rectangleDifference =
                                    JSON.stringify(pageAnnotationObject.annotations[parseInt(z.toString(), 10)].rectangleDifference);
                            }
                            var thickness = pageAnnotationObject.annotations[parseInt(z.toString(), 10)].thickness;
                            pageAnnotationObject.annotations[parseInt(z.toString(), 10)].padding = this.getPaddingValues(thickness);
                        }
                        newArray = pageAnnotationObject.annotations;
                    }
                    annotations[pageAnnotationObject.pageIndex] = newArray;
                }
                annotationCollection = null;
            }
            return JSON.stringify(annotations);
        };
        FreeTextAnnotation.prototype.getRotationValue = function (pageIndex, isAddedProgrammatically) {
            var pageDetails = this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)];
            if (!ej2_base_1.isNullOrUndefined(isAddedProgrammatically) && isAddedProgrammatically) {
                return 0;
            }
            else {
                if (pageDetails) {
                    if (pageDetails.rotation === 0) {
                        return 0;
                    }
                    else if (pageDetails.rotation === 1) {
                        return 90;
                    }
                    else if (pageDetails.rotation === 2) {
                        return 180;
                    }
                    else if (pageDetails.rotation === 3) {
                        return 270;
                    }
                }
                return 0;
            }
        };
        FreeTextAnnotation.prototype.getBoundsBasedOnRotation = function (bounds, rotateAngle, pageIndex, annotation, isAddedProgrammatically) {
            var rotateValue = this.getRotationValue(pageIndex, isAddedProgrammatically);
            var paddingValue = 0;
            annotation.rotateAngle = rotateAngle - rotateValue;
            annotation.pageRotation = rotateValue;
            if (rotateAngle === 90 || rotateAngle === -90 || rotateAngle === 270 || rotateAngle === -270) {
                var x = bounds.left + (bounds.width / 2) - (bounds.height / 2);
                var y = bounds.top - (bounds.width / 2 - bounds.height / 2);
                return { x: x + paddingValue, y: y + paddingValue, left: x + paddingValue,
                    top: y + paddingValue, width: bounds.height, height: bounds.width };
            }
            else {
                return { x: bounds.left + paddingValue, y: bounds.top + paddingValue,
                    left: bounds.left + paddingValue, top: bounds.top + paddingValue, width: bounds.width, height: bounds.height };
            }
        };
        FreeTextAnnotation.prototype.manageAnnotations = function (pageAnnotations, pageNumber) {
            var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_freetext');
            if (storeObject) {
                this.pdfViewer.annotationsCollection.delete(this.pdfViewerBase.documentId + '_annotations_freetext');
                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_freetext', storeObject);
            }
        };
        FreeTextAnnotation.prototype.getAnnotations = function (pageIndex, shapeAnnotations) {
            var annotationCollection;
            var storeObject = this.pdfViewer.annotationsCollection.get(this.pdfViewerBase.documentId + '_annotations_freetext');
            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;
        };
        FreeTextAnnotation.prototype.getRgbCode = function (colorString) {
            if (!colorString.match(/#([a-z0-9]+)/gi) && !colorString.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/)) {
                colorString = this.pdfViewer.annotationModule.nameToHash(colorString);
            }
            var stringArray = colorString.split(',');
            if (ej2_base_1.isNullOrUndefined(stringArray[1])) {
                colorString = this.pdfViewer.annotationModule.getValue(colorString, 'rgba');
                stringArray = colorString.split(',');
            }
            var r = parseFloat(stringArray[0].split('(')[1]);
            var g = parseFloat(stringArray[1]);
            var b = parseFloat(stringArray[2]);
            var a = parseFloat(stringArray[3]);
            return { r: r, g: g, b: b, a: a };
        };
        FreeTextAnnotation.prototype.onFocusOutInputBox = function () {
            var allowServerDataBind = this.pdfViewer.allowServerDataBinding;
            this.pdfViewer.enableServerDataBinding(false);
            if (!this.pdfViewerBase.isFreeTextContextMenu) {
                this.pdfViewer.fireBeforeAddFreeTextAnnotation(this.inputBoxElement.value);
                if (this.pdfViewer.enableHtmlSanitizer && this.inputBoxElement) {
                    var sanitizedString = ej2_base_1.SanitizeHtmlHelper.sanitize(this.inputBoxElement.value);
                    if (sanitizedString === this.inputBoxElement.value) {
                        this.inputBoxElement.value = sanitizedString;
                    }
                }
                var pageIndex = this.inputBoxElement.id && this.inputBoxElement.id.split('_freeText_')[1] && this.inputBoxElement.id.split('_freeText_')[1].split('_')[0] ? parseFloat(this.inputBoxElement.id.split('_freeText_')[1].split('_')[0]) : this.pdfViewerBase.currentPageNumber - 1;
                var pageDiv = this.pdfViewerBase.getElement('_pageDiv_' + (pageIndex));
                var width = parseFloat(this.inputBoxElement.style.width);
                if (this.pdfViewer.freeTextSettings.enableAutoFit && !this.isMaximumWidthReached && this.isNewFreeTextAnnot) {
                    width = parseFloat(this.inputBoxElement.style.width);
                    var characterLength = 8;
                    this.inputBoxElement.style.width = (width - characterLength) + 'px';
                }
                var inputEleHeight = parseFloat(this.inputBoxElement.style.height);
                var inputEleWidth = parseFloat(this.inputBoxElement.style.width);
                var inputEleLeft = parseFloat(this.inputBoxElement.style.left);
                if (this.pdfViewerBase.isMixedSizeDocument) {
                    var canvas = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageIndex);
                    inputEleLeft = inputEleLeft - canvas.offsetLeft;
                }
                var inputEleTop = parseFloat(this.inputBoxElement.style.top);
                var zoomFactor = this.pdfViewerBase.getZoomFactor();
                if (this.pdfViewer.isValidFreeText) {
                    this.inputBoxElement.value = 'Type Here';
                    this.pdfViewer.isValidFreeText = false;
                }
                var inputValue = this.inputBoxElement.value;
                var isNewlyAdded = false;
                if (this.isNewFreeTextAnnot === true) {
                    var currentDateString = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
                    var annotationName = this.pdfViewer.annotation.createGUID();
                    this.isNewFreeTextAnnot = false;
                    isNewlyAdded = true;
                    var commentsDivid = this.pdfViewer.annotation.stickyNotesAnnotationModule.addComments('freeText', pageIndex + 1);
                    if (commentsDivid) {
                        document.getElementById(commentsDivid).id = annotationName;
                    }
                    var annotationSelectorSettings = this.pdfViewer.freeTextSettings.annotationSelectorSettings;
                    this.pdfViewerBase.updateSelectorSettings(annotationSelectorSettings);
                    var annotationSettings = this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.freeTextSettings);
                    this.author = this.author ? this.author : this.pdfViewer.freeTextSettings.author ? this.pdfViewer.freeTextSettings.author : 'Guest';
                    this.subject = this.subject ? this.subject : this.pdfViewer.freeTextSettings.subject ? this.pdfViewer.freeTextSettings.subject : 'Text Box';
                    var allowedInteractions = this.pdfViewer.freeTextSettings.allowedInteractions ?
                        this.pdfViewer.freeTextSettings.allowedInteractions : this.pdfViewer.annotationSettings.allowedInteractions;
                    var annot = {
                        author: this.author, modifiedDate: currentDateString, subject: this.subject, id: 'free_text' + this.inputBoxCount,
                        rotateAngle: 0, dynamicText: inputValue, strokeColor: this.borderColor,
                        thickness: this.borderWidth, fillColor: this.fillColor,
                        bounds: {
                            left: inputEleLeft / zoomFactor, top: inputEleTop / zoomFactor, x: inputEleLeft / zoomFactor,
                            y: inputEleTop / zoomFactor, width: inputEleWidth / zoomFactor, height: inputEleHeight / zoomFactor
                        }, annotName: annotationName,
                        shapeAnnotationType: 'FreeText', pageIndex: pageIndex, fontColor: this.fontColor, fontSize: this.fontSize,
                        fontFamily: this.fontFamily, opacity: this.opacity, comments: [], textAlign: this.textAlign,
                        font: { isBold: this.isBold, isItalic: this.isItalic, isStrikeout: this.isStrikethrough,
                            isUnderline: this.isUnderline },
                        review: { state: 'Unmarked', stateModel: 'None', modifiedDate: currentDateString, author: this.author },
                        annotationSelectorSettings: annotationSelectorSettings, annotationSettings: annotationSettings,
                        customData: this.pdfViewer.annotationModule.getData('FreeText'), isPrint: (this.pdfViewer.freeTextSettings && !ej2_base_1.isNullOrUndefined(this.pdfViewer.freeTextSettings.isPrint)) ? this.pdfViewer.freeTextSettings.isPrint : true,
                        allowedInteractions: allowedInteractions, isReadonly: this.isReadonly, isSignatureText: false
                    };
                    var annotObject = {
                        author: this.author, modifiedDate: currentDateString, subject: this.subject, id: 'free_text' + this.inputBoxCount,
                        rotateAngle: 0, dynamicText: inputValue, strokeColor: this.borderColor,
                        thickness: this.borderWidth, fillColor: this.fillColor,
                        bounds: {
                            left: inputEleLeft / zoomFactor, top: inputEleTop / zoomFactor, x: inputEleLeft / zoomFactor,
                            y: inputEleTop / zoomFactor, width: inputEleWidth / zoomFactor, height: inputEleHeight / zoomFactor
                        }, annotName: annotationName,
                        shapeAnnotationType: 'FreeText', pageIndex: pageIndex, fontColor: this.fontColor, fontSize: this.fontSize,
                        fontFamily: this.fontFamily, opacity: this.opacity, comments: [], textAlign: this.textAlign,
                        font: { isBold: this.isBold, isItalic: this.isItalic, isStrikeout: this.isStrikethrough,
                            isUnderline: this.isUnderline },
                        review: { state: 'Unmarked', stateModel: 'None', modifiedDate: currentDateString, author: this.author },
                        annotationSelectorSettings: annotationSelectorSettings, annotationSettings: annotationSettings,
                        customData: this.pdfViewer.annotationModule.getData('FreeText'), isPrint: (this.pdfViewer.freeTextSettings && !ej2_base_1.isNullOrUndefined(this.pdfViewer.freeTextSettings.isPrint)) ? this.pdfViewer.freeTextSettings.isPrint : true,
                        allowedInteractions: allowedInteractions, isReadonly: this.isReadonly
                    };
                    if (this.pdfViewer.enableRtl) {
                        annot.textAlign = 'Right';
                        annotObject.textAlign = 'Right';
                    }
                    annot.isSignatureText = false;
                    var annotation = this.pdfViewer.add(annot);
                    if (annotObject.textAlign !== null) {
                        if (annotObject.textAlign === 'Justify') {
                            annotation.wrapper.children[1].horizontalAlignment = 'Left';
                            annotation.wrapper.children[1].setOffsetWithRespectToBounds(0, 0, null);
                        }
                        else if (annotObject.textAlign === 'Right') {
                            annotation.wrapper.children[1].horizontalAlignment = 'Right';
                            annotation.wrapper.children[1].setOffsetWithRespectToBounds(1, 0, null);
                        }
                        else if (annotObject.textAlign === 'Left') {
                            annotation.wrapper.children[1].horizontalAlignment = 'Left';
                            annotation.wrapper.children[1].setOffsetWithRespectToBounds(0, 0, null);
                        }
                        else if (annotObject.textAlign === 'Center') {
                            annotation.wrapper.children[1].horizontalAlignment = 'Center';
                            annotation.wrapper.children[1].setOffsetWithRespectToBounds(0.51, 0, null);
                        }
                    }
                    else {
                        annotation.wrapper.children[1].horizontalAlignment = 'Auto';
                    }
                    var bounds = { left: annot.bounds.x, top: annot.bounds.y, width: annot.bounds.width,
                        height: annot.bounds.height };
                    var settings = {
                        opacity: annot.opacity, borderColor: annot.strokeColor, borderWidth: annot.thickness,
                        author: annotation.author, subject: annotation.subject, modifiedDate: annotation.modifiedDate,
                        fillColor: annot.fillColor, fontSize: annot.fontSize, width: annot.bounds.width,
                        height: annot.bounds.height, fontColor: annot.fontColor, fontFamily: annot.fontFamily,
                        defaultText: annot.dynamicText, fontStyle: annot.font, textAlignment: annot.textAlign
                    };
                    this.pdfViewer.annotation.storeAnnotations(pageIndex, annotObject, '_annotations_freetext');
                    this.pdfViewerBase.updateDocumentEditedProperty(true);
                    this.pdfViewer.fireAnnotationAdd(annot.pageIndex, annot.annotName, 'FreeText', bounds, settings);
                    if (ej2_base_1.Browser.isDevice && !this.pdfViewer.enableDesktopMode) {
                        if (this.pdfViewer.toolbarModule && this.pdfViewer.toolbarModule.annotationToolbarModule) {
                            this.pdfViewer.toolbarModule.annotationToolbarModule.createAnnotationToolbarForMobile();
                            this.pdfViewer.toolbarModule.annotationToolbarModule.freetextToolbarElement.style.display = 'none';
                            var editIcon = document.getElementById(this.pdfViewer.element.id + '_annotationIcon');
                            if (editIcon && editIcon.parentElement.classList.contains('e-pv-select')) {
                                this.pdfViewer.toolbarModule.annotationToolbarModule.toolbarCreated = false;
                                this.pdfViewer.toolbarModule.annotationToolbarModule.createAnnotationToolbarForMobile();
                            }
                            if (this.pdfViewer.toolbarModule.annotationToolbarModule.toolbarElement.children.length > 0) {
                                this.pdfViewer.toolbarModule.annotationToolbarModule.toolbarElement.style.display = 'block';
                            }
                            this.pdfViewer.toolbarModule.annotationToolbarModule.adjustMobileViewer();
                        }
                    }
                    this.pdfViewer.fireCommentAdd(annot.annotName, annot.dynamicText, annot);
                    this.pdfViewer.annotation.addAction(pageIndex, null, annotation, 'Addition', '', annotation, annotation);
                    this.pdfViewer.renderSelector(annot.pageIndex);
                    this.pdfViewer.clearSelection(annot.pageIndex);
                    this.selectedAnnotation = annotation;
                }
                this.isInuptBoxInFocus = false;
                var isFreetextValueEqual = false;
                if (inputValue === this.inputBoxValue) {
                    isFreetextValueEqual = true;
                }
                var isFontSizeEqual = true;
                if (this.selectedAnnotation.fontSize !== this.prevFontsize) {
                    isFontSizeEqual = false;
                }
                this.prevFontsize = this.selectedAnnotation.fontSize;
                var borderColor = this.inputBoxElement.style.borderColor;
                var background = this.inputBoxElement.style.background;
                if (this.selectedAnnotation && this.pdfViewer.selectedItems.annotations &&
                    (!isFontSizeEqual || !isFreetextValueEqual || isNewlyAdded)) {
                    var isRotated = (Math.abs(this.selectedAnnotation.rotateAngle) !== 0 &&
                        Math.abs(this.selectedAnnotation.rotateAngle) !== 180);
                    inputEleHeight = parseFloat(isRotated ? this.inputBoxElement.style.width : this.inputBoxElement.style.height) / zoomFactor;
                    inputEleWidth = parseFloat(isRotated ? this.inputBoxElement.style.height : this.inputBoxElement.style.width) / zoomFactor;
                    var heightDiff = (inputEleHeight - this.selectedAnnotation.bounds.height);
                    var y = undefined;
                    if (heightDiff > 0) {
                        y = this.selectedAnnotation.wrapper.offsetY + (heightDiff / 2);
                        y = y > 0 ? y : undefined;
                    }
                    var widthDiff = (inputEleWidth - this.selectedAnnotation.bounds.width);
                    var x = undefined;
                    if (widthDiff > 0) {
                        x = this.selectedAnnotation.wrapper.offsetX + (widthDiff / 2);
                        x = x > 0 ? x : undefined;
                    }
                    else {
                        widthDiff = Math.abs(widthDiff);
                        x = this.selectedAnnotation.wrapper.offsetX - (widthDiff / 2);
                    }
                    this.selectedAnnotation.bounds.width = inputEleWidth;
                    this.selectedAnnotation.bounds.height = inputEleHeight;
                    var lineSpace = 0;
                    lineSpace = ((parseFloat(this.inputBoxElement.style.fontSize) / zoomFactor) / (this.defaultFontSize / 2));
                    this.selectedAnnotation.wrapper.children[1].margin.left = 0;
                    this.selectedAnnotation.wrapper.children[1].margin.top = 0;
                    this.pdfViewer.annotation.modifyDynamicTextValue(inputValue, this.selectedAnnotation.annotName, this.previousText);
                    this.selectedAnnotation.dynamicText = inputValue;
                    this.selectedAnnotation.wrapper.children[0].style.strokeColor = borderColor;
                    this.selectedAnnotation.wrapper.children[0].style.fill = background;
                    this.modifyInCollection('dynamicText', pageIndex, this.selectedAnnotation, isNewlyAdded);
                    this.modifyInCollection('bounds', pageIndex, this.selectedAnnotation, isNewlyAdded);
                    this.pdfViewer.nodePropertyChange(this.selectedAnnotation, { bounds: { width: this.selectedAnnotation.bounds.width,
                            height: this.selectedAnnotation.bounds.height, y: y, x: x } });
                    var commentsDiv = document.getElementById(this.selectedAnnotation.annotName);
                    if (commentsDiv && commentsDiv.childNodes) {
                        var sanitizedString = ej2_base_1.SanitizeHtmlHelper.sanitize(inputValue);
                        if (commentsDiv.childNodes[0].ej2_instances) {
                            if (sanitizedString !== inputValue) {
                                commentsDiv.childNodes[0].ej2_instances[0].enableHtmlSanitizer = false;
                                commentsDiv.childNodes[0].ej2_instances[0].enableHtmlParse = false;
                            }
                            commentsDiv.childNodes[0].ej2_instances[0].value = inputValue;
                            commentsDiv.childNodes[0].ej2_instances[0].dataBind();
                        }
                        else if (commentsDiv.childNodes[0].childNodes && commentsDiv.childNodes[0].childNodes[1].ej2_instances) {
                            if (sanitizedString !== inputValue) {
                                commentsDiv.childNodes[0].childNodes[1].ej2_instances[0].enableHtmlSanitizer = false;
                                commentsDiv.childNodes[0].childNodes[1].ej2_instances[0].enableHtmlParse = false;
                            }
                            commentsDiv.childNodes[0].childNodes[1].ej2_instances[0].value = inputValue;
                            commentsDiv.childNodes[0].childNodes[1].ej2_instances[0].dataBind();
                        }
                    }
                    this.pdfViewer.renderSelector(this.selectedAnnotation.pageIndex, this.selectedAnnotation.annotationSelectorSettings);
                }
                else {
                    var isRotated = (Math.abs(this.selectedAnnotation.rotateAngle) !== 0 &&
                        Math.abs(this.selectedAnnotation.rotateAngle) !== 180);
                    inputEleHeight = parseFloat(isRotated ? this.inputBoxWidth : this.inputBoxHeight) / zoomFactor;
                    inputEleWidth = parseFloat(isRotated ? this.inputBoxHeight : this.inputBoxWidth) / zoomFactor;
                    var heightDiff = (inputEleHeight - this.freetextHeight);
                    var y = undefined;
                    if (heightDiff > 0) {
                        y = this.wrapperOffsetY + (heightDiff / 2);
                        y = y > 0 ? y : undefined;
                    }
                    var widthDiff = (inputEleWidth - this.freetextWidth);
                    var x = undefined;
                    if (widthDiff > 0) {
                        x = this.wrapperOffsetX + (widthDiff / 2);
                        x = x > 0 ? x : undefined;
                    }
                    else {
                        widthDiff = Math.abs(widthDiff);
                        x = this.wrapperOffsetX - (widthDiff / 2);
                    }
                    this.selectedAnnotation.bounds.width = inputEleWidth;
                    this.selectedAnnotation.bounds.height = inputEleHeight;
                    var lineSpace = 0;
                    lineSpace = ((parseFloat(this.inputBoxElement.style.fontSize) / zoomFactor) / (this.defaultFontSize / 2));
                    this.selectedAnnotation.wrapper.children[1].margin.left = 0;
                    this.selectedAnnotation.wrapper.children[1].margin.top = 0;
                    this.pdfViewer.annotation.modifyDynamicTextValue(inputValue, this.selectedAnnotation.annotName, this.previousText);
                    this.selectedAnnotation.dynamicText = inputValue;
                    this.selectedAnnotation.wrapper.children[0].style.strokeColor = borderColor;
                    this.selectedAnnotation.wrapper.children[0].style.fill = background;
                    this.modifyInCollection('dynamicText', pageIndex, this.selectedAnnotation, isNewlyAdded);
                    this.modifyInCollection('bounds', pageIndex, this.selectedAnnotation, isNewlyAdded);
                    this.selectedAnnotation.wrapper.offsetX = this.wrapperOffsetX;
                    this.selectedAnnotation.wrapper.offsetY = this.wrapperOffsetY;
                    this.pdfViewer.nodePropertyChange(this.selectedAnnotation, { bounds: { width: this.selectedAnnotation.bounds.width,
                            height: this.selectedAnnotation.bounds.height, y: y, x: x } });
                    var commentsDiv = document.getElementById(this.selectedAnnotation.annotName);
                    if (commentsDiv && commentsDiv.childNodes) {
                        if (commentsDiv.childNodes[0].ej2_instances) {
                            commentsDiv.childNodes[0].ej2_instances[0].value = inputValue;
                            commentsDiv.childNodes[0].ej2_instances[0].dataBind();
                        }
                        else if (commentsDiv.childNodes[0].childNodes && commentsDiv.childNodes[0].childNodes[1].ej2_instances) {
                            commentsDiv.childNodes[0].childNodes[1].ej2_instances[0].value = inputValue;
                            commentsDiv.childNodes[0].childNodes[1].ej2_instances[0].dataBind();
                        }
                    }
                    this.pdfViewer.renderSelector(this.selectedAnnotation.pageIndex, this.selectedAnnotation.annotationSelectorSettings);
                }
                if (this.inputBoxElement.parentElement) {
                    if (pageDiv && (pageDiv.id === this.inputBoxElement.parentElement.id)) {
                        pageDiv.removeChild(this.inputBoxElement);
                    }
                    else {
                        this.inputBoxElement.parentElement.removeChild(this.inputBoxElement);
                    }
                }
                var canvass = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageIndex);
                this.pdfViewer.renderDrawing(canvass, pageIndex);
                this.inputBoxCount += 1;
            }
            else {
                this.inputBoxElement.focus();
                if (!this.isTextSelected) {
                    window.getSelection().removeAllRanges();
                }
            }
            this.pdfViewer.enableServerDataBinding(allowServerDataBind, true);
        };
        FreeTextAnnotation.prototype.onKeyDownInputBox = function (event) {
            var isTab = event.key === 'Tab' || event.code === 'Tab';
            var isAlt = event.key === 'Alt' || event.code === 'AltLeft' || event.code === 'AltRight';
            if (!isAlt) {
                if (event.ctrlKey && event.key.toLowerCase() === 'a') {
                    event.preventDefault();
                    this.inputBoxElement.select();
                }
                var inuptEleObj_1 = this;
                if (isTab || (ej2_base_1.isNullOrUndefined(this.pdfViewer.selectedItems.annotations[0]) && !this.isNewFreeTextAnnot)) {
                    event.preventDefault();
                }
                this.selectedAnnotation = this.pdfViewer.selectedItems.annotations &&
                    this.isNewFreeTextAnnot ? this.pdfViewer.selectedItems.annotations[0]
                    : this.selectedAnnotation;
                setTimeout(function () {
                    if (inuptEleObj_1.defaultHeight < inuptEleObj_1.inputBoxElement.scrollHeight &&
                        Math.ceil(inuptEleObj_1.inputBoxElement.clientHeight) < inuptEleObj_1.inputBoxElement.scrollHeight) {
                        inuptEleObj_1.updateFreeTextAnnotationSize(true);
                    }
                    else {
                        if (!event.ctrlKey) {
                            inuptEleObj_1.updateFreeTextAnnotationSize(false);
                        }
                    }
                }, 0);
            }
        };
        FreeTextAnnotation.prototype.updateFreeTextAnnotationSize = function (isSize) {
            var inuptEleObj = this;
            var enableAutoFit = inuptEleObj.pdfViewer.freeTextSettings.enableAutoFit;
            if (enableAutoFit) {
                this.autoFitFreeText();
            }
            else {
                this.isMaximumWidthReached = true;
            }
            if (this.isMaximumWidthReached) {
                var previousHeight = inuptEleObj.inputBoxElement.getBoundingClientRect().height;
                var zoomFactor_1 = inuptEleObj.pdfViewerBase.getZoomFactor();
                var currentInputHeight = parseFloat(inuptEleObj.inputBoxElement.style.height) || inuptEleObj.defaultHeight;
                if (!isSize && !inuptEleObj.inputBoxElement.readOnly && zoomFactor_1 >= 1) {
                    inuptEleObj.inputBoxElement.style.height = Math.max(currentInputHeight, inuptEleObj.defaultHeight) + 'px';
                }
                else {
                    inuptEleObj.inputBoxElement.style.height = Math.min(currentInputHeight, inuptEleObj.defaultHeight) + 'px';
                }
                var currentHeight = inuptEleObj.inputBoxElement.getBoundingClientRect().height;
                var difference = currentHeight - previousHeight;
                var fontSize = parseFloat(inuptEleObj.inputBoxElement.style.fontSize);
                var inuptEleObjHeight = void 0;
                if (zoomFactor_1 < 1) {
                    inuptEleObjHeight = inuptEleObj.defaultHeight - parseFloat(inuptEleObj.inputBoxElement.style.borderWidth);
                }
                else {
                    inuptEleObjHeight = inuptEleObj.defaultHeight;
                }
                if (((inuptEleObjHeight * zoomFactor_1) < inuptEleObj.inputBoxElement.scrollHeight +
                    parseFloat(inuptEleObj.inputBoxElement.style.borderWidth) / 2) &&
                    (Math.ceil(inuptEleObj.inputBoxElement.clientHeight) < inuptEleObj.inputBoxElement.scrollHeight)) {
                    inuptEleObj.inputBoxElement.style.height = inuptEleObj.inputBoxElement.readOnly ? inuptEleObj.inputBoxElement.style.height : inuptEleObj.inputBoxElement.scrollHeight + (fontSize / 2) + 'px';
                    if (parseFloat(inuptEleObj.inputBoxElement.style.borderWidth) >= 1) {
                        inuptEleObj.inputBoxElement.style.height = parseFloat(inuptEleObj.inputBoxElement.style.height) + (parseFloat(inuptEleObj.inputBoxElement.style.borderWidth) * 2) + 'px';
                    }
                }
            }
            var zoomFactor = inuptEleObj.pdfViewerBase.getZoomFactor();
            var isRotated = this.selectedAnnotation && (Math.abs(this.selectedAnnotation.rotateAngle) !== 0 &&
                Math.abs(this.selectedAnnotation.rotateAngle) !== 180);
            var inputEleHeight = parseFloat(isRotated ? this.inputBoxElement.style.width :
                this.inputBoxElement.style.height) / zoomFactor;
            var inputEleWidth = parseFloat(isRotated ? this.inputBoxElement.style.height :
                this.inputBoxElement.style.width) / zoomFactor;
            var x = 0;
            if (this.selectedAnnotation) {
                var heightDiff = void 0;
                if (isRotated) {
                    heightDiff = (inputEleWidth - inuptEleObj.selectedAnnotation.bounds.width);
                }
                else {
                    heightDiff = (inputEleHeight - inuptEleObj.selectedAnnotation.bounds.height);
                }
                var y = 0;
                if (heightDiff > 0) {
                    y = inuptEleObj.selectedAnnotation.wrapper.offsetY + (heightDiff / 2);
                }
                else {
                    heightDiff = Math.abs(heightDiff);
                    y = inuptEleObj.selectedAnnotation.wrapper.offsetY - (heightDiff / 2);
                }
                if (enableAutoFit) {
                    var widthDiff = (inputEleWidth - inuptEleObj.selectedAnnotation.bounds.width);
                    if (widthDiff > 0) {
                        x = inuptEleObj.selectedAnnotation.wrapper.offsetX + (widthDiff / 2);
                    }
                    else {
                        widthDiff = Math.abs(widthDiff);
                        x = inuptEleObj.selectedAnnotation.wrapper.offsetX - (widthDiff / 2);
                    }
                }
                inuptEleObj.selectedAnnotation.bounds.width = inputEleWidth;
                inuptEleObj.selectedAnnotation.bounds.height = inputEleHeight;
                if (enableAutoFit) {
                    inuptEleObj.pdfViewer.nodePropertyChange(inuptEleObj.selectedAnnotation, { bounds: { width: inuptEleObj.selectedAnnotation.bounds.width, height: inuptEleObj.selectedAnnotation.bounds.height, y: y, x: x } });
                }
                else {
                    inuptEleObj.pdfViewer.nodePropertyChange(inuptEleObj.selectedAnnotation, { bounds: { width: inuptEleObj.selectedAnnotation.bounds.width, height: inuptEleObj.selectedAnnotation.bounds.height, y: y } });
                }
                inuptEleObj.pdfViewer.renderSelector(inuptEleObj.selectedAnnotation.pageIndex, this.selectedAnnotation.annotationSelectorSettings);
            }
        };
        FreeTextAnnotation.prototype.autoFitFreeText = function (xPosition, yPosition) {
            var pageIndex = this.pdfViewerBase.currentPageNumber - 1;
            var canvas = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageIndex);
            var context = canvas.getContext('2d');
            var fontSize = this.inputBoxElement.style.fontSize;
            if (this.pdfViewer.freeTextSettings.fontStyle === types_1.FontStyle.Bold || this.inputBoxElement.style.fontWeight === 'bold') {
                context.font = 'bold' + ' ' + fontSize + ' ' + this.inputBoxElement.style.fontFamily;
            }
            else {
                context.font = fontSize + ' ' + this.inputBoxElement.style.fontFamily;
            }
            var highestTextNode = '';
            var textNodes = [];
            var textboxValue = this.inputBoxElement.value;
            if (textboxValue.indexOf('\n') > -1) {
                textNodes = textboxValue.split('\n');
                for (var j = 0; j < textNodes.length; j++) {
                    var textNodeData = context.measureText(textNodes[parseInt(j.toString(), 10)]);
                    var highestTextNodeData = context.measureText(highestTextNode);
                    if (textNodeData.width > highestTextNodeData.width) {
                        highestTextNode = textNodes[parseInt(j.toString(), 10)];
                    }
                }
                this.isMaximumWidthReached = true;
            }
            else {
                highestTextNode = textboxValue;
                this.isMaximumWidthReached = false;
            }
            var textwidth = context.measureText(highestTextNode);
            fontSize = parseFloat(this.inputBoxElement.style.fontSize);
            var inputEleWidth;
            var characterLength = 8;
            var inputEleHeight = (fontSize + (fontSize / 2));
            if (this.isNewFreeTextAnnot) {
                inputEleWidth = Math.ceil(textwidth.width + ((characterLength + 1) * 2));
                this.inputBoxElement.style.height = inputEleHeight + 'px';
                this.inputBoxElement.style.top = (yPosition) - (inputEleHeight / 2) + 'px';
            }
            else {
                inputEleWidth = Math.ceil(textwidth.width) + fontSize + Math.ceil(characterLength / 2);
            }
            this.inputBoxElement.style.width = inputEleWidth + 'px';
            var maxWidth = this.pdfViewerBase.getPageWidth(pageIndex) - parseFloat(this.inputBoxElement.style.left);
            if (parseFloat(this.inputBoxElement.style.width) > maxWidth) {
                this.isMaximumWidthReached = true;
                if (this.isNewAddedAnnot && xPosition) {
                    inputEleWidth = inputEleWidth - characterLength;
                    this.inputBoxElement.style.width = inputEleWidth + 'px';
                    var width = xPosition + (inputEleWidth * this.pdfViewerBase.getZoomFactor());
                    var x = parseFloat(this.inputBoxElement.style.left);
                    if (width >= this.pdfViewerBase.getPageWidth(pageIndex)) {
                        x = this.pdfViewerBase.getPageWidth(pageIndex) - inputEleWidth;
                    }
                    this.inputBoxElement.style.left = x + 'px';
                }
                else {
                    this.inputBoxElement.style.width = maxWidth + 'px';
                }
            }
        };
        FreeTextAnnotation.prototype.onMouseUpInputBox = function (event) {
            var target = event.target;
            this.selectionStart = 0;
            this.selectionEnd = 0;
            var isRightClick = event.button === 2;
            if (isRightClick && target) {
                this.selectionStart = target.selectionStart;
                this.selectionEnd = target.selectionEnd;
            }
            if (isRightClick && window.getSelection() !== null && window.getSelection().toString() !== '') {
                this.isTextSelected = true;
            }
            else {
                this.isTextSelected = false;
            }
        };
        FreeTextAnnotation.prototype.focusInputWithoutScroll = function (el) {
            var container = this.pdfViewerBase.viewerContainer || document.scrollingElement || document.documentElement;
            var prevLeft = container.scrollLeft;
            var prevTop = container.scrollTop;
            try {
                el.focus({ preventScroll: true });
            }
            catch (e) {
                el.focus();
                if (typeof container.scrollTo === 'function') {
                    container.scrollTo(prevLeft, prevTop);
                }
                else {
                    container.scrollLeft = prevLeft;
                    container.scrollTop = prevTop;
                }
            }
        };
        FreeTextAnnotation.prototype.addInuptElemet = function (currentPosition, annotation, pageIndex) {
            if (annotation === void 0) { annotation = null; }
            this.currentPosition = [];
            if (ej2_base_1.isNullOrUndefined(pageIndex)) {
                pageIndex = this.pdfViewerBase.currentPageNumber - 1;
            }
            if (annotation) {
                pageIndex = annotation.pageIndex;
            }
            if (ej2_base_1.isBlazor() && annotation === null && this.pdfViewer.selectedItems.annotations.length === 0) {
                this.updateTextProperties();
            }
            this.inputBoxElement.id = this.pdfViewer.element.id + '_freeText_' + pageIndex + '_' + this.inputBoxCount;
            var pageDiv = this.pdfViewerBase.getElement('_pageDiv_' + (pageIndex));
            var canvass = this.pdfViewerBase.getAnnotationCanvas('_annotationCanvas_', pageIndex);
            var zoomFactor = this.pdfViewerBase.getZoomFactor();
            this.inputBoxElement.value = (annotation && annotation.dynamicText) ? annotation.dynamicText : this.defaultText;
            this.inputBoxElement.style.boxSizing = 'border-box';
            this.inputBoxElement.style.left = ((currentPosition.x)) + 'px';
            this.inputBoxElement.style.top = ((currentPosition.y)) - ((this.defaultHeight * zoomFactor) / 2) + 'px';
            if (this.pdfViewer.freeTextSettings.enableAutoFit) {
                this.inputBoxElement.style.wordBreak = 'break-all';
            }
            else {
                this.inputBoxElement.style.wordBreak = 'break-word';
            }
            if (annotation) {
                this.applyFreetextStyles(zoomFactor, annotation.isReadonly);
            }
            else {
                this.applyFreetextStyles(zoomFactor);
            }
            if (this.isBold) {
                this.inputBoxElement.style.fontWeight = 'bold';
            }
            else {
                this.inputBoxElement.style.fontWeight = 'normal';
            }
            if (this.isItalic) {
                this.inputBoxElement.style.fontStyle = 'italic';
            }
            else {
                this.inputBoxElement.style.fontStyle = 'normal';
            }
            this.inputBoxElement.style.textDecoration = 'none';
            if (this.isUnderline && this.isStrikethrough) {
                this.inputBoxElement.style.textDecoration = 'underline line-through';
            }
            else if (this.isUnderline) {
                this.inputBoxElement.style.textDecoration = 'underline';
            }
            else if (this.isStrikethrough) {
                this.inputBoxElement.style.textDecoration = 'line-through';
            }
            if (this.pdfViewer.enableRtl) {
                this.inputBoxElement.style.textAlign = 'right';
                this.inputBoxElement.style.direction = 'rtl';
                this.inputBoxElement.style.left = ((currentPosition.x)) - ((this.defautWidth * zoomFactor / 2));
            }
            else {
                this.inputBoxElement.style.textAlign = this.textAlign.toLowerCase();
            }
            this.inputBoxElement.style.borderColor = this.borderColor;
            this.inputBoxElement.style.color = this.fontColor;
            this.inputBoxElement.style.background = this.fillColor;
            if (annotation && annotation.wrapper && annotation.wrapper.children[0]) {
                this.inputBoxElement.style.opacity = annotation.wrapper.children[0].style.opacity;
            }
            else {
                this.inputBoxElement.style.opacity = this.opacity;
            }
            if (this.isNewFreeTextAnnot === true) {
                this.initialStrokeWidth = 0;
                this.pdfViewer.clearSelection(pageIndex);
            }
            if (annotation && annotation.wrapper && annotation.wrapper.bounds) {
                var annotationBounds = annotation.wrapper.bounds;
                if (!ej2_base_1.isNullOrUndefined(annotationBounds.left)) {
                    this.inputBoxElement.style.left = (annotationBounds.left * zoomFactor) + 'px';
                }
                if (!ej2_base_1.isNullOrUndefined(annotationBounds.top)) {
                    this.inputBoxElement.style.top = (annotationBounds.top * zoomFactor) + 'px';
                }
                this.inputBoxElement.style.height = annotationBounds.height ? (annotationBounds.height * zoomFactor) + 'px' : (this.defaultHeight * zoomFactor) + 'px';
                this.inputBoxElement.style.width = annotationBounds.width ? (annotationBounds.width * zoomFactor) + 'px' : (this.defautWidth * zoomFactor) + 'px';
                this.selectedAnnotation = annotation;
                this.previousText = this.selectedAnnotation.dynamicText;
                this.selectedAnnotation.dynamicText = '';
                this.inputBoxElement.style.borderColor = this.selectedAnnotation.strokeColor;
                this.inputBoxElement.style.color = this.selectedAnnotation.fontColor;
                this.inputBoxElement.style.background = this.selectedAnnotation.fillColor;
                if (this.selectedAnnotation.font.isBold === true) {
                    this.inputBoxElement.style.fontWeight = 'bold';
                }
                if (this.selectedAnnotation.font.isItalic === true) {
                    this.inputBoxElement.style.fontStyle = 'italic';
                }
                if (this.selectedAnnotation.font.isUnderline && this.selectedAnnotation.font.isStrikeout) {
                    this.inputBoxElement.style.textDecoration = 'underline line-through';
                }
                else if (this.selectedAnnotation.font.isUnderline) {
                    this.inputBoxElement.style.textDecoration = 'underline';
                }
                else if (this.selectedAnnotation.font.isStrikeout) {
                    this.inputBoxElement.style.textDecoration = 'line-through';
                }
                if (this.pdfViewer.enableRtl) {
                    this.inputBoxElement.style.textAlign = 'right';
                    this.inputBoxElement.style.direction = 'rtl';
                }
                else if (this.selectedAnnotation.textAlign) {
                    this.inputBoxElement.style.textAlign = this.selectedAnnotation.textAlign;
                }
                this.inputBoxElement.style.fontSize = (this.selectedAnnotation.fontSize * zoomFactor) + 'px';
                this.inputBoxElement.style.fontFamily = this.selectedAnnotation.fontFamily;
                this.freetextHeight = this.selectedAnnotation.bounds.height;
                this.freetextWidth = this.selectedAnnotation.bounds.width;
                this.inputBoxHeight = this.inputBoxElement.style.height;
                this.inputBoxWidth = this.inputBoxElement.style.width;
                this.inputBoxValue = this.inputBoxElement.value;
                this.wrapperOffsetX = this.selectedAnnotation.wrapper.offsetX;
                this.wrapperOffsetY = this.selectedAnnotation.wrapper.offsetY;
                this.pdfViewer.nodePropertyChange(this.selectedAnnotation, {});
            }
            if (this.pdfViewerBase.isMixedSizeDocument) {
                this.inputBoxElement.style.left = (parseFloat(this.inputBoxElement.style.left)) + canvass.offsetLeft + 'px';
            }
            this.pdfViewer.annotation.freeTextAnnotationModule.isFreeTextValueChange = false;
            if (this.pdfViewer.freeTextSettings.enableAutoFit) {
                this.autoFitFreeText(currentPosition.x, currentPosition.y);
            }
            var computedPad = 0;
            if (this.selectedAnnotation && this.selectedAnnotation.wrapper && this.selectedAnnotation.wrapper.children[0]) {
                var strokeWidth = this.selectedAnnotation.wrapper.children[0].style.strokeWidth || 0;
                computedPad = Math.ceil(strokeWidth);
            }
            else if (!ej2_base_1.isNullOrUndefined(this.borderWidth)) {
                computedPad = Math.ceil(this.borderWidth);
            }
            var padPx = (computedPad * zoomFactor) + 'px';
            this.inputBoxElement.style.paddingTop = padPx;
            var align = (this.selectedAnnotation && this.selectedAnnotation.textAlign)
                ? this.selectedAnnotation.textAlign.toLowerCase()
                : this.textAlign ? this.textAlign.toLowerCase() : 'left';
            this.inputBoxElement.style.paddingLeft = (align === 'left' || align === 'justify') ? padPx : (computedPad * zoomFactor) + 'px';
            this.inputBoxElement.style.paddingRight = (align === 'right') ? padPx : (computedPad * zoomFactor) + 'px';
            if (this.selectedAnnotation && this.selectedAnnotation.wrapper.children[0].style.strokeWidth) {
                if (!this.isNewFreeTextAnnot) {
                    this.inputBoxElement.style.borderWidth = this.selectedAnnotation.wrapper.children[0].style.strokeWidth * (96 / 72) * zoomFactor + 'px';
                }
            }
            pageDiv.appendChild(this.inputBoxElement);
            if (this.isNewFreeTextAnnot) {
                this.freetextHeight = this.inputBoxElement.style.height;
            }
            if (!this.pdfViewer.freeTextSettings.enableAutoFit && (this.defaultHeight * zoomFactor)
                < this.inputBoxElement.scrollHeight && parseInt(this.inputBoxElement.style.height, 10) < this.inputBoxElement.scrollHeight) {
                this.inputBoxElement.style.height = this.inputBoxElement.scrollHeight + 'px';
                if (annotation && annotation.wrapper && annotation.wrapper.children[0]) {
                    this.inputBoxElement.style.height = parseFloat(this.inputBoxElement.style.height) + (annotation.wrapper.children[0].style.strokeWidth * 3) + 'px';
                }
            }
            if (annotation && annotation.wrapper && annotation.wrapper.bounds) {
                var inputEleHeight = parseFloat(this.inputBoxElement.style.height);
                var inputEleWidth = parseFloat(this.inputBoxElement.style.width);
                var isRotated = this.selectedAnnotation.pageRotation === 90 || this.selectedAnnotation.pageRotation === 270;
                inputEleHeight = parseFloat(isRotated ? this.inputBoxElement.style.width : this.inputBoxElement.style.height) / zoomFactor;
                inputEleWidth = parseFloat(isRotated ? this.inputBoxElement.style.height : this.inputBoxElement.style.width) / zoomFactor;
                var heightDiff = (inputEleHeight - this.selectedAnnotation.bounds.height);
                var y = undefined;
                if (heightDiff > 0) {
                    y = this.selectedAnnotation.wrapper.offsetY + (heightDiff / 2);
                    y = y > 0 ? y : undefined;
                }
                var widthDiff = (inputEleWidth - this.selectedAnnotation.bounds.width);
                var x = undefined;
                if (widthDiff > 0) {
                    x = this.selectedAnnotation.wrapper.offsetX + (widthDiff / 2);
                    x = x > 0 ? x : undefined;
                }
                else {
                    widthDiff = Math.abs(widthDiff);
                    x = this.selectedAnnotation.wrapper.offsetX - (widthDiff / 2);
                }
                this.selectedAnnotation.bounds.width = inputEleWidth;
                this.selectedAnnotation.bounds.height = inputEleHeight;
                this.pdfViewer.nodePropertyChange(this.selectedAnnotation, {
                    bounds: {
                        width: this.selectedAnnotation.bounds.width, height: this.selectedAnnotation.bounds.height, y: y, x: x
                    }
                });
                this.pdfViewer.renderSelector(this.selectedAnnotation.pageIndex, this.selectedAnnotation.annotationSelectorSettings);
            }
            this.isInuptBoxInFocus = true;
            this.focusInputWithoutScroll(this.inputBoxElement);
            if (this.isNewFreeTextAnnot === true || this.inputBoxElement.value === this.defaultText) {
                this.inputBoxElement.select();
                this.pdfViewerBase.isFreeTextSelected = true;
            }
            this.currentPosition.push(parseInt(this.inputBoxElement.style.left, 10) / zoomFactor, parseInt(this.inputBoxElement.style.top, 10) / zoomFactor, parseInt(this.inputBoxElement.style.width, 10) / zoomFactor, parseInt(this.inputBoxElement.style.height, 10) / zoomFactor);
        };
        FreeTextAnnotation.prototype.applyFreetextStyles = function (zoomFactor, isReadonly) {
            this.inputBoxElement.style.height = (this.defaultHeight * zoomFactor) + 'px';
            this.inputBoxElement.style.width = (this.defautWidth * zoomFactor) + 'px';
            this.inputBoxElement.style.borderWidth = (this.borderWidth * zoomFactor) * (96 / 72) + 'px';
            this.inputBoxElement.style.fontSize = (this.fontSize * zoomFactor) + 'px';
            this.inputBoxElement.style.fontFamily = this.fontFamily;
            this.inputBoxElement.readOnly = ej2_base_1.isNullOrUndefined(isReadonly) ? this.isReadonly : isReadonly;
        };
        FreeTextAnnotation.prototype.copySelectedText = function () {
            if (window.getSelection() !== null) {
                this.selectedText = window.getSelection().toString();
                var textArea = document.createElement('textarea');
                textArea.contentEditable = 'true';
                textArea.textContent = this.selectedText;
                textArea.style.position = 'fixed';
                document.body.appendChild(textArea);
                textArea.select();
                try {
                    document.execCommand('copy');
                }
                catch (ex) {
                    console.warn('Copy to clipboard failed.', ex);
                }
                finally {
                    if (textArea) {
                        document.body.removeChild(textArea);
                    }
                }
            }
        };
        FreeTextAnnotation.prototype.pasteSelectedText = function (target) {
            if (this.selectedText !== '' && target) {
                var text = target.value;
                target.value = text.slice(0, this.selectionStart) + this.selectedText + text.slice(this.selectionEnd, text.length);
            }
            var events = event;
            this.onKeyDownInputBox(events);
        };
        FreeTextAnnotation.prototype.cutSelectedText = function (target) {
            if (window.getSelection() !== null) {
                var text = target.value;
                this.selectedText = window.getSelection().toString();
                target.value = text.slice(0, target.selectionStart) + text.slice(target.selectionEnd);
                var textArea = document.createElement('textarea');
                textArea.contentEditable = 'true';
                textArea.textContent = this.selectedText;
                textArea.style.position = 'fixed';
                document.body.appendChild(textArea);
                textArea.select();
                try {
                    document.execCommand('cut');
                }
                catch (ex) {
                    console.warn('Copy to clipboard failed.', ex);
                }
                finally {
                    if (textArea) {
                        document.body.removeChild(textArea);
                    }
                }
            }
        };
        FreeTextAnnotation.prototype.saveImportedFreeTextAnnotations = function (shapeAnnotations, pageNumber) {
            var annotation = shapeAnnotations;
            if (annotation.AnnotType) {
                var vertexPoints = null;
                if (annotation.VertexPoints) {
                    vertexPoints = [];
                    for (var j = 0; j < annotation.VertexPoints.length; j++) {
                        var point = { x: annotation.VertexPoints[parseInt(j.toString(), 10)].X,
                            y: annotation.VertexPoints[parseInt(j.toString(), 10)].Y };
                        vertexPoints.push(point);
                    }
                }
                annotation.AnnotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings :
                    this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.freeTextSettings);
                annotation.allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions :
                    this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
                var annotationBoundsX = !ej2_base_1.isNullOrUndefined(annotation.Bounds.X) ? annotation.Bounds.X : annotation.Bounds.x;
                var annotationBoundsY = !ej2_base_1.isNullOrUndefined(annotation.Bounds.Y) ? annotation.Bounds.Y : annotation.Bounds.y;
                var annotationBoundsWidth = annotation.Bounds.Width ? annotation.Bounds.Width : annotation.Bounds.width;
                var annotationBoundsHeight = annotation.Bounds.Height ? annotation.Bounds.Height : annotation.Bounds.height;
                var annot = {
                    author: annotation.Author, allowedInteractions: annotation.allowedInteractions, modifiedDate: annotation.ModifiedDate, subject: annotation.Subject, id: 'freetext',
                    rotateAngle: annotation.Rotate, dynamicText: annotation.MarkupText, strokeColor: annotation.StrokeColor,
                    thickness: annotation.Thickness, fillColor: annotation.FillColor,
                    bounds: {
                        x: annotationBoundsX, y: annotationBoundsY, left: annotationBoundsX, top: annotationBoundsY,
                        width: annotationBoundsWidth, height: annotationBoundsHeight, right: annotation.Bounds.Right,
                        bottom: annotation.Bounds.Bottom
                    }, annotName: annotation.AnnotName, shapeAnnotationType: 'FreeText',
                    pageIndex: pageNumber, opacity: annotation.Opacity, fontColor: annotation.FontColor, fontSize: annotation.FontSize,
                    fontFamily: annotation.FontFamily, notes: annotation.MarkupText, textAlign: annotation.TextAlign,
                    comments: this.pdfViewer.annotationModule.
                        getAnnotationComments(annotation.Comments, annotation, annotation.Author),
                    review: { state: annotation.State, stateModel: annotation.StateModel,
                        modifiedDate: annotation.ModifiedDate, author: annotation.Author },
                    font: { isBold: annotation.Font.Bold, isItalic: annotation.Font.Italic,
                        isStrikeout: annotation.Font.Strikeout, isUnderline: annotation.Font.Underline },
                    annotationSelectorSettings: this.getSettings(annotation), annotationSettings: annotation.AnnotationSettings,
                    customData: this.pdfViewer.annotation.getCustomData(annotation),
                    isPrint: annotation.IsPrint, isCommentLock: annotation.IsCommentLock, isReadonly: annotation.IsReadonly
                };
                this.pdfViewer.annotationModule.storeAnnotations(pageNumber, annot, '_annotations_freetext');
            }
        };
        FreeTextAnnotation.prototype.updateFreeTextAnnotationCollections = function (shapeAnnotations, pageNumber) {
            var annotation = shapeAnnotations;
            annotation.annotationAddMode = this.pdfViewer.annotationModule.findAnnotationMode(annotation, pageNumber, annotation.AnnotType);
            if (annotation.AnnotType) {
                var vertexPoints = null;
                if (annotation.VertexPoints) {
                    vertexPoints = [];
                    for (var j = 0; j < annotation.VertexPoints.length; j++) {
                        var point = { x: annotation.VertexPoints[parseInt(j.toString(), 10)].X,
                            y: annotation.VertexPoints[parseInt(j.toString(), 10)].Y };
                        vertexPoints.push(point);
                    }
                }
                annotation.AnnotationSettings = annotation.AnnotationSettings ? annotation.AnnotationSettings :
                    this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.freeTextSettings);
                if (annotation.IsLocked) {
                    annotation.AnnotationSettings.isLock = annotation.IsLocked;
                }
                annotation.allowedInteractions = annotation.AllowedInteractions ? annotation.AllowedInteractions :
                    this.pdfViewer.annotationModule.updateAnnotationAllowedInteractions(annotation);
                var annotationBoundsX = annotation.Bounds.X ? annotation.Bounds.X : annotation.Bounds.x;
                var annotationBoundsY = annotation.Bounds.Y ? annotation.Bounds.Y : annotation.Bounds.y;
                var width = annotation.Bounds.Width ? annotation.Bounds.Width : annotation.Bounds.width;
                var height = annotation.Bounds.Height ? annotation.Bounds.Height : annotation.Bounds.height;
                var annot = {
                    author: annotation.Author, allowedInteractions: annotation.allowedInteractions, modifiedDate: annotation.ModifiedDate, subject: annotation.Subject, id: 'freetext',
                    rotateAngle: annotation.Rotate, dynamicText: annotation.MarkupText, strokeColor: annotation.StrokeColor,
                    thickness: annotation.Thickness, fillColor: annotation.FillColor,
                    bounds: {
                        x: annotationBoundsX, y: annotationBoundsY, left: annotationBoundsX, top: annotationBoundsY,
                        width: width, height: height, right: annotation.Bounds.Right,
                        bottom: annotation.Bounds.Bottom
                    }, annotationId: annotation.AnnotName, shapeAnnotationType: 'FreeText',
                    pageIndex: pageNumber, opacity: annotation.Opacity, fontColor: annotation.FontColor, fontSize: annotation.FontSize,
                    fontFamily: annotation.FontFamily, notes: annotation.MarkupText,
                    comments: this.pdfViewer.annotationModule.
                        getAnnotationComments(annotation.Comments, annotation, annotation.Author),
                    review: { state: annotation.State, stateModel: annotation.StateModel,
                        modifiedDate: annotation.ModifiedDate, author: annotation.Author },
                    customData: this.pdfViewer.annotation.getCustomData(annotation),
                    font: { isBold: annotation.Font.Bold, isItalic: annotation.Font.Italic,
                        isStrikeout: annotation.Font.Strikeout, isUnderline: annotation.Font.Underline },
                    pageNumber: pageNumber, annotationSettings: annotation.AnnotationSettings,
                    isCommentLock: annotation.IsCommentLock, isReadonly: annotation.IsReadonly, isPrint: annotation.IsPrint
                };
                return annot;
            }
        };
        FreeTextAnnotation.prototype.updateAddAnnotationDetails = function (annotationObject, offset) {
            if (!annotationObject) {
                annotationObject = { offset: { x: 1, y: 1 }, pageNumber: 0, width: undefined, height: undefined };
                offset = annotationObject.offset;
            }
            else if (!annotationObject.offset) {
                offset = { x: 1, y: 1 };
            }
            else {
                offset = annotationObject.offset;
            }
            var currentDateString = this.pdfViewer.annotation.stickyNotesAnnotationModule.getDateAndTime();
            var annotationName = this.pdfViewer.annotation.createGUID();
            var fontStyle = annotationObject.fontStyle ? annotationObject.fontStyle : types_1.FontStyle.None;
            var annotationSelectorSettings = this.pdfViewer.freeTextSettings.annotationSelectorSettings;
            this.pdfViewerBase.updateSelectorSettings(annotationSelectorSettings);
            var annotationSettings = this.pdfViewer.annotationModule.updateSettings(this.pdfViewer.freeTextSettings);
            var allowedInteractions = this.pdfViewer.freeTextSettings.allowedInteractions ?
                this.pdfViewer.freeTextSettings.allowedInteractions : this.pdfViewer.annotationSettings.allowedInteractions;
            annotationObject.author = annotationObject.author ? annotationObject.author : this.pdfViewer.annotationModule.updateAnnotationAuthor('freeText', annotationSettings.annotationSubType);
            annotationSettings.isLock = annotationObject.isLock ? annotationObject.isLock : annotationSettings.isLock;
            if (this.pdfViewer.freeTextSettings.isLock || this.pdfViewer.annotationSettings.isLock ||
                this.pdfViewer.freeTextSettings.isReadonly) {
                annotationObject.isReadonly = true;
            }
            annotationSettings.minHeight = annotationObject.minHeight ? annotationObject.minHeight : 0;
            annotationSettings.minWidth = annotationObject.minWidth ? annotationObject.minWidth : 0;
            annotationSettings.maxWidth = annotationObject.maxWidth ? annotationObject.maxWidth : 0;
            annotationSettings.maxHeight = annotationObject.maxHeight ? annotationObject.maxHeight : 0;
            annotationObject.width = annotationObject.width ? annotationObject.width : 150;
            annotationObject.height = annotationObject.height ? annotationObject.height : 24.6;
            var freeTextAnnotation = [];
            var freeText = {
                AllowedInteractions: annotationObject.allowedInteractions ? annotationObject.allowedInteractions : allowedInteractions,
                AnnotName: annotationName,
                AnnotType: 'freeText',
                AnnotationFlags: 'Default',
                AnnotationIntent: null,
                AnnotationSelectorSettings: annotationObject.annotationSelectorSettings ?
                    annotationObject.annotationSelectorSettings : annotationSelectorSettings,
                AnnotationSettings: annotationSettings,
                Author: annotationObject.author ? annotationObject.author : 'Guest',
                Border: { HorizontalRadius: 0, VerticalRadius: 0, Width: !ej2_base_1.isNullOrUndefined(annotationObject.borderWidth) ?
                        annotationObject.borderWidth : 1 },
                BorderColor: { IsEmpty: true, B: 255, Blue: 1, C: 0, G: 255 },
                Bounds: { X: offset.x, Y: offset.y, Width: annotationObject.width,
                    Height: annotationObject.height, Left: offset.x, Top: offset.y, Right: offset.x + annotationObject.width,
                    Bottom: offset.y + annotationObject.height },
                CalloutLines: null,
                Color: { IsEmpty: false, B: 51, Blue: 0.2, C: 0, G: 255 },
                Comments: null,
                CreatedDate: currentDateString,
                CustomData: annotationObject.customData ? annotationObject.customData : null,
                ExistingCustomData: null,
                FillColor: annotationObject.fillColor ? annotationObject.fillColor : '#ffffff00',
                Flatten: false,
                FlattenPopups: false,
                Font: { Bold: (fontStyle & types_1.FontStyle.Bold) === types_1.FontStyle.Bold,
                    Italic: (fontStyle & types_1.FontStyle.Italic) === types_1.FontStyle.Italic,
                    Strikeout: (fontStyle & types_1.FontStyle.Strikethrough) === types_1.FontStyle.Strikethrough,
                    Underline: (fontStyle & types_1.FontStyle.Underline) === types_1.FontStyle.Underline },
                FontColor: annotationObject.fontColor ? annotationObject.fontColor : '#000',
                FontFamily: annotationObject.fontFamily ? annotationObject.fontFamily : 'Helvetica',
                FontSize: annotationObject.fontSize ? annotationObject.fontSize : 16,
                FreeTextAnnotationType: 'Text Box',
                InnerColor: null,
                IsCommentLock: false,
                IsLock: annotationObject.isLock ? annotationObject.isLock : false,
                IsPrint: !ej2_base_1.isNullOrUndefined(annotationObject.isPrint) ? annotationObject.isPrint : true,
                Layer: null,
                LineEndingStyle: 'OpenArrow',
                Location: null,
                MarkupText: annotationObject.defaultText ? annotationObject.defaultText : 'Type Here',
                ModifiedDate: '',
                Name: annotationName,
                Opacity: annotationObject.opacity ? annotationObject.opacity : 1,
                Page: null,
                PageTags: null,
                ReviewHistory: null,
                Rotate: 0,
                IsReadonly: annotationObject.isReadonly ? annotationObject.isReadonly : false,
                State: 'Unmarked',
                StateModel: 'None',
                StrokeColor: annotationObject.borderColor ? annotationObject.borderColor : '#ffffff00',
                Subject: annotationObject.subject ? annotationObject.subject : 'Text Box',
                Text: annotationObject.defaultText ? annotationObject.defaultText : 'Type Here',
                TextAlign: annotationObject.textAlignment ? annotationObject.textAlignment : 'Left',
                TextMarkupColor: null,
                Thickness: !ej2_base_1.isNullOrUndefined(annotationObject.borderWidth) ? annotationObject.borderWidth : 1,
                isAddAnnotationProgramatically: true
            };
            freeTextAnnotation[0] = freeText;
            return { freeTextAnnotation: freeTextAnnotation };
        };
        FreeTextAnnotation.prototype.getPaddingValues = function (thickness) {
            var leftPadding = thickness / 2;
            var topPadding = thickness;
            return [leftPadding, topPadding];
        };
        FreeTextAnnotation.prototype.addInputInZoom = function (currentPosition) {
            var zoomFactor = this.pdfViewerBase.getZoomFactor();
            this.inputBoxElement.style.left = (currentPosition.x * zoomFactor) + 'px';
            this.inputBoxElement.style.top = (currentPosition.y * zoomFactor) + 'px';
            this.inputBoxElement.style.height = (currentPosition.height * zoomFactor) + 'px';
            this.inputBoxElement.style.width = (currentPosition.width * zoomFactor) + 'px';
            this.inputBoxElement.style.borderWidth = (this.borderWidth * zoomFactor) * (96 / 72) + 'px';
            this.inputBoxElement.style.fontSize = (this.fontSize * zoomFactor) + 'px';
        };
        FreeTextAnnotation.prototype.destroy = function () {
            if (this.inputBoxElement) {
                this.inputBoxElement.removeEventListener('focusout', this.onFocusOutInputBox.bind(this));
                this.inputBoxElement.removeEventListener('keydown', this.onKeyDownInputBox.bind(this));
                this.inputBoxElement.removeEventListener('mouseup', this.onMouseUpInputBox.bind(this));
            }
            this.currentAnnotationMode = null;
            this.opacity = null;
            this.borderColor = null;
            this.borderWidth = null;
            this.defautWidth = null;
            this.defaultHeight = null;
            this.inputBoxElement = null;
            this.borderStyle = null;
            this.author = null;
            this.subject = null;
            this.isNewFreeTextAnnot = null;
            this.isNewAddedAnnot = null;
            this.inputBoxCount = null;
            this.selectedAnnotation = null;
            this.isFreeTextValueChange = null;
            this.isAddAnnotationProgramatically = null;
            this.isInuptBoxInFocus = null;
            this.fontSize = null;
            this.annodationIntent = null;
            this.annotationFlags = null;
            this.fillColor = null;
            this.fontColor = null;
            this.fontFamily = null;
            this.freeTextPageNumbers = null;
            this.selectedText = null;
            this.isTextSelected = null;
            this.selectionStart = null;
            this.selectionEnd = null;
            this.isBold = null;
            this.isItalic = null;
            this.isUnderline = null;
            this.isStrikethrough = null;
            this.textAlign = null;
            this.defaultText = null;
            this.isReadonly = null;
            this.isMaximumWidthReached = null;
            this.padding = null;
            this.wordBreak = null;
            this.freeTextPaddingLeft = null;
            this.freeTextPaddingTop = null;
            this.defaultFontSize = null;
            this.lineGap = null;
            this.previousText = null;
            this.currentPosition = null;
        };
        return FreeTextAnnotation;
    }());
    exports.FreeTextAnnotation = FreeTextAnnotation;
});