2012-09-01 07:48:21 +09:00
|
|
|
/* Copyright 2012 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.
|
|
|
|
*/
|
2011-09-08 02:16:02 +09:00
|
|
|
|
2017-04-02 23:14:30 +09:00
|
|
|
import {
|
2017-10-07 01:55:28 +09:00
|
|
|
arrayByteLength, arraysToBytes, assert, createPromiseCapability, info,
|
2018-06-04 19:37:54 +09:00
|
|
|
InvalidPDFException, MissingPDFException, PasswordException,
|
2018-01-06 21:10:58 +09:00
|
|
|
setVerbosityLevel, UnexpectedResponseException, UnknownErrorException,
|
|
|
|
UNSUPPORTED_FEATURES, warn, XRefParseException
|
2017-04-02 23:14:30 +09:00
|
|
|
} from '../shared/util';
|
|
|
|
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
2018-01-06 21:10:58 +09:00
|
|
|
import isNodeJS from '../shared/is_node';
|
2018-06-04 19:37:54 +09:00
|
|
|
import { MessageHandler } from '../shared/message_handler';
|
2017-04-02 23:14:30 +09:00
|
|
|
import { Ref } from './primitives';
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2015-10-21 10:50:32 +09:00
|
|
|
var WorkerTask = (function WorkerTaskClosure() {
|
|
|
|
function WorkerTask(name) {
|
|
|
|
this.name = name;
|
|
|
|
this.terminated = false;
|
|
|
|
this._capability = createPromiseCapability();
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerTask.prototype = {
|
|
|
|
get finished() {
|
|
|
|
return this._capability.promise;
|
|
|
|
},
|
|
|
|
|
2017-04-27 19:58:44 +09:00
|
|
|
finish() {
|
2015-10-21 10:50:32 +09:00
|
|
|
this._capability.resolve();
|
|
|
|
},
|
|
|
|
|
2017-04-27 19:58:44 +09:00
|
|
|
terminate() {
|
2015-10-21 10:50:32 +09:00
|
|
|
this.terminated = true;
|
|
|
|
},
|
|
|
|
|
2017-04-27 19:58:44 +09:00
|
|
|
ensureNotTerminated() {
|
2015-10-21 10:50:32 +09:00
|
|
|
if (this.terminated) {
|
|
|
|
throw new Error('Worker task was terminated');
|
|
|
|
}
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
},
|
2015-10-21 10:50:32 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
return WorkerTask;
|
|
|
|
})();
|
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
2016-02-10 05:55:11 +09:00
|
|
|
/**
|
|
|
|
* Interface that represents PDF data transport. If possible, it allows
|
|
|
|
* progressively load entire or fragment of the PDF binary data.
|
|
|
|
*
|
|
|
|
* @interface
|
Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*
ESLint has a number of advantageous properties, compared to JSHint. Among those are:
- The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
- Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
- Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
- The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
- More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.
By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.
I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.
Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).
A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
- `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
- `object-curly-spacing`, controls spacing inside of Objects.
- `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)
Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.
Useful links:
- http://eslint.org/docs/user-guide/configuring
- http://eslint.org/docs/rules/
2016-12-15 23:52:29 +09:00
|
|
|
*/
|
|
|
|
function IPDFStream() {} // eslint-disable-line no-inner-declarations
|
2016-02-10 05:55:11 +09:00
|
|
|
IPDFStream.prototype = {
|
|
|
|
/**
|
|
|
|
* Gets a reader for the entire PDF data.
|
|
|
|
* @returns {IPDFStreamReader}
|
|
|
|
*/
|
2017-04-27 19:58:44 +09:00
|
|
|
getFullReader() {
|
2017-02-03 20:58:08 +09:00
|
|
|
return null;
|
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a reader for the range of the PDF data.
|
|
|
|
* @param {number} begin - the start offset of the data.
|
|
|
|
* @param {number} end - the end offset of the data.
|
|
|
|
* @returns {IPDFStreamRangeReader}
|
|
|
|
*/
|
2017-04-27 19:58:44 +09:00
|
|
|
getRangeReader(begin, end) {
|
2017-02-03 20:58:08 +09:00
|
|
|
return null;
|
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels all opened reader and closes all their opened requests.
|
|
|
|
* @param {Object} reason - the reason for cancelling
|
|
|
|
*/
|
2017-04-27 19:58:44 +09:00
|
|
|
cancelAllRequests(reason) {},
|
2016-02-10 05:55:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for a PDF binary data reader.
|
|
|
|
*
|
|
|
|
* @interface
|
|
|
|
*/
|
Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*
ESLint has a number of advantageous properties, compared to JSHint. Among those are:
- The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
- Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
- Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
- The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
- More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.
By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.
I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.
Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).
A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
- `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
- `object-curly-spacing`, controls spacing inside of Objects.
- `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)
Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.
Useful links:
- http://eslint.org/docs/user-guide/configuring
- http://eslint.org/docs/rules/
2016-12-15 23:52:29 +09:00
|
|
|
function IPDFStreamReader() {} // eslint-disable-line no-inner-declarations
|
2016-02-10 05:55:11 +09:00
|
|
|
IPDFStreamReader.prototype = {
|
|
|
|
/**
|
|
|
|
* Gets a promise that is resolved when the headers and other metadata of
|
|
|
|
* the PDF data stream are available.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2017-02-03 20:58:08 +09:00
|
|
|
get headersReady() {
|
|
|
|
return null;
|
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
2018-01-17 00:24:36 +09:00
|
|
|
/**
|
|
|
|
* Gets the Content-Disposition filename. It is defined after the headersReady
|
|
|
|
* promise is resolved.
|
|
|
|
* @returns {string|null} The filename, or `null` if the Content-Disposition
|
|
|
|
* header is missing/invalid.
|
|
|
|
*/
|
|
|
|
get filename() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
/**
|
|
|
|
* Gets PDF binary data length. It is defined after the headersReady promise
|
|
|
|
* is resolved.
|
|
|
|
* @returns {number} The data length (or 0 if unknown).
|
|
|
|
*/
|
2017-02-03 20:58:08 +09:00
|
|
|
get contentLength() {
|
|
|
|
return 0;
|
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets ability of the stream to handle range requests. It is defined after
|
|
|
|
* the headersReady promise is resolved. Rejected when the reader is cancelled
|
|
|
|
* or an error occurs.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-02-03 20:58:08 +09:00
|
|
|
get isRangeSupported() {
|
|
|
|
return false;
|
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets ability of the stream to progressively load binary data. It is defined
|
|
|
|
* after the headersReady promise is resolved.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-02-03 20:58:08 +09:00
|
|
|
get isStreamingSupported() {
|
|
|
|
return false;
|
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Requests a chunk of the binary data. The method returns the promise, which
|
|
|
|
* is resolved into object with properties "value" and "done". If the done
|
|
|
|
* is set to true, then the stream has reached its end, otherwise the value
|
|
|
|
* contains binary data. Cancelled requests will be resolved with the done is
|
|
|
|
* set to true.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2017-04-27 19:58:44 +09:00
|
|
|
read() {},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels all pending read requests and closes the stream.
|
|
|
|
* @param {Object} reason
|
|
|
|
*/
|
2017-04-27 19:58:44 +09:00
|
|
|
cancel(reason) {},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets or gets the progress callback. The callback can be useful when the
|
|
|
|
* isStreamingSupported property of the object is defined as false.
|
|
|
|
* The callback is called with one parameter: an object with the loaded and
|
|
|
|
* total properties.
|
|
|
|
*/
|
|
|
|
onProgress: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for a PDF binary data fragment reader.
|
|
|
|
*
|
|
|
|
* @interface
|
|
|
|
*/
|
Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*
ESLint has a number of advantageous properties, compared to JSHint. Among those are:
- The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
- Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
- Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
- The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
- More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.
By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.
I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.
Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).
A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
- `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
- `object-curly-spacing`, controls spacing inside of Objects.
- `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)
Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.
Useful links:
- http://eslint.org/docs/user-guide/configuring
- http://eslint.org/docs/rules/
2016-12-15 23:52:29 +09:00
|
|
|
function IPDFStreamRangeReader() {} // eslint-disable-line no-inner-declarations
|
2016-02-10 05:55:11 +09:00
|
|
|
IPDFStreamRangeReader.prototype = {
|
|
|
|
/**
|
|
|
|
* Gets ability of the stream to progressively load binary data.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-02-03 20:58:08 +09:00
|
|
|
get isStreamingSupported() {
|
|
|
|
return false;
|
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Requests a chunk of the binary data. The method returns the promise, which
|
|
|
|
* is resolved into object with properties "value" and "done". If the done
|
|
|
|
* is set to true, then the stream has reached its end, otherwise the value
|
|
|
|
* contains binary data. Cancelled requests will be resolved with the done is
|
|
|
|
* set to true.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2017-04-27 19:58:44 +09:00
|
|
|
read() {},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels all pending read requests and closes the stream.
|
|
|
|
* @param {Object} reason
|
|
|
|
*/
|
2017-04-27 19:58:44 +09:00
|
|
|
cancel(reason) {},
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets or gets the progress callback. The callback can be useful when the
|
|
|
|
* isStreamingSupported property of the object is defined as false.
|
|
|
|
* The callback is called with one parameter: an object with the loaded
|
|
|
|
* property.
|
|
|
|
*/
|
|
|
|
onProgress: null,
|
|
|
|
};
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2016-02-10 05:55:11 +09:00
|
|
|
|
|
|
|
/** @implements {IPDFStream} */
|
|
|
|
var PDFWorkerStream = (function PDFWorkerStreamClosure() {
|
2017-07-01 02:59:52 +09:00
|
|
|
function PDFWorkerStream(msgHandler) {
|
2016-02-10 05:55:11 +09:00
|
|
|
this._msgHandler = msgHandler;
|
2017-07-01 02:59:52 +09:00
|
|
|
this._contentLength = null;
|
2016-02-10 05:55:11 +09:00
|
|
|
this._fullRequestReader = null;
|
2017-07-01 02:59:52 +09:00
|
|
|
this._rangeRequestReaders = [];
|
2016-02-10 05:55:11 +09:00
|
|
|
}
|
|
|
|
PDFWorkerStream.prototype = {
|
2017-07-01 02:59:52 +09:00
|
|
|
getFullReader() {
|
2016-02-10 05:55:11 +09:00
|
|
|
assert(!this._fullRequestReader);
|
2017-07-01 02:59:52 +09:00
|
|
|
this._fullRequestReader = new PDFWorkerStreamReader(this._msgHandler);
|
|
|
|
return this._fullRequestReader;
|
2016-02-10 05:55:11 +09:00
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
getRangeReader(begin, end) {
|
|
|
|
let reader = new PDFWorkerStreamRangeReader(begin, end, this._msgHandler);
|
|
|
|
this._rangeRequestReaders.push(reader);
|
2016-02-10 05:55:11 +09:00
|
|
|
return reader;
|
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
cancelAllRequests(reason) {
|
2016-02-10 05:55:11 +09:00
|
|
|
if (this._fullRequestReader) {
|
|
|
|
this._fullRequestReader.cancel(reason);
|
|
|
|
}
|
2017-07-01 02:59:52 +09:00
|
|
|
let readers = this._rangeRequestReaders.slice(0);
|
|
|
|
readers.forEach(function (reader) {
|
|
|
|
reader.cancel(reason);
|
2016-02-10 05:55:11 +09:00
|
|
|
});
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @implements {IPDFStreamReader} */
|
2017-07-01 02:59:52 +09:00
|
|
|
function PDFWorkerStreamReader(msgHandler) {
|
|
|
|
this._msgHandler = msgHandler;
|
|
|
|
|
|
|
|
this._contentLength = null;
|
|
|
|
this._isRangeSupported = false;
|
|
|
|
this._isStreamingSupported = false;
|
|
|
|
|
|
|
|
let readableStream = this._msgHandler.sendWithStream('GetReader');
|
|
|
|
|
|
|
|
this._reader = readableStream.getReader();
|
|
|
|
|
|
|
|
this._headersReady = this._msgHandler.sendWithPromise('ReaderHeadersReady').
|
|
|
|
then((data) => {
|
|
|
|
this._isStreamingSupported = data.isStreamingSupported;
|
|
|
|
this._isRangeSupported = data.isRangeSupported;
|
|
|
|
this._contentLength = data.contentLength;
|
|
|
|
});
|
2016-02-10 05:55:11 +09:00
|
|
|
}
|
|
|
|
PDFWorkerStreamReader.prototype = {
|
|
|
|
get headersReady() {
|
|
|
|
return this._headersReady;
|
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
get contentLength() {
|
|
|
|
return this._contentLength;
|
2016-02-10 05:55:11 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
get isStreamingSupported() {
|
2017-07-01 02:59:52 +09:00
|
|
|
return this._isStreamingSupported;
|
2016-02-10 05:55:11 +09:00
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
get isRangeSupported() {
|
|
|
|
return this._isRangeSupported;
|
2016-02-10 05:55:11 +09:00
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
read() {
|
|
|
|
return this._reader.read().then(function({ value, done, }) {
|
|
|
|
if (done) {
|
|
|
|
return { value: undefined, done: true, };
|
|
|
|
}
|
|
|
|
// `value` is wrapped into Uint8Array, we need to
|
|
|
|
// unwrap it to ArrayBuffer for further processing.
|
|
|
|
return { value: value.buffer, done: false, };
|
|
|
|
});
|
2016-02-10 05:55:11 +09:00
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
cancel(reason) {
|
|
|
|
this._reader.cancel(reason);
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @implements {IPDFStreamRangeReader} */
|
2017-07-01 02:59:52 +09:00
|
|
|
function PDFWorkerStreamRangeReader(begin, end, msgHandler) {
|
|
|
|
this._msgHandler = msgHandler;
|
2016-02-10 05:55:11 +09:00
|
|
|
this.onProgress = null;
|
2017-07-01 02:59:52 +09:00
|
|
|
|
|
|
|
let readableStream = this._msgHandler.sendWithStream('GetRangeReader',
|
|
|
|
{ begin, end, });
|
|
|
|
|
|
|
|
this._reader = readableStream.getReader();
|
2016-02-10 05:55:11 +09:00
|
|
|
}
|
|
|
|
PDFWorkerStreamRangeReader.prototype = {
|
|
|
|
get isStreamingSupported() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
read() {
|
|
|
|
return this._reader.read().then(function({ value, done, }) {
|
|
|
|
if (done) {
|
|
|
|
return { value: undefined, done: true, };
|
|
|
|
}
|
|
|
|
return { value: value.buffer, done: false, };
|
|
|
|
});
|
2016-02-10 05:55:11 +09:00
|
|
|
},
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
cancel(reason) {
|
|
|
|
this._reader.cancel(reason);
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
},
|
2016-02-10 05:55:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
return PDFWorkerStream;
|
|
|
|
})();
|
|
|
|
|
2016-03-03 09:48:21 +09:00
|
|
|
var WorkerMessageHandler = {
|
2017-05-03 03:03:58 +09:00
|
|
|
setup(handler, port) {
|
2015-12-17 09:37:43 +09:00
|
|
|
var testMessageProcessed = false;
|
2015-10-28 00:07:20 +09:00
|
|
|
handler.on('test', function wphSetupTest(data) {
|
2015-12-17 09:37:43 +09:00
|
|
|
if (testMessageProcessed) {
|
|
|
|
return; // we already processed 'test' message once
|
|
|
|
}
|
|
|
|
testMessageProcessed = true;
|
|
|
|
|
2015-10-28 00:07:20 +09:00
|
|
|
// check if Uint8Array can be sent to worker
|
|
|
|
if (!(data instanceof Uint8Array)) {
|
Ensure that the correct data is sent, with the `test` message, from the worker if typed arrays aren't properly supported
With native typed array support now being mandatory in PDF.js, since version 2.0, this probably isn't a huge problem even though the current code seems wrong (it was changed in PR 6571).
Note how in the `!(data instanceof Uint8Array)` case we're currently attempting to send `handler.send('test', 'main', false);` to the main-thread, which doesn't really make any sense since the signature of the method reads `send(actionName, data, transfers) {`.
Hence the data that's *actually* being sent here is `'main'`, with `false` as the transferList, which just seems weird. On the main-thread, this means that we're in this case checking `data && data.supportTypedArray`, where `data` contains the string `'main'` rather than being falsy. Since a string doesn't have a `supportTypedArray` property, that check still fails as expected but it doesn't seem great nonetheless.
2018-06-06 03:29:52 +09:00
|
|
|
handler.send('test', false);
|
2015-10-28 00:07:20 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// making sure postMessage transfers are working
|
|
|
|
var supportTransfers = data[0] === 255;
|
|
|
|
handler.postMessageTransfers = supportTransfers;
|
|
|
|
// check if the response property is supported by xhr
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
var responseExists = 'response' in xhr;
|
|
|
|
// check if the property is actually implemented
|
|
|
|
try {
|
2017-01-19 22:00:36 +09:00
|
|
|
xhr.responseType; // eslint-disable-line no-unused-expressions
|
2015-10-28 00:07:20 +09:00
|
|
|
} catch (e) {
|
|
|
|
responseExists = false;
|
|
|
|
}
|
|
|
|
if (!responseExists) {
|
|
|
|
handler.send('test', false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handler.send('test', {
|
|
|
|
supportTypedArray: true,
|
2017-04-27 19:58:44 +09:00
|
|
|
supportTransfers,
|
2015-10-28 00:07:20 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-04 01:13:37 +09:00
|
|
|
handler.on('configure', function wphConfigure(data) {
|
|
|
|
setVerbosityLevel(data.verbosity);
|
|
|
|
});
|
|
|
|
|
2015-10-28 00:07:20 +09:00
|
|
|
handler.on('GetDocRequest', function wphSetupDoc(data) {
|
|
|
|
return WorkerMessageHandler.createDocumentHandler(data, port);
|
|
|
|
});
|
|
|
|
},
|
2017-05-03 03:03:58 +09:00
|
|
|
createDocumentHandler(docParams, port) {
|
2015-10-28 02:55:15 +09:00
|
|
|
// This context is actually holds references on pdfManager and handler,
|
|
|
|
// until the latter is destroyed.
|
2013-02-07 08:19:29 +09:00
|
|
|
var pdfManager;
|
2015-10-21 07:45:55 +09:00
|
|
|
var terminated = false;
|
|
|
|
var cancelXHRs = null;
|
2015-10-21 10:50:32 +09:00
|
|
|
var WorkerTasks = [];
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2017-09-27 22:19:31 +09:00
|
|
|
let apiVersion = docParams.apiVersion;
|
|
|
|
let workerVersion =
|
|
|
|
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
|
|
|
|
// The `apiVersion !== null` check is needed to avoid errors during testing.
|
|
|
|
if (apiVersion !== null && apiVersion !== workerVersion) {
|
|
|
|
throw new Error(`The API version "${apiVersion}" does not match ` +
|
|
|
|
`the Worker version "${workerVersion}".`);
|
|
|
|
}
|
|
|
|
|
2015-11-26 09:21:23 +09:00
|
|
|
var docId = docParams.docId;
|
2016-10-01 19:05:07 +09:00
|
|
|
var docBaseUrl = docParams.docBaseUrl;
|
2015-11-26 09:21:23 +09:00
|
|
|
var workerHandlerName = docParams.docId + '_worker';
|
2015-10-28 07:48:10 +09:00
|
|
|
var handler = new MessageHandler(workerHandlerName, docId, port);
|
2015-10-28 00:07:20 +09:00
|
|
|
|
2016-03-17 02:34:26 +09:00
|
|
|
// Ensure that postMessage transfers are correctly enabled/disabled,
|
|
|
|
// to prevent "DataCloneError" in older versions of IE (see issue 6957).
|
|
|
|
handler.postMessageTransfers = docParams.postMessageTransfers;
|
|
|
|
|
2015-10-21 07:45:55 +09:00
|
|
|
function ensureNotTerminated() {
|
|
|
|
if (terminated) {
|
|
|
|
throw new Error('Worker was terminated');
|
|
|
|
}
|
|
|
|
}
|
2011-10-09 17:37:53 +09:00
|
|
|
|
2015-10-21 10:50:32 +09:00
|
|
|
function startWorkerTask(task) {
|
|
|
|
WorkerTasks.push(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishWorkerTask(task) {
|
|
|
|
task.finish();
|
|
|
|
var i = WorkerTasks.indexOf(task);
|
|
|
|
WorkerTasks.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
function loadDocument(recoveryMode) {
|
2014-05-02 08:38:49 +09:00
|
|
|
var loadDocumentCapability = createPromiseCapability();
|
2013-02-07 08:19:29 +09:00
|
|
|
|
|
|
|
var parseSuccess = function parseSuccess() {
|
2017-12-21 20:03:59 +09:00
|
|
|
Promise.all([
|
|
|
|
pdfManager.ensureDoc('numPages'),
|
|
|
|
pdfManager.ensureDoc('fingerprint'),
|
|
|
|
]).then(function([numPages, fingerprint]) {
|
|
|
|
loadDocumentCapability.resolve({
|
|
|
|
numPages,
|
|
|
|
fingerprint,
|
|
|
|
});
|
|
|
|
}, parseFailure);
|
2013-02-07 08:19:29 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
var parseFailure = function parseFailure(e) {
|
2014-05-02 08:38:49 +09:00
|
|
|
loadDocumentCapability.reject(e);
|
2013-02-07 08:19:29 +09:00
|
|
|
};
|
|
|
|
|
2014-03-12 17:51:40 +09:00
|
|
|
pdfManager.ensureDoc('checkHeader', []).then(function() {
|
|
|
|
pdfManager.ensureDoc('parseStartXRef', []).then(function() {
|
|
|
|
pdfManager.ensureDoc('parse', [recoveryMode]).then(
|
2014-03-23 04:59:16 +09:00
|
|
|
parseSuccess, parseFailure);
|
2013-05-10 00:54:53 +09:00
|
|
|
}, parseFailure);
|
|
|
|
}, parseFailure);
|
2013-02-07 08:19:29 +09:00
|
|
|
|
2014-05-02 08:38:49 +09:00
|
|
|
return loadDocumentCapability.promise;
|
2013-02-07 08:19:29 +09:00
|
|
|
}
|
|
|
|
|
2016-03-03 09:48:21 +09:00
|
|
|
function getPdfManager(data, evaluatorOptions) {
|
2014-05-02 08:38:49 +09:00
|
|
|
var pdfManagerCapability = createPromiseCapability();
|
2015-10-21 07:45:55 +09:00
|
|
|
var pdfManager;
|
2013-02-07 08:19:29 +09:00
|
|
|
|
|
|
|
var source = data.source;
|
|
|
|
if (source.data) {
|
2013-05-31 06:54:49 +09:00
|
|
|
try {
|
2016-03-03 09:48:21 +09:00
|
|
|
pdfManager = new LocalPdfManager(docId, source.data, source.password,
|
2016-10-01 19:05:07 +09:00
|
|
|
evaluatorOptions, docBaseUrl);
|
2015-10-21 07:45:55 +09:00
|
|
|
pdfManagerCapability.resolve(pdfManager);
|
2013-05-31 06:54:49 +09:00
|
|
|
} catch (ex) {
|
2014-05-02 08:38:49 +09:00
|
|
|
pdfManagerCapability.reject(ex);
|
2013-05-31 06:54:49 +09:00
|
|
|
}
|
2016-03-03 00:57:33 +09:00
|
|
|
return pdfManagerCapability.promise;
|
2016-02-10 05:55:11 +09:00
|
|
|
}
|
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
var pdfStream, cachedChunks = [];
|
2016-02-10 05:55:11 +09:00
|
|
|
try {
|
2017-07-01 02:59:52 +09:00
|
|
|
pdfStream = new PDFWorkerStream(handler);
|
2016-02-10 05:55:11 +09:00
|
|
|
} catch (ex) {
|
|
|
|
pdfManagerCapability.reject(ex);
|
2014-05-02 08:38:49 +09:00
|
|
|
return pdfManagerCapability.promise;
|
2013-02-07 08:19:29 +09:00
|
|
|
}
|
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
var fullRequest = pdfStream.getFullReader();
|
|
|
|
fullRequest.headersReady.then(function () {
|
|
|
|
if (!fullRequest.isRangeSupported) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-30 03:13:28 +09:00
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
// We don't need auto-fetch when streaming is enabled.
|
|
|
|
var disableAutoFetch = source.disableAutoFetch ||
|
|
|
|
fullRequest.isStreamingSupported;
|
|
|
|
pdfManager = new NetworkPdfManager(docId, pdfStream, {
|
|
|
|
msgHandler: handler,
|
|
|
|
url: source.url,
|
|
|
|
password: source.password,
|
|
|
|
length: fullRequest.contentLength,
|
2017-04-27 19:58:44 +09:00
|
|
|
disableAutoFetch,
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
rangeChunkSize: source.rangeChunkSize,
|
2016-10-01 19:05:07 +09:00
|
|
|
}, evaluatorOptions, docBaseUrl);
|
2017-07-01 02:59:52 +09:00
|
|
|
// There may be a chance that `pdfManager` is not initialized
|
|
|
|
// for first few runs of `readchunk` block of code. Be sure
|
|
|
|
// to send all cached chunks, if any, to chunked_stream via
|
|
|
|
// pdf_manager.
|
|
|
|
for (let i = 0; i < cachedChunks.length; i++) {
|
|
|
|
pdfManager.sendProgressiveData(cachedChunks[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedChunks = [];
|
2016-02-10 05:55:11 +09:00
|
|
|
pdfManagerCapability.resolve(pdfManager);
|
|
|
|
cancelXHRs = null;
|
|
|
|
}).catch(function (reason) {
|
|
|
|
pdfManagerCapability.reject(reason);
|
|
|
|
cancelXHRs = null;
|
|
|
|
});
|
2013-02-07 08:19:29 +09:00
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
var loaded = 0;
|
2016-02-10 05:55:11 +09:00
|
|
|
var flushChunks = function () {
|
|
|
|
var pdfFile = arraysToBytes(cachedChunks);
|
|
|
|
if (source.length && pdfFile.length !== source.length) {
|
|
|
|
warn('reported HTTP length is different from actual');
|
|
|
|
}
|
|
|
|
// the data is array, instantiating directly from it
|
|
|
|
try {
|
2016-03-03 09:48:21 +09:00
|
|
|
pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
|
2016-10-01 19:05:07 +09:00
|
|
|
evaluatorOptions, docBaseUrl);
|
2016-02-10 05:55:11 +09:00
|
|
|
pdfManagerCapability.resolve(pdfManager);
|
|
|
|
} catch (ex) {
|
|
|
|
pdfManagerCapability.reject(ex);
|
|
|
|
}
|
|
|
|
cachedChunks = [];
|
|
|
|
};
|
|
|
|
var readPromise = new Promise(function (resolve, reject) {
|
|
|
|
var readChunk = function (chunk) {
|
2013-05-31 06:54:49 +09:00
|
|
|
try {
|
2016-02-10 05:55:11 +09:00
|
|
|
ensureNotTerminated();
|
|
|
|
if (chunk.done) {
|
|
|
|
if (!pdfManager) {
|
|
|
|
flushChunks();
|
|
|
|
}
|
|
|
|
cancelXHRs = null;
|
|
|
|
return;
|
|
|
|
}
|
2014-09-06 10:02:54 +09:00
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
var data = chunk.value;
|
|
|
|
loaded += arrayByteLength(data);
|
|
|
|
if (!fullRequest.isStreamingSupported) {
|
|
|
|
handler.send('DocProgress', {
|
2017-04-27 19:58:44 +09:00
|
|
|
loaded,
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
total: Math.max(loaded, fullRequest.contentLength || 0),
|
2016-02-10 05:55:11 +09:00
|
|
|
});
|
2014-09-06 10:02:54 +09:00
|
|
|
}
|
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
if (pdfManager) {
|
|
|
|
pdfManager.sendProgressiveData(data);
|
|
|
|
} else {
|
|
|
|
cachedChunks.push(data);
|
|
|
|
}
|
2013-02-07 08:19:29 +09:00
|
|
|
|
2016-02-10 05:55:11 +09:00
|
|
|
fullRequest.read().then(readChunk, reject);
|
|
|
|
} catch (e) {
|
|
|
|
reject(e);
|
2013-02-07 08:19:29 +09:00
|
|
|
}
|
2016-02-10 05:55:11 +09:00
|
|
|
};
|
|
|
|
fullRequest.read().then(readChunk, reject);
|
|
|
|
});
|
|
|
|
readPromise.catch(function (e) {
|
|
|
|
pdfManagerCapability.reject(e);
|
|
|
|
cancelXHRs = null;
|
2013-02-07 08:19:29 +09:00
|
|
|
});
|
|
|
|
|
2015-10-21 07:45:55 +09:00
|
|
|
cancelXHRs = function () {
|
2016-02-10 05:55:11 +09:00
|
|
|
pdfStream.cancelAllRequests('abort');
|
2015-10-21 07:45:55 +09:00
|
|
|
};
|
|
|
|
|
2014-05-02 08:38:49 +09:00
|
|
|
return pdfManagerCapability.promise;
|
2012-06-24 04:48:33 +09:00
|
|
|
}
|
|
|
|
|
2016-12-31 21:59:07 +09:00
|
|
|
function setupDoc(data) {
|
|
|
|
function onSuccess(doc) {
|
2015-10-21 07:45:55 +09:00
|
|
|
ensureNotTerminated();
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
handler.send('GetDoc', { pdfInfo: doc, });
|
2016-12-31 21:59:07 +09:00
|
|
|
}
|
2013-02-07 08:19:29 +09:00
|
|
|
|
2016-12-31 21:59:07 +09:00
|
|
|
function onFailure(e) {
|
2017-06-29 20:59:38 +09:00
|
|
|
ensureNotTerminated();
|
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
if (e instanceof PasswordException) {
|
2016-12-31 21:59:07 +09:00
|
|
|
var task = new WorkerTask('PasswordException: response ' + e.code);
|
|
|
|
startWorkerTask(task);
|
|
|
|
|
|
|
|
handler.sendWithPromise('PasswordRequest', e).then(function (data) {
|
|
|
|
finishWorkerTask(task);
|
|
|
|
pdfManager.updatePassword(data.password);
|
|
|
|
pdfManagerReady();
|
2018-06-01 19:52:47 +09:00
|
|
|
}).catch(function (boundException) {
|
2016-12-31 21:59:07 +09:00
|
|
|
finishWorkerTask(task);
|
2018-06-01 19:52:47 +09:00
|
|
|
handler.send('PasswordException', boundException);
|
2016-12-31 21:59:07 +09:00
|
|
|
}.bind(null, e));
|
2013-02-07 08:19:29 +09:00
|
|
|
} else if (e instanceof InvalidPDFException) {
|
2014-08-23 23:03:49 +09:00
|
|
|
handler.send('InvalidPDF', e);
|
2013-02-07 08:19:29 +09:00
|
|
|
} else if (e instanceof MissingPDFException) {
|
2014-08-23 23:03:49 +09:00
|
|
|
handler.send('MissingPDF', e);
|
2014-09-13 23:47:16 +09:00
|
|
|
} else if (e instanceof UnexpectedResponseException) {
|
|
|
|
handler.send('UnexpectedResponse', e);
|
2013-02-07 08:19:29 +09:00
|
|
|
} else {
|
2014-08-23 23:03:49 +09:00
|
|
|
handler.send('UnknownError',
|
|
|
|
new UnknownErrorException(e.message, e.toString()));
|
2013-02-07 08:19:29 +09:00
|
|
|
}
|
2016-12-31 21:59:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function pdfManagerReady() {
|
|
|
|
ensureNotTerminated();
|
|
|
|
|
|
|
|
loadDocument(false).then(onSuccess, function loadFailure(ex) {
|
|
|
|
ensureNotTerminated();
|
|
|
|
|
|
|
|
// Try again with recoveryMode == true
|
|
|
|
if (!(ex instanceof XRefParseException)) {
|
|
|
|
onFailure(ex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pdfManager.requestLoadedStream();
|
|
|
|
pdfManager.onLoadedStream().then(function() {
|
|
|
|
ensureNotTerminated();
|
|
|
|
|
|
|
|
loadDocument(true).then(onSuccess, onFailure);
|
|
|
|
});
|
|
|
|
}, onFailure);
|
|
|
|
}
|
2013-02-07 08:19:29 +09:00
|
|
|
|
2015-10-21 07:45:55 +09:00
|
|
|
ensureNotTerminated();
|
|
|
|
|
2016-03-03 09:48:21 +09:00
|
|
|
var evaluatorOptions = {
|
|
|
|
forceDataSchema: data.disableCreateObjectURL,
|
2018-02-18 00:13:33 +09:00
|
|
|
maxImageSize: data.maxImageSize,
|
2016-03-03 09:48:21 +09:00
|
|
|
disableFontFace: data.disableFontFace,
|
2017-05-08 12:32:44 +09:00
|
|
|
nativeImageDecoderSupport: data.nativeImageDecoderSupport,
|
[api-minor] Always allow e.g. rendering to continue even if there are errors, and add a `stopAtErrors` parameter to `getDocument` to opt-out of this behaviour (issue 6342, issue 3795, bug 1130815)
Other PDF readers, e.g. Adobe Reader and PDFium (in Chrome), will attempt to render as much of a page as possible even if there are errors present.
Currently we just bail as soon the first error is hit, which means that we'll usually not render anything in these cases and just display a blank page instead.
NOTE: This patch changes the default behaviour of the PDF.js API to always attempt to recover as much data as possible, even when encountering errors during e.g. `getOperatorList`/`getTextContent`, which thus improve our handling of corrupt PDF files and allow the default viewer to handle errors slightly more gracefully.
In the event that an API consumer wishes to use the old behaviour, where we stop parsing as soon as an error is encountered, the `stopAtErrors` parameter can be set at `getDocument`.
Fixes, inasmuch it's possible since the PDF files are corrupt, e.g. issue 6342, issue 3795, and [bug 1130815](https://bugzilla.mozilla.org/show_bug.cgi?id=1130815) (and probably others too).
2017-02-19 22:03:08 +09:00
|
|
|
ignoreErrors: data.ignoreErrors,
|
Check `isEvalSupported`, and test that `eval` is actually supported, before attempting to use the `PostScriptCompiler` (issue 5573)
Currently `PDFFunction` is implemented (basically) like a class with only `static` methods. Since it's used directly in a number of different `src/core/` files, attempting to pass in `isEvalSupported` would result in code that's *very* messy, not to mention difficult to maintain (since *every* single `PDFFunction` method call would need to include a `isEvalSupported` argument).
Rather than having to wait for a possible re-factoring of `PDFFunction` that would avoid the above problems by design, it probably makes sense to at least set `isEvalSupported` globally for `PDFFunction`.
Please note that there's one caveat with this solution: If `PDFJS.getDocument` is used to open multiple files simultaneously, with *different* `PDFJS.isEvalSupported` values set before each call, then the last one will always win.
However, that seems like enough of an edge-case that we shouldn't have to worry about it. Besides, since we'll also test that `eval` is actually supported, it should be fine.
Fixes 5573.
2017-09-14 22:38:57 +09:00
|
|
|
isEvalSupported: data.isEvalSupported,
|
2016-03-03 09:48:21 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
|
2015-10-21 07:45:55 +09:00
|
|
|
if (terminated) {
|
|
|
|
// We were in a process of setting up the manager, but it got
|
|
|
|
// terminated in the middle.
|
|
|
|
newPdfManager.terminate();
|
|
|
|
throw new Error('Worker was terminated');
|
|
|
|
}
|
|
|
|
pdfManager = newPdfManager;
|
2018-06-06 03:29:56 +09:00
|
|
|
|
2014-01-29 06:13:47 +09:00
|
|
|
pdfManager.onLoadedStream().then(function(stream) {
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
handler.send('DataLoaded', { length: stream.bytes.byteLength, });
|
2014-01-29 06:13:47 +09:00
|
|
|
});
|
2016-12-31 21:59:07 +09:00
|
|
|
}).then(pdfManagerReady, onFailure);
|
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2014-05-09 05:02:53 +09:00
|
|
|
handler.on('GetPage', function wphSetupGetPage(data) {
|
|
|
|
return pdfManager.getPage(data.pageIndex).then(function(page) {
|
2016-11-22 06:39:04 +09:00
|
|
|
return Promise.all([
|
2018-06-06 03:30:06 +09:00
|
|
|
pdfManager.ensure(page, 'rotate'),
|
|
|
|
pdfManager.ensure(page, 'ref'),
|
|
|
|
pdfManager.ensure(page, 'userUnit'),
|
|
|
|
pdfManager.ensure(page, 'view'),
|
|
|
|
]).then(function([rotate, ref, userUnit, view]) {
|
2014-05-09 05:02:53 +09:00
|
|
|
return {
|
2018-06-06 03:30:06 +09:00
|
|
|
rotate,
|
|
|
|
ref,
|
|
|
|
userUnit,
|
|
|
|
view,
|
2013-02-07 08:19:29 +09:00
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2011-09-08 02:16:02 +09:00
|
|
|
});
|
2011-10-09 17:37:53 +09:00
|
|
|
|
2014-05-08 08:15:25 +09:00
|
|
|
handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
|
2013-11-14 08:27:46 +09:00
|
|
|
var ref = new Ref(data.ref.num, data.ref.gen);
|
2014-03-12 17:51:40 +09:00
|
|
|
var catalog = pdfManager.pdfDocument.catalog;
|
2014-05-08 08:15:25 +09:00
|
|
|
return catalog.getPageIndex(ref);
|
2013-11-14 08:27:46 +09:00
|
|
|
});
|
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
handler.on('GetDestinations',
|
2014-05-08 08:15:25 +09:00
|
|
|
function wphSetupGetDestinations(data) {
|
|
|
|
return pdfManager.ensureCatalog('destinations');
|
2013-02-07 08:19:29 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-10-05 22:56:40 +09:00
|
|
|
handler.on('GetDestination',
|
|
|
|
function wphSetupGetDestination(data) {
|
2015-11-22 21:56:52 +09:00
|
|
|
return pdfManager.ensureCatalog('getDestination', [data.id]);
|
2014-10-05 22:56:40 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-12-26 05:57:08 +09:00
|
|
|
handler.on('GetPageLabels',
|
|
|
|
function wphSetupGetPageLabels(data) {
|
|
|
|
return pdfManager.ensureCatalog('pageLabels');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-07-18 20:08:02 +09:00
|
|
|
handler.on('GetPageMode', function wphSetupGetPageMode(data) {
|
|
|
|
return pdfManager.ensureCatalog('pageMode');
|
|
|
|
});
|
|
|
|
|
2014-03-19 05:32:47 +09:00
|
|
|
handler.on('GetAttachments',
|
2014-05-08 08:15:25 +09:00
|
|
|
function wphSetupGetAttachments(data) {
|
|
|
|
return pdfManager.ensureCatalog('attachments');
|
2014-03-19 05:32:47 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-05-08 04:15:34 +09:00
|
|
|
handler.on('GetJavaScript',
|
2014-05-08 08:15:25 +09:00
|
|
|
function wphSetupGetJavaScript(data) {
|
|
|
|
return pdfManager.ensureCatalog('javaScript');
|
2014-05-08 04:15:34 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-05-08 04:06:44 +09:00
|
|
|
handler.on('GetOutline',
|
2014-05-08 08:15:25 +09:00
|
|
|
function wphSetupGetOutline(data) {
|
|
|
|
return pdfManager.ensureCatalog('documentOutline');
|
2014-05-08 04:06:44 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-05-08 04:38:40 +09:00
|
|
|
handler.on('GetMetadata',
|
2014-05-08 08:15:25 +09:00
|
|
|
function wphSetupGetMetadata(data) {
|
|
|
|
return Promise.all([pdfManager.ensureDoc('documentInfo'),
|
|
|
|
pdfManager.ensureCatalog('metadata')]);
|
2014-05-08 04:38:40 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-05-08 08:15:25 +09:00
|
|
|
handler.on('GetData', function wphSetupGetData(data) {
|
2013-02-07 08:19:29 +09:00
|
|
|
pdfManager.requestLoadedStream();
|
2014-05-08 08:15:25 +09:00
|
|
|
return pdfManager.onLoadedStream().then(function(stream) {
|
|
|
|
return stream.bytes;
|
2013-02-07 08:19:29 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-16 23:52:04 +09:00
|
|
|
handler.on('GetStats',
|
|
|
|
function wphSetupGetStats(data) {
|
|
|
|
return pdfManager.pdfDocument.xref.stats;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-05-09 05:02:53 +09:00
|
|
|
handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
|
|
|
|
return pdfManager.getPage(data.pageIndex).then(function(page) {
|
2015-11-22 21:56:52 +09:00
|
|
|
return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
|
2012-04-15 05:54:31 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
|
2015-10-21 10:50:32 +09:00
|
|
|
var pageIndex = data.pageIndex;
|
|
|
|
pdfManager.getPage(pageIndex).then(function(page) {
|
|
|
|
var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
|
|
|
|
startWorkerTask(task);
|
2011-09-08 02:16:02 +09:00
|
|
|
|
2015-10-21 10:50:32 +09:00
|
|
|
var pageNum = pageIndex + 1;
|
2013-02-07 08:19:29 +09:00
|
|
|
var start = Date.now();
|
2011-11-29 09:55:09 +09:00
|
|
|
// Pre compile the pdf page and fetch the fonts/images.
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
page.getOperatorList({
|
|
|
|
handler,
|
|
|
|
task,
|
|
|
|
intent: data.intent,
|
|
|
|
renderInteractiveForms: data.renderInteractiveForms,
|
|
|
|
}).then(function(operatorList) {
|
2015-10-21 10:50:32 +09:00
|
|
|
finishWorkerTask(task);
|
2013-02-01 08:33:59 +09:00
|
|
|
|
2014-02-17 13:23:18 +09:00
|
|
|
info('page=' + pageNum + ' - getOperatorList: time=' +
|
2015-10-27 00:38:06 +09:00
|
|
|
(Date.now() - start) + 'ms, len=' + operatorList.totalLength);
|
2013-02-07 08:19:29 +09:00
|
|
|
}, function(e) {
|
2015-10-21 10:50:32 +09:00
|
|
|
finishWorkerTask(task);
|
|
|
|
if (task.terminated) {
|
|
|
|
return; // ignoring errors from the terminated thread
|
|
|
|
}
|
2011-09-08 02:16:02 +09:00
|
|
|
|
2015-12-01 05:42:47 +09:00
|
|
|
// For compatibility with older behavior, generating unknown
|
|
|
|
// unsupported feature notification on errors.
|
|
|
|
handler.send('UnsupportedFeature',
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
{ featureId: UNSUPPORTED_FEATURES.unknown, });
|
2015-12-01 05:42:47 +09:00
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
var minimumStackMessage =
|
2014-03-23 04:59:16 +09:00
|
|
|
'worker.js: while trying to getPage() and getOperatorList()';
|
2011-09-08 02:16:02 +09:00
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
var wrappedException;
|
|
|
|
|
|
|
|
// Turn the error into an obj that can be serialized
|
|
|
|
if (typeof e === 'string') {
|
|
|
|
wrappedException = {
|
|
|
|
message: e,
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
stack: minimumStackMessage,
|
2013-02-07 08:19:29 +09:00
|
|
|
};
|
|
|
|
} else if (typeof e === 'object') {
|
|
|
|
wrappedException = {
|
|
|
|
message: e.message || e.toString(),
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
stack: e.stack || minimumStackMessage,
|
2013-02-07 08:19:29 +09:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
wrappedException = {
|
|
|
|
message: 'Unknown exception type: ' + (typeof e),
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
stack: minimumStackMessage,
|
2013-02-07 08:19:29 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.send('PageError', {
|
2017-04-27 19:58:44 +09:00
|
|
|
pageNum,
|
2014-03-07 23:48:42 +09:00
|
|
|
error: wrappedException,
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 18:16:24 +09:00
|
|
|
intent: data.intent,
|
2013-02-07 08:19:29 +09:00
|
|
|
});
|
|
|
|
});
|
2011-09-08 02:16:02 +09:00
|
|
|
});
|
|
|
|
}, this);
|
2011-10-09 17:37:53 +09:00
|
|
|
|
2017-04-17 21:46:53 +09:00
|
|
|
handler.on('GetTextContent', function wphExtractText(data, sink) {
|
2015-10-21 10:50:32 +09:00
|
|
|
var pageIndex = data.pageIndex;
|
2017-04-17 21:46:53 +09:00
|
|
|
sink.onPull = function (desiredSize) { };
|
|
|
|
sink.onCancel = function (reason) { };
|
|
|
|
|
|
|
|
pdfManager.getPage(pageIndex).then(function(page) {
|
2015-10-21 10:50:32 +09:00
|
|
|
var task = new WorkerTask('GetTextContent: page ' + pageIndex);
|
|
|
|
startWorkerTask(task);
|
[api-minor] Always allow e.g. rendering to continue even if there are errors, and add a `stopAtErrors` parameter to `getDocument` to opt-out of this behaviour (issue 6342, issue 3795, bug 1130815)
Other PDF readers, e.g. Adobe Reader and PDFium (in Chrome), will attempt to render as much of a page as possible even if there are errors present.
Currently we just bail as soon the first error is hit, which means that we'll usually not render anything in these cases and just display a blank page instead.
NOTE: This patch changes the default behaviour of the PDF.js API to always attempt to recover as much data as possible, even when encountering errors during e.g. `getOperatorList`/`getTextContent`, which thus improve our handling of corrupt PDF files and allow the default viewer to handle errors slightly more gracefully.
In the event that an API consumer wishes to use the old behaviour, where we stop parsing as soon as an error is encountered, the `stopAtErrors` parameter can be set at `getDocument`.
Fixes, inasmuch it's possible since the PDF files are corrupt, e.g. issue 6342, issue 3795, and [bug 1130815](https://bugzilla.mozilla.org/show_bug.cgi?id=1130815) (and probably others too).
2017-02-19 22:03:08 +09:00
|
|
|
|
2015-10-21 10:50:32 +09:00
|
|
|
var pageNum = pageIndex + 1;
|
2013-02-07 08:19:29 +09:00
|
|
|
var start = Date.now();
|
2017-04-17 21:46:53 +09:00
|
|
|
page.extractTextContent({
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
handler,
|
|
|
|
task,
|
2017-04-17 21:46:53 +09:00
|
|
|
sink,
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
normalizeWhitespace: data.normalizeWhitespace,
|
|
|
|
combineTextItems: data.combineTextItems,
|
2017-04-17 21:46:53 +09:00
|
|
|
}).then(function() {
|
2015-10-21 10:50:32 +09:00
|
|
|
finishWorkerTask(task);
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
|
2014-02-17 13:23:18 +09:00
|
|
|
info('text indexing: page=' + pageNum + ' - time=' +
|
|
|
|
(Date.now() - start) + 'ms');
|
2017-04-17 21:46:53 +09:00
|
|
|
sink.close();
|
2015-10-21 10:50:32 +09:00
|
|
|
}, function (reason) {
|
|
|
|
finishWorkerTask(task);
|
|
|
|
if (task.terminated) {
|
|
|
|
return; // ignoring errors from the terminated thread
|
|
|
|
}
|
2017-04-17 21:46:53 +09:00
|
|
|
sink.error(reason);
|
2015-10-21 10:50:32 +09:00
|
|
|
throw reason;
|
2013-02-07 08:19:29 +09:00
|
|
|
});
|
|
|
|
});
|
2011-12-11 08:24:54 +09:00
|
|
|
});
|
2013-04-13 03:37:49 +09:00
|
|
|
|
2014-05-08 08:15:25 +09:00
|
|
|
handler.on('Cleanup', function wphCleanup(data) {
|
2014-05-10 10:21:15 +09:00
|
|
|
return pdfManager.cleanup();
|
2013-11-15 06:43:38 +09:00
|
|
|
});
|
|
|
|
|
2014-05-08 08:15:25 +09:00
|
|
|
handler.on('Terminate', function wphTerminate(data) {
|
2015-10-21 07:45:55 +09:00
|
|
|
terminated = true;
|
|
|
|
if (pdfManager) {
|
|
|
|
pdfManager.terminate();
|
|
|
|
pdfManager = null;
|
|
|
|
}
|
|
|
|
if (cancelXHRs) {
|
|
|
|
cancelXHRs();
|
|
|
|
}
|
2015-10-21 10:50:32 +09:00
|
|
|
|
|
|
|
var waitOn = [];
|
|
|
|
WorkerTasks.forEach(function (task) {
|
|
|
|
waitOn.push(task.finished);
|
|
|
|
task.terminate();
|
|
|
|
});
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
return Promise.all(waitOn).then(function () {
|
|
|
|
// Notice that even if we destroying handler, resolved response promise
|
|
|
|
// must be sent back.
|
2017-10-07 01:55:28 +09:00
|
|
|
handler.destroy();
|
2015-10-28 02:55:15 +09:00
|
|
|
handler = null;
|
|
|
|
});
|
2013-04-13 03:37:49 +09:00
|
|
|
});
|
2015-10-28 00:07:20 +09:00
|
|
|
|
2015-11-26 09:21:23 +09:00
|
|
|
handler.on('Ready', function wphReady(data) {
|
|
|
|
setupDoc(docParams);
|
|
|
|
docParams = null; // we don't need docParams anymore -- saving memory.
|
|
|
|
});
|
2015-10-28 00:07:20 +09:00
|
|
|
return workerHandlerName;
|
2017-05-03 03:03:58 +09:00
|
|
|
},
|
|
|
|
initializeFromPort(port) {
|
|
|
|
var handler = new MessageHandler('worker', 'main', port);
|
|
|
|
WorkerMessageHandler.setup(handler, port);
|
|
|
|
handler.send('ready', null);
|
|
|
|
},
|
2011-10-09 17:37:53 +09:00
|
|
|
};
|
2011-10-26 02:16:20 +09:00
|
|
|
|
2017-05-03 03:03:58 +09:00
|
|
|
function isMessagePort(maybePort) {
|
|
|
|
return typeof maybePort.postMessage === 'function' &&
|
|
|
|
('onmessage' in maybePort);
|
2015-12-17 09:37:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// Worker thread (and not node.js)?
|
2017-05-03 03:03:58 +09:00
|
|
|
if (typeof window === 'undefined' && !isNodeJS() &&
|
|
|
|
typeof self !== 'undefined' && isMessagePort(self)) {
|
|
|
|
WorkerMessageHandler.initializeFromPort(self);
|
2011-10-26 07:43:41 +09:00
|
|
|
}
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2017-04-02 23:14:30 +09:00
|
|
|
export {
|
|
|
|
WorkerTask,
|
|
|
|
WorkerMessageHandler,
|
|
|
|
};
|