@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
70 lines (69 loc) • 2.7 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 { _PdfBaseStream } from '../base-stream';
import { _PdfDecodeStream } from '../decode-stream';
import { _PdfJbig2Image } from '../graphics/images/jbig2-image';
import { _PdfDictionary } from '../pdf-primitives';
/**
* Provides a JBIG2 decoding stream that reads from a base stream and outputs inverted bitmap data.
*
* @private
*/
var _PdfJbig2Stream = /** @class */ (function (_super) {
__extends(_PdfJbig2Stream, _super);
function _PdfJbig2Stream(stream, maybeLength, params) {
var _this = _super.call(this, maybeLength) || this;
_this.stream = stream;
_this.maybeLength = maybeLength;
_this.params = params;
return _this;
}
Object.defineProperty(_PdfJbig2Stream.prototype, "bytes", {
get: function () {
return this.stream.getBytes(this.maybeLength);
},
enumerable: true,
configurable: true
});
_PdfJbig2Stream.prototype.readBlock = function () {
this.decodeImage();
};
_PdfJbig2Stream.prototype.decodeImage = function (bytes) {
if (this.eof) {
return this.buffer;
}
bytes = bytes || this.bytes;
var jbig2Image = new _PdfJbig2Image();
var chunks = []; // eslint-disable-line
if (this.params instanceof _PdfDictionary) {
var globalsStream = this.params.get('JBIG2Globals'); // eslint-disable-line
if (globalsStream instanceof _PdfBaseStream) {
var globals = globalsStream.getBytes(); // eslint-disable-line
chunks.push({ data: globals, start: 0, end: globals.length });
}
}
chunks.push({ data: bytes, start: 0, end: bytes.length });
var data = jbig2Image._parseChunks(chunks); // eslint-disable-line
var dataLength = data.length;
for (var i = 0; i < dataLength; i++) {
data[i] ^= 0xff;
}
this.buffer = data;
this.bufferLength = dataLength;
this.eof = true;
return this.buffer;
};
return _PdfJbig2Stream;
}(_PdfDecodeStream));
export { _PdfJbig2Stream };