@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
82 lines (81 loc) • 3.52 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 dynamic field that maintains a single cached value for rendering.
*
* @private
*/
var PdfSingleValueField = /** @class */ (function (_super) {
__extends(PdfSingleValueField, _super);
function PdfSingleValueField() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Initializes the base dynamic field with optional font, brush, and string format settings.
*
* @private
*
* @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} Does not return a value.
*/
PdfSingleValueField.prototype._initializeBase = function (font, brush, stringFormat) {
_super.prototype._initializeBase.call(this, font, brush, stringFormat);
};
/**
* Performs single-value rendering with caching.
*
* @private
* @param {PdfGraphics} graphics The graphics context.
* @param {Point} location The drawing location.
* @returns {void} Nothing.
*/
PdfSingleValueField.prototype._performDraw = function (graphics, location) {
_super.prototype._performDraw.call(this, graphics, location);
var value = this._getValue(graphics);
var page = this._getPageFromGraphics(graphics);
var doc = (page && page._crossReference) ? page._crossReference._document : null;
if (!this._template || this._cachedValue !== value || this._cachedDocument !== doc) {
var font = this._obtainFont();
var brush = this._obtainBrush();
var templateSize = this._obtainSize();
var template = new PdfTemplate({ x: 0, y: 0, width: templateSize.width, height: templateSize.height });
template.graphics.drawString(value, font, { x: 0, y: 0, width: templateSize.width, height: templateSize.height }, brush);
this._template = template;
this._cachedValue = value;
this._cachedDocument = doc;
}
var size = this._obtainSize();
var bounds = { x: location.x, y: location.y, width: size.width, height: size.height };
graphics.drawTemplate(this._template, bounds);
};
/**
* Gets the string value produced by this field.
*
* @private
* @param {PdfGraphics} graphics
* The graphics context used during rendering.
*
* @returns {string} The resolved string value for the field.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
PdfSingleValueField.prototype._getValue = function (graphics) {
return '';
};
return PdfSingleValueField;
}(PdfDynamicField));
export { PdfSingleValueField };