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;
});
|