all files / pdfviewer/base/ text-layer.js

7.36% Statements 34/462
0% Branches 0/342
15.38% Functions 4/26
7.36% Lines 34/462
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 6921×   1× 1× 1× 2× 2× 2× 2×   1×                                 1×                                                                                                                                                                                                                                                                         1×                                                                                                       1× 1× 1×   1×                                                                                                                                                                                                                                                                                                                                                 1×       1×                                                     1×   1×                                           1×                                   1×                                                   1×                                                             1×                                                                                                                                       1×                               1×                         1×               1×                             1×               1×                           1×                           1×               1×               1×   1×    
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TextLayer = (function () {
        function TextLayer(pdfViewer, pdfViewerBase) {
            this.textBoundsArray = [];
            this.characterBound = [];
            this.pdfViewer = pdfViewer;
            this.pdfViewerBase = pdfViewerBase;
        }
        TextLayer.prototype.addTextLayer = function (pageNumber, pageWidth, pageHeight, pageDiv) {
            var textDiv = document.getElementById(this.pdfViewer.element.id + '_textLayer_' + pageNumber);
            var textLayer;
            if (!textDiv) {
                textLayer = ej2_base_1.createElement('div', { id: this.pdfViewer.element.id + '_textLayer_' + pageNumber, className: 'e-pv-text-layer' });
                textLayer.style.width = pageWidth + 'px';
                textLayer.style.height = pageHeight + 'px';
                if ((ej2_base_1.Browser.isDevice && !this.pdfViewer.enableDesktopMode)) {
                    textLayer.classList.add('e-pv-text-selection-none');
                }
                if (pageDiv) {
                    pageDiv.appendChild(textLayer);
                }
            }
            this.pdfViewerBase.applyElementStyles(textLayer, pageNumber);
            return textLayer;
        };
        TextLayer.prototype.renderTextContents = function (pageNumber, textContents, textBounds, rotation, rtldoc) {
            var textLayer = document.getElementById(this.pdfViewer.element.id + '_textLayer_' + pageNumber);
            var canvasElement = ej2_base_1.createElement('canvas');
            var isRTLText;
            if (this.pdfViewerBase.clientSideRendering) {
                isRTLText = false;
            }
            var linebounds = [];
            var lineContent = [];
            var yValue;
            var heightValue;
            if (textBounds.length > 1) {
                if (textBounds[0].Width === 0 && textBounds.length > 2) {
                    yValue = textBounds[1].Y;
                    heightValue = textBounds[1].Height;
                }
                else {
                    yValue = textBounds[0].Y;
                    heightValue = textBounds[0].Height;
                }
            }
            var idNumber = 0;
            if (canvasElement && textLayer && textLayer.childNodes.length === 0) {
                for (var i = 0; i < textContents.length; i++) {
                    if ((!(textContents[parseInt(i.toString(), 10)].includes('\r\n')) && !(textContents[parseInt(i.toString(), 10)].includes('\u0002'))) && i !== textBounds.length - 1 && rotation === 0 && !rtldoc) {
                        linebounds.push(textBounds[parseInt(i.toString(), 10)]);
                        lineContent.push(textContents[parseInt(i.toString(), 10)]);
                        if (yValue > textBounds[parseInt(i.toString(), 10)].Y && textBounds[parseInt(i.toString(), 10)].Width !== 0) {
                            yValue = textBounds[parseInt(i.toString(), 10)].Y;
                        }
                        if (heightValue < textBounds[parseInt(i.toString(), 10)].Height && textBounds[parseInt(i.toString(), 10)].Width !== 0) {
                            heightValue = textBounds[parseInt(i.toString(), 10)].Height;
                        }
                    }
                    else {
                        linebounds.push(textBounds[parseInt(i.toString(), 10)]);
                        lineContent.push(textContents[parseInt(i.toString(), 10)]);
                        if (yValue > textBounds[parseInt(i.toString(), 10)].Y && textBounds[parseInt(i.toString(), 10)].Width !== 0) {
                            yValue = textBounds[parseInt(i.toString(), 10)].Y;
                        }
                        if (heightValue < textBounds[parseInt(i.toString(), 10)].Height && textBounds[parseInt(i.toString(), 10)].Width !== 0) {
                            heightValue = textBounds[parseInt(i.toString(), 10)].Height;
                        }
                        for (var j = 0; j < linebounds.length; j++) {
                            var bounds = linebounds[parseInt(j.toString(), 10)];
                            var textDiv = ej2_base_1.createElement('div', { id: this.pdfViewer.element.id + '_text_' + pageNumber + '_' + idNumber, className: 'e-pv-text', attrs: { 'tabindex': '-1' } });
                            var textContent = lineContent[parseInt(j.toString(), 10)];
                            if (textContent === ' ' && j !== linebounds.length - 1 && j !== 0) {
                                bounds.Height = linebounds[j - 1].Height;
                                bounds.Y = linebounds[j - 1].Y;
                            }
                            textDiv.textContent = textContent.replace(/&nbsp;/g, ' ');
                            var newLine = lineContent[parseInt(j.toString(), 10)].replace(/  +/g, ' ');
                            if (newLine !== ' ') {
                                textDiv.style.whiteSpace = 'pre';
                            }
                            if (this.pdfViewerBase.clientSideRendering) {
                                if (textContent === ' ') {
                                    textDiv.style.whiteSpace = 'pre';
                                }
                                if (!ej2_base_1.isNullOrUndefined(textDiv.textContent) && textContent !== ' ') {
                                    isRTLText = this.pdfViewerBase.checkIsRtlText(textDiv.textContent);
                                    textDiv.style.direction = isRTLText ? 'rtl' : 'ltr';
                                }
                                else {
                                    textDiv.style.direction = isRTLText ? 'rtl' : 'ltr';
                                }
                            }
                            if (bounds.Width === 0 && j !== linebounds.length - 1 && j !== 0) {
                                if (linebounds[j + 1].X - (linebounds[j - 1].X + linebounds[j - 1].Width) < 30 && (!lineContent[j - 1].includes('\r\n') && !(textContents[parseInt(j.toString(), 10)].includes('\u0002')))) {
                                    bounds.Width = linebounds[j + 1].X - (linebounds[j - 1].X + linebounds[j - 1].Width);
                                    bounds.X = linebounds[j - 1].X + linebounds[j - 1].Width;
                                    if (bounds.Width < 0) {
                                        bounds.Width = 0;
                                    }
                                    else {
                                        textDiv.style.whiteSpace = 'pre';
                                    }
                                }
                            }
                            if ((j !== 0 || linebounds.length - 1 === 0 || (bounds.Y - yValue) > 20 && bounds.Width !== 0) && idNumber !== 0 && ((textBounds[idNumber - 1].Y - textBounds[parseInt(idNumber.toString(), 10)].Y) > 11 || ((textBounds[parseInt(idNumber.toString(), 10)].Y - textBounds[idNumber - 1].Y) > 11)) && lineContent[parseInt(j.toString(), 10)] !== ' ') {
                                yValue = linebounds[parseInt(j.toString(), 10)].Y;
                                heightValue = linebounds[parseInt(j.toString(), 10)].Height;
                            }
                            if (bounds) {
                                if (bounds.Rotation !== 270) {
                                    bounds.Y = yValue;
                                    bounds.Height = heightValue;
                                }
                                this.setStyleToTextDiv(textDiv, bounds.X, bounds.Y, bounds.Bottom, bounds.Width, bounds.Height, bounds.Rotation);
                            }
                            this.setTextElementProperties(textDiv);
                            var context = canvasElement.getContext('2d');
                            context.font = textDiv.style.fontSize + ' ' + textDiv.style.fontFamily;
                            var contextWidth = context.measureText(lineContent[parseInt(j.toString(), 10)].replace(/(\r\n|\n|\r)/gm, '')).width;
                            if (bounds) {
                                var scale = void 0;
                                if (bounds.Rotation === 90 || (this.pdfViewerBase.clientSideRendering && bounds.Rotation === 270)) {
                                    scale = bounds.Height * this.pdfViewerBase.getZoomFactor() / contextWidth;
                                }
                                else {
                                    scale = bounds.Width * this.pdfViewerBase.getZoomFactor() / contextWidth;
                                }
                                this.applyTextRotation(scale, textDiv, rotation, bounds.Rotation, bounds);
                            }
                            textLayer.appendChild(textDiv);
                            this.resizeExcessDiv(textLayer, textDiv);
                            if (this.pdfViewer.textSelectionModule && this.pdfViewer.enableTextSelection && !this.pdfViewerBase.isTextSelectionDisabled && textDiv.className !== 'e-pdfviewer-formFields'
                                && textDiv.className !== 'e-pdfviewer-signatureformfields' && textDiv.className !== 'e-pdfviewer-signatureformfields-signature') {
                                textDiv.classList.add('e-pv-cursor');
                            }
                            if (ej2_base_1.Browser.isDevice && !this.pdfViewer.enableDesktopMode) {
                                textDiv.classList.add('e-enable-text-selection');
                            }
                            idNumber++;
                        }
                        linebounds = [];
                        lineContent = [];
                        if (i < textBounds.length - 1) {
                            if (textBounds[i + 1].Width === 0 && !ej2_base_1.isNullOrUndefined(textBounds[i + 2])) {
                                yValue = textBounds[i + 2].Y;
                                heightValue = textBounds[i + 2].Height;
                            }
                            else {
                                yValue = textBounds[i + 1].Y;
                                heightValue = textBounds[i + 1].Height;
                            }
                        }
                    }
                }
                this.pdfViewerBase.releaseCanvas(canvasElement);
            }
        };
        TextLayer.prototype.resizeTextContents = function (pageNumber, textContents, textBounds, rotation, isTextSearch) {
            var textLayer = this.pdfViewerBase.getElement('_textLayer_' + pageNumber);
            var canvasElement = ej2_base_1.createElement('canvas');
            if (canvasElement) {
                for (var i = 0; i < textLayer.childNodes.length; i++) {
                    var bounds = void 0;
                    var textDiv = this.pdfViewerBase.getElement('_text_' + pageNumber + '_' + i);
                    if (ej2_base_1.isNullOrUndefined(textDiv)) {
                        break;
                    }
                    if (textBounds) {
                        bounds = textBounds[parseInt(i.toString(), 10)];
                        if (bounds) {
                            this.setStyleToTextDiv(textDiv, bounds.X, bounds.Y, bounds.Bottom, bounds.Width, bounds.Height, bounds.Rotation);
                        }
                    }
                    this.setTextElementProperties(textDiv);
                    var context = canvasElement.getContext('2d');
                    context.font = textDiv.style.fontSize + ' ' + textDiv.style.fontFamily;
                    var contextWidth = void 0;
                    if (textContents) {
                        var textContent = textContents[parseInt(i.toString(), 10)];
                        if (textContent) {
                            contextWidth = context.measureText(textContent.replace(/(\r\n|\n|\r)/gm, '')).width;
                        }
                    }
                    else {
                        contextWidth = context.measureText(textDiv.textContent.replace(/(\r\n|\n|\r)/gm, '')).width;
                    }
                    if (bounds) {
                        var scale = void 0;
                        if (bounds.Rotation === 90 || (this.pdfViewerBase.clientSideRendering && bounds.Rotation === 270)) {
                            scale = bounds.Height * this.pdfViewerBase.getZoomFactor() / contextWidth;
                        }
                        else {
                            scale = bounds.Width * this.pdfViewerBase.getZoomFactor() / contextWidth;
                        }
                        this.applyTextRotation(scale, textDiv, rotation, bounds.Rotation, bounds);
                    }
                    this.resizeExcessDiv(textLayer, textDiv);
                }
                this.pdfViewerBase.releaseCanvas(canvasElement);
            }
            else {
                textLayer.parentElement.removeChild(textLayer);
            }
            if (this.pdfViewer.textSearch) {
                if (!isTextSearch) {
                    this.pdfViewer.textSearch.resizeSearchElements(pageNumber);
                }
            }
        };
        TextLayer.prototype.destroy = function () {
            this.textBoundsArray = null;
            this.characterBound = null;
        };
        TextLayer.prototype.applyTextRotation = function (scale, textDiv, rotation, textRotation, bounds) {
            var scaleString = 'scaleX(' + scale + ')';
            if (this.pdfViewerBase.clientSideRendering) {
                if (rotation === 0) {
                    if (textRotation === 0) {
                        textDiv.style.transform = scaleString;
                    }
                    else if (textRotation === 90) {
                        textDiv.style.left = (bounds.X + bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = bounds.Y * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 180) {
                        textDiv.style.left = (bounds.X + bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y + bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 270) {
                        textDiv.style.left = bounds.X * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y + bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                    else {
                        textDiv.style.transform = scaleString;
                    }
                }
                else if (rotation === 1) {
                    var textRotationAngle = textRotation + 90;
                    if (textRotationAngle >= 360) {
                        textRotationAngle -= 360;
                    }
                    if (textRotation === 0) {
                        textDiv.style.transform = 'rotate(90deg) ' + scaleString;
                    }
                    else if (textRotation === 90) {
                        textDiv.style.left = bounds.X * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y + bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + textRotationAngle + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 180) {
                        textDiv.style.left = (bounds.X - bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y + bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + textRotationAngle + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 270) {
                        textDiv.style.left = (bounds.X - bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + textRotationAngle + 'deg) ' + scaleString;
                    }
                    else {
                        textDiv.style.transform = 'rotate(90deg) ' + scaleString;
                    }
                }
                else if (rotation === 2) {
                    var textRotationAngle = textRotation + 180;
                    if (textRotationAngle >= 360) {
                        textRotationAngle -= 360;
                    }
                    if (textRotation === 0) {
                        textDiv.style.transform = 'rotate(180deg) ' + scaleString;
                    }
                    else if (textRotation === 90) {
                        textDiv.style.left = (bounds.X - bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = bounds.Y * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + (textRotationAngle) + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 180) {
                        textDiv.style.left = (bounds.X - bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y - bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + (textRotationAngle) + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 270) {
                        textDiv.style.left = bounds.X * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y - bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + (textRotationAngle) + 'deg) ' + scaleString;
                    }
                    else {
                        textDiv.style.transform = 'rotate(180deg) ' + scaleString;
                    }
                }
                else if (rotation === 3) {
                    var textRotationAngle = textRotation + 270;
                    if (textRotationAngle >= 360) {
                        textRotationAngle -= 360;
                    }
                    if (textRotation === 0) {
                        textDiv.style.transform = 'rotate(270deg) ' + scaleString;
                    }
                    else if (textRotation === 90) {
                        textDiv.style.left = bounds.X * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y - bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + (textRotationAngle) + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 180) {
                        textDiv.style.left = (bounds.X + bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y - bounds.Width) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + (textRotationAngle) + 'deg) ' + scaleString;
                    }
                    else if (textRotation === 270) {
                        textDiv.style.left = (bounds.X + bounds.Height) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.top = (bounds.Y) * this.pdfViewerBase.getZoomFactor() + 'px';
                        textDiv.style.transform = 'rotate(' + (textRotationAngle) + 'deg) ' + scaleString;
                    }
                    else {
                        textDiv.style.transform = 'rotate(270deg) ' + scaleString;
                    }
                }
            }
            else {
                if (rotation === 0) {
                    if ((textRotation >= 0 && textRotation < 90)) {
                        textDiv.style.transform = scaleString;
                    }
                    else if ((textRotation === 90) || (textRotation === 270)) {
                        if ((textRotation === 270)) {
                            textDiv.style.left = (bounds.X * this.pdfViewerBase.getZoomFactor()) + 'px';
                            textDiv.style.top = ((bounds.Y + bounds.Width) * this.pdfViewerBase.getZoomFactor()) + 'px';
                            textDiv.style.height = (bounds.Height * this.pdfViewerBase.getZoomFactor()) + 'px';
                            textDiv.style.fontSize = (bounds.Height * this.pdfViewerBase.getZoomFactor()) + 'px';
                        }
                        else {
                            textDiv.style.left = ((bounds.X + bounds.Width) * this.pdfViewerBase.getZoomFactor()) + 'px';
                            textDiv.style.top = (bounds.Y * this.pdfViewerBase.getZoomFactor()) + 'px';
                            textDiv.style.height = (bounds.Width * this.pdfViewerBase.getZoomFactor()) + 'px';
                            textDiv.style.fontSize = (bounds.Width * this.pdfViewerBase.getZoomFactor()) + 'px';
                            textDiv.style.transformOrigin = '0% 0%';
                        }
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                    else {
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                }
                else if (rotation === 1) {
                    if (textRotation === 0) {
                        textDiv.style.transform = 'rotate(90deg) ' + scaleString;
                    }
                    else if (textRotation === -90) {
                        textDiv.style.transform = scaleString;
                    }
                    else {
                        textRotation = textRotation + 90;
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                }
                else if (rotation === 2) {
                    if (textRotation === 0) {
                        textDiv.style.transform = 'rotate(180deg) ' + scaleString;
                    }
                    else if (textRotation === 180) {
                        textDiv.style.transform = scaleString;
                    }
                    else {
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                }
                else if (rotation === 3) {
                    if (textRotation === 0) {
                        textDiv.style.transform = 'rotate(-90deg) ' + scaleString;
                    }
                    else if (textRotation === 90) {
                        textDiv.style.transform = scaleString;
                    }
                    else {
                        textDiv.style.transform = 'rotate(' + textRotation + 'deg) ' + scaleString;
                    }
                }
            }
        };
        TextLayer.prototype.setTextElementProperties = function (textDiv) {
            textDiv.style.fontFamily = 'serif';
            textDiv.style.transformOrigin = this.pdfViewerBase.clientSideRendering ? '0% 0%' : '0%';
        };
        TextLayer.prototype.resizeTextContentsOnZoom = function (pageNumber) {
            var renderObject = this.pdfViewerBase.sessionStorageManager.getItem(this.pdfViewerBase.getDocumentId() + '_' + pageNumber + '_' + this.getPreviousZoomFactor());
            var textBounds = [];
            var textContents = [];
            var rotation;
            if (renderObject) {
                var data = JSON.parse(renderObject);
                textBounds = data['textBounds'];
                textContents = data['textContent'];
                rotation = data['rotation'];
            }
            if (textBounds.length !== 0) {
                this.textBoundsArray.push({ pageNumber: pageNumber, textBounds: textBounds });
                this.resizeTextContents(pageNumber, textContents, textBounds, rotation);
            }
            else {
                var textElements = this.textBoundsArray.filter(function (obj) {
                    return obj.pageNumber === pageNumber;
                });
                if (textElements) {
                    if (textElements.length !== 0) {
                        textBounds = textElements[0]['textBounds'];
                        this.resizeTextContents(pageNumber, null, textBounds, rotation);
                    }
                }
            }
        };
        TextLayer.prototype.resizeExcessDiv = function (textLayer, textDiv) {
        };
        TextLayer.prototype.clearTextLayers = function (isPinchZoomed) {
            var lowerPageValue = this.pdfViewerBase.currentPageNumber - 3;
            lowerPageValue = (lowerPageValue > 0) ? lowerPageValue : 0;
            var higherPageValue = this.pdfViewerBase.currentPageNumber + 1;
            higherPageValue = (higherPageValue < this.pdfViewerBase.pageCount) ? higherPageValue : (this.pdfViewerBase.pageCount - 1);
            var textLayers = document.querySelectorAll('div[id*="' + this.pdfViewer.element.id + '_textLayer_"]');
            for (var i = 0; i < textLayers.length; i++) {
                textLayers[parseInt(i.toString(), 10)].style.display = 'block';
                if (this.pdfViewerBase.getMagnified() && (this.getTextSelectionStatus() || this.getTextSearchStatus())) {
                    var pageNumber = parseInt(textLayers[parseInt(i.toString(), 10)].id.split('_textLayer_')[1], 10);
                    if (!(((lowerPageValue + 1) <= pageNumber) && (pageNumber <= (higherPageValue - 1)))) {
                        this.removeElement(textLayers[parseInt(i.toString(), 10)], isPinchZoomed);
                    }
                }
                else if (this.pdfViewerBase.getPinchZoomed()) {
                    this.removeElement(textLayers[parseInt(i.toString(), 10)], isPinchZoomed);
                }
                else {
                    this.removeElement(textLayers[parseInt(i.toString(), 10)], isPinchZoomed);
                }
            }
        };
        TextLayer.prototype.removeElement = function (element, isPinchZoomed) {
            if (isPinchZoomed) {
                this.removeForeignObjects(element);
            }
            else {
                if (ej2_base_1.Browser.isIE) {
                    if (element.parentElement) {
                        element.parentElement.removeChild(element);
                    }
                    else if (element.parentNode) {
                        element.parentNode.removeChild(element);
                    }
                }
                else {
                    element.remove();
                }
            }
        };
        TextLayer.prototype.removeForeignObjects = function (element) {
            var childElements = element.getElementsByClassName('foreign-object');
            if (childElements) {
                for (var i = 0; i < childElements.length; i++) {
                    var child = childElements[parseInt(i.toString(), 10)];
                    var parent_1 = child.parentElement;
                    if (ej2_base_1.Browser.isDevice) {
                        if (parent_1.classList.contains('e-pv-text-layer') && parent_1.className !== 'e-pv-checkbox-outer-div') {
                            element.removeChild(child);
                            i--;
                        }
                        else if (parent_1.className === 'e-pv-checkbox-outer-div') {
                            var outerDivParent = document.getElementById(child.id);
                            if (outerDivParent) {
                                outerDivParent.remove();
                                i--;
                            }
                        }
                    }
                    else if (parent_1.className === 'e-pv-text-layer') {
                        element.removeChild(child);
                        i--;
                    }
                }
            }
        };
        TextLayer.prototype.convertToSpan = function (pageNumber, divId, fromOffset, toOffset, textString, className, isRTLText) {
            var textDiv = this.pdfViewerBase.getElement('_text_' + pageNumber + '_' + divId);
            var textContent = textString.substring(fromOffset, toOffset);
            var node = document.createTextNode(textContent);
            if (className) {
                var spanElement = ej2_base_1.createElement('span');
                spanElement.className = className + ' e-pv-text';
                if (this.pdfViewerBase.clientSideRendering && isRTLText) {
                    if (toOffset === textString.length) {
                        spanElement.style.left = 0 + 'px';
                        spanElement.style.top = 0 + 'px';
                    }
                    else {
                        if (textDiv.style.direction === 'rtl') {
                            var currentText = textDiv.textContent;
                            textDiv.textContent = textString.substring(toOffset, textString.length);
                            var textBounds = textDiv.getBoundingClientRect();
                            spanElement.style.left = textBounds.width + 'px';
                            spanElement.style.top = 0 + 'px';
                            textDiv.textContent = currentText;
                        }
                    }
                }
                spanElement.style.height = textDiv.style.height;
                spanElement.appendChild(node);
                textDiv.appendChild(spanElement);
            }
            else {
                textDiv.appendChild(node);
            }
        };
        TextLayer.prototype.applySpanForSelection = function (startPage, endPage, anchorOffsetDiv, focusOffsetDiv, anchorOffset, focusOffset) {
            if (this.pdfViewer.textSelectionModule) {
                for (var i = startPage; i <= endPage; i++) {
                    var isRTLText = void 0;
                    if (this.pdfViewerBase.clientSideRendering) {
                        var storedData = JSON.parse(this.pdfViewerBase.pageTextDetails[this.pdfViewerBase.documentId + '_' + i + '_textDetails']);
                        var pageText = storedData['pageText'];
                        isRTLText = this.pdfViewerBase.checkIsRtlText(pageText);
                    }
                    var startId = void 0;
                    var endId = void 0;
                    var textDivs = this.pdfViewerBase.getElement('_textLayer_' + i).childNodes;
                    if (i === startPage) {
                        startId = anchorOffsetDiv;
                        endId = textDivs.length - 1;
                    }
                    else if (i === endPage) {
                        startId = 0;
                        endId = focusOffsetDiv;
                    }
                    else {
                        startId = 0;
                        endId = textDivs.length - 1;
                    }
                    if (startPage === endPage) {
                        startId = anchorOffsetDiv;
                        endId = focusOffsetDiv;
                    }
                    for (var j = startId; j <= endId; j++) {
                        var textDiv = this.pdfViewerBase.getElement('_text_' + i + '_' + j);
                        var initId = void 0;
                        var lastId = void 0;
                        var length_1 = void 0;
                        if (textDiv && textDiv.textContent) {
                            length_1 = textDiv.textContent.length;
                            var textContent = textDiv.textContent;
                            textDiv.textContent = '';
                            if (j === startId) {
                                if (i === startPage) {
                                    initId = anchorOffset;
                                }
                                else {
                                    initId = 0;
                                }
                                lastId = length_1;
                                this.convertToSpan(i, j, 0, initId, textContent, null, isRTLText);
                            }
                            else if (j === endId && i === endPage) {
                                initId = 0;
                                lastId = focusOffset;
                            }
                            else {
                                initId = 0;
                                lastId = length_1;
                            }
                            if (startId === endId && startPage === endPage) {
                                initId = anchorOffset;
                                lastId = focusOffset;
                            }
                            this.convertToSpan(i, j, initId, lastId, textContent, 'e-pv-maintaincontent', isRTLText);
                            if (j === endId && i === endPage) {
                                this.convertToSpan(i, j, lastId, textContent.length, textContent, null, isRTLText);
                            }
                        }
                    }
                }
            }
        };
        TextLayer.prototype.clearDivSelection = function () {
            var textLayers = document.querySelectorAll('div[id*="' + this.pdfViewer.element.id + '_textLayer_"]');
            for (var i = 0; i < textLayers.length; i++) {
                var childNodes = textLayers[parseInt(i.toString(), 10)].childNodes;
                for (var j = 0; j < childNodes.length; j++) {
                    var textDiv = childNodes[parseInt(j.toString(), 10)];
                    if (textDiv.className !== 'e-pdfviewer-formFields' && textDiv.className !== 'e-pdfviewer-signatureformfields' && textDiv.className !== 'e-pdfviewer-signatureformfields-signature') {
                        var textContent = textDiv.textContent;
                        if (textDiv.childNodes.length > 1 || textDiv.childNodes.length === 1 && (textDiv.childNodes[0].tagName === 'SPAN')) {
                            textDiv.textContent = '';
                            textDiv.textContent = textContent;
                        }
                    }
                }
            }
        };
        TextLayer.prototype.setStyleToTextDiv = function (textDiv, left, top, bottom, width, height, rotation) {
            textDiv.style.left = left * this.pdfViewerBase.getZoomFactor() + 'px';
            textDiv.style.top = top * this.pdfViewerBase.getZoomFactor() + 'px';
            var textHeight;
            if (rotation === 90 || (this.pdfViewerBase.clientSideRendering && rotation === 270)) {
                textHeight = width * this.pdfViewerBase.getZoomFactor();
            }
            else {
                textHeight = height * this.pdfViewerBase.getZoomFactor();
            }
            textDiv.style.height = textHeight + 'px';
            textDiv.style.fontSize = textHeight + 'px';
        };
        TextLayer.prototype.getTextSelectionStatus = function () {
            if (this.pdfViewer.textSelectionModule) {
                return this.pdfViewer.textSelectionModule.isTextSelection;
            }
            else {
                return false;
            }
        };
        TextLayer.prototype.modifyTextCursor = function (isAdd) {
            var textLayerList = document.querySelectorAll('div[id*="' + this.pdfViewer.element.id + '_textLayer_"]');
            for (var i = 0; i < textLayerList.length; i++) {
                var childNodes = textLayerList[parseInt(i.toString(), 10)].childNodes;
                for (var j = 0; j < childNodes.length; j++) {
                    var textElement = childNodes[parseInt(j.toString(), 10)];
                    if (isAdd && textElement.className !== 'e-pdfviewer-formFields' && textElement.className !== 'e-pdfviewer-signatureformfields' && textElement.className !== 'e-pdfviewer-signatureformfields-signature') {
                        textElement.classList.add('e-pv-cursor');
                    }
                    else {
                        textElement.classList.remove('e-pv-cursor');
                    }
                }
            }
        };
        TextLayer.prototype.isBackWardSelection = function (selection) {
            var position = selection.anchorNode.compareDocumentPosition(selection.focusNode);
            var backward = false;
            if (!position && selection.anchorOffset > selection.focusOffset || position === Node.DOCUMENT_POSITION_PRECEDING) {
                backward = true;
            }
            return backward;
        };
        TextLayer.prototype.getPageIndex = function (element) {
            var pageId;
            var parentElement = element.parentElement;
            if (!parentElement) {
                parentElement = element.parentNode;
            }
            if (parentElement.className === 'e-pv-text-layer') {
                pageId = parseInt(element.id.split('_text_')[1], 10);
            }
            else {
                pageId = parseInt(parentElement.id.split('_text_')[1], 10);
            }
            return pageId;
        };
        TextLayer.prototype.getTextIndex = function (element, pageIndex) {
            var textIndex;
            var parentElement = element.parentElement;
            if (!parentElement) {
                parentElement = element.parentNode;
            }
            if (parentElement.className === 'e-pv-text-layer') {
                textIndex = parseInt(element.id.split('_text_' + pageIndex + '_')[1], 10);
            }
            else {
                textIndex = parseInt(parentElement.id.split('_text_' + pageIndex + '_')[1], 10);
            }
            return textIndex;
        };
        TextLayer.prototype.getPreviousZoomFactor = function () {
            if (this.pdfViewer.magnificationModule) {
                return this.pdfViewer.magnificationModule.previousZoomFactor;
            }
            else {
                return 1;
            }
        };
        TextLayer.prototype.getTextSearchStatus = function () {
            if (this.pdfViewer.textSearchModule) {
                return this.pdfViewer.textSearchModule.isTextSearch;
            }
            else {
                return false;
            }
        };
        return TextLayer;
    }());
    exports.TextLayer = TextLayer;
});