Merge pull request #13304 from Snuffleupagus/src-core-classes

Convert more code in `src/core/` to use standard classes
This commit is contained in:
Tim van der Meij 2021-04-27 19:37:09 +02:00 committed by GitHub
commit fae183b7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 978 additions and 1015 deletions

File diff suppressed because it is too large Load Diff

View File

@ -17,9 +17,10 @@ import { Dict, isDict } from "./primitives.js";
import { CCITTFaxDecoder } from "./ccitt.js"; import { CCITTFaxDecoder } from "./ccitt.js";
import { DecodeStream } from "./stream.js"; import { DecodeStream } from "./stream.js";
const CCITTFaxStream = (function CCITTFaxStreamClosure() { class CCITTFaxStream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(str, maybeLength, params) {
function CCITTFaxStream(str, maybeLength, params) { super(maybeLength);
this.str = str; this.str = str;
this.dict = str.dict; this.dict = str.dict;
@ -41,13 +42,9 @@ const CCITTFaxStream = (function CCITTFaxStreamClosure() {
EndOfBlock: params.get("EndOfBlock"), EndOfBlock: params.get("EndOfBlock"),
BlackIs1: params.get("BlackIs1"), BlackIs1: params.get("BlackIs1"),
}); });
DecodeStream.call(this, maybeLength);
} }
CCITTFaxStream.prototype = Object.create(DecodeStream.prototype); readBlock() {
CCITTFaxStream.prototype.readBlock = function () {
while (!this.eof) { while (!this.eof) {
const c = this.ccittFaxDecoder.readNextChar(); const c = this.ccittFaxDecoder.readNextChar();
if (c === -1) { if (c === -1) {
@ -57,9 +54,7 @@ const CCITTFaxStream = (function CCITTFaxStreamClosure() {
this.ensureBuffer(this.bufferLength + 1); this.ensureBuffer(this.bufferLength + 1);
this.buffer[this.bufferLength++] = c; this.buffer[this.bufferLength++] = c;
} }
}; }
}
return CCITTFaxStream;
})();
export { CCITTFaxStream }; export { CCITTFaxStream };

View File

@ -22,33 +22,27 @@ import { shadow } from "../shared/util.js";
* For JBIG2's we use a library to decode these images and * For JBIG2's we use a library to decode these images and
* the stream behaves like all the other DecodeStreams. * the stream behaves like all the other DecodeStreams.
*/ */
const Jbig2Stream = (function Jbig2StreamClosure() { class Jbig2Stream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(stream, maybeLength, dict, params) {
function Jbig2Stream(stream, maybeLength, dict, params) { super(maybeLength);
this.stream = stream; this.stream = stream;
this.maybeLength = maybeLength; this.maybeLength = maybeLength;
this.dict = dict; this.dict = dict;
this.params = params; this.params = params;
DecodeStream.call(this, maybeLength);
} }
Jbig2Stream.prototype = Object.create(DecodeStream.prototype); get bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
Object.defineProperty(Jbig2Stream.prototype, "bytes", { ensureBuffer(requested) {
get() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
Jbig2Stream.prototype.ensureBuffer = function (requested) {
// No-op, since `this.readBlock` will always parse the entire image and // No-op, since `this.readBlock` will always parse the entire image and
// directly insert all of its data into `this.buffer`. // directly insert all of its data into `this.buffer`.
}; }
Jbig2Stream.prototype.readBlock = function () { readBlock() {
if (this.eof) { if (this.eof) {
return; return;
} }
@ -73,9 +67,7 @@ const Jbig2Stream = (function Jbig2StreamClosure() {
this.buffer = data; this.buffer = data;
this.bufferLength = dataLength; this.bufferLength = dataLength;
this.eof = true; this.eof = true;
}; }
}
return Jbig2Stream;
})();
export { Jbig2Stream }; export { Jbig2Stream };

View File

@ -22,9 +22,8 @@ import { shadow } from "../shared/util.js";
* For JPEG's we use a library to decode these images and the stream behaves * For JPEG's we use a library to decode these images and the stream behaves
* like all the other DecodeStreams. * like all the other DecodeStreams.
*/ */
const JpegStream = (function JpegStreamClosure() { class JpegStream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(stream, maybeLength, dict, params) {
function JpegStream(stream, maybeLength, dict, params) {
// Some images may contain 'junk' before the SOI (start-of-image) marker. // Some images may contain 'junk' before the SOI (start-of-image) marker.
// Note: this seems to mainly affect inline images. // Note: this seems to mainly affect inline images.
let ch; let ch;
@ -35,30 +34,25 @@ const JpegStream = (function JpegStreamClosure() {
break; break;
} }
} }
super(maybeLength);
this.stream = stream; this.stream = stream;
this.maybeLength = maybeLength; this.maybeLength = maybeLength;
this.dict = dict; this.dict = dict;
this.params = params; this.params = params;
DecodeStream.call(this, maybeLength);
} }
JpegStream.prototype = Object.create(DecodeStream.prototype); get bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
Object.defineProperty(JpegStream.prototype, "bytes", { ensureBuffer(requested) {
get: function JpegStream_bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
JpegStream.prototype.ensureBuffer = function (requested) {
// No-op, since `this.readBlock` will always parse the entire image and // No-op, since `this.readBlock` will always parse the entire image and
// directly insert all of its data into `this.buffer`. // directly insert all of its data into `this.buffer`.
}; }
JpegStream.prototype.readBlock = function () { readBlock() {
if (this.eof) { if (this.eof) {
return; return;
} }
@ -105,9 +99,7 @@ const JpegStream = (function JpegStreamClosure() {
this.buffer = data; this.buffer = data;
this.bufferLength = data.length; this.bufferLength = data.length;
this.eof = true; this.eof = true;
}; }
}
return JpegStream;
})();
export { JpegStream }; export { JpegStream };

View File

@ -21,33 +21,27 @@ import { shadow } from "../shared/util.js";
* For JPEG 2000's we use a library to decode these images and * For JPEG 2000's we use a library to decode these images and
* the stream behaves like all the other DecodeStreams. * the stream behaves like all the other DecodeStreams.
*/ */
const JpxStream = (function JpxStreamClosure() { class JpxStream extends DecodeStream {
// eslint-disable-next-line no-shadow constructor(stream, maybeLength, dict, params) {
function JpxStream(stream, maybeLength, dict, params) { super(maybeLength);
this.stream = stream; this.stream = stream;
this.maybeLength = maybeLength; this.maybeLength = maybeLength;
this.dict = dict; this.dict = dict;
this.params = params; this.params = params;
DecodeStream.call(this, maybeLength);
} }
JpxStream.prototype = Object.create(DecodeStream.prototype); get bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
}
Object.defineProperty(JpxStream.prototype, "bytes", { ensureBuffer(requested) {
get: function JpxStream_bytes() {
// If `this.maybeLength` is null, we'll get the entire stream.
return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
},
configurable: true,
});
JpxStream.prototype.ensureBuffer = function (requested) {
// No-op, since `this.readBlock` will always parse the entire image and // No-op, since `this.readBlock` will always parse the entire image and
// directly insert all of its data into `this.buffer`. // directly insert all of its data into `this.buffer`.
}; }
JpxStream.prototype.readBlock = function () { readBlock() {
if (this.eof) { if (this.eof) {
return; return;
} }
@ -87,9 +81,7 @@ const JpxStream = (function JpxStreamClosure() {
} }
this.bufferLength = this.buffer.length; this.bufferLength = this.buffer.length;
this.eof = true; this.eof = true;
}; }
}
return JpxStream;
})();
export { JpxStream }; export { JpxStream };