UNPKG

@syncfusion/ej2-pdf

Version:

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

78 lines (77 loc) 2.73 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'; /** * Decodes ASCII hexadecimal encoded data from an underlying byte stream into binary content. * * @private */ var _PdfAsciiHexStream = /** @class */ (function (_super) { __extends(_PdfAsciiHexStream, _super); function _PdfAsciiHexStream(str, maybeLength) { var _this = this; if (maybeLength) { maybeLength *= 0.5; } _this = _super.call(this, maybeLength) || this; _this.stream = str; _this.firstDigit = -1; return _this; } _PdfAsciiHexStream.prototype.readBlock = function () { var blockSize = 8000; var bytes = this.stream.getBytes(blockSize); // eslint-disable-line if (!bytes.length) { this.eof = true; return; } var maxDecodeLength = (bytes.length + 1) >> 1; var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength); var bufferLength = this.bufferLength; var firstDigit = this.firstDigit; for (var _i = 0, bytes_1 = bytes; _i < bytes_1.length; _i++) { var ch = bytes_1[_i]; var digit = void 0; // eslint-disable-line if (ch >= 0x30 && ch <= 0x39) { digit = ch & 0x0f; } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) { digit = (ch & 0x0f) + 9; } else if (ch === 0x3e) { this.eof = true; break; } else { continue; } if (firstDigit < 0) { firstDigit = digit; } else { buffer[bufferLength++] = (firstDigit << 4) | digit; firstDigit = -1; } } if (firstDigit >= 0 && this.eof) { buffer[bufferLength++] = firstDigit << 4; firstDigit = -1; } this.firstDigit = firstDigit; this.bufferLength = bufferLength; }; return _PdfAsciiHexStream; }(_PdfDecodeStream)); export { _PdfAsciiHexStream };