devexpress-reporting
Version:
DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.
32 lines (31 loc) • 1.29 kB
JavaScript
/**
* DevExpress HTML/JS Reporting (designer\helpers\_textElementSizeHelper.js)
* Version: 25.1.3
* Build date: Jun 26, 2025
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* License: https://www.devexpress.com/Support/EULAs/universal.xml
*/
import * as $ from 'jquery';
export class TextElementSizeHelper {
constructor() {
this._spaceSymbol = ' ';
}
_$createElement(options, processElement) {
return processElement($.fn.constructor('<div>').css(options)).appendTo($.fn.constructor('body'));
}
$createTextElement(text, options) {
return this._$createElement(options, ($element) => { return $element.text(text); });
}
$createSpaceElement(options) {
return this._$createElement(options, ($element) => { return $element.html(this._spaceSymbol); });
}
getTextContainerSize(text, options, increaseHeight = 2) {
const $div = text !== this._spaceSymbol ? this.$createTextElement(text, options) : this.$createSpaceElement(options);
$div.height($div.height() + increaseHeight);
const rect = $div[0].getBoundingClientRect();
const height = Math.ceil(rect.height);
const width = Math.ceil(rect.width);
$div.remove();
return { width, height };
}
}