UNPKG

@syncfusion/ej2-pdf

Version:

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

90 lines (89 loc) 3.11 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 __()); }; })(); import { _PdfDecodeStream } from '../decode-stream'; import { _isWhiteSpace } from '../utils'; /** * Decodes ASCII85 encoded data from an underlying byte stream into binary content. * * @private */ var _PdfAscii85Stream = /** @class */ (function (_super) { __extends(_PdfAscii85Stream, _super); function _PdfAscii85Stream(str, maybeLength) { var _this = this; if (maybeLength) { maybeLength *= 0.8; } _this = _super.call(this, maybeLength) || this; _this.stream = str; _this.input = new Uint8Array(5); return _this; } _PdfAscii85Stream.prototype.readBlock = function () { var tildaCharacter = 0x7e; var lowerCharacter = 0x7a; var eof = -1; var str = this.stream; // eslint-disable-line var c = str.getByte(); // eslint-disable-line while (_isWhiteSpace(c)) { c = str.getByte(); } if (c === eof || c === tildaCharacter) { this.eof = true; return; } var bufferLength = this.bufferLength; var buffer; // eslint-disable-line var i; if (c === lowerCharacter) { buffer = this.ensureBuffer(bufferLength + 4); for (i = 0; i < 4; ++i) { buffer[bufferLength + i] = 0; } this.bufferLength += 4; } else { var input = this.input; // eslint-disable-line input[0] = c; for (i = 1; i < 5; ++i) { c = str.getByte(); while (_isWhiteSpace(c)) { c = str.getByte(); } input[Number.parseInt(i.toString(), 10)] = c; if (c === eof || c === tildaCharacter) { break; } } buffer = this.ensureBuffer(bufferLength + i - 1); this.bufferLength += i - 1; if (i < 5) { for (; i < 5; ++i) { input[Number.parseInt(i.toString(), 10)] = 0x21 + 84; } this.eof = true; } var t = 0; for (i = 0; i < 5; ++i) { t = t * 85 + (input[Number.parseInt(i.toString(), 10)] - 0x21); } for (i = 3; i >= 0; --i) { buffer[bufferLength + i] = t & 0xff; t >>= 8; } } }; return _PdfAscii85Stream; }(_PdfDecodeStream)); export { _PdfAscii85Stream };