@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
87 lines (86 loc) • 3.69 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 { PdfTemplate } from '../pdf-template';
import { PdfDynamicField } from './dynamic-field';
/**
* Represents an internal field that maintains multiple rendered values across different PdfGraphics contexts.
*
* @private
*/
var PdfMultipleValueField = /** @class */ (function (_super) {
__extends(PdfMultipleValueField, _super);
function PdfMultipleValueField() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* Stores a mapping between PdfGraphics instances and their corresponding template value pairs.
*
* @private
*/
_this._templateValueMap = new Map();
return _this;
}
/**
* Initializes the base dynamic field with optional font, brush, and string format settings.
*
* @param {PdfFont} [font] - The font used for rendering the field text.
* @param {PdfBrush} [brush] - The brush used to define the text color.
* @param {PdfStringFormat} [stringFormat] - The format used for text layout and alignment.
* @returns {void}
* @private
*/
PdfMultipleValueField.prototype._initializeBase = function (font, brush, stringFormat) {
_super.prototype._initializeBase.call(this, font, brush, stringFormat);
};
/**
* Performs rendering with value reuse logic.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @param {Point} location The drawing location.
* @returns {void} Nothing.
*/
PdfMultipleValueField.prototype._performDraw = function (graphics, location) {
_super.prototype._performDraw.call(this, graphics, location);
var value = this._getValue(graphics);
var cached = this._templateValueMap.get(graphics); // eslint-disable-line
if (!cached || cached.value !== value) {
var font = this._obtainFont();
var brush = this._obtainBrush();
var size_1 = this._obtainSize();
var template = new PdfTemplate({ x: 0, y: 0, width: size_1.width, height: size_1.height });
if (value) {
template.graphics.drawString(value, font, { x: 0, y: 0, width: size_1.width, height: size_1.height }, brush);
}
cached = { template: template, value: value };
this._templateValueMap.set(graphics, cached);
}
var size = this._obtainSize();
var bounds = { x: location.x, y: location.y, width: size.width, height: size.height };
graphics.drawTemplate(cached.template, bounds);
};
/**
* Default value resolver for multiple-value fields.
* Derived classes should override to provide actual values.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @returns {string} The computed value (default empty string).
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
PdfMultipleValueField.prototype._getValue = function (graphics) {
return '';
};
return PdfMultipleValueField;
}(PdfDynamicField));
export { PdfMultipleValueField };