2017-02-24 07:35:35 +09:00
|
|
|
/* Copyright 2017 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2018-02-18 07:51:24 +09:00
|
|
|
|
|
|
|
const globalScope = require('./global_scope');
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2017-04-02 20:14:36 +09:00
|
|
|
// Skip compatibility checks for the extensions and if we already ran
|
2017-02-24 07:35:35 +09:00
|
|
|
// this module.
|
|
|
|
if ((typeof PDFJSDev === 'undefined' ||
|
2018-01-26 20:18:57 +09:00
|
|
|
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) &&
|
2018-02-18 07:51:24 +09:00
|
|
|
!globalScope._pdfjsCompatibilityChecked) {
|
|
|
|
|
|
|
|
globalScope._pdfjsCompatibilityChecked = true;
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2018-01-26 20:18:57 +09:00
|
|
|
// In the Chrome extension, most of the polyfills are unnecessary.
|
|
|
|
// We support down to Chrome 49, because it's still commonly used by Windows XP
|
|
|
|
// users - https://github.com/mozilla/pdf.js/issues/9397
|
|
|
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) {
|
|
|
|
|
2018-01-06 21:10:58 +09:00
|
|
|
const isNodeJS = require('./is_node');
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2018-02-17 20:57:15 +09:00
|
|
|
const hasDOM = typeof window === 'object' && typeof document === 'object';
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2018-01-06 21:10:58 +09:00
|
|
|
// Support: Node.js
|
|
|
|
(function checkNodeBtoa() {
|
|
|
|
if (globalScope.btoa || !isNodeJS()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
globalScope.btoa = function(chars) {
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
return Buffer.from(chars, 'binary').toString('base64');
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Support: Node.js
|
|
|
|
(function checkNodeAtob() {
|
|
|
|
if (globalScope.atob || !isNodeJS()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
globalScope.atob = function(input) {
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
return Buffer.from(input, 'base64').toString('binary');
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2017-02-24 07:35:35 +09:00
|
|
|
// Provides document.currentScript support
|
|
|
|
// Support: IE, Chrome<29.
|
|
|
|
(function checkCurrentScript() {
|
|
|
|
if (!hasDOM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ('currentScript' in document) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object.defineProperty(document, 'currentScript', {
|
2017-04-25 23:07:59 +09:00
|
|
|
get() {
|
2017-02-24 07:35:35 +09:00
|
|
|
var scripts = document.getElementsByTagName('script');
|
|
|
|
return scripts[scripts.length - 1];
|
|
|
|
},
|
|
|
|
enumerable: true,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
configurable: true,
|
2017-02-24 07:35:35 +09:00
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Provides support for ChildNode.remove in legacy browsers.
|
|
|
|
// Support: IE.
|
|
|
|
(function checkChildNodeRemove() {
|
|
|
|
if (!hasDOM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (typeof Element.prototype.remove !== 'undefined') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Element.prototype.remove = function () {
|
|
|
|
if (this.parentNode) {
|
2018-02-11 00:19:45 +09:00
|
|
|
// eslint-disable-next-line mozilla/avoid-removeChild
|
2017-02-24 07:35:35 +09:00
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
2018-02-04 22:31:59 +09:00
|
|
|
|
|
|
|
// Provides support for String.prototype.includes in legacy browsers.
|
|
|
|
// Support: IE, Chrome<41
|
|
|
|
(function checkStringIncludes() {
|
|
|
|
if (String.prototype.includes) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-28 20:04:32 +09:00
|
|
|
require('core-js/fn/string/includes');
|
2018-02-04 22:31:59 +09:00
|
|
|
})();
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2017-10-16 16:09:08 +09:00
|
|
|
// Provides support for Array.prototype.includes in legacy browsers.
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Chrome<47
|
2017-10-16 16:09:08 +09:00
|
|
|
(function checkArrayIncludes() {
|
|
|
|
if (Array.prototype.includes) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-28 20:04:32 +09:00
|
|
|
require('core-js/fn/array/includes');
|
2017-10-16 16:09:08 +09:00
|
|
|
})();
|
|
|
|
|
2018-06-11 02:59:03 +09:00
|
|
|
// Provides support for Object.assign in legacy browsers.
|
|
|
|
// Support: IE
|
|
|
|
(function checkObjectAssign() {
|
|
|
|
if (Object.assign) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/fn/object/assign');
|
|
|
|
})();
|
|
|
|
|
2017-12-10 01:24:31 +09:00
|
|
|
// Provides support for Math.log2 in legacy browsers.
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Chrome<38
|
2017-12-10 01:24:31 +09:00
|
|
|
(function checkMathLog2() {
|
|
|
|
if (Math.log2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Math.log2 = require('core-js/fn/math/log2');
|
|
|
|
})();
|
2017-10-16 16:09:08 +09:00
|
|
|
|
2017-07-13 18:48:17 +09:00
|
|
|
// Provides support for Number.isNaN in legacy browsers.
|
|
|
|
// Support: IE.
|
|
|
|
(function checkNumberIsNaN() {
|
|
|
|
if (Number.isNaN) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-21 19:58:53 +09:00
|
|
|
Number.isNaN = require('core-js/fn/number/is-nan');
|
2017-07-13 18:48:17 +09:00
|
|
|
})();
|
|
|
|
|
|
|
|
// Provides support for Number.isInteger in legacy browsers.
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Chrome<34
|
2017-07-13 18:48:17 +09:00
|
|
|
(function checkNumberIsInteger() {
|
|
|
|
if (Number.isInteger) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-21 19:58:53 +09:00
|
|
|
Number.isInteger = require('core-js/fn/number/is-integer');
|
2017-07-13 18:48:17 +09:00
|
|
|
})();
|
|
|
|
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Safari<8, Chrome<32
|
2017-02-24 07:35:35 +09:00
|
|
|
(function checkPromise() {
|
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.
2018-05-16 20:49:26 +09:00
|
|
|
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;
|
|
|
|
}
|
2017-02-24 07:35:35 +09:00
|
|
|
if (globalScope.Promise) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-21 19:49:15 +09:00
|
|
|
globalScope.Promise = require('core-js/fn/promise');
|
2017-02-24 07:35:35 +09:00
|
|
|
})();
|
|
|
|
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE<11, Safari<8, Chrome<36
|
2017-02-24 07:35:35 +09:00
|
|
|
(function checkWeakMap() {
|
|
|
|
if (globalScope.WeakMap) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-15 17:22:06 +09:00
|
|
|
globalScope.WeakMap = require('core-js/fn/weak-map');
|
2017-02-24 07:35:35 +09:00
|
|
|
})();
|
|
|
|
|
2018-01-26 20:18:57 +09:00
|
|
|
} // End of !PDFJSDev.test('CHROME')
|
|
|
|
|
|
|
|
// Provides support for Object.values in legacy browsers.
|
|
|
|
// Support: IE, Chrome<54
|
|
|
|
(function checkObjectValues() {
|
|
|
|
if (Object.values) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object.values = require('core-js/fn/object/values');
|
|
|
|
})();
|
|
|
|
|
2017-02-24 07:35:35 +09:00
|
|
|
}
|