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.
|
|
|
|
*/
|
2017-02-11 02:24:35 +09:00
|
|
|
/* globals requirejs, __pdfjsdev_webpack__ */
|
2012-04-10 14:20:57 +09:00
|
|
|
|
2017-04-02 21:25:33 +09:00
|
|
|
import {
|
|
|
|
createPromiseCapability, deprecated, error, getVerbosityLevel, globalScope,
|
|
|
|
info, InvalidPDFException, isArray, isArrayBuffer, isInt, isSameOrigin,
|
2017-05-08 12:32:44 +09:00
|
|
|
loadJpegStream, MessageHandler, MissingPDFException, NativeImageDecoding,
|
|
|
|
PageViewport, PasswordException, StatTimer, stringToBytes,
|
|
|
|
UnexpectedResponseException, UnknownErrorException, Util, warn
|
2017-04-02 21:25:33 +09:00
|
|
|
} from '../shared/util';
|
|
|
|
import {
|
|
|
|
DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting,
|
|
|
|
RenderingCancelledException
|
|
|
|
} from './dom_utils';
|
|
|
|
import { FontFaceObject, FontLoader } from './font_loader';
|
|
|
|
import { CanvasGraphics } from './canvas';
|
|
|
|
import { Metadata } from './metadata';
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2015-10-22 08:56:27 +09:00
|
|
|
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
|
|
|
|
2016-03-29 04:49:22 +09:00
|
|
|
var isWorkerDisabled = false;
|
|
|
|
var workerSrc;
|
|
|
|
var isPostMessageTransfersDisabled = false;
|
|
|
|
|
2017-02-09 07:32:15 +09:00
|
|
|
var pdfjsFilePath =
|
|
|
|
typeof PDFJSDev !== 'undefined' &&
|
|
|
|
PDFJSDev.test('PRODUCTION && !(MOZCENTRAL || FIREFOX)') &&
|
|
|
|
typeof document !== 'undefined' && document.currentScript ?
|
|
|
|
document.currentScript.src : null;
|
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
var fakeWorkerFilesLoader = null;
|
|
|
|
var useRequireEnsure = false;
|
2017-02-09 07:32:15 +09:00
|
|
|
// The if below protected by __pdfjsdev_webpack__ check from webpack parsing.
|
2016-10-15 00:57:53 +09:00
|
|
|
if (typeof PDFJSDev !== 'undefined' &&
|
2017-02-09 07:32:15 +09:00
|
|
|
PDFJSDev.test('GENERIC && !SINGLE_FILE') &&
|
|
|
|
typeof __pdfjsdev_webpack__ === 'undefined') {
|
2016-10-15 00:57:53 +09:00
|
|
|
// For GENERIC build we need add support of different fake file loaders
|
|
|
|
// for different frameworks.
|
|
|
|
if (typeof window === 'undefined') {
|
|
|
|
// node.js - disable worker and set require.ensure.
|
|
|
|
isWorkerDisabled = true;
|
|
|
|
if (typeof require.ensure === 'undefined') {
|
|
|
|
require.ensure = require('node-ensure');
|
|
|
|
}
|
|
|
|
useRequireEnsure = true;
|
2017-02-09 07:32:15 +09:00
|
|
|
} else if (typeof require !== 'undefined' &&
|
|
|
|
typeof require.ensure === 'function') {
|
2016-10-15 00:57:53 +09:00
|
|
|
useRequireEnsure = true;
|
|
|
|
}
|
|
|
|
if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
|
|
|
|
workerSrc = requirejs.toUrl('pdfjs-dist/build/pdf.worker.js');
|
|
|
|
}
|
|
|
|
var dynamicLoaderSupported =
|
|
|
|
typeof requirejs !== 'undefined' && requirejs.load;
|
|
|
|
fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) {
|
|
|
|
require.ensure([], function () {
|
2017-04-09 00:09:54 +09:00
|
|
|
var worker;
|
|
|
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) {
|
|
|
|
worker = require('../pdf.worker.js');
|
|
|
|
} else {
|
|
|
|
worker = require('./pdf.worker.js');
|
|
|
|
}
|
2016-10-15 00:57:53 +09:00
|
|
|
callback(worker.WorkerMessageHandler);
|
|
|
|
});
|
|
|
|
}) : dynamicLoaderSupported ? (function (callback) {
|
|
|
|
requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
|
|
|
|
callback(worker.WorkerMessageHandler);
|
|
|
|
});
|
|
|
|
}) : null;
|
|
|
|
}
|
2015-12-22 04:46:50 +09:00
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Document initialization / loading parameters object.
|
|
|
|
*
|
|
|
|
* @typedef {Object} DocumentInitParameters
|
|
|
|
* @property {string} url - The URL of the PDF.
|
2015-01-13 05:52:52 +09:00
|
|
|
* @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
|
|
|
|
* (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
|
|
|
|
* use atob() to convert it to a binary string first.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @property {Object} httpHeaders - Basic authentication headers.
|
|
|
|
* @property {boolean} withCredentials - Indicates whether or not cross-site
|
|
|
|
* Access-Control requests should be made using credentials such as cookies
|
|
|
|
* or authorization headers. The default is false.
|
|
|
|
* @property {string} password - For decrypting password-protected PDFs.
|
|
|
|
* @property {TypedArray} initialData - A typed array with the first portion or
|
|
|
|
* all of the pdf data. Used by the extension since some data is already
|
|
|
|
* loaded before the switch to range requests.
|
2015-01-06 12:45:01 +09:00
|
|
|
* @property {number} length - The PDF file length. It's used for progress
|
|
|
|
* reports and range requests operations.
|
|
|
|
* @property {PDFDataRangeTransport} range
|
2015-10-22 08:56:27 +09:00
|
|
|
* @property {number} rangeChunkSize - Optional parameter to specify
|
|
|
|
* maximum number of bytes fetched per range request. The default value is
|
|
|
|
* 2^16 = 65536.
|
2015-10-28 02:55:15 +09:00
|
|
|
* @property {PDFWorker} worker - The worker that will be used for the loading
|
|
|
|
* and parsing of the PDF data.
|
2016-10-01 19:05:07 +09:00
|
|
|
* @property {string} docBaseUrl - (optional) The base URL of the document,
|
|
|
|
* used when attempting to recover valid absolute URLs for annotations, and
|
|
|
|
* outline items, that (incorrectly) only specify relative URLs.
|
2017-05-08 12:32:44 +09:00
|
|
|
* @property {boolean} disableNativeImageDecoder - (deprecated) Disable decoding
|
2017-02-07 06:09:19 +09:00
|
|
|
* of certain (simple) JPEG images in the browser. This is useful for
|
|
|
|
* environments without DOM image support, such as e.g. Node.js.
|
|
|
|
* The default value is `false`.
|
2017-05-08 12:32:44 +09:00
|
|
|
* @property {string} nativeImageDecoderSupport - (optional) Strategy for
|
|
|
|
* decoding certain (simple) JPEG images in the browser. This is useful for
|
|
|
|
* environments without DOM image and canvas support, such as e.g. Node.js.
|
|
|
|
* Valid values are 'decode', 'display' or 'none'; where 'decode' is intended
|
|
|
|
* for browsers with full image/canvas support, 'display' for environments
|
|
|
|
* with limited image support through stubs (useful for SVG conversion),
|
|
|
|
* and 'none' where JPEG images will be decoded entirely by PDF.js.
|
|
|
|
* The default value is 'decode'.
|
2017-02-12 23:54:41 +09:00
|
|
|
* @property {Object} CMapReaderFactory - (optional) The factory that will be
|
|
|
|
* used when reading built-in CMap files. Providing a custom factory is useful
|
|
|
|
* for environments without `XMLHttpRequest` support, such as e.g. Node.js.
|
|
|
|
* The default value is {DOMCMapReaderFactory}.
|
[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
|
|
|
* @property {boolean} stopAtErrors - (optional) Reject certain promises, e.g.
|
|
|
|
* `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
|
|
|
|
* PDF data cannot be successfully parsed, instead of attempting to recover
|
|
|
|
* whatever possible of the data. The default value is `false`.
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
|
|
|
|
2014-06-16 23:52:04 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} PDFDocumentStats
|
|
|
|
* @property {Array} streamTypes - Used stream types in the document (an item
|
|
|
|
* is set to true if specific stream ID was used in the document).
|
|
|
|
* @property {Array} fontTypes - Used font type in the document (an item is set
|
|
|
|
* to true if specific font ID was used in the document).
|
|
|
|
*/
|
|
|
|
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* This is the main entry point for loading a PDF and interacting with it.
|
|
|
|
* NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
|
|
|
|
* is used, which means it must follow the same origin rules that any XHR does
|
|
|
|
* e.g. No cross domain requests without CORS.
|
|
|
|
*
|
2015-01-06 12:45:01 +09:00
|
|
|
* @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
|
|
|
|
* Can be a url to where a PDF is located, a typed array (Uint8Array)
|
|
|
|
* already populated with data or parameter object.
|
2012-05-15 03:45:07 +09:00
|
|
|
*
|
2015-01-06 12:45:01 +09:00
|
|
|
* @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
|
|
|
|
* if you want to manually serve range requests for data in the PDF.
|
2013-02-07 08:19:29 +09:00
|
|
|
*
|
2015-01-06 12:45:01 +09:00
|
|
|
* @param {function} passwordCallback (deprecated) It is used to request a
|
2013-05-10 07:35:23 +09:00
|
|
|
* password if wrong or no password was provided. The callback receives two
|
|
|
|
* parameters: function that needs to be called with new password and reason
|
|
|
|
* (see {PasswordResponses}).
|
|
|
|
*
|
2015-01-06 12:45:01 +09:00
|
|
|
* @param {function} progressCallback (deprecated) It is used to be able to
|
2014-08-28 21:11:14 +09:00
|
|
|
* monitor the loading progress of the PDF file (necessary to implement e.g.
|
|
|
|
* a loading bar). The callback receives an {Object} with the properties:
|
|
|
|
* {number} loaded and {number} total.
|
|
|
|
*
|
2015-01-06 12:45:01 +09:00
|
|
|
* @return {PDFDocumentLoadingTask}
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2016-03-29 04:49:22 +09:00
|
|
|
function getDocument(src, pdfDataRangeTransport,
|
|
|
|
passwordCallback, progressCallback) {
|
2015-01-06 12:45:01 +09:00
|
|
|
var task = new PDFDocumentLoadingTask();
|
|
|
|
|
|
|
|
// Support of the obsolete arguments (for compatibility with API v1.0)
|
2015-10-21 22:54:31 +09:00
|
|
|
if (arguments.length > 1) {
|
|
|
|
deprecated('getDocument is called with pdfDataRangeTransport, ' +
|
|
|
|
'passwordCallback or progressCallback argument');
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
if (pdfDataRangeTransport) {
|
|
|
|
if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
|
|
|
|
// Not a PDFDataRangeTransport instance, trying to add missing properties.
|
|
|
|
pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
|
|
|
|
pdfDataRangeTransport.length = src.length;
|
|
|
|
pdfDataRangeTransport.initialData = src.initialData;
|
2015-10-21 07:45:55 +09:00
|
|
|
if (!pdfDataRangeTransport.abort) {
|
|
|
|
pdfDataRangeTransport.abort = function () {};
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
}
|
|
|
|
src = Object.create(src);
|
|
|
|
src.range = pdfDataRangeTransport;
|
2012-06-28 19:33:32 +09:00
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
task.onPassword = passwordCallback || null;
|
|
|
|
task.onProgress = progressCallback || null;
|
|
|
|
|
|
|
|
var source;
|
|
|
|
if (typeof src === 'string') {
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
source = { url: src, };
|
2015-01-06 12:45:01 +09:00
|
|
|
} else if (isArrayBuffer(src)) {
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
source = { data: src, };
|
2015-01-06 12:45:01 +09:00
|
|
|
} else if (src instanceof PDFDataRangeTransport) {
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
source = { range: src, };
|
2015-01-06 12:45:01 +09:00
|
|
|
} else {
|
|
|
|
if (typeof src !== 'object') {
|
|
|
|
error('Invalid parameter in getDocument, need either Uint8Array, ' +
|
|
|
|
'string or a parameter object');
|
|
|
|
}
|
|
|
|
if (!src.url && !src.data && !src.range) {
|
|
|
|
error('Invalid parameter object: need either .data, .range or .url');
|
|
|
|
}
|
2012-06-28 19:33:32 +09:00
|
|
|
|
2015-01-06 12:45:01 +09:00
|
|
|
source = src;
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2012-06-24 04:48:33 +09:00
|
|
|
|
2012-07-27 02:11:28 +09:00
|
|
|
var params = {};
|
2015-10-28 02:55:15 +09:00
|
|
|
var rangeTransport = null;
|
|
|
|
var worker = null;
|
2012-07-27 02:11:28 +09:00
|
|
|
for (var key in source) {
|
|
|
|
if (key === 'url' && typeof window !== 'undefined') {
|
2015-01-13 05:52:52 +09:00
|
|
|
// The full path is required in the 'url' field.
|
2016-04-16 01:03:10 +09:00
|
|
|
params[key] = new URL(source[key], window.location).href;
|
2012-07-27 02:11:28 +09:00
|
|
|
continue;
|
2015-01-06 12:45:01 +09:00
|
|
|
} else if (key === 'range') {
|
2015-10-28 02:55:15 +09:00
|
|
|
rangeTransport = source[key];
|
|
|
|
continue;
|
|
|
|
} else if (key === 'worker') {
|
|
|
|
worker = source[key];
|
2015-01-06 12:45:01 +09:00
|
|
|
continue;
|
2015-01-13 05:52:52 +09:00
|
|
|
} else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
|
|
|
|
// Converting string or array-like data to Uint8Array.
|
|
|
|
var pdfBytes = source[key];
|
|
|
|
if (typeof pdfBytes === 'string') {
|
|
|
|
params[key] = stringToBytes(pdfBytes);
|
|
|
|
} else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
|
|
|
|
!isNaN(pdfBytes.length)) {
|
|
|
|
params[key] = new Uint8Array(pdfBytes);
|
2015-08-20 00:54:41 +09:00
|
|
|
} else if (isArrayBuffer(pdfBytes)) {
|
|
|
|
params[key] = new Uint8Array(pdfBytes);
|
2015-01-13 05:52:52 +09:00
|
|
|
} else {
|
|
|
|
error('Invalid PDF binary data: either typed array, string or ' +
|
|
|
|
'array-like object is expected in the data property.');
|
|
|
|
}
|
|
|
|
continue;
|
2012-07-27 02:11:28 +09:00
|
|
|
}
|
|
|
|
params[key] = source[key];
|
|
|
|
}
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
|
[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
|
|
|
params.ignoreErrors = params.stopAtErrors !== true;
|
2017-02-12 23:54:41 +09:00
|
|
|
var CMapReaderFactory = params.CMapReaderFactory || DOMCMapReaderFactory;
|
2015-10-22 08:56:27 +09:00
|
|
|
|
2017-05-08 12:32:44 +09:00
|
|
|
if (params.disableNativeImageDecoder !== undefined) {
|
|
|
|
deprecated('parameter disableNativeImageDecoder, ' +
|
|
|
|
'use nativeImageDecoderSupport instead');
|
|
|
|
}
|
|
|
|
params.nativeImageDecoderSupport = params.nativeImageDecoderSupport ||
|
|
|
|
(params.disableNativeImageDecoder === true ? NativeImageDecoding.NONE :
|
|
|
|
NativeImageDecoding.DECODE);
|
|
|
|
if (params.nativeImageDecoderSupport !== NativeImageDecoding.DECODE &&
|
|
|
|
params.nativeImageDecoderSupport !== NativeImageDecoding.NONE &&
|
|
|
|
params.nativeImageDecoderSupport !== NativeImageDecoding.DISPLAY) {
|
|
|
|
warn('Invalid parameter nativeImageDecoderSupport: ' +
|
|
|
|
'need a state of enum {NativeImageDecoding}');
|
|
|
|
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
|
|
|
}
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
if (!worker) {
|
2017-02-25 04:33:18 +09:00
|
|
|
// Worker was not provided -- creating and owning our own. If message port
|
|
|
|
// is specified in global settings, using it.
|
|
|
|
var workerPort = getDefaultSetting('workerPort');
|
2017-06-10 10:07:51 +09:00
|
|
|
worker = workerPort ? PDFWorker.fromPort(workerPort) : new PDFWorker();
|
2015-10-28 02:55:15 +09:00
|
|
|
task._worker = worker;
|
|
|
|
}
|
|
|
|
var docId = task.docId;
|
|
|
|
worker.promise.then(function () {
|
|
|
|
if (task.destroyed) {
|
|
|
|
throw new Error('Loading aborted');
|
|
|
|
}
|
|
|
|
return _fetchDocument(worker, params, rangeTransport, docId).then(
|
|
|
|
function (workerId) {
|
|
|
|
if (task.destroyed) {
|
|
|
|
throw new Error('Loading aborted');
|
|
|
|
}
|
|
|
|
var messageHandler = new MessageHandler(docId, workerId, worker.port);
|
2017-02-12 23:54:41 +09:00
|
|
|
var transport = new WorkerTransport(messageHandler, task, rangeTransport,
|
|
|
|
CMapReaderFactory);
|
2015-10-28 02:55:15 +09:00
|
|
|
task._transport = transport;
|
2016-01-30 02:43:19 +09:00
|
|
|
messageHandler.send('Ready', null);
|
2015-10-28 02:55:15 +09:00
|
|
|
});
|
2015-12-17 09:37:43 +09:00
|
|
|
}).catch(task._capability.reject);
|
2015-01-06 12:45:01 +09:00
|
|
|
|
|
|
|
return task;
|
2016-03-29 04:49:22 +09:00
|
|
|
}
|
2012-04-13 04:11:22 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
/**
|
|
|
|
* Starts fetching of specified PDF document/data.
|
|
|
|
* @param {PDFWorker} worker
|
|
|
|
* @param {Object} source
|
|
|
|
* @param {PDFDataRangeTransport} pdfDataRangeTransport
|
|
|
|
* @param {string} docId Unique document id, used as MessageHandler id.
|
|
|
|
* @returns {Promise} The promise, which is resolved when worker id of
|
|
|
|
* MessageHandler is known.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|
|
|
if (worker.destroyed) {
|
|
|
|
return Promise.reject(new Error('Worker was destroyed'));
|
|
|
|
}
|
|
|
|
|
2016-03-29 04:49:22 +09:00
|
|
|
source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
|
|
|
|
source.disableStream = getDefaultSetting('disableStream');
|
2015-10-28 02:55:15 +09:00
|
|
|
source.chunkedViewerLoading = !!pdfDataRangeTransport;
|
|
|
|
if (pdfDataRangeTransport) {
|
|
|
|
source.length = pdfDataRangeTransport.length;
|
|
|
|
source.initialData = pdfDataRangeTransport.initialData;
|
|
|
|
}
|
|
|
|
return worker.messageHandler.sendWithPromise('GetDocRequest', {
|
2017-04-25 23:17:18 +09:00
|
|
|
docId,
|
|
|
|
source,
|
2016-03-29 04:49:22 +09:00
|
|
|
disableRange: getDefaultSetting('disableRange'),
|
|
|
|
maxImageSize: getDefaultSetting('maxImageSize'),
|
|
|
|
disableFontFace: getDefaultSetting('disableFontFace'),
|
|
|
|
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
|
|
|
|
postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
|
|
|
|
!isPostMessageTransfersDisabled,
|
2016-10-01 19:05:07 +09:00
|
|
|
docBaseUrl: source.docBaseUrl,
|
2017-05-08 12:32:44 +09:00
|
|
|
nativeImageDecoderSupport: source.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: source.ignoreErrors,
|
2015-10-28 02:55:15 +09:00
|
|
|
}).then(function (workerId) {
|
|
|
|
if (worker.destroyed) {
|
|
|
|
throw new Error('Worker was destroyed');
|
|
|
|
}
|
|
|
|
return workerId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-06 12:45:01 +09:00
|
|
|
/**
|
|
|
|
* PDF document loading operation.
|
|
|
|
* @class
|
2015-11-13 04:39:58 +09:00
|
|
|
* @alias PDFDocumentLoadingTask
|
2015-01-06 12:45:01 +09:00
|
|
|
*/
|
|
|
|
var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
|
2015-10-28 02:55:15 +09:00
|
|
|
var nextDocumentId = 0;
|
|
|
|
|
|
|
|
/** @constructs PDFDocumentLoadingTask */
|
2015-01-06 12:45:01 +09:00
|
|
|
function PDFDocumentLoadingTask() {
|
|
|
|
this._capability = createPromiseCapability();
|
2015-10-21 07:45:55 +09:00
|
|
|
this._transport = null;
|
2015-10-28 02:55:15 +09:00
|
|
|
this._worker = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unique document loading task id -- used in MessageHandlers.
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
this.docId = 'd' + (nextDocumentId++);
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2015-10-28 00:07:20 +09:00
|
|
|
/**
|
|
|
|
* Shows if loading task is destroyed.
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.destroyed = false;
|
2015-01-06 12:45:01 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to request a password if wrong or no password was provided.
|
|
|
|
* The callback receives two parameters: function that needs to be called
|
|
|
|
* with new password and reason (see {PasswordResponses}).
|
|
|
|
*/
|
|
|
|
this.onPassword = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to be able to monitor the loading progress of the PDF file
|
|
|
|
* (necessary to implement e.g. a loading bar). The callback receives
|
|
|
|
* an {Object} with the properties: {number} loaded and {number} total.
|
|
|
|
*/
|
|
|
|
this.onProgress = null;
|
2015-12-01 05:42:47 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to when unsupported feature is used. The callback receives
|
2016-03-29 04:49:22 +09:00
|
|
|
* an {UNSUPPORTED_FEATURES} argument.
|
2015-12-01 05:42:47 +09:00
|
|
|
*/
|
|
|
|
this.onUnsupportedFeature = null;
|
2015-01-06 12:45:01 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
PDFDocumentLoadingTask.prototype =
|
|
|
|
/** @lends PDFDocumentLoadingTask.prototype */ {
|
|
|
|
/**
|
|
|
|
* @return {Promise}
|
|
|
|
*/
|
|
|
|
get promise() {
|
|
|
|
return this._capability.promise;
|
|
|
|
},
|
|
|
|
|
2015-10-21 07:45:55 +09:00
|
|
|
/**
|
|
|
|
* Aborts all network requests and destroys worker.
|
|
|
|
* @return {Promise} A promise that is resolved after destruction activity
|
|
|
|
* is completed.
|
|
|
|
*/
|
2017-04-25 23:17:18 +09:00
|
|
|
destroy() {
|
2015-10-28 00:07:20 +09:00
|
|
|
this.destroyed = true;
|
2015-10-28 02:55:15 +09:00
|
|
|
|
|
|
|
var transportDestroyed = !this._transport ? Promise.resolve() :
|
|
|
|
this._transport.destroy();
|
2017-05-03 23:39:54 +09:00
|
|
|
return transportDestroyed.then(() => {
|
2015-10-28 02:55:15 +09:00
|
|
|
this._transport = null;
|
|
|
|
if (this._worker) {
|
|
|
|
this._worker.destroy();
|
|
|
|
this._worker = null;
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2015-10-21 07:45:55 +09:00
|
|
|
},
|
2015-01-06 12:45:01 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers callbacks to indicate the document loading completion.
|
|
|
|
*
|
|
|
|
* @param {function} onFulfilled The callback for the loading completion.
|
|
|
|
* @param {function} onRejected The callback for the loading failure.
|
|
|
|
* @return {Promise} A promise that is resolved after the onFulfilled or
|
|
|
|
* onRejected callback.
|
|
|
|
*/
|
|
|
|
then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
|
|
|
|
return this.promise.then.apply(this.promise, arguments);
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2015-01-06 12:45:01 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
return PDFDocumentLoadingTask;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class to support range requests file loading.
|
|
|
|
* @class
|
2016-03-29 04:49:22 +09:00
|
|
|
* @alias PDFDataRangeTransport
|
2015-11-13 04:39:58 +09:00
|
|
|
* @param {number} length
|
|
|
|
* @param {Uint8Array} initialData
|
2015-01-06 12:45:01 +09:00
|
|
|
*/
|
|
|
|
var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
|
|
|
|
function PDFDataRangeTransport(length, initialData) {
|
|
|
|
this.length = length;
|
|
|
|
this.initialData = initialData;
|
|
|
|
|
|
|
|
this._rangeListeners = [];
|
|
|
|
this._progressListeners = [];
|
|
|
|
this._progressiveReadListeners = [];
|
|
|
|
this._readyCapability = createPromiseCapability();
|
|
|
|
}
|
|
|
|
PDFDataRangeTransport.prototype =
|
|
|
|
/** @lends PDFDataRangeTransport.prototype */ {
|
|
|
|
addRangeListener:
|
|
|
|
function PDFDataRangeTransport_addRangeListener(listener) {
|
|
|
|
this._rangeListeners.push(listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
addProgressListener:
|
|
|
|
function PDFDataRangeTransport_addProgressListener(listener) {
|
|
|
|
this._progressListeners.push(listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
addProgressiveReadListener:
|
|
|
|
function PDFDataRangeTransport_addProgressiveReadListener(listener) {
|
|
|
|
this._progressiveReadListeners.push(listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
|
|
|
|
var listeners = this._rangeListeners;
|
|
|
|
for (var i = 0, n = listeners.length; i < n; ++i) {
|
|
|
|
listeners[i](begin, chunk);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
|
2017-05-03 23:39:54 +09:00
|
|
|
this._readyCapability.promise.then(() => {
|
2015-01-06 12:45:01 +09:00
|
|
|
var listeners = this._progressListeners;
|
|
|
|
for (var i = 0, n = listeners.length; i < n; ++i) {
|
|
|
|
listeners[i](loaded);
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2015-01-06 12:45:01 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
onDataProgressiveRead:
|
|
|
|
function PDFDataRangeTransport_onDataProgress(chunk) {
|
2017-05-03 23:39:54 +09:00
|
|
|
this._readyCapability.promise.then(() => {
|
2015-01-06 12:45:01 +09:00
|
|
|
var listeners = this._progressiveReadListeners;
|
|
|
|
for (var i = 0, n = listeners.length; i < n; ++i) {
|
|
|
|
listeners[i](chunk);
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2015-01-06 12:45:01 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
transportReady: function PDFDataRangeTransport_transportReady() {
|
|
|
|
this._readyCapability.resolve();
|
|
|
|
},
|
|
|
|
|
|
|
|
requestDataRange:
|
|
|
|
function PDFDataRangeTransport_requestDataRange(begin, end) {
|
|
|
|
throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
|
2015-10-21 07:45:55 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
abort: function PDFDataRangeTransport_abort() {
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2015-01-06 12:45:01 +09:00
|
|
|
};
|
|
|
|
return PDFDataRangeTransport;
|
|
|
|
})();
|
|
|
|
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used
|
|
|
|
* properties that can be read synchronously.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @class
|
2015-11-13 04:39:58 +09:00
|
|
|
* @alias PDFDocumentProxy
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2012-05-02 02:54:16 +09:00
|
|
|
var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
2015-10-21 07:45:55 +09:00
|
|
|
function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
|
2012-04-13 04:11:22 +09:00
|
|
|
this.pdfInfo = pdfInfo;
|
|
|
|
this.transport = transport;
|
2015-10-21 07:45:55 +09:00
|
|
|
this.loadingTask = loadingTask;
|
2012-04-13 04:11:22 +09:00
|
|
|
}
|
2014-01-22 04:28:18 +09:00
|
|
|
PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* @return {number} Total number of pages the PDF contains.
|
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
get numPages() {
|
|
|
|
return this.pdfInfo.numPages;
|
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* @return {string} A unique ID to identify a PDF. Not guaranteed to be
|
|
|
|
* unique.
|
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
get fingerprint() {
|
|
|
|
return this.pdfInfo.fingerprint;
|
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2014-01-22 04:28:18 +09:00
|
|
|
* @param {number} pageNumber The page number to get. The first page is 1.
|
|
|
|
* @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
|
2012-04-14 01:25:08 +09:00
|
|
|
* object.
|
|
|
|
*/
|
2014-01-22 04:28:18 +09:00
|
|
|
getPage: function PDFDocumentProxy_getPage(pageNumber) {
|
|
|
|
return this.transport.getPage(pageNumber);
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2013-11-14 08:27:46 +09:00
|
|
|
/**
|
2014-01-22 04:28:18 +09:00
|
|
|
* @param {{num: number, gen: number}} ref The page reference. Must have
|
|
|
|
* the 'num' and 'gen' properties.
|
2013-11-14 08:27:46 +09:00
|
|
|
* @return {Promise} A promise that is resolved with the page index that is
|
|
|
|
* associated with the reference.
|
|
|
|
*/
|
|
|
|
getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
|
|
|
|
return this.transport.getPageIndex(ref);
|
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* @return {Promise} A promise that is resolved with a lookup table for
|
|
|
|
* mapping named destinations to reference numbers.
|
2014-10-05 22:56:40 +09:00
|
|
|
*
|
|
|
|
* This can be slow for large documents: use getDestination instead
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2012-05-02 02:48:07 +09:00
|
|
|
getDestinations: function PDFDocumentProxy_getDestinations() {
|
2013-02-07 08:19:29 +09:00
|
|
|
return this.transport.getDestinations();
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2014-10-05 22:56:40 +09:00
|
|
|
/**
|
|
|
|
* @param {string} id The named destination to get.
|
|
|
|
* @return {Promise} A promise that is resolved with all information
|
|
|
|
* of the given named destination.
|
|
|
|
*/
|
|
|
|
getDestination: function PDFDocumentProxy_getDestination(id) {
|
|
|
|
return this.transport.getDestination(id);
|
|
|
|
},
|
2015-12-26 05:57:08 +09:00
|
|
|
/**
|
2016-01-27 07:01:38 +09:00
|
|
|
* @return {Promise} A promise that is resolved with:
|
|
|
|
* an Array containing the pageLabels that correspond to the pageIndexes,
|
|
|
|
* or `null` when no pageLabels are present in the PDF file.
|
2015-12-26 05:57:08 +09:00
|
|
|
*/
|
|
|
|
getPageLabels: function PDFDocumentProxy_getPageLabels() {
|
|
|
|
return this.transport.getPageLabels();
|
|
|
|
},
|
2014-03-19 05:32:47 +09:00
|
|
|
/**
|
|
|
|
* @return {Promise} A promise that is resolved with a lookup table for
|
|
|
|
* mapping named attachments to their content.
|
|
|
|
*/
|
|
|
|
getAttachments: function PDFDocumentProxy_getAttachments() {
|
|
|
|
return this.transport.getAttachments();
|
|
|
|
},
|
2013-03-01 08:29:07 +09:00
|
|
|
/**
|
|
|
|
* @return {Promise} A promise that is resolved with an array of all the
|
|
|
|
* JavaScript strings in the name tree.
|
|
|
|
*/
|
2013-12-17 05:40:43 +09:00
|
|
|
getJavaScript: function PDFDocumentProxy_getJavaScript() {
|
2014-05-08 04:15:34 +09:00
|
|
|
return this.transport.getJavaScript();
|
2013-03-01 08:29:07 +09:00
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2014-01-22 04:28:18 +09:00
|
|
|
* @return {Promise} A promise that is resolved with an {Array} that is a
|
2012-04-14 01:25:08 +09:00
|
|
|
* tree outline (if it has one) of the PDF. The tree is in the format of:
|
|
|
|
* [
|
|
|
|
* {
|
|
|
|
* title: string,
|
|
|
|
* bold: boolean,
|
|
|
|
* italic: boolean,
|
2016-01-31 23:35:57 +09:00
|
|
|
* color: rgb Uint8Array,
|
2012-04-14 01:25:08 +09:00
|
|
|
* dest: dest obj,
|
2015-12-22 20:59:23 +09:00
|
|
|
* url: string,
|
2012-04-14 01:25:08 +09:00
|
|
|
* items: array of more items like this
|
|
|
|
* },
|
|
|
|
* ...
|
|
|
|
* ].
|
|
|
|
*/
|
2012-05-02 02:48:07 +09:00
|
|
|
getOutline: function PDFDocumentProxy_getOutline() {
|
2014-05-08 04:06:44 +09:00
|
|
|
return this.transport.getOutline();
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2014-01-22 04:28:18 +09:00
|
|
|
* @return {Promise} A promise that is resolved with an {Object} that has
|
|
|
|
* info and metadata properties. Info is an {Object} filled with anything
|
2012-04-14 01:25:08 +09:00
|
|
|
* available in the information dictionary and similarly metadata is a
|
|
|
|
* {Metadata} object with information from the metadata section of the PDF.
|
|
|
|
*/
|
2012-05-02 02:48:07 +09:00
|
|
|
getMetadata: function PDFDocumentProxy_getMetadata() {
|
2014-05-08 04:38:40 +09:00
|
|
|
return this.transport.getMetadata();
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2012-06-02 06:17:09 +09:00
|
|
|
/**
|
|
|
|
* @return {Promise} A promise that is resolved with a TypedArray that has
|
|
|
|
* the raw data from the PDF.
|
|
|
|
*/
|
|
|
|
getData: function PDFDocumentProxy_getData() {
|
2014-05-14 08:20:21 +09:00
|
|
|
return this.transport.getData();
|
2012-06-02 06:17:09 +09:00
|
|
|
},
|
2013-02-07 08:19:29 +09:00
|
|
|
/**
|
|
|
|
* @return {Promise} A promise that is resolved when the document's data
|
2014-01-29 06:13:47 +09:00
|
|
|
* is loaded. It is resolved with an {Object} that contains the length
|
|
|
|
* property that indicates size of the PDF data in bytes.
|
2013-02-07 08:19:29 +09:00
|
|
|
*/
|
2014-01-29 06:13:47 +09:00
|
|
|
getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
|
2014-04-30 00:07:05 +09:00
|
|
|
return this.transport.downloadInfoCapability.promise;
|
2013-02-07 08:19:29 +09:00
|
|
|
},
|
2014-06-16 23:52:04 +09:00
|
|
|
/**
|
2015-01-06 12:45:01 +09:00
|
|
|
* @return {Promise} A promise this is resolved with current stats about
|
2014-06-16 23:52:04 +09:00
|
|
|
* document structures (see {@link PDFDocumentStats}).
|
|
|
|
*/
|
|
|
|
getStats: function PDFDocumentProxy_getStats() {
|
|
|
|
return this.transport.getStats();
|
|
|
|
},
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Cleans up resources allocated by the document, e.g. created @font-face.
|
|
|
|
*/
|
2013-11-15 06:43:38 +09:00
|
|
|
cleanup: function PDFDocumentProxy_cleanup() {
|
|
|
|
this.transport.startCleanup();
|
|
|
|
},
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Destroys current document instance and terminates worker.
|
|
|
|
*/
|
2012-05-02 02:48:07 +09:00
|
|
|
destroy: function PDFDocumentProxy_destroy() {
|
2015-10-28 02:55:15 +09:00
|
|
|
return this.loadingTask.destroy();
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2012-04-13 04:11:22 +09:00
|
|
|
};
|
|
|
|
return PDFDocumentProxy;
|
|
|
|
})();
|
|
|
|
|
2015-11-24 00:57:43 +09:00
|
|
|
/**
|
|
|
|
* Page getTextContent parameters.
|
|
|
|
*
|
|
|
|
* @typedef {Object} getTextContentParameters
|
2016-10-17 20:04:55 +09:00
|
|
|
* @property {boolean} normalizeWhitespace - replaces all occurrences of
|
2015-11-24 00:57:43 +09:00
|
|
|
* whitespace with standard spaces (0x20). The default value is `false`.
|
2016-10-17 20:04:55 +09:00
|
|
|
* @property {boolean} disableCombineTextItems - do not attempt to combine
|
2016-07-04 01:29:47 +09:00
|
|
|
* same line {@link TextItem}'s. The default value is `false`.
|
2015-11-24 00:57:43 +09:00
|
|
|
*/
|
|
|
|
|
2014-04-10 08:44:07 +09:00
|
|
|
/**
|
|
|
|
* Page text content.
|
|
|
|
*
|
|
|
|
* @typedef {Object} TextContent
|
|
|
|
* @property {array} items - array of {@link TextItem}
|
2016-10-17 20:04:55 +09:00
|
|
|
* @property {Object} styles - {@link TextStyles} objects, indexed by font name.
|
2014-04-10 08:44:07 +09:00
|
|
|
*/
|
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Page text content part.
|
|
|
|
*
|
2014-04-10 08:44:07 +09:00
|
|
|
* @typedef {Object} TextItem
|
2014-01-22 04:28:18 +09:00
|
|
|
* @property {string} str - text content.
|
|
|
|
* @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
|
2014-04-10 08:44:07 +09:00
|
|
|
* @property {array} transform - transformation matrix.
|
|
|
|
* @property {number} width - width in device space.
|
|
|
|
* @property {number} height - height in device space.
|
|
|
|
* @property {string} fontName - font name used by pdf.js for converted font.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-12 00:57:48 +09:00
|
|
|
* Text style.
|
|
|
|
*
|
2014-04-10 08:44:07 +09:00
|
|
|
* @typedef {Object} TextStyle
|
|
|
|
* @property {number} ascent - font ascent.
|
|
|
|
* @property {number} descent - font descent.
|
|
|
|
* @property {boolean} vertical - text is in vertical mode.
|
|
|
|
* @property {string} fontFamily - possible font family
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
|
|
|
|
2015-11-22 21:56:52 +09:00
|
|
|
/**
|
|
|
|
* Page annotation parameters.
|
|
|
|
*
|
|
|
|
* @typedef {Object} GetAnnotationsParameters
|
2016-10-17 20:04:55 +09:00
|
|
|
* @property {string} intent - Determines the annotations that will be fetched,
|
|
|
|
* can be either 'display' (viewable annotations) or 'print'
|
|
|
|
* (printable annotations).
|
|
|
|
* If the parameter is omitted, all annotations are fetched.
|
2015-11-22 21:56:52 +09:00
|
|
|
*/
|
|
|
|
|
2014-04-12 00:57:48 +09:00
|
|
|
/**
|
|
|
|
* Page render parameters.
|
|
|
|
*
|
|
|
|
* @typedef {Object} RenderParameters
|
|
|
|
* @property {Object} canvasContext - A 2D context of a DOM Canvas object.
|
2016-03-29 04:49:22 +09:00
|
|
|
* @property {PageViewport} viewport - Rendering viewport obtained by
|
2014-05-06 04:09:47 +09:00
|
|
|
* calling of PDFPage.getViewport method.
|
2014-04-12 00:57:48 +09:00
|
|
|
* @property {string} intent - Rendering intent, can be 'display' or 'print'
|
|
|
|
* (default value is 'display').
|
2016-09-15 05:49:37 +09:00
|
|
|
* @property {boolean} renderInteractiveForms - (optional) Whether or not
|
|
|
|
* interactive form elements are rendered in the display
|
|
|
|
* layer. If so, we do not render them on canvas as well.
|
2015-11-17 01:50:02 +09:00
|
|
|
* @property {Array} transform - (optional) Additional transform, applied
|
|
|
|
* just before viewport transform.
|
2014-04-12 00:57:48 +09:00
|
|
|
* @property {Object} imageLayer - (optional) An object that has beginLayout,
|
|
|
|
* endLayout and appendImage functions.
|
2015-01-06 12:45:01 +09:00
|
|
|
* @property {function} continueCallback - (deprecated) A function that will be
|
2014-04-12 00:57:48 +09:00
|
|
|
* called each time the rendering is paused. To continue
|
|
|
|
* rendering call the function that is the first argument
|
|
|
|
* to the callback.
|
2017-01-28 02:58:39 +09:00
|
|
|
* @property {Object} canvasFactory - (optional) The factory that will be used
|
|
|
|
* when creating canvases. The default value is
|
|
|
|
* {DOMCanvasFactory}.
|
2017-05-16 20:01:03 +09:00
|
|
|
* @property {Object} background - (optional) Background to use for the canvas.
|
|
|
|
* Can use any valid canvas.fillStyle: A DOMString parsed as
|
|
|
|
* CSS <color> value, a CanvasGradient object (a linear or
|
|
|
|
* radial gradient) or a CanvasPattern object (a repetitive
|
|
|
|
* image). The default value is 'rgb(255,255,255)'.
|
2014-04-12 00:57:48 +09:00
|
|
|
*/
|
2015-02-03 00:12:52 +09:00
|
|
|
|
2014-06-17 03:35:38 +09:00
|
|
|
/**
|
|
|
|
* PDF page operator list.
|
|
|
|
*
|
|
|
|
* @typedef {Object} PDFOperatorList
|
|
|
|
* @property {Array} fnArray - Array containing the operator functions.
|
|
|
|
* @property {Array} argsArray - Array containing the arguments of the
|
|
|
|
* functions.
|
|
|
|
*/
|
2014-04-12 00:57:48 +09:00
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Proxy to a PDFPage in the worker thread.
|
|
|
|
* @class
|
2015-11-13 04:39:58 +09:00
|
|
|
* @alias PDFPageProxy
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
var PDFPageProxy = (function PDFPageProxyClosure() {
|
2014-05-09 05:02:53 +09:00
|
|
|
function PDFPageProxy(pageIndex, pageInfo, transport) {
|
|
|
|
this.pageIndex = pageIndex;
|
2012-04-13 04:11:22 +09:00
|
|
|
this.pageInfo = pageInfo;
|
|
|
|
this.transport = transport;
|
2012-04-13 06:07:11 +09:00
|
|
|
this.stats = new StatTimer();
|
2016-03-29 04:49:22 +09:00
|
|
|
this.stats.enabled = getDefaultSetting('enableStats');
|
2012-10-29 05:10:34 +09:00
|
|
|
this.commonObjs = transport.commonObjs;
|
|
|
|
this.objs = new PDFObjects();
|
|
|
|
this.cleanupAfterRender = false;
|
2015-10-21 07:45:55 +09:00
|
|
|
this.pendingCleanup = false;
|
2016-01-28 02:04:13 +09:00
|
|
|
this.intentStates = Object.create(null);
|
2015-10-21 07:45:55 +09:00
|
|
|
this.destroyed = false;
|
2012-04-13 04:11:22 +09:00
|
|
|
}
|
2014-01-22 04:28:18 +09:00
|
|
|
PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* @return {number} Page number of the page. First page is 1.
|
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
get pageNumber() {
|
2014-05-09 05:02:53 +09:00
|
|
|
return this.pageIndex + 1;
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* @return {number} The number of degrees the page is rotated clockwise.
|
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
get rotate() {
|
|
|
|
return this.pageInfo.rotate;
|
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2014-01-22 04:28:18 +09:00
|
|
|
* @return {Object} The reference that points to this page. It has 'num' and
|
2012-04-14 01:25:08 +09:00
|
|
|
* 'gen' properties.
|
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
get ref() {
|
|
|
|
return this.pageInfo.ref;
|
|
|
|
},
|
2016-11-22 06:39:04 +09:00
|
|
|
/**
|
|
|
|
* @return {number} The default size of units in 1/72nds of an inch.
|
|
|
|
*/
|
|
|
|
get userUnit() {
|
|
|
|
return this.pageInfo.userUnit;
|
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2014-01-22 04:28:18 +09:00
|
|
|
* @return {Array} An array of the visible portion of the PDF page in the
|
2012-04-14 01:25:08 +09:00
|
|
|
* user space units - [x1, y1, x2, y2].
|
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
get view() {
|
|
|
|
return this.pageInfo.view;
|
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* @param {number} scale The desired scale of the viewport.
|
|
|
|
* @param {number} rotate Degrees to rotate the viewport. If omitted this
|
|
|
|
* defaults to the page rotation.
|
2016-03-29 04:49:22 +09:00
|
|
|
* @return {PageViewport} Contains 'width' and 'height' properties
|
2014-05-06 04:09:47 +09:00
|
|
|
* along with transforms required for rendering.
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2012-05-02 02:48:07 +09:00
|
|
|
getViewport: function PDFPageProxy_getViewport(scale, rotate) {
|
2014-03-14 21:24:04 +09:00
|
|
|
if (arguments.length < 2) {
|
2012-04-13 04:11:22 +09:00
|
|
|
rotate = this.rotate;
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2016-03-29 04:49:22 +09:00
|
|
|
return new PageViewport(this.view, scale, rotate, 0, 0);
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2015-11-22 21:56:52 +09:00
|
|
|
* @param {GetAnnotationsParameters} params - Annotation parameters.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @return {Promise} A promise that is resolved with an {Array} of the
|
2012-04-14 01:25:08 +09:00
|
|
|
* annotation objects.
|
|
|
|
*/
|
2015-11-22 21:56:52 +09:00
|
|
|
getAnnotations: function PDFPageProxy_getAnnotations(params) {
|
|
|
|
var intent = (params && params.intent) || null;
|
|
|
|
|
|
|
|
if (!this.annotationsPromise || this.annotationsIntent !== intent) {
|
|
|
|
this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
|
|
|
|
intent);
|
|
|
|
this.annotationsIntent = intent;
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2015-07-19 00:52:03 +09:00
|
|
|
return this.annotationsPromise;
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* Begins the process of rendering a page to the desired context.
|
2014-04-12 00:57:48 +09:00
|
|
|
* @param {RenderParameters} params Page render parameters.
|
|
|
|
* @return {RenderTask} An object that contains the promise, which
|
|
|
|
* is resolved when the page finishes rendering.
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2012-05-02 02:48:07 +09:00
|
|
|
render: function PDFPageProxy_render(params) {
|
2012-04-13 04:11:22 +09:00
|
|
|
var stats = this.stats;
|
|
|
|
stats.time('Overall');
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2013-08-07 09:35:54 +09:00
|
|
|
// If there was a pending destroy cancel it so no cleanup happens during
|
|
|
|
// this call to render.
|
2015-10-21 07:45:55 +09:00
|
|
|
this.pendingCleanup = false;
|
2013-08-07 09:35:54 +09:00
|
|
|
|
2014-08-01 19:39:31 +09:00
|
|
|
var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
|
2017-01-28 02:58:39 +09:00
|
|
|
var canvasFactory = params.canvasFactory || new DOMCanvasFactory();
|
2014-03-07 23:48:42 +09:00
|
|
|
|
|
|
|
if (!this.intentStates[renderingIntent]) {
|
2016-01-28 02:04:13 +09:00
|
|
|
this.intentStates[renderingIntent] = Object.create(null);
|
2014-03-07 23:48:42 +09:00
|
|
|
}
|
|
|
|
var intentState = this.intentStates[renderingIntent];
|
|
|
|
|
2014-04-30 00:07:05 +09:00
|
|
|
// If there's no displayReadyCapability yet, then the operatorList
|
|
|
|
// was never requested before. Make the request and create the promise.
|
|
|
|
if (!intentState.displayReadyCapability) {
|
2014-03-07 23:48:42 +09:00
|
|
|
intentState.receivingOperatorList = true;
|
2014-04-30 00:07:05 +09:00
|
|
|
intentState.displayReadyCapability = createPromiseCapability();
|
2014-03-07 23:48:42 +09:00
|
|
|
intentState.operatorList = {
|
2013-08-01 03:17:36 +09:00
|
|
|
fnArray: [],
|
|
|
|
argsArray: [],
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
lastChunk: false,
|
2013-08-01 03:17:36 +09:00
|
|
|
};
|
2012-04-13 04:11:22 +09:00
|
|
|
|
|
|
|
this.stats.time('Page Request');
|
|
|
|
this.transport.messageHandler.send('RenderPageRequest', {
|
2014-03-07 23:48:42 +09:00
|
|
|
pageIndex: this.pageNumber - 1,
|
2016-09-15 05:49:37 +09:00
|
|
|
intent: renderingIntent,
|
[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
|
|
|
renderInteractiveForms: (params.renderInteractiveForms === true),
|
2012-04-13 04:11:22 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-03 23:39:54 +09:00
|
|
|
var complete = (error) => {
|
|
|
|
var i = intentState.renderTasks.indexOf(internalRenderTask);
|
|
|
|
if (i >= 0) {
|
|
|
|
intentState.renderTasks.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.cleanupAfterRender) {
|
|
|
|
this.pendingCleanup = true;
|
|
|
|
}
|
|
|
|
this._tryCleanup();
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
internalRenderTask.capability.reject(error);
|
|
|
|
} else {
|
|
|
|
internalRenderTask.capability.resolve();
|
|
|
|
}
|
|
|
|
stats.timeEnd('Rendering');
|
|
|
|
stats.timeEnd('Overall');
|
|
|
|
};
|
|
|
|
|
2013-08-01 03:17:36 +09:00
|
|
|
var internalRenderTask = new InternalRenderTask(complete, params,
|
2014-03-14 21:24:04 +09:00
|
|
|
this.objs,
|
|
|
|
this.commonObjs,
|
|
|
|
intentState.operatorList,
|
2017-01-28 02:58:39 +09:00
|
|
|
this.pageNumber,
|
|
|
|
canvasFactory);
|
2015-05-12 22:44:42 +09:00
|
|
|
internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
|
2014-03-07 23:48:42 +09:00
|
|
|
if (!intentState.renderTasks) {
|
|
|
|
intentState.renderTasks = [];
|
|
|
|
}
|
|
|
|
intentState.renderTasks.push(internalRenderTask);
|
2015-01-06 12:45:01 +09:00
|
|
|
var renderTask = internalRenderTask.task;
|
|
|
|
|
|
|
|
// Obsolete parameter support
|
|
|
|
if (params.continueCallback) {
|
2015-10-21 22:54:31 +09:00
|
|
|
deprecated('render is used with continueCallback parameter');
|
2015-01-06 12:45:01 +09:00
|
|
|
renderTask.onContinue = params.continueCallback;
|
|
|
|
}
|
2012-04-13 04:11:22 +09:00
|
|
|
|
2017-05-03 23:39:54 +09:00
|
|
|
intentState.displayReadyCapability.promise.then((transparency) => {
|
|
|
|
if (this.pendingCleanup) {
|
|
|
|
complete();
|
|
|
|
return;
|
2012-12-01 08:31:22 +09:00
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
stats.time('Rendering');
|
|
|
|
internalRenderTask.initializeGraphics(transparency);
|
|
|
|
internalRenderTask.operatorListChanged();
|
|
|
|
}, complete);
|
2012-04-13 04:11:22 +09:00
|
|
|
|
2013-08-01 03:17:36 +09:00
|
|
|
return renderTask;
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2014-06-17 03:35:38 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {Promise} A promise resolved with an {@link PDFOperatorList}
|
[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
|
|
|
* object that represents page's operator list.
|
2014-06-17 03:35:38 +09:00
|
|
|
*/
|
|
|
|
getOperatorList: function PDFPageProxy_getOperatorList() {
|
|
|
|
function operatorListChanged() {
|
|
|
|
if (intentState.operatorList.lastChunk) {
|
|
|
|
intentState.opListReadCapability.resolve(intentState.operatorList);
|
2016-01-22 21:28:30 +09:00
|
|
|
|
|
|
|
var i = intentState.renderTasks.indexOf(opListTask);
|
|
|
|
if (i >= 0) {
|
|
|
|
intentState.renderTasks.splice(i, 1);
|
|
|
|
}
|
2014-06-17 03:35:38 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var renderingIntent = 'oplist';
|
|
|
|
if (!this.intentStates[renderingIntent]) {
|
2016-01-28 02:04:13 +09:00
|
|
|
this.intentStates[renderingIntent] = Object.create(null);
|
2014-06-17 03:35:38 +09:00
|
|
|
}
|
|
|
|
var intentState = this.intentStates[renderingIntent];
|
2016-01-22 21:28:30 +09:00
|
|
|
var opListTask;
|
2014-06-17 03:35:38 +09:00
|
|
|
|
|
|
|
if (!intentState.opListReadCapability) {
|
2016-01-22 21:28:30 +09:00
|
|
|
opListTask = {};
|
2014-06-17 03:35:38 +09:00
|
|
|
opListTask.operatorListChanged = operatorListChanged;
|
|
|
|
intentState.receivingOperatorList = true;
|
|
|
|
intentState.opListReadCapability = createPromiseCapability();
|
|
|
|
intentState.renderTasks = [];
|
|
|
|
intentState.renderTasks.push(opListTask);
|
|
|
|
intentState.operatorList = {
|
|
|
|
fnArray: [],
|
|
|
|
argsArray: [],
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
lastChunk: false,
|
2014-06-17 03:35:38 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
this.transport.messageHandler.send('RenderPageRequest', {
|
|
|
|
pageIndex: this.pageIndex,
|
[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
|
|
|
intent: renderingIntent,
|
2014-06-17 03:35:38 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return intentState.opListReadCapability.promise;
|
|
|
|
},
|
|
|
|
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2015-11-24 00:57:43 +09:00
|
|
|
* @param {getTextContentParameters} params - getTextContent parameters.
|
2014-04-10 08:44:07 +09:00
|
|
|
* @return {Promise} That is resolved a {@link TextContent}
|
|
|
|
* object that represent the page text content.
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2015-11-24 00:57:43 +09:00
|
|
|
getTextContent: function PDFPageProxy_getTextContent(params) {
|
[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
|
|
|
params = params || {};
|
2014-05-08 08:15:25 +09:00
|
|
|
return this.transport.messageHandler.sendWithPromise('GetTextContent', {
|
2015-11-24 00:57:43 +09:00
|
|
|
pageIndex: this.pageNumber - 1,
|
[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
|
|
|
normalizeWhitespace: (params.normalizeWhitespace === true),
|
|
|
|
combineTextItems: (params.disableCombineTextItems !== true),
|
2014-05-08 08:15:25 +09:00
|
|
|
});
|
2012-04-13 04:11:22 +09:00
|
|
|
},
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2012-04-17 04:13:41 +09:00
|
|
|
/**
|
2015-10-21 07:45:55 +09:00
|
|
|
* Destroys page object.
|
2012-04-17 04:13:41 +09:00
|
|
|
*/
|
2015-10-21 07:45:55 +09:00
|
|
|
_destroy: function PDFPageProxy_destroy() {
|
|
|
|
this.destroyed = true;
|
|
|
|
this.transport.pageCache[this.pageIndex] = null;
|
|
|
|
|
2015-10-21 10:50:32 +09:00
|
|
|
var waitOn = [];
|
2015-10-21 07:45:55 +09:00
|
|
|
Object.keys(this.intentStates).forEach(function(intent) {
|
2016-01-22 21:28:30 +09:00
|
|
|
if (intent === 'oplist') {
|
|
|
|
// Avoid errors below, since the renderTasks are just stubs.
|
|
|
|
return;
|
|
|
|
}
|
2015-10-21 07:45:55 +09:00
|
|
|
var intentState = this.intentStates[intent];
|
|
|
|
intentState.renderTasks.forEach(function(renderTask) {
|
2015-10-21 10:50:32 +09:00
|
|
|
var renderCompleted = renderTask.capability.promise.
|
|
|
|
catch(function () {}); // ignoring failures
|
|
|
|
waitOn.push(renderCompleted);
|
2015-10-21 07:45:55 +09:00
|
|
|
renderTask.cancel();
|
|
|
|
});
|
|
|
|
}, this);
|
|
|
|
this.objs.clear();
|
|
|
|
this.annotationsPromise = null;
|
|
|
|
this.pendingCleanup = false;
|
2015-10-21 10:50:32 +09:00
|
|
|
return Promise.all(waitOn);
|
2015-10-21 07:45:55 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-10-21 22:54:31 +09:00
|
|
|
* Cleans up resources allocated by the page. (deprecated)
|
2015-10-21 07:45:55 +09:00
|
|
|
*/
|
2017-04-25 23:17:18 +09:00
|
|
|
destroy() {
|
2015-10-21 22:54:31 +09:00
|
|
|
deprecated('page destroy method, use cleanup() instead');
|
2015-10-21 07:45:55 +09:00
|
|
|
this.cleanup();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up resources allocated by the page.
|
|
|
|
*/
|
|
|
|
cleanup: function PDFPageProxy_cleanup() {
|
|
|
|
this.pendingCleanup = true;
|
|
|
|
this._tryCleanup();
|
2013-08-01 03:17:36 +09:00
|
|
|
},
|
|
|
|
/**
|
2013-08-07 09:35:54 +09:00
|
|
|
* For internal use only. Attempts to clean up if rendering is in a state
|
|
|
|
* where that's possible.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @ignore
|
2013-08-01 03:17:36 +09:00
|
|
|
*/
|
2015-10-21 07:45:55 +09:00
|
|
|
_tryCleanup: function PDFPageProxy_tryCleanup() {
|
|
|
|
if (!this.pendingCleanup ||
|
2014-03-07 23:48:42 +09:00
|
|
|
Object.keys(this.intentStates).some(function(intent) {
|
|
|
|
var intentState = this.intentStates[intent];
|
2014-03-14 21:24:04 +09:00
|
|
|
return (intentState.renderTasks.length !== 0 ||
|
|
|
|
intentState.receivingOperatorList);
|
2014-03-07 23:48:42 +09:00
|
|
|
}, this)) {
|
2013-08-07 09:35:54 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-07 23:48:42 +09:00
|
|
|
Object.keys(this.intentStates).forEach(function(intent) {
|
|
|
|
delete this.intentStates[intent];
|
|
|
|
}, this);
|
2013-08-01 03:17:36 +09:00
|
|
|
this.objs.clear();
|
2014-05-09 05:02:53 +09:00
|
|
|
this.annotationsPromise = null;
|
2015-10-21 07:45:55 +09:00
|
|
|
this.pendingCleanup = false;
|
2013-08-01 03:17:36 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* For internal use only.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @ignore
|
2013-08-01 03:17:36 +09:00
|
|
|
*/
|
2014-03-07 23:48:42 +09:00
|
|
|
_startRenderPage: function PDFPageProxy_startRenderPage(transparency,
|
|
|
|
intent) {
|
|
|
|
var intentState = this.intentStates[intent];
|
2014-06-17 03:35:38 +09:00
|
|
|
// TODO Refactor RenderPageRequest to separate rendering
|
|
|
|
// and operator list logic
|
|
|
|
if (intentState.displayReadyCapability) {
|
|
|
|
intentState.displayReadyCapability.resolve(transparency);
|
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* For internal use only.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @ignore
|
2013-08-01 03:17:36 +09:00
|
|
|
*/
|
2014-03-07 23:48:42 +09:00
|
|
|
_renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
|
|
|
|
intent) {
|
|
|
|
var intentState = this.intentStates[intent];
|
2014-04-09 04:48:16 +09:00
|
|
|
var i, ii;
|
2013-08-01 03:17:36 +09:00
|
|
|
// Add the new chunk to the current operator list.
|
2014-04-09 04:48:16 +09:00
|
|
|
for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
|
2014-03-07 23:48:42 +09:00
|
|
|
intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
|
|
|
|
intentState.operatorList.argsArray.push(
|
|
|
|
operatorListChunk.argsArray[i]);
|
2013-11-14 04:43:38 +09:00
|
|
|
}
|
2014-03-07 23:48:42 +09:00
|
|
|
intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
|
2013-08-01 03:17:36 +09:00
|
|
|
|
|
|
|
// Notify all the rendering tasks there are more operators to be consumed.
|
2014-04-09 04:48:16 +09:00
|
|
|
for (i = 0; i < intentState.renderTasks.length; i++) {
|
2014-03-07 23:48:42 +09:00
|
|
|
intentState.renderTasks[i].operatorListChanged();
|
2012-04-17 04:49:55 +09:00
|
|
|
}
|
2013-08-07 09:35:54 +09:00
|
|
|
|
|
|
|
if (operatorListChunk.lastChunk) {
|
2014-03-07 23:48:42 +09:00
|
|
|
intentState.receivingOperatorList = false;
|
2015-10-21 07:45:55 +09:00
|
|
|
this._tryCleanup();
|
2013-08-07 09:35:54 +09:00
|
|
|
}
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2012-04-13 04:11:22 +09:00
|
|
|
};
|
|
|
|
return PDFPageProxy;
|
|
|
|
})();
|
2014-01-22 04:28:18 +09:00
|
|
|
|
2017-05-03 02:20:13 +09:00
|
|
|
class LoopbackPort {
|
|
|
|
constructor(defer) {
|
|
|
|
this._listeners = [];
|
|
|
|
this._defer = defer;
|
|
|
|
this._deferred = Promise.resolve(undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
postMessage(obj, transfers) {
|
|
|
|
function cloneValue(value) {
|
|
|
|
// Trying to perform a structured clone close to the spec, including
|
|
|
|
// transfers.
|
|
|
|
if (typeof value !== 'object' || value === null) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
if (cloned.has(value)) { // already cloned the object
|
|
|
|
return cloned.get(value);
|
|
|
|
}
|
|
|
|
var result;
|
|
|
|
var buffer;
|
|
|
|
if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
|
|
|
|
// We found object with ArrayBuffer (typed array).
|
|
|
|
var transferable = transfers && transfers.indexOf(buffer) >= 0;
|
|
|
|
if (value === buffer) {
|
|
|
|
// Special case when we are faking typed arrays in compatibility.js.
|
|
|
|
result = value;
|
|
|
|
} else if (transferable) {
|
|
|
|
result = new value.constructor(buffer, value.byteOffset,
|
|
|
|
value.byteLength);
|
|
|
|
} else {
|
|
|
|
result = new value.constructor(value);
|
|
|
|
}
|
|
|
|
cloned.set(value, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = isArray(value) ? [] : {};
|
|
|
|
cloned.set(value, result); // adding to cache now for cyclic references
|
|
|
|
// Cloning all value and object properties, however ignoring properties
|
|
|
|
// defined via getter.
|
|
|
|
for (var i in value) {
|
|
|
|
var desc, p = value;
|
|
|
|
while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
|
|
|
|
p = Object.getPrototypeOf(p);
|
|
|
|
}
|
|
|
|
if (typeof desc.value === 'undefined' ||
|
|
|
|
typeof desc.value === 'function') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result[i] = cloneValue(desc.value);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._defer) {
|
|
|
|
this._listeners.forEach(function (listener) {
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
listener.call(this, { data: obj, });
|
2017-05-03 02:20:13 +09:00
|
|
|
}, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cloned = new WeakMap();
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
var e = { data: cloneValue(obj), };
|
2017-05-03 23:39:54 +09:00
|
|
|
this._deferred.then(() => {
|
2017-05-03 02:20:13 +09:00
|
|
|
this._listeners.forEach(function (listener) {
|
|
|
|
listener.call(this, e);
|
|
|
|
}, this);
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2017-05-03 02:20:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
addEventListener(name, listener) {
|
|
|
|
this._listeners.push(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeEventListener(name, listener) {
|
|
|
|
var i = this._listeners.indexOf(listener);
|
|
|
|
this._listeners.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
terminate() {
|
|
|
|
this._listeners = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2015-10-28 02:55:15 +09:00
|
|
|
* PDF.js web worker abstraction, it controls instantiation of PDF documents and
|
|
|
|
* WorkerTransport for them. If creation of a web worker is not possible,
|
|
|
|
* a "fake" worker will be used instead.
|
|
|
|
* @class
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2015-10-28 02:55:15 +09:00
|
|
|
var PDFWorker = (function PDFWorkerClosure() {
|
2017-06-10 10:07:51 +09:00
|
|
|
let nextFakeWorkerId = 0;
|
2015-10-28 02:55:15 +09:00
|
|
|
|
2015-12-24 08:46:08 +09:00
|
|
|
function getWorkerSrc() {
|
2016-03-29 04:49:22 +09:00
|
|
|
if (typeof workerSrc !== 'undefined') {
|
|
|
|
return workerSrc;
|
|
|
|
}
|
|
|
|
if (getDefaultSetting('workerSrc')) {
|
|
|
|
return getDefaultSetting('workerSrc');
|
2015-12-24 08:46:08 +09:00
|
|
|
}
|
2016-10-15 00:57:53 +09:00
|
|
|
if (typeof PDFJSDev !== 'undefined' &&
|
|
|
|
PDFJSDev.test('PRODUCTION && !(MOZCENTRAL || FIREFOX)') &&
|
|
|
|
pdfjsFilePath) {
|
2017-04-18 21:07:09 +09:00
|
|
|
return pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, '.worker$1$2');
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2015-12-24 08:46:08 +09:00
|
|
|
error('No PDFJS.workerSrc specified');
|
|
|
|
}
|
|
|
|
|
2017-06-10 10:07:51 +09:00
|
|
|
let fakeWorkerFilesLoadedCapability;
|
2016-03-03 10:16:38 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
// Loads worker code into main thread.
|
|
|
|
function setupFakeWorkerGlobal() {
|
2016-03-03 10:16:38 +09:00
|
|
|
var WorkerMessageHandler;
|
2016-10-15 00:57:53 +09:00
|
|
|
if (fakeWorkerFilesLoadedCapability) {
|
|
|
|
return fakeWorkerFilesLoadedCapability.promise;
|
|
|
|
}
|
|
|
|
fakeWorkerFilesLoadedCapability = createPromiseCapability();
|
|
|
|
// In the developer build load worker_loader which in turn loads all the
|
|
|
|
// other files and resolves the promise. In production only the
|
|
|
|
// pdf.worker.js file is needed.
|
|
|
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
2017-04-02 21:25:33 +09:00
|
|
|
if (typeof SystemJS === 'object') {
|
|
|
|
Promise.all([SystemJS.import('pdfjs/core/network'),
|
|
|
|
SystemJS.import('pdfjs/core/worker')]).then((modules) => {
|
|
|
|
var worker = modules[1];
|
2016-03-03 10:16:38 +09:00
|
|
|
WorkerMessageHandler = worker.WorkerMessageHandler;
|
|
|
|
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
|
2015-11-24 02:46:40 +09:00
|
|
|
});
|
|
|
|
} else if (typeof require === 'function') {
|
2016-03-03 10:16:38 +09:00
|
|
|
var worker = require('../core/worker.js');
|
|
|
|
WorkerMessageHandler = worker.WorkerMessageHandler;
|
|
|
|
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
|
2015-11-24 02:46:40 +09:00
|
|
|
} else {
|
2017-04-02 21:25:33 +09:00
|
|
|
throw new Error(
|
|
|
|
'SystemJS or CommonJS must be used to load fake worker.');
|
2015-11-24 02:46:40 +09:00
|
|
|
}
|
2016-10-15 00:57:53 +09:00
|
|
|
} else if (PDFJSDev.test('SINGLE_FILE')) {
|
2017-02-11 02:24:35 +09:00
|
|
|
var pdfjsCoreWorker = require('../core/worker.js');
|
|
|
|
require('../core/network.js');
|
|
|
|
WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;
|
2016-10-15 00:57:53 +09:00
|
|
|
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
|
|
|
|
} else {
|
|
|
|
var loader = fakeWorkerFilesLoader || function (callback) {
|
|
|
|
Util.loadScript(getWorkerSrc(), function () {
|
|
|
|
callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
loader(fakeWorkerFilesLoadedCapability.resolve);
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
2016-03-03 10:16:38 +09:00
|
|
|
return fakeWorkerFilesLoadedCapability.promise;
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2016-01-16 06:05:46 +09:00
|
|
|
function createCDNWrapper(url) {
|
|
|
|
// We will rely on blob URL's property to specify origin.
|
|
|
|
// We want this function to fail in case if createObjectURL or Blob do not
|
|
|
|
// exist or fail for some reason -- our Worker creation will fail anyway.
|
|
|
|
var wrapper = 'importScripts(\'' + url + '\');';
|
|
|
|
return URL.createObjectURL(new Blob([wrapper]));
|
|
|
|
}
|
|
|
|
|
2017-06-10 10:07:51 +09:00
|
|
|
let pdfWorkerPorts = new WeakMap();
|
|
|
|
|
2017-02-25 04:33:18 +09:00
|
|
|
function PDFWorker(name, port) {
|
2017-06-10 10:07:51 +09:00
|
|
|
if (pdfWorkerPorts.has(port)) {
|
|
|
|
throw new Error('Cannot use more than one PDFWorker per port');
|
|
|
|
}
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
this.name = name;
|
2015-10-21 07:45:55 +09:00
|
|
|
this.destroyed = false;
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
this._readyCapability = createPromiseCapability();
|
|
|
|
this._port = null;
|
|
|
|
this._webWorker = null;
|
|
|
|
this._messageHandler = null;
|
2017-02-25 04:33:18 +09:00
|
|
|
|
|
|
|
if (port) {
|
2017-06-10 10:07:51 +09:00
|
|
|
pdfWorkerPorts.set(port, this);
|
2017-02-25 04:33:18 +09:00
|
|
|
this._initializeFromPort(port);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
this._initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
|
|
|
|
get promise() {
|
|
|
|
return this._readyCapability.promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
get port() {
|
|
|
|
return this._port;
|
|
|
|
},
|
2013-05-10 07:35:23 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
get messageHandler() {
|
|
|
|
return this._messageHandler;
|
|
|
|
},
|
|
|
|
|
2017-02-25 04:33:18 +09:00
|
|
|
_initializeFromPort: function PDFWorker_initializeFromPort(port) {
|
|
|
|
this._port = port;
|
|
|
|
this._messageHandler = new MessageHandler('main', 'worker', port);
|
|
|
|
this._messageHandler.on('ready', function () {
|
|
|
|
// Ignoring 'ready' event -- MessageHandler shall be already initialized
|
|
|
|
// and ready to accept the messages.
|
|
|
|
});
|
|
|
|
this._readyCapability.resolve();
|
|
|
|
},
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
_initialize: function PDFWorker_initialize() {
|
|
|
|
// If worker support isn't disabled explicit and the browser has worker
|
2016-02-11 10:48:56 +09:00
|
|
|
// support, create a new web worker and test if it/the browser fulfills
|
2015-10-28 02:55:15 +09:00
|
|
|
// all requirements to run parts of pdf.js in a web worker.
|
|
|
|
// Right now, the requirement is, that an Uint8Array is still an
|
|
|
|
// Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
|
2016-10-15 00:57:53 +09:00
|
|
|
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('SINGLE_FILE')) &&
|
|
|
|
!isWorkerDisabled && !getDefaultSetting('disableWorker') &&
|
2016-03-29 04:49:22 +09:00
|
|
|
typeof Worker !== 'undefined') {
|
2015-12-24 08:46:08 +09:00
|
|
|
var workerSrc = getWorkerSrc();
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
try {
|
2016-10-15 00:57:53 +09:00
|
|
|
// Wraps workerSrc path into blob URL, if the former does not belong
|
|
|
|
// to the same origin.
|
|
|
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC') &&
|
|
|
|
!isSameOrigin(window.location.href, workerSrc)) {
|
|
|
|
workerSrc = createCDNWrapper(
|
|
|
|
new URL(workerSrc, window.location).href);
|
|
|
|
}
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
// Some versions of FF can't create a worker on localhost, see:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=683280
|
|
|
|
var worker = new Worker(workerSrc);
|
|
|
|
var messageHandler = new MessageHandler('main', 'worker', worker);
|
2017-05-03 23:39:54 +09:00
|
|
|
var terminateEarly = () => {
|
2015-12-25 21:24:19 +09:00
|
|
|
worker.removeEventListener('error', onWorkerError);
|
|
|
|
messageHandler.destroy();
|
|
|
|
worker.terminate();
|
2015-10-28 02:55:15 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
this._readyCapability.reject(new Error('Worker was destroyed'));
|
2015-12-25 21:24:19 +09:00
|
|
|
} else {
|
|
|
|
// Fall back to fake worker if the termination is caused by an
|
|
|
|
// error (e.g. NetworkError / SecurityError).
|
|
|
|
this._setupFakeWorker();
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
};
|
2015-12-25 21:24:19 +09:00
|
|
|
|
2017-05-03 23:39:54 +09:00
|
|
|
var onWorkerError = () => {
|
2015-12-25 21:24:19 +09:00
|
|
|
if (!this._webWorker) {
|
|
|
|
// Worker failed to initialize due to an error. Clean up and fall
|
|
|
|
// back to the fake worker.
|
|
|
|
terminateEarly();
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
};
|
2015-12-25 21:24:19 +09:00
|
|
|
worker.addEventListener('error', onWorkerError);
|
|
|
|
|
2017-05-03 23:39:54 +09:00
|
|
|
messageHandler.on('test', (data) => {
|
2015-12-25 21:24:19 +09:00
|
|
|
worker.removeEventListener('error', onWorkerError);
|
|
|
|
if (this.destroyed) {
|
|
|
|
terminateEarly();
|
2015-10-28 02:55:15 +09:00
|
|
|
return; // worker was destroyed
|
2013-11-12 12:30:26 +09:00
|
|
|
}
|
2015-10-28 02:55:15 +09:00
|
|
|
var supportTypedArray = data && data.supportTypedArray;
|
|
|
|
if (supportTypedArray) {
|
|
|
|
this._messageHandler = messageHandler;
|
|
|
|
this._port = worker;
|
|
|
|
this._webWorker = worker;
|
|
|
|
if (!data.supportTransfers) {
|
2016-03-29 04:49:22 +09:00
|
|
|
isPostMessageTransfersDisabled = true;
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
|
|
|
this._readyCapability.resolve();
|
2016-03-29 04:49:22 +09:00
|
|
|
// Send global setting, e.g. verbosity level.
|
2016-03-04 01:13:37 +09:00
|
|
|
messageHandler.send('configure', {
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
verbosity: getVerbosityLevel(),
|
2016-03-04 01:13:37 +09:00
|
|
|
});
|
2015-10-28 02:55:15 +09:00
|
|
|
} else {
|
|
|
|
this._setupFakeWorker();
|
|
|
|
messageHandler.destroy();
|
|
|
|
worker.terminate();
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2015-10-28 02:55:15 +09:00
|
|
|
|
|
|
|
messageHandler.on('console_log', function (data) {
|
|
|
|
console.log.apply(console, data);
|
|
|
|
});
|
|
|
|
messageHandler.on('console_error', function (data) {
|
|
|
|
console.error.apply(console, data);
|
|
|
|
});
|
|
|
|
|
2017-05-03 23:39:54 +09:00
|
|
|
messageHandler.on('ready', (data) => {
|
2015-12-25 21:24:19 +09:00
|
|
|
worker.removeEventListener('error', onWorkerError);
|
2015-12-17 09:37:43 +09:00
|
|
|
if (this.destroyed) {
|
2015-12-25 21:24:19 +09:00
|
|
|
terminateEarly();
|
2015-12-17 09:37:43 +09:00
|
|
|
return; // worker was destroyed
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
sendTest();
|
2016-12-10 22:28:27 +09:00
|
|
|
} catch (e) {
|
2015-12-17 09:37:43 +09:00
|
|
|
// We need fallback to a faked worker.
|
|
|
|
this._setupFakeWorker();
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2015-12-17 09:37:43 +09:00
|
|
|
|
|
|
|
var sendTest = function () {
|
2016-03-29 04:49:22 +09:00
|
|
|
var postMessageTransfers =
|
|
|
|
getDefaultSetting('postMessageTransfers') &&
|
|
|
|
!isPostMessageTransfersDisabled;
|
|
|
|
var testObj = new Uint8Array([postMessageTransfers ? 255 : 0]);
|
2015-12-17 09:37:43 +09:00
|
|
|
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
|
|
|
|
// typed array. Also, checking if we can use transfers.
|
|
|
|
try {
|
|
|
|
messageHandler.send('test', testObj, [testObj.buffer]);
|
|
|
|
} catch (ex) {
|
|
|
|
info('Cannot use postMessage transfers');
|
|
|
|
testObj[0] = 0;
|
|
|
|
messageHandler.send('test', testObj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// It might take time for worker to initialize (especially when AMD
|
|
|
|
// loader is used). We will try to send test immediately, and then
|
|
|
|
// when 'ready' message will arrive. The worker shall process only
|
|
|
|
// first received 'test'.
|
|
|
|
sendTest();
|
2015-10-28 02:55:15 +09:00
|
|
|
return;
|
|
|
|
} catch (e) {
|
|
|
|
info('The worker has been disabled.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Either workers are disabled, not supported or have thrown an exception.
|
|
|
|
// Thus, we fallback to a faked worker.
|
|
|
|
this._setupFakeWorker();
|
|
|
|
},
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
_setupFakeWorker: function PDFWorker_setupFakeWorker() {
|
2016-03-29 04:49:22 +09:00
|
|
|
if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
|
2015-12-22 04:46:50 +09:00
|
|
|
warn('Setting up fake worker.');
|
2016-03-29 04:49:22 +09:00
|
|
|
isWorkerDisabled = true;
|
2015-12-22 04:46:50 +09:00
|
|
|
}
|
2015-10-28 00:07:20 +09:00
|
|
|
|
2017-05-03 23:39:54 +09:00
|
|
|
setupFakeWorkerGlobal().then((WorkerMessageHandler) => {
|
2015-10-28 02:55:15 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
this._readyCapability.reject(new Error('Worker was destroyed'));
|
|
|
|
return;
|
2013-11-12 12:30:26 +09:00
|
|
|
}
|
2015-10-28 02:55:15 +09:00
|
|
|
|
2016-02-02 04:21:08 +09:00
|
|
|
// We cannot turn on proper fake port simulation (this includes
|
|
|
|
// structured cloning) when typed arrays are not supported. Relying
|
|
|
|
// on a chance that messages will be sent in proper order.
|
|
|
|
var isTypedArraysPresent = Uint8Array !== Float32Array;
|
2017-05-03 02:20:13 +09:00
|
|
|
var port = new LoopbackPort(isTypedArraysPresent);
|
2015-10-28 02:55:15 +09:00
|
|
|
this._port = port;
|
|
|
|
|
|
|
|
// All fake workers use the same port, making id unique.
|
|
|
|
var id = 'fake' + (nextFakeWorkerId++);
|
|
|
|
|
|
|
|
// If the main thread is our worker, setup the handling for the
|
|
|
|
// messages -- the main thread sends to it self.
|
|
|
|
var workerHandler = new MessageHandler(id + '_worker', id, port);
|
2016-03-03 10:16:38 +09:00
|
|
|
WorkerMessageHandler.setup(workerHandler, port);
|
2015-10-28 02:55:15 +09:00
|
|
|
|
|
|
|
var messageHandler = new MessageHandler(id, id + '_worker', port);
|
|
|
|
this._messageHandler = messageHandler;
|
|
|
|
this._readyCapability.resolve();
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2015-10-28 02:55:15 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the worker instance.
|
|
|
|
*/
|
|
|
|
destroy: function PDFWorker_destroy() {
|
|
|
|
this.destroyed = true;
|
|
|
|
if (this._webWorker) {
|
|
|
|
// We need to terminate only web worker created resource.
|
|
|
|
this._webWorker.terminate();
|
|
|
|
this._webWorker = null;
|
|
|
|
}
|
|
|
|
this._port = null;
|
|
|
|
if (this._messageHandler) {
|
|
|
|
this._messageHandler.destroy();
|
|
|
|
this._messageHandler = null;
|
2012-04-12 07:52:15 +09:00
|
|
|
}
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2015-10-28 02:55:15 +09:00
|
|
|
};
|
|
|
|
|
2017-06-10 10:07:51 +09:00
|
|
|
PDFWorker.fromPort = function (port) {
|
|
|
|
if (pdfWorkerPorts.has(port)) {
|
|
|
|
return pdfWorkerPorts.get(port);
|
|
|
|
}
|
|
|
|
return new PDFWorker(null, port);
|
|
|
|
};
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
return PDFWorker;
|
|
|
|
})();
|
|
|
|
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* For internal use only.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @ignore
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
var WorkerTransport = (function WorkerTransportClosure() {
|
2017-02-12 23:54:41 +09:00
|
|
|
function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport,
|
|
|
|
CMapReaderFactory) {
|
2015-10-28 02:55:15 +09:00
|
|
|
this.messageHandler = messageHandler;
|
|
|
|
this.loadingTask = loadingTask;
|
2013-02-07 08:19:29 +09:00
|
|
|
this.pdfDataRangeTransport = pdfDataRangeTransport;
|
2012-10-29 05:10:34 +09:00
|
|
|
this.commonObjs = new PDFObjects();
|
2015-10-28 07:48:10 +09:00
|
|
|
this.fontLoader = new FontLoader(loadingTask.docId);
|
2017-02-12 23:54:41 +09:00
|
|
|
this.CMapReaderFactory = new CMapReaderFactory({
|
|
|
|
baseUrl: getDefaultSetting('cMapUrl'),
|
|
|
|
isCompressed: getDefaultSetting('cMapPacked'),
|
|
|
|
});
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2015-10-21 07:45:55 +09:00
|
|
|
this.destroyed = false;
|
|
|
|
this.destroyCapability = null;
|
2016-12-31 21:59:07 +09:00
|
|
|
this._passwordCapability = null;
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2012-04-12 07:52:15 +09:00
|
|
|
this.pageCache = [];
|
2014-05-09 05:02:53 +09:00
|
|
|
this.pagePromises = [];
|
2014-04-30 00:07:05 +09:00
|
|
|
this.downloadInfoCapability = createPromiseCapability();
|
2013-05-10 07:35:23 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
this.setupMessageHandler();
|
2012-04-12 07:52:15 +09:00
|
|
|
}
|
|
|
|
WorkerTransport.prototype = {
|
2012-04-12 09:09:55 +09:00
|
|
|
destroy: function WorkerTransport_destroy() {
|
2015-10-21 07:45:55 +09:00
|
|
|
if (this.destroyCapability) {
|
|
|
|
return this.destroyCapability.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.destroyed = true;
|
|
|
|
this.destroyCapability = createPromiseCapability();
|
|
|
|
|
2016-12-31 21:59:07 +09:00
|
|
|
if (this._passwordCapability) {
|
|
|
|
this._passwordCapability.reject(
|
|
|
|
new Error('Worker was destroyed during onPassword callback'));
|
|
|
|
}
|
|
|
|
|
2015-10-21 10:50:32 +09:00
|
|
|
var waitOn = [];
|
|
|
|
// We need to wait for all renderings to be completed, e.g.
|
|
|
|
// timeout/rAF can take a long time.
|
2015-10-21 07:45:55 +09:00
|
|
|
this.pageCache.forEach(function (page) {
|
|
|
|
if (page) {
|
2015-10-21 10:50:32 +09:00
|
|
|
waitOn.push(page._destroy());
|
2015-10-21 07:45:55 +09:00
|
|
|
}
|
|
|
|
});
|
2012-04-13 02:01:07 +09:00
|
|
|
this.pageCache = [];
|
2014-05-09 05:02:53 +09:00
|
|
|
this.pagePromises = [];
|
2015-10-21 10:50:32 +09:00
|
|
|
// We also need to wait for the worker to finish its long running tasks.
|
|
|
|
var terminated = this.messageHandler.sendWithPromise('Terminate', null);
|
|
|
|
waitOn.push(terminated);
|
2017-05-03 23:39:54 +09:00
|
|
|
Promise.all(waitOn).then(() => {
|
|
|
|
this.fontLoader.clear();
|
|
|
|
if (this.pdfDataRangeTransport) {
|
|
|
|
this.pdfDataRangeTransport.abort();
|
|
|
|
this.pdfDataRangeTransport = null;
|
2015-10-21 07:45:55 +09:00
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
if (this.messageHandler) {
|
|
|
|
this.messageHandler.destroy();
|
|
|
|
this.messageHandler = null;
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
this.destroyCapability.resolve();
|
2015-10-21 07:45:55 +09:00
|
|
|
}, this.destroyCapability.reject);
|
|
|
|
return this.destroyCapability.promise;
|
2012-04-12 09:09:55 +09:00
|
|
|
},
|
2013-08-13 02:48:06 +09:00
|
|
|
|
2016-12-31 21:59:07 +09:00
|
|
|
setupMessageHandler: function WorkerTransport_setupMessageHandler() {
|
2015-10-28 02:55:15 +09:00
|
|
|
var messageHandler = this.messageHandler;
|
2016-12-31 21:59:07 +09:00
|
|
|
var loadingTask = this.loadingTask;
|
2013-05-10 07:35:23 +09:00
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
var pdfDataRangeTransport = this.pdfDataRangeTransport;
|
|
|
|
if (pdfDataRangeTransport) {
|
2013-04-20 05:53:22 +09:00
|
|
|
pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
|
2013-02-07 08:19:29 +09:00
|
|
|
messageHandler.send('OnDataRange', {
|
2017-04-25 23:17:18 +09:00
|
|
|
begin,
|
|
|
|
chunk,
|
2013-02-07 08:19:29 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-04-20 05:53:22 +09:00
|
|
|
pdfDataRangeTransport.addProgressListener(function(loaded) {
|
|
|
|
messageHandler.send('OnDataProgress', {
|
2017-04-25 23:17:18 +09:00
|
|
|
loaded,
|
2013-04-20 05:53:22 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-06 10:02:54 +09:00
|
|
|
pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
|
|
|
|
messageHandler.send('OnDataRange', {
|
2017-04-25 23:17:18 +09:00
|
|
|
chunk,
|
2014-09-06 10:02:54 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
messageHandler.on('RequestDataRange',
|
|
|
|
function transportDataRange(data) {
|
|
|
|
pdfDataRangeTransport.requestDataRange(data.begin, data.end);
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
2012-04-13 04:11:22 +09:00
|
|
|
messageHandler.on('GetDoc', function transportDoc(data) {
|
2012-04-12 07:52:15 +09:00
|
|
|
var pdfInfo = data.pdfInfo;
|
2014-02-24 03:16:14 +09:00
|
|
|
this.numPages = data.pdfInfo.numPages;
|
2015-10-21 07:45:55 +09:00
|
|
|
var loadingTask = this.loadingTask;
|
|
|
|
var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
|
2012-04-12 07:52:15 +09:00
|
|
|
this.pdfDocument = pdfDocument;
|
2015-10-21 07:45:55 +09:00
|
|
|
loadingTask._capability.resolve(pdfDocument);
|
2012-04-12 07:52:15 +09:00
|
|
|
}, this);
|
|
|
|
|
2016-12-31 21:59:07 +09:00
|
|
|
messageHandler.on('PasswordRequest',
|
|
|
|
function transportPasswordRequest(exception) {
|
|
|
|
this._passwordCapability = createPromiseCapability();
|
|
|
|
|
2015-01-06 12:45:01 +09:00
|
|
|
if (loadingTask.onPassword) {
|
2017-04-25 23:17:18 +09:00
|
|
|
var updatePassword = (password) => {
|
2016-12-31 21:59:07 +09:00
|
|
|
this._passwordCapability.resolve({
|
2017-04-25 23:17:18 +09:00
|
|
|
password,
|
2016-12-31 21:59:07 +09:00
|
|
|
});
|
2017-04-25 23:17:18 +09:00
|
|
|
};
|
2016-12-31 21:59:07 +09:00
|
|
|
loadingTask.onPassword(updatePassword, exception.code);
|
|
|
|
} else {
|
|
|
|
this._passwordCapability.reject(
|
|
|
|
new PasswordException(exception.message, exception.code));
|
2013-05-10 07:35:23 +09:00
|
|
|
}
|
2016-12-31 21:59:07 +09:00
|
|
|
return this._passwordCapability.promise;
|
2012-05-15 03:45:07 +09:00
|
|
|
}, this);
|
|
|
|
|
2016-12-31 21:59:07 +09:00
|
|
|
messageHandler.on('PasswordException',
|
|
|
|
function transportPasswordException(exception) {
|
2015-01-06 12:45:01 +09:00
|
|
|
loadingTask._capability.reject(
|
2014-08-23 23:03:49 +09:00
|
|
|
new PasswordException(exception.message, exception.code));
|
2012-05-15 03:45:07 +09:00
|
|
|
}, this);
|
|
|
|
|
2014-08-23 23:03:49 +09:00
|
|
|
messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
|
2015-01-06 12:45:01 +09:00
|
|
|
this.loadingTask._capability.reject(
|
2014-08-23 23:03:49 +09:00
|
|
|
new InvalidPDFException(exception.message));
|
2012-10-16 19:10:37 +09:00
|
|
|
}, this);
|
|
|
|
|
2014-08-23 23:03:49 +09:00
|
|
|
messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
|
2015-01-06 12:45:01 +09:00
|
|
|
this.loadingTask._capability.reject(
|
2014-08-23 23:03:49 +09:00
|
|
|
new MissingPDFException(exception.message));
|
2013-01-30 03:13:28 +09:00
|
|
|
}, this);
|
|
|
|
|
2014-09-13 23:47:16 +09:00
|
|
|
messageHandler.on('UnexpectedResponse',
|
|
|
|
function transportUnexpectedResponse(exception) {
|
2015-01-06 12:45:01 +09:00
|
|
|
this.loadingTask._capability.reject(
|
2014-09-13 23:47:16 +09:00
|
|
|
new UnexpectedResponseException(exception.message, exception.status));
|
|
|
|
}, this);
|
|
|
|
|
2014-08-23 23:03:49 +09:00
|
|
|
messageHandler.on('UnknownError',
|
|
|
|
function transportUnknownError(exception) {
|
2015-01-06 12:45:01 +09:00
|
|
|
this.loadingTask._capability.reject(
|
2014-08-23 23:03:49 +09:00
|
|
|
new UnknownErrorException(exception.message, exception.details));
|
2012-10-16 19:10:37 +09:00
|
|
|
}, this);
|
|
|
|
|
2014-01-29 06:13:47 +09:00
|
|
|
messageHandler.on('DataLoaded', function transportPage(data) {
|
2014-04-30 00:07:05 +09:00
|
|
|
this.downloadInfoCapability.resolve(data);
|
2014-01-29 06:13:47 +09:00
|
|
|
}, this);
|
|
|
|
|
2014-09-06 10:02:54 +09:00
|
|
|
messageHandler.on('PDFManagerReady', function transportPage(data) {
|
|
|
|
if (this.pdfDataRangeTransport) {
|
|
|
|
this.pdfDataRangeTransport.transportReady();
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
2013-08-01 03:17:36 +09:00
|
|
|
messageHandler.on('StartRenderPage', function transportRender(data) {
|
2015-10-24 03:44:18 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
2012-04-13 02:01:07 +09:00
|
|
|
var page = this.pageCache[data.pageIndex];
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2012-04-13 02:01:07 +09:00
|
|
|
page.stats.timeEnd('Page Request');
|
2014-03-07 23:48:42 +09:00
|
|
|
page._startRenderPage(data.transparency, data.intent);
|
2013-08-01 03:17:36 +09:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
messageHandler.on('RenderPageChunk', function transportRender(data) {
|
2015-10-24 03:44:18 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
var page = this.pageCache[data.pageIndex];
|
|
|
|
|
2014-03-07 23:48:42 +09:00
|
|
|
page._renderPageChunk(data.operatorList, data.intent);
|
2012-04-12 07:52:15 +09:00
|
|
|
}, this);
|
|
|
|
|
2012-10-29 05:10:34 +09:00
|
|
|
messageHandler.on('commonobj', function transportObj(data) {
|
2015-10-30 03:06:22 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
|
2012-04-12 07:52:15 +09:00
|
|
|
var id = data[0];
|
|
|
|
var type = data[1];
|
2014-03-14 21:24:04 +09:00
|
|
|
if (this.commonObjs.hasData(id)) {
|
2012-04-17 08:44:51 +09:00
|
|
|
return;
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'Font':
|
2012-09-13 09:31:04 +09:00
|
|
|
var exportedData = data[2];
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2013-08-01 03:17:36 +09:00
|
|
|
if ('error' in exportedData) {
|
2016-04-22 17:02:17 +09:00
|
|
|
var exportedError = exportedData.error;
|
|
|
|
warn('Error during font loading: ' + exportedError);
|
|
|
|
this.commonObjs.resolve(id, exportedError);
|
2013-08-01 03:17:36 +09:00
|
|
|
break;
|
|
|
|
}
|
2016-04-22 17:02:17 +09:00
|
|
|
var fontRegistry = null;
|
|
|
|
if (getDefaultSetting('pdfBug') && globalScope.FontInspector &&
|
|
|
|
globalScope['FontInspector'].enabled) {
|
|
|
|
fontRegistry = {
|
2017-04-25 23:17:18 +09:00
|
|
|
registerFont(font, url) {
|
2016-04-22 17:02:17 +09:00
|
|
|
globalScope['FontInspector'].fontAdded(font, url);
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2016-04-22 17:02:17 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
var font = new FontFaceObject(exportedData, {
|
|
|
|
isEvalSuported: getDefaultSetting('isEvalSupported'),
|
|
|
|
disableFontFace: getDefaultSetting('disableFontFace'),
|
2017-04-25 23:17:18 +09:00
|
|
|
fontRegistry,
|
2016-04-22 17:02:17 +09:00
|
|
|
});
|
2017-05-03 23:39:54 +09:00
|
|
|
var fontReady = (fontObjs) => {
|
|
|
|
this.commonObjs.resolve(id, font);
|
|
|
|
};
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2017-05-03 23:39:54 +09:00
|
|
|
this.fontLoader.bind([font], fontReady);
|
2012-10-29 05:10:34 +09:00
|
|
|
break;
|
2013-08-20 08:33:20 +09:00
|
|
|
case 'FontPath':
|
|
|
|
this.commonObjs.resolve(id, data[2]);
|
|
|
|
break;
|
2012-10-29 05:10:34 +09:00
|
|
|
default:
|
|
|
|
error('Got unknown common object type ' + type);
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
messageHandler.on('obj', function transportObj(data) {
|
2015-10-30 03:06:22 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
|
2012-10-29 05:10:34 +09:00
|
|
|
var id = data[0];
|
|
|
|
var pageIndex = data[1];
|
|
|
|
var type = data[2];
|
|
|
|
var pageProxy = this.pageCache[pageIndex];
|
2014-04-09 04:48:16 +09:00
|
|
|
var imageData;
|
2014-03-07 23:48:42 +09:00
|
|
|
if (pageProxy.objs.hasData(id)) {
|
2012-10-29 05:10:34 +09:00
|
|
|
return;
|
2014-03-07 23:48:42 +09:00
|
|
|
}
|
2012-10-29 05:10:34 +09:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'JpegStream':
|
2014-04-09 04:48:16 +09:00
|
|
|
imageData = data[3];
|
2012-10-29 05:10:34 +09:00
|
|
|
loadJpegStream(id, imageData, pageProxy.objs);
|
|
|
|
break;
|
|
|
|
case 'Image':
|
2014-04-09 04:48:16 +09:00
|
|
|
imageData = data[3];
|
2012-10-29 05:10:34 +09:00
|
|
|
pageProxy.objs.resolve(id, imageData);
|
|
|
|
|
|
|
|
// heuristics that will allow not to store large data
|
|
|
|
var MAX_IMAGE_SIZE_TO_STORE = 8000000;
|
2014-04-15 05:22:35 +09:00
|
|
|
if (imageData && 'data' in imageData &&
|
2012-10-29 05:10:34 +09:00
|
|
|
imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
|
|
|
|
pageProxy.cleanupAfterRender = true;
|
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-29 05:10:34 +09:00
|
|
|
error('Got unknown object type ' + type);
|
2012-04-12 07:52:15 +09:00
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
2012-06-24 04:48:33 +09:00
|
|
|
messageHandler.on('DocProgress', function transportDocProgress(data) {
|
2015-10-30 03:06:22 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
|
2015-01-06 12:45:01 +09:00
|
|
|
var loadingTask = this.loadingTask;
|
|
|
|
if (loadingTask.onProgress) {
|
|
|
|
loadingTask.onProgress({
|
2013-06-15 23:04:54 +09:00
|
|
|
loaded: data.loaded,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
total: data.total,
|
2013-06-15 23:04:54 +09:00
|
|
|
});
|
|
|
|
}
|
2012-06-24 04:48:33 +09:00
|
|
|
}, this);
|
|
|
|
|
2014-05-08 08:15:25 +09:00
|
|
|
messageHandler.on('PageError', function transportError(data) {
|
2015-10-30 03:06:22 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
|
2012-04-13 07:14:18 +09:00
|
|
|
var page = this.pageCache[data.pageNum - 1];
|
2014-05-08 08:15:25 +09:00
|
|
|
var intentState = page.intentStates[data.intent];
|
2016-03-11 22:59:09 +09:00
|
|
|
|
2014-08-14 03:59:28 +09:00
|
|
|
if (intentState.displayReadyCapability) {
|
2014-04-30 00:07:05 +09:00
|
|
|
intentState.displayReadyCapability.reject(data.error);
|
2014-03-14 21:24:04 +09:00
|
|
|
} else {
|
2012-04-12 07:52:15 +09:00
|
|
|
error(data.error);
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2016-03-11 22:59:09 +09:00
|
|
|
|
|
|
|
if (intentState.operatorList) {
|
|
|
|
// Mark operator list as complete.
|
|
|
|
intentState.operatorList.lastChunk = true;
|
|
|
|
for (var i = 0; i < intentState.renderTasks.length; i++) {
|
|
|
|
intentState.renderTasks[i].operatorListChanged();
|
|
|
|
}
|
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
}, this);
|
|
|
|
|
2015-12-01 05:42:47 +09:00
|
|
|
messageHandler.on('UnsupportedFeature',
|
|
|
|
function transportUnsupportedFeature(data) {
|
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
var featureId = data.featureId;
|
|
|
|
var loadingTask = this.loadingTask;
|
|
|
|
if (loadingTask.onUnsupportedFeature) {
|
|
|
|
loadingTask.onUnsupportedFeature(featureId);
|
|
|
|
}
|
2016-03-29 04:49:22 +09:00
|
|
|
_UnsupportedManager.notify(featureId);
|
2015-12-01 05:42:47 +09:00
|
|
|
}, this);
|
|
|
|
|
2014-05-08 08:15:25 +09:00
|
|
|
messageHandler.on('JpegDecode', function(data) {
|
2015-10-30 03:06:22 +09:00
|
|
|
if (this.destroyed) {
|
2016-09-05 21:43:16 +09:00
|
|
|
return Promise.reject(new Error('Worker was destroyed'));
|
2015-10-30 03:06:22 +09:00
|
|
|
}
|
|
|
|
|
2017-01-28 02:58:39 +09:00
|
|
|
if (typeof document === 'undefined') {
|
|
|
|
// Make sure that this code is not executing in node.js, as
|
|
|
|
// it's using DOM image, and there is no library to support that.
|
|
|
|
return Promise.reject(new Error('"document" is not defined.'));
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:25:03 +09:00
|
|
|
var imageUrl = data[0];
|
2012-04-12 07:52:15 +09:00
|
|
|
var components = data[1];
|
2014-08-01 19:39:31 +09:00
|
|
|
if (components !== 3 && components !== 1) {
|
2014-05-08 08:15:25 +09:00
|
|
|
return Promise.reject(
|
2014-05-09 05:02:53 +09:00
|
|
|
new Error('Only 3 components or 1 component can be returned'));
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2014-05-08 08:15:25 +09:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
var img = new Image();
|
|
|
|
img.onload = function () {
|
|
|
|
var width = img.width;
|
|
|
|
var height = img.height;
|
|
|
|
var size = width * height;
|
|
|
|
var rgbaLength = size * 4;
|
|
|
|
var buf = new Uint8Array(size * components);
|
2017-01-28 02:58:39 +09:00
|
|
|
var tmpCanvas = document.createElement('canvas');
|
|
|
|
tmpCanvas.width = width;
|
|
|
|
tmpCanvas.height = height;
|
2014-05-08 08:15:25 +09:00
|
|
|
var tmpCtx = tmpCanvas.getContext('2d');
|
|
|
|
tmpCtx.drawImage(img, 0, 0);
|
|
|
|
var data = tmpCtx.getImageData(0, 0, width, height).data;
|
|
|
|
var i, j;
|
|
|
|
|
2014-08-01 19:39:31 +09:00
|
|
|
if (components === 3) {
|
2014-05-08 08:15:25 +09:00
|
|
|
for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
|
|
|
|
buf[j] = data[i];
|
|
|
|
buf[j + 1] = data[i + 1];
|
|
|
|
buf[j + 2] = data[i + 2];
|
|
|
|
}
|
2014-08-01 19:39:31 +09:00
|
|
|
} else if (components === 1) {
|
2014-05-08 08:15:25 +09:00
|
|
|
for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
|
|
|
|
buf[j] = data[i];
|
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
}
|
2017-04-25 23:17:18 +09:00
|
|
|
resolve({ data: buf, width, height, });
|
2014-05-08 08:15:25 +09:00
|
|
|
};
|
|
|
|
img.onerror = function () {
|
|
|
|
reject(new Error('JpegDecode failed to load image'));
|
|
|
|
};
|
|
|
|
img.src = imageUrl;
|
|
|
|
});
|
2015-10-30 03:06:22 +09:00
|
|
|
}, this);
|
2017-02-12 23:54:41 +09:00
|
|
|
|
|
|
|
messageHandler.on('FetchBuiltInCMap', function (data) {
|
|
|
|
if (this.destroyed) {
|
|
|
|
return Promise.reject(new Error('Worker was destroyed'));
|
|
|
|
}
|
|
|
|
return this.CMapReaderFactory.fetch({
|
|
|
|
name: data.name,
|
|
|
|
});
|
|
|
|
}, this);
|
2012-04-12 07:52:15 +09:00
|
|
|
},
|
|
|
|
|
2014-05-14 08:20:21 +09:00
|
|
|
getData: function WorkerTransport_getData() {
|
|
|
|
return this.messageHandler.sendWithPromise('GetData', null);
|
2012-06-02 06:17:09 +09:00
|
|
|
},
|
|
|
|
|
2014-04-30 00:07:05 +09:00
|
|
|
getPage: function WorkerTransport_getPage(pageNumber, capability) {
|
2016-09-05 21:43:16 +09:00
|
|
|
if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
|
2014-05-08 06:25:24 +09:00
|
|
|
return Promise.reject(new Error('Invalid page request'));
|
2014-02-24 03:16:14 +09:00
|
|
|
}
|
|
|
|
|
2012-04-13 02:01:07 +09:00
|
|
|
var pageIndex = pageNumber - 1;
|
2014-05-09 05:02:53 +09:00
|
|
|
if (pageIndex in this.pagePromises) {
|
|
|
|
return this.pagePromises[pageIndex];
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2014-05-09 05:02:53 +09:00
|
|
|
var promise = this.messageHandler.sendWithPromise('GetPage', {
|
2017-04-25 23:17:18 +09:00
|
|
|
pageIndex,
|
2017-05-03 23:39:54 +09:00
|
|
|
}).then((pageInfo) => {
|
2015-10-21 07:45:55 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
throw new Error('Transport destroyed');
|
|
|
|
}
|
2014-05-09 05:02:53 +09:00
|
|
|
var page = new PDFPageProxy(pageIndex, pageInfo, this);
|
|
|
|
this.pageCache[pageIndex] = page;
|
|
|
|
return page;
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2014-05-09 05:02:53 +09:00
|
|
|
this.pagePromises[pageIndex] = promise;
|
|
|
|
return promise;
|
2012-04-15 05:54:31 +09:00
|
|
|
},
|
|
|
|
|
2013-11-14 08:27:46 +09:00
|
|
|
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
|
2016-09-05 21:43:16 +09:00
|
|
|
return this.messageHandler.sendWithPromise('GetPageIndex', {
|
2017-04-25 23:17:18 +09:00
|
|
|
ref,
|
2016-09-05 21:43:16 +09:00
|
|
|
}).catch(function (reason) {
|
|
|
|
return Promise.reject(new Error(reason));
|
|
|
|
});
|
2013-11-14 08:27:46 +09:00
|
|
|
},
|
|
|
|
|
2015-11-22 21:56:52 +09:00
|
|
|
getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
|
|
|
|
return this.messageHandler.sendWithPromise('GetAnnotations', {
|
2017-04-25 23:17:18 +09:00
|
|
|
pageIndex,
|
|
|
|
intent,
|
2015-11-22 21:56:52 +09:00
|
|
|
});
|
2013-02-07 08:19:29 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
getDestinations: function WorkerTransport_getDestinations() {
|
2014-05-08 08:15:25 +09:00
|
|
|
return this.messageHandler.sendWithPromise('GetDestinations', null);
|
2013-11-15 06:43:38 +09:00
|
|
|
},
|
|
|
|
|
2014-10-05 22:56:40 +09:00
|
|
|
getDestination: function WorkerTransport_getDestination(id) {
|
2017-04-25 23:17:18 +09:00
|
|
|
return this.messageHandler.sendWithPromise('GetDestination', {
|
|
|
|
id,
|
|
|
|
});
|
2014-10-05 22:56:40 +09:00
|
|
|
},
|
|
|
|
|
2015-12-26 05:57:08 +09:00
|
|
|
getPageLabels: function WorkerTransport_getPageLabels() {
|
|
|
|
return this.messageHandler.sendWithPromise('GetPageLabels', null);
|
|
|
|
},
|
|
|
|
|
2014-03-19 05:32:47 +09:00
|
|
|
getAttachments: function WorkerTransport_getAttachments() {
|
2014-05-08 08:15:25 +09:00
|
|
|
return this.messageHandler.sendWithPromise('GetAttachments', null);
|
2014-03-19 05:32:47 +09:00
|
|
|
},
|
|
|
|
|
2014-05-08 04:15:34 +09:00
|
|
|
getJavaScript: function WorkerTransport_getJavaScript() {
|
2014-05-08 08:15:25 +09:00
|
|
|
return this.messageHandler.sendWithPromise('GetJavaScript', null);
|
2014-05-08 04:15:34 +09:00
|
|
|
},
|
|
|
|
|
2014-05-08 04:06:44 +09:00
|
|
|
getOutline: function WorkerTransport_getOutline() {
|
2014-05-08 08:15:25 +09:00
|
|
|
return this.messageHandler.sendWithPromise('GetOutline', null);
|
2014-05-08 04:06:44 +09:00
|
|
|
},
|
|
|
|
|
2014-05-08 04:38:40 +09:00
|
|
|
getMetadata: function WorkerTransport_getMetadata() {
|
2014-05-08 08:15:25 +09:00
|
|
|
return this.messageHandler.sendWithPromise('GetMetadata', null).
|
|
|
|
then(function transportMetadata(results) {
|
|
|
|
return {
|
|
|
|
info: results[0],
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
metadata: (results[1] ? new Metadata(results[1]) : null),
|
2014-05-08 08:15:25 +09:00
|
|
|
};
|
|
|
|
});
|
2014-05-08 04:38:40 +09:00
|
|
|
},
|
|
|
|
|
2014-06-16 23:52:04 +09:00
|
|
|
getStats: function WorkerTransport_getStats() {
|
|
|
|
return this.messageHandler.sendWithPromise('GetStats', null);
|
|
|
|
},
|
|
|
|
|
2013-11-15 06:43:38 +09:00
|
|
|
startCleanup: function WorkerTransport_startCleanup() {
|
2017-05-03 23:39:54 +09:00
|
|
|
this.messageHandler.sendWithPromise('Cleanup', null).then(() => {
|
2014-05-08 08:15:25 +09:00
|
|
|
for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
|
|
|
|
var page = this.pageCache[i];
|
|
|
|
if (page) {
|
2015-10-21 07:45:55 +09:00
|
|
|
page.cleanup();
|
2013-11-15 06:43:38 +09:00
|
|
|
}
|
2014-05-08 08:15:25 +09:00
|
|
|
}
|
|
|
|
this.commonObjs.clear();
|
2015-10-28 07:48:10 +09:00
|
|
|
this.fontLoader.clear();
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2012-04-12 07:52:15 +09:00
|
|
|
};
|
2012-04-13 04:11:22 +09:00
|
|
|
return WorkerTransport;
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2012-04-10 14:20:57 +09:00
|
|
|
})();
|
2013-08-01 03:17:36 +09:00
|
|
|
|
|
|
|
/**
|
2013-08-13 02:48:06 +09:00
|
|
|
* A PDF document and page is built of many objects. E.g. there are objects
|
|
|
|
* for fonts, images, rendering code and such. These objects might get processed
|
|
|
|
* inside of a worker. The `PDFObjects` implements some basic functions to
|
|
|
|
* manage these objects.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @ignore
|
2013-08-13 02:48:06 +09:00
|
|
|
*/
|
|
|
|
var PDFObjects = (function PDFObjectsClosure() {
|
|
|
|
function PDFObjects() {
|
2016-01-28 02:04:13 +09:00
|
|
|
this.objs = Object.create(null);
|
2013-08-13 02:48:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
PDFObjects.prototype = {
|
|
|
|
/**
|
|
|
|
* Internal function.
|
|
|
|
* Ensures there is an object defined for `objId`.
|
|
|
|
*/
|
|
|
|
ensureObj: function PDFObjects_ensureObj(objId) {
|
2014-03-14 21:24:04 +09:00
|
|
|
if (this.objs[objId]) {
|
2013-08-13 02:48:06 +09:00
|
|
|
return this.objs[objId];
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2013-08-13 02:48:06 +09:00
|
|
|
|
|
|
|
var obj = {
|
2014-04-30 00:07:05 +09:00
|
|
|
capability: createPromiseCapability(),
|
2013-08-13 02:48:06 +09:00
|
|
|
data: null,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
resolved: false,
|
2013-08-13 02:48:06 +09:00
|
|
|
};
|
|
|
|
this.objs[objId] = obj;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If called *without* callback, this returns the data of `objId` but the
|
|
|
|
* object needs to be resolved. If it isn't, this function throws.
|
|
|
|
*
|
|
|
|
* If called *with* a callback, the callback is called with the data of the
|
|
|
|
* object once the object is resolved. That means, if you call this
|
|
|
|
* function and the object is already resolved, the callback gets called
|
|
|
|
* right away.
|
|
|
|
*/
|
|
|
|
get: function PDFObjects_get(objId, callback) {
|
|
|
|
// If there is a callback, then the get can be async and the object is
|
|
|
|
// not required to be resolved right now
|
|
|
|
if (callback) {
|
2014-04-30 00:07:05 +09:00
|
|
|
this.ensureObj(objId).capability.promise.then(callback);
|
2013-08-13 02:48:06 +09:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there isn't a callback, the user expects to get the resolved data
|
|
|
|
// directly.
|
|
|
|
var obj = this.objs[objId];
|
|
|
|
|
|
|
|
// If there isn't an object yet or the object isn't resolved, then the
|
|
|
|
// data isn't ready yet!
|
2014-03-14 21:24:04 +09:00
|
|
|
if (!obj || !obj.resolved) {
|
2013-08-13 02:48:06 +09:00
|
|
|
error('Requesting object that isn\'t resolved yet ' + objId);
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2013-08-13 02:48:06 +09:00
|
|
|
|
|
|
|
return obj.data;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves the object `objId` with optional `data`.
|
|
|
|
*/
|
|
|
|
resolve: function PDFObjects_resolve(objId, data) {
|
|
|
|
var obj = this.ensureObj(objId);
|
|
|
|
|
|
|
|
obj.resolved = true;
|
|
|
|
obj.data = data;
|
2014-04-30 00:07:05 +09:00
|
|
|
obj.capability.resolve(data);
|
2013-08-13 02:48:06 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
isResolved: function PDFObjects_isResolved(objId) {
|
|
|
|
var objs = this.objs;
|
|
|
|
|
|
|
|
if (!objs[objId]) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-16 21:05:33 +09:00
|
|
|
return objs[objId].resolved;
|
2013-08-13 02:48:06 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
hasData: function PDFObjects_hasData(objId) {
|
|
|
|
return this.isResolved(objId);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the data of `objId` if object exists, null otherwise.
|
|
|
|
*/
|
|
|
|
getData: function PDFObjects_getData(objId) {
|
|
|
|
var objs = this.objs;
|
|
|
|
if (!objs[objId] || !objs[objId].resolved) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-12-16 21:05:33 +09:00
|
|
|
return objs[objId].data;
|
2013-08-13 02:48:06 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
clear: function PDFObjects_clear() {
|
2016-01-28 02:04:13 +09:00
|
|
|
this.objs = Object.create(null);
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2013-08-13 02:48:06 +09:00
|
|
|
};
|
|
|
|
return PDFObjects;
|
|
|
|
})();
|
2014-01-04 09:17:05 +09:00
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Allows controlling of the rendering tasks.
|
|
|
|
* @class
|
2015-11-13 04:39:58 +09:00
|
|
|
* @alias RenderTask
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
2013-08-01 03:17:36 +09:00
|
|
|
var RenderTask = (function RenderTaskClosure() {
|
|
|
|
function RenderTask(internalRenderTask) {
|
2015-01-06 12:45:01 +09:00
|
|
|
this._internalRenderTask = internalRenderTask;
|
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
2015-01-06 12:45:01 +09:00
|
|
|
* Callback for incremental rendering -- a function that will be called
|
|
|
|
* each time the rendering is paused. To continue rendering call the
|
|
|
|
* function that is the first argument to the callback.
|
|
|
|
* @type {function}
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
2015-01-06 12:45:01 +09:00
|
|
|
this.onContinue = null;
|
2013-08-01 03:17:36 +09:00
|
|
|
}
|
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
RenderTask.prototype = /** @lends RenderTask.prototype */ {
|
2015-01-06 12:45:01 +09:00
|
|
|
/**
|
|
|
|
* Promise for rendering task completion.
|
|
|
|
* @return {Promise}
|
|
|
|
*/
|
|
|
|
get promise() {
|
|
|
|
return this._internalRenderTask.capability.promise;
|
|
|
|
},
|
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Cancels the rendering task. If the task is currently rendering it will
|
|
|
|
* not be cancelled until graphics pauses with a timeout. The promise that
|
2017-03-14 01:35:33 +09:00
|
|
|
* this object extends will be rejected when cancelled.
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
|
|
|
cancel: function RenderTask_cancel() {
|
2015-01-06 12:45:01 +09:00
|
|
|
this._internalRenderTask.cancel();
|
2014-04-12 02:10:42 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-01-06 12:45:01 +09:00
|
|
|
* Registers callbacks to indicate the rendering task completion.
|
2014-04-12 02:10:42 +09:00
|
|
|
*
|
|
|
|
* @param {function} onFulfilled The callback for the rendering completion.
|
|
|
|
* @param {function} onRejected The callback for the rendering failure.
|
|
|
|
* @return {Promise} A promise that is resolved after the onFulfilled or
|
|
|
|
* onRejected callback.
|
|
|
|
*/
|
|
|
|
then: function RenderTask_then(onFulfilled, onRejected) {
|
2015-01-06 12:45:01 +09:00
|
|
|
return this.promise.then.apply(this.promise, arguments);
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2013-08-01 03:17:36 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
return RenderTask;
|
|
|
|
})();
|
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* For internal use only.
|
|
|
|
* @ignore
|
|
|
|
*/
|
2013-08-01 03:17:36 +09:00
|
|
|
var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|
|
|
|
|
|
|
function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
|
2017-01-28 02:58:39 +09:00
|
|
|
pageNumber, canvasFactory) {
|
2013-08-01 03:17:36 +09:00
|
|
|
this.callback = callback;
|
|
|
|
this.params = params;
|
|
|
|
this.objs = objs;
|
|
|
|
this.commonObjs = commonObjs;
|
|
|
|
this.operatorListIdx = null;
|
|
|
|
this.operatorList = operatorList;
|
|
|
|
this.pageNumber = pageNumber;
|
2017-01-28 02:58:39 +09:00
|
|
|
this.canvasFactory = canvasFactory;
|
2013-08-01 03:17:36 +09:00
|
|
|
this.running = false;
|
|
|
|
this.graphicsReadyCallback = null;
|
|
|
|
this.graphicsReady = false;
|
2015-05-12 22:44:42 +09:00
|
|
|
this.useRequestAnimationFrame = false;
|
2013-08-01 03:17:36 +09:00
|
|
|
this.cancelled = false;
|
2014-04-30 00:07:05 +09:00
|
|
|
this.capability = createPromiseCapability();
|
2015-01-06 12:45:01 +09:00
|
|
|
this.task = new RenderTask(this);
|
2014-05-09 21:00:47 +09:00
|
|
|
// caching this-bound methods
|
|
|
|
this._continueBound = this._continue.bind(this);
|
|
|
|
this._scheduleNextBound = this._scheduleNext.bind(this);
|
|
|
|
this._nextBound = this._next.bind(this);
|
2013-08-01 03:17:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
InternalRenderTask.prototype = {
|
|
|
|
|
2016-05-03 07:34:58 +09:00
|
|
|
initializeGraphics:
|
|
|
|
function InternalRenderTask_initializeGraphics(transparency) {
|
2013-08-01 03:17:36 +09:00
|
|
|
|
|
|
|
if (this.cancelled) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-29 04:49:22 +09:00
|
|
|
if (getDefaultSetting('pdfBug') && globalScope.StepperManager &&
|
2013-08-01 03:17:36 +09:00
|
|
|
globalScope.StepperManager.enabled) {
|
|
|
|
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
|
|
|
|
this.stepper.init(this.operatorList);
|
|
|
|
this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
var params = this.params;
|
|
|
|
this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
|
2017-01-28 02:58:39 +09:00
|
|
|
this.objs, this.canvasFactory,
|
|
|
|
params.imageLayer);
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2017-05-16 20:01:03 +09:00
|
|
|
this.gfx.beginDrawing({
|
|
|
|
transform: params.transform,
|
|
|
|
viewport: params.viewport,
|
|
|
|
transparency,
|
|
|
|
background: params.background,
|
|
|
|
});
|
2013-08-01 03:17:36 +09:00
|
|
|
this.operatorListIdx = 0;
|
|
|
|
this.graphicsReady = true;
|
|
|
|
if (this.graphicsReadyCallback) {
|
|
|
|
this.graphicsReadyCallback();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel: function InternalRenderTask_cancel() {
|
|
|
|
this.running = false;
|
|
|
|
this.cancelled = true;
|
2017-03-13 21:32:23 +09:00
|
|
|
|
|
|
|
if ((typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PDFJS_NEXT')) ||
|
|
|
|
getDefaultSetting('pdfjsNext')) {
|
|
|
|
this.callback(new RenderingCancelledException(
|
|
|
|
'Rendering cancelled, page ' + this.pageNumber, 'canvas'));
|
|
|
|
} else {
|
|
|
|
this.callback('cancelled');
|
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
operatorListChanged: function InternalRenderTask_operatorListChanged() {
|
|
|
|
if (!this.graphicsReady) {
|
|
|
|
if (!this.graphicsReadyCallback) {
|
2014-05-09 21:00:47 +09:00
|
|
|
this.graphicsReadyCallback = this._continueBound;
|
2013-08-01 03:17:36 +09:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.stepper) {
|
|
|
|
this.stepper.updateOperatorList(this.operatorList);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._continue();
|
|
|
|
},
|
|
|
|
|
|
|
|
_continue: function InternalRenderTask__continue() {
|
|
|
|
this.running = true;
|
|
|
|
if (this.cancelled) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
if (this.task.onContinue) {
|
2017-01-22 01:08:25 +09:00
|
|
|
this.task.onContinue(this._scheduleNextBound);
|
2013-08-01 03:17:36 +09:00
|
|
|
} else {
|
2014-05-09 21:00:47 +09:00
|
|
|
this._scheduleNext();
|
2013-08-01 03:17:36 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-09 21:00:47 +09:00
|
|
|
_scheduleNext: function InternalRenderTask__scheduleNext() {
|
2016-04-07 00:38:48 +09:00
|
|
|
if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
|
2015-05-12 22:44:42 +09:00
|
|
|
window.requestAnimationFrame(this._nextBound);
|
|
|
|
} else {
|
|
|
|
Promise.resolve(undefined).then(this._nextBound);
|
|
|
|
}
|
2014-05-09 21:00:47 +09:00
|
|
|
},
|
|
|
|
|
2013-08-01 03:17:36 +09:00
|
|
|
_next: function InternalRenderTask__next() {
|
|
|
|
if (this.cancelled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
|
|
|
|
this.operatorListIdx,
|
2014-05-09 21:00:47 +09:00
|
|
|
this._continueBound,
|
2013-08-01 03:17:36 +09:00
|
|
|
this.stepper);
|
2013-11-14 04:43:38 +09:00
|
|
|
if (this.operatorListIdx === this.operatorList.argsArray.length) {
|
2013-08-01 03:17:36 +09:00
|
|
|
this.running = false;
|
|
|
|
if (this.operatorList.lastChunk) {
|
|
|
|
this.gfx.endDrawing();
|
|
|
|
this.callback();
|
|
|
|
}
|
|
|
|
}
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2013-08-01 03:17:36 +09:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return InternalRenderTask;
|
|
|
|
})();
|
2015-12-01 05:42:47 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* (Deprecated) Global observer of unsupported feature usages. Use
|
|
|
|
* onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
|
|
|
|
*/
|
2016-03-29 04:49:22 +09:00
|
|
|
var _UnsupportedManager = (function UnsupportedManagerClosure() {
|
2015-12-01 05:42:47 +09:00
|
|
|
var listeners = [];
|
|
|
|
return {
|
2017-04-25 23:17:18 +09:00
|
|
|
listen(cb) {
|
2015-12-01 05:42:47 +09:00
|
|
|
deprecated('Global UnsupportedManager.listen is used: ' +
|
|
|
|
' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
|
|
|
|
listeners.push(cb);
|
|
|
|
},
|
2017-04-25 23:17:18 +09:00
|
|
|
notify(featureId) {
|
2015-12-01 05:42:47 +09:00
|
|
|
for (var i = 0, ii = listeners.length; i < ii; i++) {
|
|
|
|
listeners[i](featureId);
|
|
|
|
}
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
},
|
2015-12-01 05:42:47 +09:00
|
|
|
};
|
|
|
|
})();
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2017-04-02 21:25:33 +09:00
|
|
|
var version, build;
|
2017-02-09 07:32:15 +09:00
|
|
|
if (typeof PDFJSDev !== 'undefined') {
|
2017-04-02 21:25:33 +09:00
|
|
|
version = PDFJSDev.eval('BUNDLE_VERSION');
|
|
|
|
build = PDFJSDev.eval('BUNDLE_BUILD');
|
2016-03-29 06:44:27 +09:00
|
|
|
}
|
|
|
|
|
2017-04-02 21:25:33 +09:00
|
|
|
export {
|
|
|
|
getDocument,
|
2017-05-03 02:20:13 +09:00
|
|
|
LoopbackPort,
|
2017-04-02 21:25:33 +09:00
|
|
|
PDFDataRangeTransport,
|
|
|
|
PDFWorker,
|
|
|
|
PDFDocumentProxy,
|
|
|
|
PDFPageProxy,
|
|
|
|
_UnsupportedManager,
|
|
|
|
version,
|
|
|
|
build,
|
|
|
|
};
|