@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
175 lines (174 loc) • 5.51 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Size } from '../../primitives/size';
import { DrawingElement } from './drawing-element';
import { measureText } from './../../utility/dom-util';
/**
* @hidden
* TextElement is used to display text/annotations
*/
var TextElement = /** @class */ (function (_super) {
__extends(TextElement, _super);
/**
* set the id for each element
*/
function TextElement() {
var _this = _super.call(this) || this;
/**
* sets or gets the image source
*/
_this.textContent = '';
/** @private */
_this.canMeasure = true;
/** @private */
_this.canConsiderBounds = true;
/** @private */
_this.doWrap = true;
_this.textNodes = [];
/**
* Defines the appearance of the text element
*/
_this.style = {
color: 'black', fill: 'transparent', strokeColor: 'black',
strokeWidth: 1, fontFamily: 'Arial', fontSize: 12, whiteSpace: 'CollapseSpace',
textWrapping: 'WrapWithOverflow', textAlign: 'Center', italic: false, bold: false,
textDecoration: 'None', strokeDashArray: '', opacity: 1,
textOverflow: 'Wrap'
};
_this.style.fill = 'transparent';
_this.style.strokeColor = 'transparent';
return _this;
}
Object.defineProperty(TextElement.prototype, "content", {
/**
* gets the content for the text element
*
* @private
* @returns {string} - string
*/
get: function () {
return this.textContent;
},
/**
* sets the content for the text element
*
* @param {string} value - value
* @private
*/
set: function (value) {
if (this.textContent !== value) {
this.textContent = value;
this.isDirt = true;
this.doWrap = true;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextElement.prototype, "childNodes", {
/**
* sets the content for the text element
*
* @private
* @returns {SubTextElement[]} - Array of SubTextElement
*/
get: function () {
return this.textNodes;
},
/**
* gets the content for the text element
*
* @param {SubTextElement[]} value - array of SubTextElement
* @private
*/
set: function (value) {
this.textNodes = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextElement.prototype, "wrapBounds", {
/**
* gets the wrapBounds for the text
*
* @private
* @returns {TextBounds} - TextBounds
*/
get: function () {
return this.textWrapBounds;
},
/**
* sets the wrapBounds for the text
*
* @param {TextBounds} value - value
* @private
*/
set: function (value) {
this.textWrapBounds = value;
},
enumerable: true,
configurable: true
});
/**
* Measures the minimum space that is required to render the element
*
* @private
* @returns {void} - void
*/
TextElement.prototype.refreshTextElement = function () {
this.isDirt = true;
};
/**
* Measures the minimum size that is required for the text element
*
* @param {Size} availableSize - availableSize
* @private
* @returns {Size} - Size
*/
TextElement.prototype.measure = function (availableSize) {
var size;
if (this.isDirt && this.canMeasure) {
size = measureText(this, this.style, this.content, this.width || availableSize.width, availableSize.height);
}
else {
size = this.desiredSize;
}
if (this.width === undefined || this.height === undefined) {
this.desiredSize = new Size(size.width, size.height);
}
else {
this.desiredSize = new Size(this.width, this.height);
}
this.desiredSize = this.validateDesiredSize(this.desiredSize, availableSize);
return this.desiredSize;
};
/**
* Arranges the text element
*
* @param {Size} desiredSize - desiredSize
* @private
* @returns {Size} - Size
*/
TextElement.prototype.arrange = function (desiredSize) {
if (desiredSize.width !== this.actualSize.width || desiredSize.height !== this.actualSize.height || this.isDirt) {
this.doWrap = true;
}
this.actualSize = desiredSize;
this.updateBounds();
this.isDirt = false;
return this.actualSize;
};
return TextElement;
}(DrawingElement));
export { TextElement };