UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

273 lines (272 loc) 7.81 kB
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 __()); }; })(); /** * Holds font metadata including names character range width table and style flags. * * @private */ var _PdfFontMetrics = /** @class */ (function () { function _PdfFontMetrics() { } return _PdfFontMetrics; }()); export { _PdfFontMetrics }; /** * Base type for width lookup tables that provide character width access and serialization. * * @private */ var _WidthTable = /** @class */ (function () { function _WidthTable() { } return _WidthTable; }()); export { _WidthTable }; /** * Stores per character widths with direct indexed access. * * @private */ var _StandardWidthTable = /** @class */ (function (_super) { __extends(_StandardWidthTable, _super); function _StandardWidthTable(widths) { var _this = _super.call(this) || this; _this.widths = widths; return _this; } /** * Returns the width for the requested character code with bounds validation. * * @private * @param {number} index Character code index. * @returns {number} width. */ _StandardWidthTable.prototype._itemAt = function (index) { if (index < 0 || index >= this.widths.length) { throw new Error('The character is not supported by the font.'); } return this.widths[index]; }; /** * Returns the underlying widths array without transformation. * * @private * @returns {number[]} widths. */ _StandardWidthTable.prototype._toArray = function () { return this.widths; }; return _StandardWidthTable; }(_WidthTable)); export { _StandardWidthTable }; /** * Manages CJK width ranges with a default width and range overrides. * * @private */ var _CjkWidthTable = /** @class */ (function (_super) { __extends(_CjkWidthTable, _super); function _CjkWidthTable(defaultWidth) { var _this = _super.call(this) || this; _this._defaultWidth = defaultWidth; _this.widths = []; return _this; } /** * Returns the width for the requested code using default and matching range entries. * * @private * @param {number} index Character code. * @returns {number} width. */ _CjkWidthTable.prototype._itemAt = function (index) { var width = this._defaultWidth; this.widths.forEach(function (entry) { if (index >= entry._from && index <= entry._to) { width = entry._itemAt(index); } }); return width; }; /** * Produces a compact array representation of all range width data. * * @private * @returns {number[]} array. */ _CjkWidthTable.prototype._toArray = function () { var array = []; this.widths.forEach(function (width) { width._appendToArray(array); }); return array; }; /** * Adds a CJK width range entry to the table. * * @private * @param {_CjkWidth} width Range entry. * @returns {void} nothing. */ _CjkWidthTable.prototype._add = function (width) { this.widths.push(width); }; return _CjkWidthTable; }(_WidthTable)); export { _CjkWidthTable }; /** * Represents a CJK width range entry that exposes bounds and width accessors. * * @private */ var _CjkWidth = /** @class */ (function () { function _CjkWidth() { } return _CjkWidth; }()); export { _CjkWidth }; /** * Describes a CJK range where all codes share the same width. * * @private */ var _CjkSameWidth = /** @class */ (function (_super) { __extends(_CjkSameWidth, _super); function _CjkSameWidth(from, to, width) { var _this = _super.call(this) || this; _this._widthFrom = from; _this._widthTo = to; _this._width = width; return _this; } Object.defineProperty(_CjkSameWidth.prototype, "_from", { /** * Gets the starting code of the uniform width range. * * @private * @returns {number} from. */ get: function () { return this._widthFrom; }, enumerable: true, configurable: true }); Object.defineProperty(_CjkSameWidth.prototype, "_to", { /** * Gets the ending code of the uniform width range. * * @private * @returns {number} to. */ get: function () { return this._widthTo; }, enumerable: true, configurable: true }); /** * Returns the uniform width for any code within the range. * * @private * @param {number} index Character code. * @returns {number} width. */ _CjkSameWidth.prototype._itemAt = function (index) { if (index < this._from || index > this._to) { throw new Error('Index is out of range.'); } return this._width; }; /** * Appends the range using start end and width triplet. * * @private * @param {number[]} array Output array. * @returns {void} nothing. */ _CjkSameWidth.prototype._appendToArray = function (array) { array.push(this._from, this._to, this._width); }; return _CjkSameWidth; }(_CjkWidth)); export { _CjkSameWidth }; /** * Describes a CJK range where codes have varying widths. * * @private */ var _CjkDifferentWidth = /** @class */ (function (_super) { __extends(_CjkDifferentWidth, _super); function _CjkDifferentWidth(from, widths) { var _this = _super.call(this) || this; _this._widthFrom = from; _this._widths = widths; return _this; } Object.defineProperty(_CjkDifferentWidth.prototype, "_from", { /** * Gets the starting code of the varying width range. * * @private * @returns {number} from. */ get: function () { return this._widthFrom; }, enumerable: true, configurable: true }); Object.defineProperty(_CjkDifferentWidth.prototype, "_to", { /** * Gets the ending code of the varying width range. * * @private * @returns {number} to. */ get: function () { return this._widthFrom + this._widths.length - 1; }, enumerable: true, configurable: true }); /** * Returns the width for a code within the varying range. * * @private * @param {number} index Character code. * @returns {number} width. */ _CjkDifferentWidth.prototype._itemAt = function (index) { if (index < this._widthFrom || index > this._to) { throw new Error('Index is out of range.'); } return this._widths[index]; }; /** * Appends the starting code followed by the widths for the range. * * @private * @param {number[]} array Output array. * @returns {void} nothing. */ _CjkDifferentWidth.prototype._appendToArray = function (array) { array.push(this._from); array.forEach(function (entry) { array.push(entry); }); }; return _CjkDifferentWidth; }(_CjkWidth)); export { _CjkDifferentWidth };