all files / document-editor/implementation/text-helper/ regular.js

96.23% Statements 51/53
80% Branches 16/20
100% Functions 7/7
96.23% Lines 51/53
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     9300×                                          
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Regular = (function () {
        function Regular(documentHelper) {
            this.documentHelper = documentHelper;
        }
        Regular.prototype.getModuleName = function () {
            return 'Regular';
        };
        Regular.prototype.getHeightInternal = function (characterFormat, fontToRender) {
            var textHeight = 0;
            var baselineOffset = 0;
            var spanElement = document.createElement('span');
            spanElement.innerText = 'm';
            var iframe = ej2_base_1.createElement('iframe');
            document.body.appendChild(iframe);
            var innerHtml = '<!DOCTYPE html>'
                + '<html><head></head>'
                + '<body>'
                + '</body>'
                + '</html>';
            Eif (!ej2_base_1.isNullOrUndefined(iframe.contentDocument)) {
                iframe.contentDocument.open();
                iframe.contentDocument.write(innerHtml);
                iframe.contentDocument.close();
            }
            this.applyStyle(spanElement, characterFormat, fontToRender);
            var parentDiv = document.createElement('div');
            parentDiv.setAttribute('style', 'display:inline-block;position:absolute;');
            var tempDiv = document.createElement('div');
            tempDiv.setAttribute('style', 'display:inline-block;width: 1px; height: 0px;vertical-align: baseline;');
            parentDiv.appendChild(spanElement);
            parentDiv.appendChild(tempDiv);
            iframe.contentDocument.body.appendChild(parentDiv);
            textHeight = spanElement.offsetHeight;
            var textTopVal = spanElement.offsetTop;
            var tempDivTopVal = tempDiv.offsetTop;
            baselineOffset = tempDivTopVal - textTopVal;
            document.body.removeChild(iframe);
            return { 'Height': textHeight, 'BaselineOffset': baselineOffset };
        };
        Regular.prototype.applyStyle = function (spanElement, characterFormat, fontToRender) {
            if (!ej2_base_1.isNullOrUndefined(spanElement) && !ej2_base_1.isNullOrUndefined(characterFormat)) {
                var style = 'white-space:nowrap;';
                Eif (!ej2_base_1.isNullOrUndefined(fontToRender) && fontToRender !== '') {
                    style += 'font-family:' + fontToRender + ';';
                }
                else {
                    style += 'font-family:' + characterFormat.fontFamily + ';';
                }
                var isBidi = characterFormat.bidi || characterFormat.complexScript;
                var fontSize = isBidi ? characterFormat.fontSizeBidi : characterFormat.fontSize;
                Iif (fontSize <= 0.5) {
                    fontSize = 0.5;
                }
                style += 'font-size:' + fontSize.toString() + 'pt;';
                if (characterFormat.bold) {
                    style += 'font-weight:bold;';
                }
                if (characterFormat.italic) {
                    style += 'font-style:italic;';
                }
                spanElement.setAttribute('style', style);
            }
        };
        Regular.prototype.destroy = function () {
            this.documentHelper = undefined;
        };
        return Regular;
    }());
    exports.Regular = Regular;
});