Add a gulp image_decoders command to allow packaging/distributing the image decoders (i.e. jpg.js, jpx.js, jbig2.js) separately from the main PDF.js library

Please note that the standalone `pdf.image_decoders.js` file will be including the complete `src/shared/util.js` file, despite only using parts of it.[1] This was done *purposely*, to not negatively impact the readability/maintainability of the core PDF.js code.

Furthermore, to ensure that the compatibility is the same in the regular PDF.js library *and* in the the standalone image decoders, `src/shared/compatibility.js` was included as well.

To (hopefully) prevent future complaints about the size of the built `pdf.image_decoders.js` file, a few existing async-related polyfills are being skipped (since all of the image decoders are completely synchronous).
Obviously this required adding a couple of pre-processor statements, but given that these are all limited to "compatibility" code, I think this might be OK!?

---
[1] However, please note that previous commits moved `PageViewport` and `MessageHandler` out of `src/shared/util.js` which reduced its size.
This commit is contained in:
Jonas Jenwald 2018-05-16 13:49:26 +02:00
parent bfc88ead66
commit 303537bcb1
4 changed files with 111 additions and 4 deletions

View file

@ -138,6 +138,11 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
// Support: IE, Safari<8, Chrome<32
(function checkPromise() {
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
// The current image decoders are synchronous, hence `Promise` shouldn't
// need to be polyfilled for the IMAGE_DECODERS build target.
return;
}
if (globalScope.Promise) {
return;
}
@ -157,6 +162,11 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
(function checkURLConstructor() {
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
// The current image decoders doesn't utilize the `URL` constructor, hence
// it shouldn't need to be polyfilled for the IMAGE_DECODERS build target.
return;
}
// feature detect for URL constructor
var hasWorkingUrl = false;
try {