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.
|
|
|
|
*/
|
2012-04-10 14:20:57 +09:00
|
|
|
|
2019-10-13 01:33:49 +09:00
|
|
|
/**
|
|
|
|
* @module pdfjsLib
|
|
|
|
*/
|
|
|
|
|
2017-04-02 21:25:33 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
AbortException,
|
|
|
|
assert,
|
|
|
|
createPromiseCapability,
|
|
|
|
getVerbosityLevel,
|
|
|
|
info,
|
|
|
|
InvalidPDFException,
|
|
|
|
isArrayBuffer,
|
|
|
|
isSameOrigin,
|
|
|
|
MissingPDFException,
|
|
|
|
PasswordException,
|
|
|
|
setVerbosityLevel,
|
|
|
|
shadow,
|
|
|
|
stringToBytes,
|
|
|
|
UnexpectedResponseException,
|
|
|
|
UnknownErrorException,
|
|
|
|
unreachable,
|
|
|
|
warn,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "../shared/util.js";
|
2017-04-02 21:25:33 +09:00
|
|
|
import {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
deprecated,
|
|
|
|
DOMCanvasFactory,
|
|
|
|
DOMCMapReaderFactory,
|
|
|
|
loadScript,
|
|
|
|
PageViewport,
|
|
|
|
RenderingCancelledException,
|
|
|
|
StatTimer,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./display_utils.js";
|
|
|
|
import { FontFaceObject, FontLoader } from "./font_loader.js";
|
2020-06-29 20:18:51 +09:00
|
|
|
import { NodeCanvasFactory, NodeCMapReaderFactory } from "./node_utils.js";
|
2020-07-22 20:55:52 +09:00
|
|
|
import { AnnotationStorage } from "./annotation_storage.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { apiCompatibilityParams } from "./api_compatibility.js";
|
|
|
|
import { CanvasGraphics } from "./canvas.js";
|
|
|
|
import { GlobalWorkerOptions } from "./worker_options.js";
|
|
|
|
import { isNodeJS } from "../shared/is_node.js";
|
|
|
|
import { MessageHandler } from "../shared/message_handler.js";
|
|
|
|
import { Metadata } from "./metadata.js";
|
2020-07-15 07:17:27 +09:00
|
|
|
import { OptionalContentConfig } from "./optional_content_config.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { PDFDataTransportStream } from "./transport_stream.js";
|
|
|
|
import { WebGLContext } from "./webgl.js";
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2018-10-07 21:28:16 +09:00
|
|
|
const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
|
2015-10-22 08:56:27 +09:00
|
|
|
|
2020-06-29 20:18:51 +09:00
|
|
|
const DefaultCanvasFactory =
|
|
|
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
|
|
|
? NodeCanvasFactory
|
|
|
|
: DOMCanvasFactory;
|
|
|
|
const DefaultCMapReaderFactory =
|
|
|
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && isNodeJS
|
|
|
|
? NodeCMapReaderFactory
|
|
|
|
: DOMCMapReaderFactory;
|
|
|
|
|
2018-01-14 08:34:46 +09:00
|
|
|
/**
|
|
|
|
* @typedef {function} IPDFStreamFactory
|
2020-03-24 00:34:25 +09:00
|
|
|
* @param {DocumentInitParameters} params - The document initialization
|
|
|
|
* parameters. The "url" key is always present.
|
2020-05-19 22:10:05 +09:00
|
|
|
* @returns {Promise} A promise, which is resolved with an instance of
|
|
|
|
* {IPDFStream}.
|
2020-03-24 00:34:25 +09:00
|
|
|
* @ignore
|
2018-01-14 08:34:46 +09:00
|
|
|
*/
|
|
|
|
|
2020-03-24 00:34:25 +09:00
|
|
|
/**
|
|
|
|
* @type IPDFStreamFactory
|
|
|
|
* @private
|
|
|
|
*/
|
2018-11-09 00:24:20 +09:00
|
|
|
let createPDFNetworkStream;
|
2017-07-01 02:59:52 +09:00
|
|
|
|
|
|
|
/**
|
2020-03-24 00:34:25 +09:00
|
|
|
* Sets the function that instantiates an {IPDFStream} as an alternative PDF
|
|
|
|
* data transport.
|
2020-08-03 03:24:43 +09:00
|
|
|
*
|
2020-03-24 00:34:25 +09:00
|
|
|
* @param {IPDFStreamFactory} pdfNetworkStreamFactory - The factory function
|
|
|
|
* that takes document initialization parameters (including a "url") and
|
2020-05-19 22:10:05 +09:00
|
|
|
* returns a promise which is resolved with an instance of {IPDFStream}.
|
2020-03-24 00:34:25 +09:00
|
|
|
* @ignore
|
2017-07-01 02:59:52 +09:00
|
|
|
*/
|
2018-01-14 08:34:46 +09:00
|
|
|
function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|
|
|
createPDFNetworkStream = pdfNetworkStreamFactory;
|
2017-07-01 02:59:52 +09:00
|
|
|
}
|
|
|
|
|
2020-07-23 05:38:04 +09:00
|
|
|
/**
|
2020-08-05 12:47:21 +09:00
|
|
|
* @typedef { Int8Array | Uint8Array | Uint8ClampedArray |
|
|
|
|
* Int16Array | Uint16Array |
|
|
|
|
* Int32Array | Uint32Array | Float32Array |
|
|
|
|
* Float64Array
|
2020-08-03 03:24:43 +09:00
|
|
|
* } TypedArray
|
2020-07-23 05:38:04 +09:00
|
|
|
*/
|
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Document initialization / loading parameters object.
|
|
|
|
*
|
|
|
|
* @typedef {Object} DocumentInitParameters
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {string} [url] - The URL of the PDF.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @property {TypedArray|Array<number>|string} [data] - Binary PDF data. Use
|
|
|
|
* typed arrays (Uint8Array) to improve the memory usage. If PDF data is
|
2020-08-03 03:24:43 +09:00
|
|
|
* BASE64-encoded, use `atob()` to convert it to a binary string first.
|
|
|
|
* @property {Object} [httpHeaders] - Basic authentication headers.
|
|
|
|
* @property {boolean} [withCredentials] - Indicates whether or not
|
2019-10-08 20:34:17 +09:00
|
|
|
* cross-site Access-Control requests should be made using credentials such
|
2020-08-03 03:24:43 +09:00
|
|
|
* as cookies or authorization headers. The default is `false`.
|
|
|
|
* @property {string} [password] - For decrypting password-protected PDFs.
|
2019-10-08 20:34:17 +09:00
|
|
|
* @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
|
2014-01-22 04:28:18 +09:00
|
|
|
* loaded before the switch to range requests.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {number} [length] - The PDF file length. It's used for progress
|
|
|
|
* reports and range requests operations.
|
|
|
|
* @property {PDFDataRangeTransport} [range] - Allows for using a custom range
|
|
|
|
* transport implementation.
|
|
|
|
* @property {number} [rangeChunkSize] - Specify maximum number of bytes fetched
|
|
|
|
* per range request. The default value is {@link DEFAULT_RANGE_CHUNK_SIZE}.
|
|
|
|
* @property {PDFWorker} [worker] - The worker that will be used for loading and
|
|
|
|
* parsing the PDF data.
|
|
|
|
* @property {number} [verbosity] - Controls the logging level; the constants
|
|
|
|
* from {@link VerbosityLevel} should be used.
|
|
|
|
* @property {string} [docBaseUrl] - 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.
|
|
|
|
* @property {string} [cMapUrl] - The URL where the predefined Adobe CMaps are
|
|
|
|
* located. Include the trailing slash.
|
|
|
|
* @property {boolean} [cMapPacked] - Specifies if the Adobe CMaps are binary
|
|
|
|
* packed or not.
|
|
|
|
* @property {Object} [CMapReaderFactory] - The factory that will be used when
|
|
|
|
* reading built-in CMap files. Providing a custom factory is useful for
|
|
|
|
* environments without Fetch API or `XMLHttpRequest` support, such as
|
|
|
|
* Node.js. The default value is {DOMCMapReaderFactory}.
|
2019-10-08 20:34:17 +09:00
|
|
|
* @property {boolean} [stopAtErrors] - Reject certain promises, e.g.
|
[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
|
|
|
* `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`.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {number} [maxImageSize] - The maximum allowed image size in total
|
|
|
|
* pixels, i.e. width * height. Images above this value will not be rendered.
|
|
|
|
* Use -1 for no limit, which is also the default value.
|
|
|
|
* @property {boolean} [isEvalSupported] - Determines if we can evaluate strings
|
|
|
|
* as JavaScript. Primarily used to improve performance of font rendering, and
|
|
|
|
* when parsing PDF functions. The default value is `true`.
|
|
|
|
* @property {boolean} [disableFontFace] - By default fonts are converted to
|
|
|
|
* OpenType fonts and loaded via `@font-face` rules. If disabled, fonts will
|
|
|
|
* be rendered using a built-in font renderer that constructs the glyphs with
|
|
|
|
* primitive path commands. The default value is `false`.
|
[api-minor] Change `Font.exportData` to, by default, stop exporting properties which are completely unused on the main-thread and/or in the API (PR 11773 follow-up)
For years now, the `Font.exportData` method has (because of its previous implementation) been exporting many properties despite them being completely unused on the main-thread and/or in the API.
This is unfortunate, since among those properties there's a number of potentially very large data-structures, containing e.g. Arrays and Objects, which thus have to be first structured cloned and then stored on the main-thread.
With the changes in this patch, we'll thus by default save memory for *every* `Font` instance created (there can be a lot in longer documents). The memory savings obviously depends a lot on the actual font data, but some approximate figures are: For non-embedded fonts it can save a couple of kilobytes, for simple embedded fonts a handful of kilobytes, and for composite fonts the size of this auxiliary can even be larger than the actual font program itself.
All-in-all, there's no good reason to keep exporting these properties by default when they're unused. However, since we cannot be sure that every property is unused in custom implementations of the PDF.js library, this patch adds a new `getDocument` option (named `fontExtraProperties`) that still allows access to the following properties:
- "cMap": An internal data structure, only used with composite fonts and never really intended to be exposed on the main-thread and/or in the API.
Note also that the `CMap`/`IdentityCMap` classes are a lot more complex than simple Objects, but only their "internal" properties survive the structured cloning used to send data to the main-thread. Given that CMaps can often be *very* large, not exporting them can also save a fair bit of memory.
- "defaultEncoding": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "differences": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "isSymbolicFont": An internal property, used during font parsing and building of the glyph mapping on the worker-thread.
- "seacMap": An internal map, only potentially used with *some* Type1/CFF fonts and never intended to be exposed in the API. The existing `Font.{charToGlyph, charToGlyphs}` functionality already takes this data into account when handling text.
- "toFontChar": The glyph map, necessary for mapping characters to glyphs in the font, which is built upon the various encoding information contained in the font dictionary and/or font program. This is not directly used on the main-thread and/or in the API.
- "toUnicode": The unicode map, necessary for text-extraction to work correctly, which is built upon the ToUnicode/CMap information contained in the font dictionary, but not directly used on the main-thread and/or in the API.
- "vmetrics": An array of width data used with fonts which are composite *and* vertical, but not directly used on the main-thread and/or in the API.
- "widths": An array of width data used with most fonts, but not directly used on the main-thread and/or in the API.
2020-04-03 18:51:46 +09:00
|
|
|
* @property {boolean} [fontExtraProperties] - Include additional properties,
|
|
|
|
* which are unused during rendering of PDF documents, when exporting the
|
|
|
|
* parsed font data from the worker-thread. This may be useful for debugging
|
|
|
|
* purposes (and backwards compatibility), but note that it will lead to
|
|
|
|
* increased memory usage. The default value is `false`.
|
2020-07-28 02:22:45 +09:00
|
|
|
* @property {HTMLDocument} [ownerDocument] - Specify an explicit document
|
|
|
|
* context to create elements with and to load resources, such as fonts,
|
|
|
|
* into. Defaults to the current document.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {boolean} [disableRange] - Disable range request loading of PDF
|
|
|
|
* files. When enabled, and if the server supports partial content requests,
|
|
|
|
* then the PDF will be fetched in chunks. The default value is `false`.
|
|
|
|
* @property {boolean} [disableStream] - Disable streaming of PDF file data.
|
|
|
|
* By default PDF.js attempts to load PDF files in chunks. The default value
|
|
|
|
* is `false`.
|
|
|
|
* @property {boolean} [disableAutoFetch] - Disable pre-fetching of PDF file
|
|
|
|
* data. When range requests are enabled PDF.js will automatically keep
|
2018-02-18 06:08:45 +09:00
|
|
|
* fetching more data even if it isn't needed to display the current page.
|
|
|
|
* The default value is `false`.
|
2020-08-03 03:24:43 +09:00
|
|
|
*
|
|
|
|
* NOTE: It is also necessary to disable streaming, see above, in order for
|
|
|
|
* disabling of pre-fetching to work correctly.
|
|
|
|
* @property {boolean} [pdfBug] - Enables special hooks for debugging PDF.js
|
|
|
|
* (see `web/debugger.js`). The default value is `false`.
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
|
|
|
|
2014-06-16 23:52:04 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} PDFDocumentStats
|
2020-07-23 05:38:04 +09:00
|
|
|
* @property {Object<string, boolean>} streamTypes - Used stream types in the
|
|
|
|
* document (an item is set to true if specific stream ID was used in the
|
|
|
|
* document).
|
|
|
|
* @property {Object<string, boolean>} fontTypes - Used font types in the
|
|
|
|
* document (an item is set to true if specific font ID was used in the
|
|
|
|
* document).
|
2014-06-16 23:52:04 +09:00
|
|
|
*/
|
|
|
|
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
|
|
|
* This is the main entry point for loading a PDF and interacting with it.
|
|
|
|
*
|
2020-08-03 03:24:43 +09:00
|
|
|
* NOTE: If a URL is used to fetch the PDF data a standard Fetch API call (or
|
|
|
|
* XHR as fallback) is used, which means it must follow same origin rules,
|
|
|
|
* e.g. no cross-domain requests without CORS.
|
|
|
|
*
|
|
|
|
* @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src -
|
|
|
|
* Can be a URL to where a PDF file is located, a typed array (Uint8Array)
|
|
|
|
* already populated with data or parameter object.
|
2019-10-13 01:14:29 +09:00
|
|
|
* @returns {PDFDocumentLoadingTask}
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2017-10-03 06:05:32 +09:00
|
|
|
function getDocument(src) {
|
2018-11-09 00:24:20 +09:00
|
|
|
const task = new PDFDocumentLoadingTask();
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2018-11-09 00:24:20 +09:00
|
|
|
let source;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof src === "string") {
|
|
|
|
source = { url: src };
|
2015-01-06 12:45:01 +09:00
|
|
|
} else if (isArrayBuffer(src)) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
source = { data: src };
|
2015-01-06 12:45:01 +09:00
|
|
|
} else if (src instanceof PDFDataRangeTransport) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
source = { range: src };
|
2015-01-06 12:45:01 +09:00
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof src !== "object") {
|
|
|
|
throw new Error(
|
|
|
|
"Invalid parameter in getDocument, " +
|
|
|
|
"need either Uint8Array, string or a parameter object"
|
|
|
|
);
|
2015-01-06 12:45:01 +09:00
|
|
|
}
|
|
|
|
if (!src.url && !src.data && !src.range) {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new Error(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
"Invalid parameter object: need either .data, .range or .url"
|
|
|
|
);
|
2015-01-06 12:45:01 +09:00
|
|
|
}
|
|
|
|
source = src;
|
2014-03-14 21:24:04 +09:00
|
|
|
}
|
2018-11-09 00:24:20 +09:00
|
|
|
const params = Object.create(null);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let rangeTransport = null,
|
|
|
|
worker = null;
|
2012-06-24 04:48:33 +09:00
|
|
|
|
2018-11-09 00:24:20 +09:00
|
|
|
for (const key in source) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
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;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (key === "range") {
|
2015-10-28 02:55:15 +09:00
|
|
|
rangeTransport = source[key];
|
|
|
|
continue;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (key === "worker") {
|
2015-10-28 02:55:15 +09:00
|
|
|
worker = source[key];
|
2015-01-06 12:45:01 +09:00
|
|
|
continue;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (key === "data" && !(source[key] instanceof Uint8Array)) {
|
2015-01-13 05:52:52 +09:00
|
|
|
// Converting string or array-like data to Uint8Array.
|
2018-11-09 00:24:20 +09:00
|
|
|
const pdfBytes = source[key];
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof pdfBytes === "string") {
|
2015-01-13 05:52:52 +09:00
|
|
|
params[key] = stringToBytes(pdfBytes);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (
|
|
|
|
typeof pdfBytes === "object" &&
|
|
|
|
pdfBytes !== null &&
|
|
|
|
!isNaN(pdfBytes.length)
|
|
|
|
) {
|
2015-01-13 05:52:52 +09:00
|
|
|
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 {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error(
|
|
|
|
"Invalid PDF binary data: either typed array, " +
|
|
|
|
"string or array-like object is expected in the " +
|
|
|
|
"data property."
|
|
|
|
);
|
2015-01-13 05:52:52 +09:00
|
|
|
}
|
|
|
|
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;
|
2020-06-29 20:18:51 +09:00
|
|
|
params.CMapReaderFactory =
|
|
|
|
params.CMapReaderFactory || DefaultCMapReaderFactory;
|
[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;
|
[api-minor] Change `Font.exportData` to, by default, stop exporting properties which are completely unused on the main-thread and/or in the API (PR 11773 follow-up)
For years now, the `Font.exportData` method has (because of its previous implementation) been exporting many properties despite them being completely unused on the main-thread and/or in the API.
This is unfortunate, since among those properties there's a number of potentially very large data-structures, containing e.g. Arrays and Objects, which thus have to be first structured cloned and then stored on the main-thread.
With the changes in this patch, we'll thus by default save memory for *every* `Font` instance created (there can be a lot in longer documents). The memory savings obviously depends a lot on the actual font data, but some approximate figures are: For non-embedded fonts it can save a couple of kilobytes, for simple embedded fonts a handful of kilobytes, and for composite fonts the size of this auxiliary can even be larger than the actual font program itself.
All-in-all, there's no good reason to keep exporting these properties by default when they're unused. However, since we cannot be sure that every property is unused in custom implementations of the PDF.js library, this patch adds a new `getDocument` option (named `fontExtraProperties`) that still allows access to the following properties:
- "cMap": An internal data structure, only used with composite fonts and never really intended to be exposed on the main-thread and/or in the API.
Note also that the `CMap`/`IdentityCMap` classes are a lot more complex than simple Objects, but only their "internal" properties survive the structured cloning used to send data to the main-thread. Given that CMaps can often be *very* large, not exporting them can also save a fair bit of memory.
- "defaultEncoding": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "differences": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "isSymbolicFont": An internal property, used during font parsing and building of the glyph mapping on the worker-thread.
- "seacMap": An internal map, only potentially used with *some* Type1/CFF fonts and never intended to be exposed in the API. The existing `Font.{charToGlyph, charToGlyphs}` functionality already takes this data into account when handling text.
- "toFontChar": The glyph map, necessary for mapping characters to glyphs in the font, which is built upon the various encoding information contained in the font dictionary and/or font program. This is not directly used on the main-thread and/or in the API.
- "toUnicode": The unicode map, necessary for text-extraction to work correctly, which is built upon the ToUnicode/CMap information contained in the font dictionary, but not directly used on the main-thread and/or in the API.
- "vmetrics": An array of width data used with fonts which are composite *and* vertical, but not directly used on the main-thread and/or in the API.
- "widths": An array of width data used with most fonts, but not directly used on the main-thread and/or in the API.
2020-04-03 18:51:46 +09:00
|
|
|
params.fontExtraProperties = params.fontExtraProperties === true;
|
2018-02-18 07:13:49 +09:00
|
|
|
params.pdfBug = params.pdfBug === true;
|
2015-10-22 08:56:27 +09:00
|
|
|
|
2018-02-18 00:13:33 +09:00
|
|
|
if (!Number.isInteger(params.maxImageSize)) {
|
|
|
|
params.maxImageSize = -1;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof params.isEvalSupported !== "boolean") {
|
2018-02-18 05:49:14 +09:00
|
|
|
params.isEvalSupported = true;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof params.disableFontFace !== "boolean") {
|
2018-06-01 19:52:29 +09:00
|
|
|
params.disableFontFace = apiCompatibilityParams.disableFontFace || false;
|
2018-02-18 05:57:20 +09:00
|
|
|
}
|
2020-07-28 02:22:45 +09:00
|
|
|
if (typeof params.ownerDocument === "undefined") {
|
|
|
|
params.ownerDocument = globalThis.document;
|
|
|
|
}
|
2017-05-08 12:32:44 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof params.disableRange !== "boolean") {
|
2018-06-21 15:12:30 +09:00
|
|
|
params.disableRange = false;
|
2018-02-18 06:22:10 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof params.disableStream !== "boolean") {
|
2018-06-21 15:12:30 +09:00
|
|
|
params.disableStream = false;
|
2018-02-18 06:28:08 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof params.disableAutoFetch !== "boolean") {
|
2018-02-18 06:08:45 +09:00
|
|
|
params.disableAutoFetch = false;
|
|
|
|
}
|
|
|
|
|
2018-02-15 01:35:08 +09:00
|
|
|
// Set the main-thread verbosity level.
|
|
|
|
setVerbosityLevel(params.verbosity);
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
if (!worker) {
|
2018-02-15 00:03:54 +09:00
|
|
|
const workerParams = {
|
2018-02-15 01:35:08 +09:00
|
|
|
verbosity: params.verbosity,
|
2018-11-09 00:22:26 +09:00
|
|
|
port: GlobalWorkerOptions.workerPort,
|
2018-02-15 00:03:54 +09:00
|
|
|
};
|
2017-02-25 04:33:18 +09:00
|
|
|
// Worker was not provided -- creating and owning our own. If message port
|
2018-02-14 22:25:47 +09:00
|
|
|
// is specified in global worker options, using it.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
worker = workerParams.port
|
|
|
|
? PDFWorker.fromPort(workerParams)
|
|
|
|
: new PDFWorker(workerParams);
|
2015-10-28 02:55:15 +09:00
|
|
|
task._worker = worker;
|
|
|
|
}
|
2018-11-09 00:24:20 +09:00
|
|
|
const docId = task.docId;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
worker.promise
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function () {
|
2015-10-28 02:55:15 +09:00
|
|
|
if (task.destroyed) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Loading aborted");
|
2017-07-01 02:59:52 +09:00
|
|
|
}
|
|
|
|
|
2020-05-19 22:10:05 +09:00
|
|
|
const workerIdPromise = _fetchDocument(
|
|
|
|
worker,
|
|
|
|
params,
|
|
|
|
rangeTransport,
|
|
|
|
docId
|
|
|
|
);
|
|
|
|
const networkStreamPromise = new Promise(function (resolve) {
|
|
|
|
let networkStream;
|
|
|
|
if (rangeTransport) {
|
|
|
|
networkStream = new PDFDataTransportStream(
|
|
|
|
{
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
length: params.length,
|
2020-05-19 22:10:05 +09:00
|
|
|
initialData: params.initialData,
|
|
|
|
progressiveDone: params.progressiveDone,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
disableRange: params.disableRange,
|
|
|
|
disableStream: params.disableStream,
|
2020-05-19 22:10:05 +09:00
|
|
|
},
|
|
|
|
rangeTransport
|
|
|
|
);
|
|
|
|
} else if (!params.data) {
|
|
|
|
networkStream = createPDFNetworkStream({
|
|
|
|
url: params.url,
|
|
|
|
length: params.length,
|
|
|
|
httpHeaders: params.httpHeaders,
|
|
|
|
withCredentials: params.withCredentials,
|
|
|
|
rangeChunkSize: params.rangeChunkSize,
|
|
|
|
disableRange: params.disableRange,
|
|
|
|
disableStream: params.disableStream,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
resolve(networkStream);
|
|
|
|
});
|
|
|
|
|
|
|
|
return Promise.all([workerIdPromise, networkStreamPromise]).then(
|
|
|
|
function ([workerId, networkStream]) {
|
|
|
|
if (task.destroyed) {
|
|
|
|
throw new Error("Loading aborted");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const messageHandler = new MessageHandler(
|
|
|
|
docId,
|
|
|
|
workerId,
|
|
|
|
worker.port
|
|
|
|
);
|
|
|
|
messageHandler.postMessageTransfers = worker.postMessageTransfers;
|
|
|
|
const transport = new WorkerTransport(
|
|
|
|
messageHandler,
|
|
|
|
task,
|
|
|
|
networkStream,
|
|
|
|
params
|
|
|
|
);
|
|
|
|
task._transport = transport;
|
|
|
|
messageHandler.send("Ready", null);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.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.
|
2020-08-03 03:24:43 +09:00
|
|
|
*
|
2015-10-28 02:55:15 +09:00
|
|
|
* @param {PDFWorker} worker
|
|
|
|
* @param {Object} source
|
|
|
|
* @param {PDFDataRangeTransport} pdfDataRangeTransport
|
2020-08-03 03:24:43 +09:00
|
|
|
* @param {string} docId - Unique document ID, used in `MessageHandler`.
|
|
|
|
* @returns {Promise} A promise that is resolved when the worker ID of the
|
|
|
|
* `MessageHandler` is known.
|
2015-10-28 02:55:15 +09:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|
|
|
if (worker.destroyed) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return Promise.reject(new Error("Worker was destroyed"));
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pdfDataRangeTransport) {
|
|
|
|
source.length = pdfDataRangeTransport.length;
|
|
|
|
source.initialData = pdfDataRangeTransport.initialData;
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
source.progressiveDone = pdfDataRangeTransport.progressiveDone;
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return worker.messageHandler
|
|
|
|
.sendWithPromise("GetDocRequest", {
|
|
|
|
docId,
|
|
|
|
apiVersion:
|
|
|
|
typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")
|
|
|
|
? PDFJSDev.eval("BUNDLE_VERSION")
|
|
|
|
: null,
|
2019-12-26 04:03:46 +09:00
|
|
|
// Only send the required properties, and *not* the entire object.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
source: {
|
|
|
|
data: source.data,
|
|
|
|
url: source.url,
|
|
|
|
password: source.password,
|
|
|
|
disableAutoFetch: source.disableAutoFetch,
|
|
|
|
rangeChunkSize: source.rangeChunkSize,
|
|
|
|
length: source.length,
|
|
|
|
},
|
|
|
|
maxImageSize: source.maxImageSize,
|
|
|
|
disableFontFace: source.disableFontFace,
|
|
|
|
postMessageTransfers: worker.postMessageTransfers,
|
|
|
|
docBaseUrl: source.docBaseUrl,
|
|
|
|
ignoreErrors: source.ignoreErrors,
|
|
|
|
isEvalSupported: source.isEvalSupported,
|
[api-minor] Change `Font.exportData` to, by default, stop exporting properties which are completely unused on the main-thread and/or in the API (PR 11773 follow-up)
For years now, the `Font.exportData` method has (because of its previous implementation) been exporting many properties despite them being completely unused on the main-thread and/or in the API.
This is unfortunate, since among those properties there's a number of potentially very large data-structures, containing e.g. Arrays and Objects, which thus have to be first structured cloned and then stored on the main-thread.
With the changes in this patch, we'll thus by default save memory for *every* `Font` instance created (there can be a lot in longer documents). The memory savings obviously depends a lot on the actual font data, but some approximate figures are: For non-embedded fonts it can save a couple of kilobytes, for simple embedded fonts a handful of kilobytes, and for composite fonts the size of this auxiliary can even be larger than the actual font program itself.
All-in-all, there's no good reason to keep exporting these properties by default when they're unused. However, since we cannot be sure that every property is unused in custom implementations of the PDF.js library, this patch adds a new `getDocument` option (named `fontExtraProperties`) that still allows access to the following properties:
- "cMap": An internal data structure, only used with composite fonts and never really intended to be exposed on the main-thread and/or in the API.
Note also that the `CMap`/`IdentityCMap` classes are a lot more complex than simple Objects, but only their "internal" properties survive the structured cloning used to send data to the main-thread. Given that CMaps can often be *very* large, not exporting them can also save a fair bit of memory.
- "defaultEncoding": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "differences": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "isSymbolicFont": An internal property, used during font parsing and building of the glyph mapping on the worker-thread.
- "seacMap": An internal map, only potentially used with *some* Type1/CFF fonts and never intended to be exposed in the API. The existing `Font.{charToGlyph, charToGlyphs}` functionality already takes this data into account when handling text.
- "toFontChar": The glyph map, necessary for mapping characters to glyphs in the font, which is built upon the various encoding information contained in the font dictionary and/or font program. This is not directly used on the main-thread and/or in the API.
- "toUnicode": The unicode map, necessary for text-extraction to work correctly, which is built upon the ToUnicode/CMap information contained in the font dictionary, but not directly used on the main-thread and/or in the API.
- "vmetrics": An array of width data used with fonts which are composite *and* vertical, but not directly used on the main-thread and/or in the API.
- "widths": An array of width data used with most fonts, but not directly used on the main-thread and/or in the API.
2020-04-03 18:51:46 +09:00
|
|
|
fontExtraProperties: source.fontExtraProperties,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
})
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function (workerId) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (worker.destroyed) {
|
|
|
|
throw new Error("Worker was destroyed");
|
|
|
|
}
|
|
|
|
return workerId;
|
|
|
|
});
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
|
|
|
|
2020-07-23 05:38:04 +09:00
|
|
|
/**
|
|
|
|
* The loading task controls the operations required to load a PDF document
|
|
|
|
* (such as network requests) and provides a way to listen for completion,
|
|
|
|
* after which individual pages can be rendered.
|
|
|
|
*
|
|
|
|
* @typedef {Object} PDFDocumentLoadingTask
|
2020-08-03 02:55:08 +09:00
|
|
|
* @property {string} docId - Unique identifier for the document loading task.
|
|
|
|
* @property {boolean} destroyed - Whether the loading task is destroyed or not.
|
|
|
|
* @property {function} [onPassword] - Callback to request a password if a wrong
|
|
|
|
* or no password was provided. The callback receives two parameters: a
|
|
|
|
* function that should be called with the new password, and a reason (see
|
|
|
|
* {@link PasswordResponses}).
|
|
|
|
* @property {function} [onProgress] - 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 `loaded`
|
|
|
|
* ({number}) and `total` ({number}) that indicate how many bytes are loaded.
|
|
|
|
* @property {function} [onUnsupportedFeature] - Callback for when an
|
|
|
|
* unsupported feature is used in the PDF document. The callback receives an
|
|
|
|
* {@link UNSUPPORTED_FEATURES} argument.
|
|
|
|
* @property {Promise<PDFDocumentProxy>} promise - Promise for document loading
|
|
|
|
* task completion.
|
2020-08-07 16:10:19 +09:00
|
|
|
* @property {function} destroy - Abort all network requests and destroy
|
2020-08-03 02:55:08 +09:00
|
|
|
* the worker. Returns a promise that is resolved when destruction is
|
|
|
|
* completed.
|
2020-07-23 05:38:04 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {any}
|
|
|
|
* @ignore
|
|
|
|
*/
|
2018-11-08 21:40:06 +09:00
|
|
|
const PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
|
|
|
|
let nextDocumentId = 0;
|
2015-10-28 02:55:15 +09:00
|
|
|
|
2019-10-13 21:21:39 +09:00
|
|
|
/**
|
|
|
|
* The loading task controls the operations required to load a PDF document
|
|
|
|
* (such as network requests) and provides a way to listen for completion,
|
|
|
|
* after which individual pages can be rendered.
|
|
|
|
*/
|
2020-03-25 18:15:50 +09:00
|
|
|
// eslint-disable-next-line no-shadow
|
2018-11-08 21:40:06 +09:00
|
|
|
class PDFDocumentLoadingTask {
|
|
|
|
constructor() {
|
|
|
|
this._capability = createPromiseCapability();
|
|
|
|
this._transport = null;
|
|
|
|
this._worker = null;
|
|
|
|
|
|
|
|
/**
|
2020-08-03 02:55:08 +09:00
|
|
|
* Unique identifier for the document loading task.
|
2018-11-08 21:40:06 +09:00
|
|
|
* @type {string}
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.docId = "d" + nextDocumentId++;
|
2018-11-08 21:40:06 +09:00
|
|
|
|
|
|
|
/**
|
2020-08-03 02:55:08 +09:00
|
|
|
* Whether the loading task is destroyed or not.
|
2018-11-08 21:40:06 +09:00
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.destroyed = false;
|
|
|
|
|
|
|
|
/**
|
2020-08-03 02:55:08 +09:00
|
|
|
* Callback to request a password if a wrong or no password was provided.
|
|
|
|
* The callback receives two parameters: a function that should be called
|
|
|
|
* with the new password, and a reason (see {@link PasswordResponses}).
|
|
|
|
* @type {function}
|
2018-11-08 21:40:06 +09:00
|
|
|
*/
|
|
|
|
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
|
2020-08-03 02:55:08 +09:00
|
|
|
* an {Object} with the properties `loaded` ({number}) and `total`
|
|
|
|
* ({number}) that indicate how many bytes are loaded.
|
|
|
|
* @type {function}
|
2018-11-08 21:40:06 +09:00
|
|
|
*/
|
|
|
|
this.onProgress = null;
|
|
|
|
|
|
|
|
/**
|
2020-08-03 02:55:08 +09:00
|
|
|
* Callback for when an unsupported feature is used in the PDF document.
|
|
|
|
* The callback receives an {@link UNSUPPORTED_FEATURES} argument.
|
|
|
|
* @type {function}
|
2018-11-08 21:40:06 +09:00
|
|
|
*/
|
|
|
|
this.onUnsupportedFeature = null;
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
|
|
|
/**
|
2019-10-09 06:25:32 +09:00
|
|
|
* Promise for document loading task completion.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @type {Promise<PDFDocumentProxy>}
|
2015-01-06 12:45:01 +09:00
|
|
|
*/
|
|
|
|
get promise() {
|
|
|
|
return this._capability.promise;
|
2018-11-08 21:40:06 +09:00
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2015-10-21 07:45:55 +09:00
|
|
|
/**
|
2020-08-03 02:55:08 +09:00
|
|
|
* @returns {Promise<void>} A promise that is resolved when destruction is
|
|
|
|
* completed.
|
2015-10-21 07:45:55 +09:00
|
|
|
*/
|
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
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const 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
|
|
|
});
|
2018-11-08 21:40:06 +09:00
|
|
|
}
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
return PDFDocumentLoadingTask;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class to support range requests file loading.
|
|
|
|
*/
|
2018-10-21 00:15:27 +09:00
|
|
|
class PDFDataRangeTransport {
|
2020-07-23 05:38:04 +09:00
|
|
|
/**
|
|
|
|
* @param {number} length
|
|
|
|
* @param {Uint8Array} initialData
|
2020-08-03 03:24:43 +09:00
|
|
|
* @param {boolean} [progressiveDone]
|
2020-07-23 05:38:04 +09:00
|
|
|
*/
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
constructor(length, initialData, progressiveDone = false) {
|
2015-01-06 12:45:01 +09:00
|
|
|
this.length = length;
|
|
|
|
this.initialData = initialData;
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
this.progressiveDone = progressiveDone;
|
2015-01-06 12:45:01 +09:00
|
|
|
|
|
|
|
this._rangeListeners = [];
|
|
|
|
this._progressListeners = [];
|
|
|
|
this._progressiveReadListeners = [];
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
this._progressiveDoneListeners = [];
|
2015-01-06 12:45:01 +09:00
|
|
|
this._readyCapability = createPromiseCapability();
|
|
|
|
}
|
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
addRangeListener(listener) {
|
|
|
|
this._rangeListeners.push(listener);
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
addProgressListener(listener) {
|
|
|
|
this._progressListeners.push(listener);
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
addProgressiveReadListener(listener) {
|
|
|
|
this._progressiveReadListeners.push(listener);
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
addProgressiveDoneListener(listener) {
|
|
|
|
this._progressiveDoneListeners.push(listener);
|
|
|
|
}
|
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
onDataRange(begin, chunk) {
|
|
|
|
for (const listener of this._rangeListeners) {
|
|
|
|
listener(begin, chunk);
|
|
|
|
}
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2019-04-06 18:04:44 +09:00
|
|
|
onDataProgress(loaded, total) {
|
2018-10-21 00:15:27 +09:00
|
|
|
this._readyCapability.promise.then(() => {
|
|
|
|
for (const listener of this._progressListeners) {
|
2019-04-06 18:04:44 +09:00
|
|
|
listener(loaded, total);
|
2018-10-21 00:15:27 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
onDataProgressiveRead(chunk) {
|
|
|
|
this._readyCapability.promise.then(() => {
|
|
|
|
for (const listener of this._progressiveReadListeners) {
|
|
|
|
listener(chunk);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
onDataProgressiveDone() {
|
|
|
|
this._readyCapability.promise.then(() => {
|
|
|
|
for (const listener of this._progressiveDoneListeners) {
|
|
|
|
listener();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
transportReady() {
|
|
|
|
this._readyCapability.resolve();
|
|
|
|
}
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
requestDataRange(begin, end) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
unreachable("Abstract method PDFDataRangeTransport.requestDataRange");
|
2018-10-21 00:15:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
abort() {}
|
|
|
|
}
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2012-04-14 01:25:08 +09:00
|
|
|
/**
|
2020-08-03 03:24:43 +09:00
|
|
|
* Proxy to a `PDFDocument` in the worker thread.
|
2012-04-14 01:25:08 +09:00
|
|
|
*/
|
2018-08-27 01:04:57 +09:00
|
|
|
class PDFDocumentProxy {
|
2019-03-11 20:43:44 +09:00
|
|
|
constructor(pdfInfo, transport) {
|
2018-08-27 01:04:57 +09:00
|
|
|
this._pdfInfo = pdfInfo;
|
|
|
|
this._transport = transport;
|
2020-07-22 20:55:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {AnnotationStorage} Storage for annotation data in forms.
|
|
|
|
*/
|
|
|
|
get annotationStorage() {
|
2020-08-10 23:59:16 +09:00
|
|
|
return shadow(this, "annotationStorage", new AnnotationStorage());
|
2012-04-13 04:11:22 +09:00
|
|
|
}
|
2018-02-18 06:08:45 +09:00
|
|
|
|
2018-08-27 01:04:57 +09:00
|
|
|
/**
|
2020-08-03 03:24:43 +09:00
|
|
|
* @type {number} Total number of pages in the PDF file.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
get numPages() {
|
|
|
|
return this._pdfInfo.numPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {string} A (not guaranteed to be) unique ID to identify a PDF.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
get fingerprint() {
|
|
|
|
return this._pdfInfo.fingerprint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} pageNumber - The page number to get. The first page is 1.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<PDFPageProxy>} A promise that is resolved with
|
2020-08-03 03:24:43 +09:00
|
|
|
* a {@link PDFPageProxy} object.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getPage(pageNumber) {
|
|
|
|
return this._transport.getPage(pageNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {{num: number, gen: number}} ref - The page reference. Must have
|
|
|
|
* the `num` and `gen` properties.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<{num: number, gen: number}>} A promise that is resolved
|
|
|
|
* with the page index (starting from zero) that is associated with the
|
|
|
|
* reference.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getPageIndex(ref) {
|
|
|
|
return this._transport.getPageIndex(ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-03 03:09:31 +09:00
|
|
|
* @returns {Promise<Object<string, Array<any>>>} A promise that is resolved
|
|
|
|
* with a mapping from named destinations to references.
|
2018-08-27 01:04:57 +09:00
|
|
|
*
|
|
|
|
* This can be slow for large documents. Use `getDestination` instead.
|
|
|
|
*/
|
|
|
|
getDestinations() {
|
|
|
|
return this._transport.getDestinations();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} id - The named destination to get.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<Array<any>>} A promise that is resolved with all
|
|
|
|
* information of the given named destination.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getDestination(id) {
|
|
|
|
return this._transport.getDestination(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-03 03:09:31 +09:00
|
|
|
* @returns {Promise<Array<string> | null>} A promise that is resolved with
|
|
|
|
* an {Array} containing the page labels that correspond to the page
|
|
|
|
* indexes, or `null` when no page labels are present in the PDF file.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getPageLabels() {
|
|
|
|
return this._transport.getPageLabels();
|
|
|
|
}
|
|
|
|
|
2019-04-03 20:48:18 +09:00
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<string>} A promise that is resolved with a {string}
|
|
|
|
* containing the page layout name.
|
2019-04-03 20:48:18 +09:00
|
|
|
*/
|
|
|
|
getPageLayout() {
|
|
|
|
return this._transport.getPageLayout();
|
|
|
|
}
|
|
|
|
|
2018-08-27 01:04:57 +09:00
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<string>} A promise that is resolved with a {string}
|
|
|
|
* containing the page mode name.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getPageMode() {
|
|
|
|
return this._transport.getPageMode();
|
|
|
|
}
|
|
|
|
|
2019-04-14 20:13:59 +09:00
|
|
|
/**
|
2020-08-03 03:09:31 +09:00
|
|
|
* @returns {Promise<Object | null>} A promise that is resolved with an
|
|
|
|
* {Object} containing the viewer preferences, or `null` when no viewer
|
|
|
|
* preferences are present in the PDF file.
|
2019-04-14 20:13:59 +09:00
|
|
|
*/
|
|
|
|
getViewerPreferences() {
|
|
|
|
return this._transport.getViewerPreferences();
|
|
|
|
}
|
|
|
|
|
2018-12-06 04:09:15 +09:00
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<any | null>} A promise that is resolved with an {Array}
|
|
|
|
* containing the destination, or `null` when no open action is present
|
|
|
|
* in the PDF.
|
2018-12-06 04:09:15 +09:00
|
|
|
*/
|
2020-02-28 22:54:07 +09:00
|
|
|
getOpenAction() {
|
|
|
|
return this._transport.getOpenAction();
|
|
|
|
}
|
|
|
|
|
2018-08-27 01:04:57 +09:00
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<any>} A promise that is resolved with a lookup table
|
|
|
|
* for mapping named attachments to their content.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getAttachments() {
|
|
|
|
return this._transport.getAttachments();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-03 03:24:43 +09:00
|
|
|
* @returns {Promise<Array<string> | null>} A promise that is resolved with
|
|
|
|
* an {Array} of all the JavaScript strings in the name tree, or `null`
|
|
|
|
* if no JavaScript exists.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getJavaScript() {
|
|
|
|
return this._transport.getJavaScript();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @typedef {Object} OutlineNode
|
|
|
|
* @property {string} title
|
|
|
|
* @property {boolean} bold
|
|
|
|
* @property {boolean} italic
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {Uint8ClampedArray} color - The color in RGB format to use for
|
|
|
|
* display purposes.
|
|
|
|
* @property {string | Array<any> | null} dest
|
|
|
|
* @property {string | null} url
|
|
|
|
* @property {string | undefined} unsafeUrl
|
|
|
|
* @property {boolean | undefined} newWindow
|
|
|
|
* @property {number | undefined} count
|
2020-07-23 05:38:04 +09:00
|
|
|
* @property {Array<OutlineNode>} items
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-08-03 03:24:43 +09:00
|
|
|
* @returns {Promise<Array<OutlineNode>>} A promise that is resolved with an
|
|
|
|
* {Array} that is a tree outline (if it has one) of the PDF file.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getOutline() {
|
|
|
|
return this._transport.getOutline();
|
|
|
|
}
|
|
|
|
|
2020-07-15 07:17:27 +09:00
|
|
|
/**
|
2020-08-07 03:59:46 +09:00
|
|
|
* @returns {Promise<OptionalContentConfig>} A promise that is resolved with
|
|
|
|
* an {@link OptionalContentConfig} that contains all the optional content
|
|
|
|
* groups (assuming that the document has any).
|
2020-07-15 07:17:27 +09:00
|
|
|
*/
|
|
|
|
getOptionalContentConfig() {
|
|
|
|
return this._transport.getOptionalContentConfig();
|
|
|
|
}
|
|
|
|
|
2018-08-27 04:37:05 +09:00
|
|
|
/**
|
2020-08-03 03:09:31 +09:00
|
|
|
* @returns {Promise<Array<number> | null>} A promise that is resolved with
|
2020-07-23 05:38:04 +09:00
|
|
|
* an {Array} that contains the permission flags for the PDF document, or
|
|
|
|
* `null` when no permissions are present in the PDF file.
|
2018-08-27 04:37:05 +09:00
|
|
|
*/
|
|
|
|
getPermissions() {
|
|
|
|
return this._transport.getPermissions();
|
|
|
|
}
|
|
|
|
|
2018-08-27 01:04:57 +09:00
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<{ info: Object, metadata: Metadata }>} A promise that is
|
|
|
|
* resolved with an {Object} that has `info` and `metadata` properties.
|
|
|
|
* `info` is an {Object} filled with anything available in the information
|
|
|
|
* dictionary and similarly `metadata` is a {Metadata} object with
|
|
|
|
* information from the metadata section of the PDF.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getMetadata() {
|
|
|
|
return this._transport.getMetadata();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<TypedArray>} A promise that is resolved with a
|
|
|
|
* {TypedArray} that has the raw data from the PDF.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getData() {
|
|
|
|
return this._transport.getData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<{ length: number }>} A promise that is resolved when the
|
|
|
|
* document's data is loaded. It is resolved with an {Object} that contains
|
|
|
|
* the `length` property that indicates size of the PDF data in bytes.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getDownloadInfo() {
|
|
|
|
return this._transport.downloadInfoCapability.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<PDFDocumentStats>} A promise this is resolved with
|
2020-08-03 03:24:43 +09:00
|
|
|
* current statistics about document structures (see
|
|
|
|
* {@link PDFDocumentStats}).
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
getStats() {
|
|
|
|
return this._transport.getStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-03 03:24:43 +09:00
|
|
|
* Cleans up resources allocated by the document on both the main and worker
|
|
|
|
* threads.
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
*
|
|
|
|
* NOTE: Do not, under any circumstances, call this method when rendering is
|
2020-08-03 03:24:43 +09:00
|
|
|
* currently ongoing since that may lead to rendering errors.
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
*
|
|
|
|
* @returns {Promise} A promise that is resolved when clean-up has finished.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
cleanup() {
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
return this._transport.startCleanup();
|
2018-08-27 01:04:57 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the current document instance and terminates the worker.
|
|
|
|
*/
|
|
|
|
destroy() {
|
|
|
|
return this.loadingTask.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @type {DocumentInitParameters} A subset of the current
|
|
|
|
* {DocumentInitParameters}, which are either needed in the viewer and/or
|
|
|
|
* whose default values may be affected by the `apiCompatibilityParams`.
|
2018-08-27 01:04:57 +09:00
|
|
|
*/
|
|
|
|
get loadingParams() {
|
|
|
|
return this._transport.loadingParams;
|
|
|
|
}
|
2019-03-11 20:43:44 +09:00
|
|
|
|
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {PDFDocumentLoadingTask} The loadingTask for the current document.
|
2019-03-11 20:43:44 +09:00
|
|
|
*/
|
|
|
|
get loadingTask() {
|
|
|
|
return this._transport.loadingTask;
|
|
|
|
}
|
2020-08-04 02:44:04 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {AnnotationStorage} annotationStorage - Storage for annotation
|
|
|
|
* data in forms.
|
|
|
|
* @returns {Promise<Uint8Array>} A promise that is resolved with a
|
|
|
|
* {Uint8Array} containing the full data of the saved document.
|
|
|
|
*/
|
|
|
|
saveDocument(annotationStorage) {
|
|
|
|
return this._transport.saveDocument(annotationStorage);
|
|
|
|
}
|
2018-08-27 01:04:57 +09:00
|
|
|
}
|
2012-04-13 04:11:22 +09:00
|
|
|
|
2018-12-21 19:47:37 +09:00
|
|
|
/**
|
|
|
|
* Page getViewport parameters.
|
|
|
|
*
|
|
|
|
* @typedef {Object} GetViewportParameters
|
|
|
|
* @property {number} scale - The desired scale of the viewport.
|
2019-10-08 20:34:17 +09:00
|
|
|
* @property {number} [rotation] - The desired rotation, in degrees, of
|
2018-12-21 19:47:37 +09:00
|
|
|
* the viewport. If omitted it defaults to the page rotation.
|
2019-10-24 03:35:49 +09:00
|
|
|
* @property {number} [offsetX] - The horizontal, i.e. x-axis, offset.
|
|
|
|
* The default value is `0`.
|
|
|
|
* @property {number} [offsetY] - The vertical, i.e. y-axis, offset.
|
|
|
|
* The default value is `0`.
|
2019-10-08 20:34:17 +09:00
|
|
|
* @property {boolean} [dontFlip] - If true, the y-axis will not be
|
2018-12-21 19:47:37 +09:00
|
|
|
* flipped. The default value is `false`.
|
|
|
|
*/
|
|
|
|
|
2015-11-24 00:57:43 +09:00
|
|
|
/**
|
|
|
|
* Page getTextContent parameters.
|
|
|
|
*
|
|
|
|
* @typedef {Object} getTextContentParameters
|
2020-08-03 03:24:43 +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`.
|
2020-08-03 03:24:43 +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
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {Array<TextItem>} items - Array of {@link TextItem} objects.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @property {Object<string, TextStyle>} styles - {@link TextStyle} 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
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {string} str - Text content.
|
|
|
|
* @property {string} dir - Text direction: 'ttb', 'ltr' or 'rtl'.
|
|
|
|
* @property {Array<any>} 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-10 08:44:07 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-12 00:57:48 +09:00
|
|
|
* Text style.
|
|
|
|
*
|
2014-04-10 08:44:07 +09:00
|
|
|
* @typedef {Object} TextStyle
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {number} ascent - Font ascent.
|
|
|
|
* @property {number} descent - Font descent.
|
|
|
|
* @property {boolean} vertical - Whether or not the text is in vertical mode.
|
|
|
|
* @property {string} fontFamily - The 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,
|
2020-08-03 03:24:43 +09:00
|
|
|
* 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.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {PageViewport} viewport - Rendering viewport obtained by calling
|
|
|
|
* the `PDFPageProxy.getViewport` method.
|
|
|
|
* @property {string} [intent] - Rendering intent, can be 'display' or 'print'.
|
|
|
|
* The default value is 'display'.
|
|
|
|
* @property {boolean} [enableWebGL] - Enables WebGL accelerated rendering for
|
|
|
|
* some operations. The default value is `false`.
|
|
|
|
* @property {boolean} [renderInteractiveForms] - Whether or not interactive
|
|
|
|
* form elements are rendered in the display layer. If so, we do not render
|
|
|
|
* them on the canvas as well.
|
|
|
|
* @property {Array<any>} [transform] - Additional transform, applied just
|
|
|
|
* before viewport transform.
|
|
|
|
* @property {Object} [imageLayer] - An object that has `beginLayout`,
|
|
|
|
* `endLayout` and `appendImage` functions.
|
2020-06-29 20:18:51 +09:00
|
|
|
* @property {Object} [canvasFactory] - The factory instance that will be used
|
2020-08-03 03:24:43 +09:00
|
|
|
* when creating canvases. The default value is {new DOMCanvasFactory()}.
|
|
|
|
* @property {Object | string} [background] - Background to use for the canvas.
|
|
|
|
* Any valid `canvas.fillStyle` can be used: 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)'.
|
|
|
|
* @property {AnnotationStorage} [annotationStorage] - Storage for annotation
|
|
|
|
* data in forms.
|
|
|
|
* @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
|
|
|
|
* A promise that should resolve with an {@link OptionalContentConfig}
|
|
|
|
* created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`,
|
|
|
|
* the configuration will be fetched automatically with the default visibility
|
|
|
|
* states set.
|
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
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {Array<number>} fnArray - Array containing the operator functions.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @property {Array<any>} argsArray - Array containing the arguments of the
|
2020-08-03 03:24:43 +09:00
|
|
|
* functions.
|
2014-06-17 03:35:38 +09:00
|
|
|
*/
|
2014-04-12 00:57:48 +09:00
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
2020-08-03 03:24:43 +09:00
|
|
|
* Proxy to a `PDFPage` in the worker thread.
|
2014-01-22 04:28:18 +09:00
|
|
|
*/
|
2018-11-08 22:13:42 +09:00
|
|
|
class PDFPageProxy {
|
2020-07-28 02:22:45 +09:00
|
|
|
constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
|
2020-03-19 23:36:09 +09:00
|
|
|
this._pageIndex = pageIndex;
|
2018-06-06 03:30:06 +09:00
|
|
|
this._pageInfo = pageInfo;
|
2020-07-28 02:22:45 +09:00
|
|
|
this._ownerDocument = ownerDocument;
|
2018-11-08 22:13:42 +09:00
|
|
|
this._transport = transport;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._stats = pdfBug ? new StatTimer() : null;
|
2018-02-18 07:13:49 +09:00
|
|
|
this._pdfBug = pdfBug;
|
2012-10-29 05:10:34 +09:00
|
|
|
this.commonObjs = transport.commonObjs;
|
|
|
|
this.objs = new PDFObjects();
|
2018-11-08 22:13:42 +09:00
|
|
|
|
2012-10-29 05:10:34 +09:00
|
|
|
this.cleanupAfterRender = false;
|
2015-10-21 07:45:55 +09:00
|
|
|
this.pendingCleanup = false;
|
2020-06-21 23:42:39 +09:00
|
|
|
this._intentStates = new Map();
|
2015-10-21 07:45:55 +09:00
|
|
|
this.destroyed = false;
|
2012-04-13 04:11:22 +09:00
|
|
|
}
|
2018-03-18 01:10:37 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {number} Page number of the page. First page is 1.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
get pageNumber() {
|
2020-03-19 23:36:09 +09:00
|
|
|
return this._pageIndex + 1;
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
2015-11-22 21:56:52 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {number} The number of degrees the page is rotated clockwise.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
get rotate() {
|
|
|
|
return this._pageInfo.rotate;
|
|
|
|
}
|
2014-03-07 23:48:42 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {Object} The reference that points to this page. It has `num` and
|
|
|
|
* `gen` properties.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
get ref() {
|
|
|
|
return this._pageInfo.ref;
|
|
|
|
}
|
2012-04-13 04:11:22 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {number} The default size of units in 1/72nds of an inch.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
get userUnit() {
|
|
|
|
return this._pageInfo.userUnit;
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @type {Array<number>} An array of the visible portion of the PDF page in
|
|
|
|
* user space units [x1, y1, x2, y2].
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
get view() {
|
|
|
|
return this._pageInfo.view;
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2018-12-21 19:47:37 +09:00
|
|
|
* @param {GetViewportParameters} params - Viewport parameters.
|
2019-10-13 01:14:29 +09:00
|
|
|
* @returns {PageViewport} Contains 'width' and 'height' properties
|
2018-12-21 19:47:37 +09:00
|
|
|
* along with transforms required for rendering.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
getViewport({
|
|
|
|
scale,
|
|
|
|
rotation = this.rotate,
|
|
|
|
offsetX = 0,
|
|
|
|
offsetY = 0,
|
|
|
|
dontFlip = false,
|
|
|
|
} = {}) {
|
2018-11-08 22:13:42 +09:00
|
|
|
return new PageViewport({
|
|
|
|
viewBox: this.view,
|
|
|
|
scale,
|
2018-12-21 19:47:37 +09:00
|
|
|
rotation,
|
2019-10-24 03:35:49 +09:00
|
|
|
offsetX,
|
|
|
|
offsetY,
|
2018-11-08 22:13:42 +09:00
|
|
|
dontFlip,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {GetAnnotationsParameters} params - Annotation parameters.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<Array<any>>} A promise that is resolved with an
|
|
|
|
* {Array} of the annotation objects.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
getAnnotations({ intent = null } = {}) {
|
2018-11-08 22:13:42 +09:00
|
|
|
if (!this.annotationsPromise || this.annotationsIntent !== intent) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.annotationsPromise = this._transport.getAnnotations(
|
2020-03-19 23:36:09 +09:00
|
|
|
this._pageIndex,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
intent
|
|
|
|
);
|
2018-11-08 22:13:42 +09:00
|
|
|
this.annotationsIntent = intent;
|
|
|
|
}
|
|
|
|
return this.annotationsPromise;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Begins the process of rendering a page to the desired context.
|
2020-08-03 03:24:43 +09:00
|
|
|
*
|
2018-11-08 22:13:42 +09:00
|
|
|
* @param {RenderParameters} params Page render parameters.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @returns {RenderTask} An object that contains a promise that is
|
|
|
|
* resolved when the page finishes rendering.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
render({
|
|
|
|
canvasContext,
|
|
|
|
viewport,
|
|
|
|
intent = "display",
|
|
|
|
enableWebGL = false,
|
|
|
|
renderInteractiveForms = false,
|
|
|
|
transform = null,
|
|
|
|
imageLayer = null,
|
|
|
|
canvasFactory = null,
|
|
|
|
background = null,
|
2020-07-22 20:55:52 +09:00
|
|
|
annotationStorage = null,
|
2020-07-15 07:17:27 +09:00
|
|
|
optionalContentConfigPromise = null,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}) {
|
2019-10-23 20:23:41 +09:00
|
|
|
if (this._stats) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._stats.time("Overall");
|
2019-10-23 20:23:41 +09:00
|
|
|
}
|
2018-11-08 22:13:42 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const renderingIntent = intent === "print" ? "print" : "display";
|
2019-06-03 05:18:21 +09:00
|
|
|
// If there was a pending destroy, cancel it so no cleanup happens during
|
2018-11-08 22:13:42 +09:00
|
|
|
// this call to render.
|
|
|
|
this.pendingCleanup = false;
|
|
|
|
|
2020-07-15 07:17:27 +09:00
|
|
|
if (!optionalContentConfigPromise) {
|
|
|
|
optionalContentConfigPromise = this._transport.getOptionalContentConfig();
|
|
|
|
}
|
|
|
|
|
2020-06-21 23:42:39 +09:00
|
|
|
let intentState = this._intentStates.get(renderingIntent);
|
|
|
|
if (!intentState) {
|
|
|
|
intentState = Object.create(null);
|
|
|
|
this._intentStates.set(renderingIntent, intentState);
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
|
|
|
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
// Ensure that a pending `streamReader` cancel timeout is always aborted.
|
|
|
|
if (intentState.streamReaderCancelTimeout) {
|
|
|
|
clearTimeout(intentState.streamReaderCancelTimeout);
|
|
|
|
intentState.streamReaderCancelTimeout = null;
|
|
|
|
}
|
|
|
|
|
2020-07-28 02:22:45 +09:00
|
|
|
const canvasFactoryInstance =
|
|
|
|
canvasFactory ||
|
|
|
|
new DefaultCanvasFactory({ ownerDocument: this._ownerDocument });
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
const webGLContext = new WebGLContext({
|
|
|
|
enable: enableWebGL,
|
|
|
|
});
|
|
|
|
|
2018-11-08 22:13:42 +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) {
|
|
|
|
intentState.displayReadyCapability = createPromiseCapability();
|
|
|
|
intentState.operatorList = {
|
|
|
|
fnArray: [],
|
|
|
|
argsArray: [],
|
|
|
|
lastChunk: false,
|
2017-05-03 23:39:54 +09:00
|
|
|
};
|
|
|
|
|
2019-10-23 20:23:41 +09:00
|
|
|
if (this._stats) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._stats.time("Page Request");
|
2019-10-23 20:23:41 +09:00
|
|
|
}
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
this._pumpOperatorList({
|
2020-03-19 23:36:09 +09:00
|
|
|
pageIndex: this._pageIndex,
|
2018-11-08 22:13:42 +09:00
|
|
|
intent: renderingIntent,
|
|
|
|
renderInteractiveForms: renderInteractiveForms === true,
|
2020-08-05 19:43:29 +09:00
|
|
|
annotationStorage:
|
|
|
|
(annotationStorage && annotationStorage.getAll()) || null,
|
2018-11-08 22:13:42 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const complete = error => {
|
2018-11-08 22:13:42 +09:00
|
|
|
const i = intentState.renderTasks.indexOf(internalRenderTask);
|
|
|
|
if (i >= 0) {
|
|
|
|
intentState.renderTasks.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
2019-06-03 05:18:21 +09:00
|
|
|
// Attempt to reduce memory usage during *printing*, by always running
|
|
|
|
// cleanup once rendering has finished (regardless of cleanupAfterRender).
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (this.cleanupAfterRender || renderingIntent === "print") {
|
2018-11-08 22:13:42 +09:00
|
|
|
this.pendingCleanup = true;
|
|
|
|
}
|
|
|
|
this._tryCleanup();
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
internalRenderTask.capability.reject(error);
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
|
|
|
|
this._abortOperatorList({
|
|
|
|
intentState,
|
|
|
|
reason: error,
|
|
|
|
});
|
2018-11-08 22:13:42 +09:00
|
|
|
} else {
|
|
|
|
internalRenderTask.capability.resolve();
|
|
|
|
}
|
2019-10-23 20:23:41 +09:00
|
|
|
if (this._stats) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._stats.timeEnd("Rendering");
|
|
|
|
this._stats.timeEnd("Overall");
|
2019-10-23 20:23:41 +09:00
|
|
|
}
|
2018-11-08 22:13:42 +09:00
|
|
|
};
|
|
|
|
|
2018-11-08 22:33:56 +09:00
|
|
|
const internalRenderTask = new InternalRenderTask({
|
|
|
|
callback: complete,
|
2019-12-26 04:03:46 +09:00
|
|
|
// Only include the required properties, and *not* the entire object.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
params: {
|
2018-11-08 22:33:56 +09:00
|
|
|
canvasContext,
|
|
|
|
viewport,
|
|
|
|
transform,
|
|
|
|
imageLayer,
|
|
|
|
background,
|
|
|
|
},
|
|
|
|
objs: this.objs,
|
|
|
|
commonObjs: this.commonObjs,
|
|
|
|
operatorList: intentState.operatorList,
|
2020-03-19 23:36:09 +09:00
|
|
|
pageIndex: this._pageIndex,
|
2018-11-08 22:33:56 +09:00
|
|
|
canvasFactory: canvasFactoryInstance,
|
|
|
|
webGLContext,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
useRequestAnimationFrame: renderingIntent !== "print",
|
2018-11-08 22:33:56 +09:00
|
|
|
pdfBug: this._pdfBug,
|
|
|
|
});
|
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
if (!intentState.renderTasks) {
|
|
|
|
intentState.renderTasks = [];
|
|
|
|
}
|
|
|
|
intentState.renderTasks.push(internalRenderTask);
|
|
|
|
const renderTask = internalRenderTask.task;
|
|
|
|
|
2020-07-15 07:17:27 +09:00
|
|
|
Promise.all([
|
|
|
|
intentState.displayReadyCapability.promise,
|
|
|
|
optionalContentConfigPromise,
|
|
|
|
])
|
|
|
|
.then(([transparency, optionalContentConfig]) => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (this.pendingCleanup) {
|
|
|
|
complete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._stats) {
|
|
|
|
this._stats.time("Rendering");
|
|
|
|
}
|
2020-07-15 07:17:27 +09:00
|
|
|
internalRenderTask.initializeGraphics({
|
|
|
|
transparency,
|
|
|
|
optionalContentConfig,
|
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
internalRenderTask.operatorListChanged();
|
|
|
|
})
|
|
|
|
.catch(complete);
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
return renderTask;
|
|
|
|
}
|
2012-04-13 04:11:22 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2020-07-23 05:38:04 +09:00
|
|
|
* @returns {Promise<PDFOperatorList>} A promise resolved with an
|
|
|
|
* {@link PDFOperatorList} object that represents page's operator list.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
getOperatorList() {
|
|
|
|
function operatorListChanged() {
|
|
|
|
if (intentState.operatorList.lastChunk) {
|
|
|
|
intentState.opListReadCapability.resolve(intentState.operatorList);
|
2014-06-17 03:35:38 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
const i = intentState.renderTasks.indexOf(opListTask);
|
|
|
|
if (i >= 0) {
|
|
|
|
intentState.renderTasks.splice(i, 1);
|
2014-06-17 03:35:38 +09:00
|
|
|
}
|
|
|
|
}
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
2014-06-17 03:35:38 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const renderingIntent = "oplist";
|
2020-06-21 23:42:39 +09:00
|
|
|
let intentState = this._intentStates.get(renderingIntent);
|
|
|
|
if (!intentState) {
|
|
|
|
intentState = Object.create(null);
|
|
|
|
this._intentStates.set(renderingIntent, intentState);
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
|
|
|
let opListTask;
|
|
|
|
|
|
|
|
if (!intentState.opListReadCapability) {
|
2020-06-21 23:42:39 +09:00
|
|
|
opListTask = Object.create(null);
|
2018-11-08 22:13:42 +09:00
|
|
|
opListTask.operatorListChanged = operatorListChanged;
|
|
|
|
intentState.opListReadCapability = createPromiseCapability();
|
|
|
|
intentState.renderTasks = [];
|
|
|
|
intentState.renderTasks.push(opListTask);
|
|
|
|
intentState.operatorList = {
|
|
|
|
fnArray: [],
|
|
|
|
argsArray: [],
|
|
|
|
lastChunk: false,
|
|
|
|
};
|
2014-06-17 03:35:38 +09:00
|
|
|
|
2019-10-23 20:23:41 +09:00
|
|
|
if (this._stats) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._stats.time("Page Request");
|
2019-10-23 20:23:41 +09:00
|
|
|
}
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
this._pumpOperatorList({
|
2020-03-19 23:36:09 +09:00
|
|
|
pageIndex: this._pageIndex,
|
2018-11-08 22:13:42 +09:00
|
|
|
intent: renderingIntent,
|
2017-04-17 21:46:53 +09:00
|
|
|
});
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
|
|
|
return intentState.opListReadCapability.promise;
|
|
|
|
}
|
2017-04-17 21:46:53 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
|
|
|
* @param {getTextContentParameters} params - getTextContent parameters.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @returns {ReadableStream} Stream for reading text content chunks.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
streamTextContent({
|
|
|
|
normalizeWhitespace = false,
|
|
|
|
disableCombineTextItems = false,
|
|
|
|
} = {}) {
|
2018-11-08 22:13:42 +09:00
|
|
|
const TEXT_CONTENT_CHUNK_SIZE = 100;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this._transport.messageHandler.sendWithStream(
|
|
|
|
"GetTextContent",
|
|
|
|
{
|
2020-03-19 23:36:09 +09:00
|
|
|
pageIndex: this._pageIndex,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
normalizeWhitespace: normalizeWhitespace === true,
|
|
|
|
combineTextItems: disableCombineTextItems !== true,
|
2018-11-08 22:13:42 +09:00
|
|
|
},
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
{
|
|
|
|
highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
|
|
|
|
size(textContent) {
|
|
|
|
return textContent.items.length;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
2017-04-17 21:46:53 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
|
|
|
* @param {getTextContentParameters} params - getTextContent parameters.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @returns {Promise<TextContent>} A promise that is resolved with a
|
|
|
|
* {@link TextContent} object that represents the page's text content.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
getTextContent(params = {}) {
|
|
|
|
const readableStream = this.streamTextContent(params);
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
return new Promise(function (resolve, reject) {
|
2018-11-08 22:13:42 +09:00
|
|
|
function pump() {
|
2020-04-14 19:28:14 +09:00
|
|
|
reader.read().then(function ({ value, done }) {
|
2018-11-08 22:13:42 +09:00
|
|
|
if (done) {
|
|
|
|
resolve(textContent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object.assign(textContent.styles, value.styles);
|
|
|
|
textContent.items.push(...value.items);
|
|
|
|
pump();
|
|
|
|
}, reject);
|
|
|
|
}
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
const reader = readableStream.getReader();
|
|
|
|
const textContent = {
|
|
|
|
items: [],
|
|
|
|
styles: Object.create(null),
|
|
|
|
};
|
|
|
|
pump();
|
|
|
|
});
|
|
|
|
}
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-13 21:28:15 +09:00
|
|
|
* Destroys the page object.
|
|
|
|
* @private
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
_destroy() {
|
|
|
|
this.destroyed = true;
|
2020-03-19 23:36:09 +09:00
|
|
|
this._transport.pageCache[this._pageIndex] = null;
|
2018-11-08 22:13:42 +09:00
|
|
|
|
|
|
|
const waitOn = [];
|
2020-06-21 23:42:39 +09:00
|
|
|
for (const [intent, intentState] of this._intentStates) {
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
this._abortOperatorList({
|
|
|
|
intentState,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
reason: new Error("Page was destroyed."),
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
force: true,
|
|
|
|
});
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (intent === "oplist") {
|
2018-11-08 22:13:42 +09:00
|
|
|
// Avoid errors below, since the renderTasks are just stubs.
|
2020-06-21 23:42:39 +09:00
|
|
|
continue;
|
2013-08-07 09:35:54 +09:00
|
|
|
}
|
2020-06-21 22:38:09 +09:00
|
|
|
for (const internalRenderTask of intentState.renderTasks) {
|
|
|
|
waitOn.push(internalRenderTask.completed);
|
|
|
|
internalRenderTask.cancel();
|
|
|
|
}
|
2020-06-21 23:42:39 +09:00
|
|
|
}
|
2018-11-08 22:13:42 +09:00
|
|
|
this.objs.clear();
|
|
|
|
this.annotationsPromise = null;
|
|
|
|
this.pendingCleanup = false;
|
|
|
|
return Promise.all(waitOn);
|
|
|
|
}
|
2013-08-07 09:35:54 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
|
|
|
* Cleans up resources allocated by the page.
|
2020-08-03 03:24:43 +09:00
|
|
|
*
|
2019-10-08 20:34:17 +09:00
|
|
|
* @param {boolean} [resetStats] - Reset page stats, if enabled.
|
2018-11-08 22:13:42 +09:00
|
|
|
* The default value is `false`.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @returns {boolean} Indicates if clean-up was successfully run.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
cleanup(resetStats = false) {
|
|
|
|
this.pendingCleanup = true;
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
return this._tryCleanup(resetStats);
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-13 21:28:15 +09:00
|
|
|
* Attempts to clean up if rendering is in a state where that's possible.
|
|
|
|
* @private
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
_tryCleanup(resetStats = false) {
|
2020-06-21 23:42:39 +09:00
|
|
|
if (!this.pendingCleanup) {
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
return false;
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
2020-06-21 23:42:39 +09:00
|
|
|
for (const { renderTasks, operatorList } of this._intentStates.values()) {
|
|
|
|
if (renderTasks.length !== 0 || !operatorList.lastChunk) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-08-07 09:35:54 +09:00
|
|
|
|
2020-06-21 23:42:39 +09:00
|
|
|
this._intentStates.clear();
|
2018-11-08 22:13:42 +09:00
|
|
|
this.objs.clear();
|
|
|
|
this.annotationsPromise = null;
|
2019-10-23 20:23:41 +09:00
|
|
|
if (resetStats && this._stats) {
|
2018-11-08 22:13:42 +09:00
|
|
|
this._stats = new StatTimer();
|
|
|
|
}
|
|
|
|
this.pendingCleanup = false;
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
return true;
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
[api-major] Only create a `StatTimer` for pages when `enableStats == true` (issue 5215)
Unless the debugging tools (i.e. `PDFBug`) are enabled, or the `browsertest` is running, the `PDFPageProxy.stats` aren't actually used for anything.
Rather than initializing unnecessary `StatTimer` instances, we can simply re-use *one* dummy class (with static methods) for every page. Note that by using a dummy `StatTimer` in this way, rather than letting `PDFPageProxy.stats` be undefined, we don't need to guard *every* single stats collection callsite.
Since it wouldn't make much sense to attempt to use `PDFPageProxy.stats` when stat collection is disabled, it was instead changed to a "private" property (i.e. `PDFPageProxy._stats`) and a getter was added for accessing `PDFPageProxy.stats`. This getter will now return `null` when stat collection is disabled, making that case easy to handle.
For benchmarking purposes, the test-suite used to re-create the `StatTimer` after loading/rendering each page. However, modifying properties on various API code from the outside in this way seems very error-prone, and is an anti-pattern that we really should avoid at all cost. Hence the `PDFPageProxy.cleanup` method was modified to accept an optional parameter, which will take care of resetting `this.stats` when necessary, and `test/driver.js` was updated accordingly.
Finally, a tiny bit more validation was added on the viewer side, to ensure that all the code we're attempting to access is defined when handling `PDFPageProxy` stats.
2017-12-07 00:30:04 +09:00
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-13 21:28:15 +09:00
|
|
|
* @private
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
_startRenderPage(transparency, intent) {
|
2020-06-21 23:42:39 +09:00
|
|
|
const intentState = this._intentStates.get(intent);
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
if (!intentState) {
|
|
|
|
return; // Rendering was cancelled.
|
|
|
|
}
|
2019-10-23 20:23:41 +09:00
|
|
|
if (this._stats) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._stats.timeEnd("Page Request");
|
2019-10-23 20:23:41 +09:00
|
|
|
}
|
2018-11-08 22:13:42 +09:00
|
|
|
// TODO Refactor RenderPageRequest to separate rendering
|
|
|
|
// and operator list logic
|
|
|
|
if (intentState.displayReadyCapability) {
|
|
|
|
intentState.displayReadyCapability.resolve(transparency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-13 21:28:15 +09:00
|
|
|
* @private
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
_renderPageChunk(operatorListChunk, intentState) {
|
2018-11-08 22:13:42 +09:00
|
|
|
// Add the new chunk to the current operator list.
|
|
|
|
for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
|
|
|
|
intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
|
|
|
intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
|
|
|
|
|
|
|
|
// Notify all the rendering tasks there are more operators to be consumed.
|
|
|
|
for (let i = 0; i < intentState.renderTasks.length; i++) {
|
|
|
|
intentState.renderTasks[i].operatorListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (operatorListChunk.lastChunk) {
|
|
|
|
this._tryCleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
/**
|
2019-10-13 21:28:15 +09:00
|
|
|
* @private
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
*/
|
|
|
|
_pumpOperatorList(args) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
assert(
|
|
|
|
args.intent,
|
|
|
|
'PDFPageProxy._pumpOperatorList: Expected "intent" argument.'
|
|
|
|
);
|
|
|
|
|
|
|
|
const readableStream = this._transport.messageHandler.sendWithStream(
|
|
|
|
"GetOperatorList",
|
|
|
|
args
|
|
|
|
);
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
const reader = readableStream.getReader();
|
|
|
|
|
2020-06-21 23:42:39 +09:00
|
|
|
const intentState = this._intentStates.get(args.intent);
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
intentState.streamReader = reader;
|
|
|
|
|
|
|
|
const pump = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
reader.read().then(
|
|
|
|
({ value, done }) => {
|
|
|
|
if (done) {
|
|
|
|
intentState.streamReader = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._transport.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
this._renderPageChunk(value, intentState);
|
|
|
|
pump();
|
|
|
|
},
|
|
|
|
reason => {
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
intentState.streamReader = null;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (this._transport.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
if (intentState.operatorList) {
|
|
|
|
// Mark operator list as complete.
|
|
|
|
intentState.operatorList.lastChunk = true;
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
for (let i = 0; i < intentState.renderTasks.length; i++) {
|
|
|
|
intentState.renderTasks[i].operatorListChanged();
|
|
|
|
}
|
|
|
|
this._tryCleanup();
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (intentState.displayReadyCapability) {
|
|
|
|
intentState.displayReadyCapability.reject(reason);
|
|
|
|
} else if (intentState.opListReadCapability) {
|
|
|
|
intentState.opListReadCapability.reject(reason);
|
|
|
|
} else {
|
|
|
|
throw reason;
|
|
|
|
}
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
);
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
};
|
|
|
|
pump();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-13 21:28:15 +09:00
|
|
|
* @private
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
_abortOperatorList({ intentState, reason, force = false }) {
|
|
|
|
assert(
|
|
|
|
reason instanceof Error ||
|
|
|
|
(typeof reason === "object" && reason !== null),
|
|
|
|
'PDFPageProxy._abortOperatorList: Expected "reason" argument.'
|
|
|
|
);
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
|
|
|
|
if (!intentState.streamReader) {
|
|
|
|
return;
|
|
|
|
}
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
if (!force) {
|
|
|
|
// Ensure that an Error occurring in *only* one `InternalRenderTask`, e.g.
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
// multiple render() calls on the same canvas, won't break all rendering.
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
if (intentState.renderTasks.length !== 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Don't immediately abort parsing on the worker-thread when rendering is
|
|
|
|
// cancelled, since that will unnecessarily delay re-rendering when (for
|
|
|
|
// partially parsed pages) e.g. zooming/rotation occurs in the viewer.
|
|
|
|
if (reason instanceof RenderingCancelledException) {
|
|
|
|
intentState.streamReaderCancelTimeout = setTimeout(() => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._abortOperatorList({ intentState, reason, force: true });
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
intentState.streamReaderCancelTimeout = null;
|
|
|
|
}, RENDERING_CANCELLED_TIMEOUT);
|
|
|
|
return;
|
|
|
|
}
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
}
|
|
|
|
intentState.streamReader.cancel(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
new AbortException(reason && reason.message)
|
|
|
|
);
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
intentState.streamReader = null;
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
|
|
|
|
if (this._transport.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
// Remove the current `intentState`, since a cancelled `getOperatorList`
|
|
|
|
// call on the worker-thread cannot be re-started...
|
2020-06-21 23:42:39 +09:00
|
|
|
for (const [intent, curIntentState] of this._intentStates) {
|
|
|
|
if (curIntentState === intentState) {
|
|
|
|
this._intentStates.delete(intent);
|
|
|
|
break;
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
}
|
2020-06-21 23:42:39 +09:00
|
|
|
}
|
Abort, with a small delay, `getOperatorList` on the worker-thread when rendering is cancelled (PR 11069 follow-up)
With this patch we're finally able to abort worker-thread parsing of the `OperatorList`, rather than *only* aborting the main-thread rendering itself, when the `RenderTask.cancel` method is being called.
This will help improve perceived performance in the default viewer, especially when reading longer and more complex documents, since pages that've been scrolled out-of-view (and thus evicted from the cache) will no longer compete for parsing resources on the worker-thread.
*Please note:* With the implementation in this patch we're *not* aborting worker-thread parsing immediately on `RenderTask.cancel`, since that would lead to *worse* performance in many cases. For example: When zoom/rotation occurs in the viewer, while parsing/rendering is still ongoing, a `cancel` call will usually be (almost) immediately folled by a new `PDFPageProxy.render` call. In that case you obviously don't want to abort parsing on the worker-thread, since that would risk throwing away a partially parsed `OperatorList` and thus force unnecessary re-parsing which will regress perceived performance (especially for more complex documents).
When choosing a reasonable delay, before cancelling `getOperatorList` on the worker-thread when `RenderTask.cancel` is called, two different positions need to be considered:
1. The delay needs to be short enough, since a timeout in the multiple seconds range would essentially make this entire functionality meaningless (by always allowing most/all pages enough time to finish parsing).
2. The delay cannot be *too* short, since that would actually *reduce* performance in the zoom/rotation case outlined above. Furthermore, the time between `RenderTask.cancel` and `PDFPageProxy.render` calls will obviously be affected by both general computer performance and current CPU load.
It's certainly possible that the timeout may require some further tweaks, however the value settled on in this patch was easily *one order* of magnitude larger than the delta between cancel/render in my tests.
2019-08-21 23:19:24 +09:00
|
|
|
// ... and force clean-up to ensure that any old state is always removed.
|
|
|
|
this.cleanup();
|
Use streams for OperatorList chunking (issue 10023)
*Please note:* The majority of this patch was written by Yury, and it's simply been rebased and slightly extended to prevent issues when dealing with `RenderingCancelledException`.
By leveraging streams this (finally) provides a simple way in which parsing can be aborted on the worker-thread, which will ultimately help save resources.
With this patch worker-thread parsing will *only* be aborted when the document is destroyed, and not when rendering is cancelled. There's a couple of reasons for this:
- The API currently expects the *entire* OperatorList to be extracted, or an Error to occur, once it's been started. Hence additional re-factoring/re-writing of the API code will be necessary to properly support cancelling and re-starting of OperatorList parsing in cases where the `lastChunk` hasn't yet been seen.
- Even with the above addressed, immediately cancelling when encountering a `RenderingCancelledException` will lead to worse performance in e.g. the default viewer. When zooming and/or rotation of the document occurs it's very likely that `cancel` will be (almost) immediately followed by a new `render` call. In that case you'd obviously *not* want to abort parsing on the worker-thread, since then you'd risk throwing away a partially parsed Page and thus be forced to re-parse it again which will regress perceived performance.
- This patch is already *somewhat* risky, given that it touches fundamentally important/critical code, and trying to keep it somewhat small should hopefully reduce the risk of regressions (and simplify reviewing as well).
Time permitting, once this has landed and been in Nightly for awhile, I'll try to work on the remaining points outlined above.
Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>
Co-Authored-By: Jonas Jenwald <jonas.jenwald@gmail.com>
2017-11-10 10:58:43 +09:00
|
|
|
}
|
|
|
|
|
2018-11-08 22:13:42 +09:00
|
|
|
/**
|
2019-10-23 20:23:41 +09:00
|
|
|
* @type {Object} Returns page stats, if enabled; returns `null` otherwise.
|
2018-11-08 22:13:42 +09:00
|
|
|
*/
|
|
|
|
get stats() {
|
2019-10-23 20:23:41 +09:00
|
|
|
return this._stats;
|
2018-11-08 22:13:42 +09:00
|
|
|
}
|
|
|
|
}
|
2014-01-22 04:28:18 +09:00
|
|
|
|
2017-05-03 02:20:13 +09:00
|
|
|
class LoopbackPort {
|
2018-06-04 19:38:05 +09:00
|
|
|
constructor(defer = true) {
|
2017-05-03 02:20:13 +09:00
|
|
|
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.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof value !== "object" || value === null) {
|
2017-05-03 02:20:13 +09:00
|
|
|
return value;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (cloned.has(value)) {
|
|
|
|
// already cloned the object
|
2017-05-03 02:20:13 +09:00
|
|
|
return cloned.get(value);
|
|
|
|
}
|
2018-11-09 00:24:20 +09:00
|
|
|
let buffer, result;
|
2017-05-03 02:20:13 +09:00
|
|
|
if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
|
|
|
|
// We found object with ArrayBuffer (typed array).
|
2018-11-09 00:24:20 +09:00
|
|
|
const transferable = transfers && transfers.includes(buffer);
|
2020-02-13 20:46:29 +09:00
|
|
|
if (transferable) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
result = new value.constructor(
|
|
|
|
buffer,
|
|
|
|
value.byteOffset,
|
|
|
|
value.byteLength
|
|
|
|
);
|
2017-05-03 02:20:13 +09:00
|
|
|
} else {
|
|
|
|
result = new value.constructor(value);
|
|
|
|
}
|
|
|
|
cloned.set(value, result);
|
|
|
|
return result;
|
|
|
|
}
|
2017-08-23 07:50:27 +09:00
|
|
|
result = Array.isArray(value) ? [] : {};
|
2017-05-03 02:20:13 +09:00
|
|
|
cloned.set(value, result); // adding to cache now for cyclic references
|
|
|
|
// Cloning all value and object properties, however ignoring properties
|
|
|
|
// defined via getter.
|
2018-11-09 00:24:20 +09:00
|
|
|
for (const i in value) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let desc,
|
|
|
|
p = value;
|
2017-05-03 02:20:13 +09:00
|
|
|
while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
|
|
|
|
p = Object.getPrototypeOf(p);
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof desc.value === "undefined") {
|
2019-09-26 23:04:41 +09:00
|
|
|
continue;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof desc.value === "function") {
|
2019-09-26 23:04:41 +09:00
|
|
|
if (value.hasOwnProperty && value.hasOwnProperty(i)) {
|
|
|
|
throw new Error(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
`LoopbackPort.postMessage - cannot clone: ${value[i]}`
|
|
|
|
);
|
2019-09-26 23:04:41 +09:00
|
|
|
}
|
2017-05-03 02:20:13 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result[i] = cloneValue(desc.value);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._defer) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._listeners.forEach(listener => {
|
|
|
|
listener.call(this, { data: obj });
|
2019-08-30 18:35:05 +09:00
|
|
|
});
|
2017-05-03 02:20:13 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-09 00:24:20 +09:00
|
|
|
const cloned = new WeakMap();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const e = { data: cloneValue(obj) };
|
2017-05-03 23:39:54 +09:00
|
|
|
this._deferred.then(() => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._listeners.forEach(listener => {
|
2017-05-03 02:20:13 +09:00
|
|
|
listener.call(this, e);
|
2019-08-30 18:35:05 +09:00
|
|
|
});
|
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) {
|
2018-11-09 00:24:20 +09:00
|
|
|
const i = this._listeners.indexOf(listener);
|
2017-05-03 02:20:13 +09:00
|
|
|
this._listeners.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
terminate() {
|
2019-05-30 23:25:48 +09:00
|
|
|
this._listeners.length = 0;
|
2017-05-03 02:20:13 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:03:54 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} PDFWorkerParameters
|
2019-10-08 20:34:17 +09:00
|
|
|
* @property {string} [name] - The name of the worker.
|
2020-08-03 03:24:43 +09:00
|
|
|
* @property {Object} [port] - The `workerPort` object.
|
2019-10-08 20:34:17 +09:00
|
|
|
* @property {number} [verbosity] - Controls the logging level; the
|
2020-08-03 03:24:43 +09:00
|
|
|
* constants from {@link VerbosityLevel} should be used.
|
2018-02-15 00:03:54 +09:00
|
|
|
*/
|
|
|
|
|
2020-07-23 05:38:04 +09:00
|
|
|
/** @type {any} */
|
2018-11-09 00:22:26 +09:00
|
|
|
const PDFWorker = (function PDFWorkerClosure() {
|
|
|
|
const pdfWorkerPorts = new WeakMap();
|
2019-12-20 01:36:36 +09:00
|
|
|
let isWorkerDisabled = false;
|
|
|
|
let fallbackWorkerSrc;
|
2017-06-10 10:07:51 +09:00
|
|
|
let nextFakeWorkerId = 0;
|
2019-12-20 02:11:56 +09:00
|
|
|
let fakeWorkerCapability;
|
2015-10-28 02:55:15 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) {
|
2019-12-20 02:32:51 +09:00
|
|
|
// eslint-disable-next-line no-undef
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (isNodeJS && typeof __non_webpack_require__ === "function") {
|
2019-12-20 01:36:36 +09:00
|
|
|
// Workers aren't supported in Node.js, force-disabling them there.
|
|
|
|
isWorkerDisabled = true;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("LIB")) {
|
|
|
|
fallbackWorkerSrc = "../pdf.worker.js";
|
2019-12-20 01:39:55 +09:00
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fallbackWorkerSrc = "./pdf.worker.js";
|
2019-12-20 01:39:55 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else if (typeof document === "object" && "currentScript" in document) {
|
|
|
|
const pdfjsFilePath =
|
|
|
|
document.currentScript && document.currentScript.src;
|
2019-12-20 01:36:36 +09:00
|
|
|
if (pdfjsFilePath) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fallbackWorkerSrc = pdfjsFilePath.replace(
|
|
|
|
/(\.(?:min\.)?js)(\?.*)?$/i,
|
|
|
|
".worker$1$2"
|
|
|
|
);
|
2019-12-20 01:36:36 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-24 08:46:08 +09:00
|
|
|
function getWorkerSrc() {
|
2018-02-14 22:49:24 +09:00
|
|
|
if (GlobalWorkerOptions.workerSrc) {
|
|
|
|
return GlobalWorkerOptions.workerSrc;
|
2015-12-24 08:46:08 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof fallbackWorkerSrc !== "undefined") {
|
2019-12-20 01:39:55 +09:00
|
|
|
if (!isNodeJS) {
|
|
|
|
deprecated('No "GlobalWorkerOptions.workerSrc" specified.');
|
|
|
|
}
|
2018-10-07 21:28:16 +09:00
|
|
|
return fallbackWorkerSrc;
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2018-02-14 22:49:24 +09:00
|
|
|
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
2015-12-24 08:46:08 +09:00
|
|
|
}
|
|
|
|
|
2018-01-20 02:16:17 +09:00
|
|
|
function getMainThreadWorkerMessageHandler() {
|
2019-12-08 22:03:32 +09:00
|
|
|
let mainWorkerMessageHandler;
|
2018-10-09 22:35:28 +09:00
|
|
|
try {
|
2019-12-08 22:03:32 +09:00
|
|
|
mainWorkerMessageHandler =
|
|
|
|
globalThis.pdfjsWorker && globalThis.pdfjsWorker.WorkerMessageHandler;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} catch (ex) {
|
|
|
|
/* Ignore errors. */
|
|
|
|
}
|
2019-12-08 22:03:32 +09:00
|
|
|
return mainWorkerMessageHandler || null;
|
2018-01-20 02:16:17 +09:00
|
|
|
}
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
// Loads worker code into main thread.
|
|
|
|
function setupFakeWorkerGlobal() {
|
2019-12-20 02:11:56 +09:00
|
|
|
if (fakeWorkerCapability) {
|
|
|
|
return fakeWorkerCapability.promise;
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
2019-12-20 02:11:56 +09:00
|
|
|
fakeWorkerCapability = createPromiseCapability();
|
2018-01-20 02:16:17 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
const loader = async function () {
|
2019-12-20 02:11:56 +09:00
|
|
|
const mainWorkerMessageHandler = getMainThreadWorkerMessageHandler();
|
|
|
|
|
|
|
|
if (mainWorkerMessageHandler) {
|
|
|
|
// The worker was already loaded using e.g. a `<script>` tag.
|
|
|
|
return mainWorkerMessageHandler;
|
2015-11-24 02:46:40 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
|
|
|
if (typeof SystemJS !== "object") {
|
2020-05-20 01:00:23 +09:00
|
|
|
// Manually load SystemJS, since it's only necessary for fake workers.
|
|
|
|
await loadScript("../node_modules/systemjs/dist/system.js");
|
|
|
|
await loadScript("../systemjs.config.js");
|
2019-12-20 02:11:56 +09:00
|
|
|
}
|
2020-01-02 20:00:16 +09:00
|
|
|
const worker = await SystemJS.import("pdfjs/core/worker.js");
|
2019-12-20 02:11:56 +09:00
|
|
|
return worker.WorkerMessageHandler;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
PDFJSDev.test("GENERIC") &&
|
|
|
|
isNodeJS &&
|
2019-12-26 04:03:46 +09:00
|
|
|
// eslint-disable-next-line no-undef
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
typeof __non_webpack_require__ === "function"
|
|
|
|
) {
|
2019-12-20 02:32:51 +09:00
|
|
|
// Since bundlers, such as Webpack, cannot be told to leave `require`
|
|
|
|
// statements alone we are thus forced to jump through hoops in order
|
|
|
|
// to prevent `Critical dependency: ...` warnings in third-party
|
|
|
|
// deployments of the built `pdf.js`/`pdf.worker.js` files; see
|
|
|
|
// https://github.com/webpack/webpack/issues/8826
|
|
|
|
//
|
|
|
|
// The following hack is based on the assumption that code running in
|
|
|
|
// Node.js won't ever be affected by e.g. Content Security Policies that
|
|
|
|
// prevent the use of `eval`. If that ever occurs, we should revert this
|
|
|
|
// to a normal `__non_webpack_require__` statement and simply document
|
|
|
|
// the Webpack warnings instead (telling users to ignore them).
|
|
|
|
//
|
|
|
|
// eslint-disable-next-line no-eval
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const worker = eval("require")(getWorkerSrc());
|
2019-12-20 02:11:56 +09:00
|
|
|
return worker.WorkerMessageHandler;
|
|
|
|
}
|
|
|
|
await loadScript(getWorkerSrc());
|
|
|
|
return window.pdfjsWorker.WorkerMessageHandler;
|
|
|
|
};
|
|
|
|
loader().then(fakeWorkerCapability.resolve, fakeWorkerCapability.reject);
|
|
|
|
|
|
|
|
return fakeWorkerCapability.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.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const wrapper = "importScripts('" + url + "');";
|
2016-01-16 06:05:46 +09:00
|
|
|
return URL.createObjectURL(new Blob([wrapper]));
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:03:54 +09:00
|
|
|
/**
|
2020-08-03 03:24:43 +09:00
|
|
|
* PDF.js web worker abstraction that controls the instantiation of PDF
|
2019-10-13 21:21:39 +09:00
|
|
|
* documents. Message handlers are used to pass information from the main
|
|
|
|
* thread to the worker thread and vice versa. If the creation of a web
|
|
|
|
* worker is not possible, a "fake" worker will be used instead.
|
2018-02-15 00:03:54 +09:00
|
|
|
*/
|
2020-03-25 18:15:50 +09:00
|
|
|
// eslint-disable-next-line no-shadow
|
2018-11-09 00:22:26 +09:00
|
|
|
class PDFWorker {
|
2019-10-13 21:21:39 +09:00
|
|
|
/**
|
|
|
|
* @param {PDFWorkerParameters} params - Worker initialization parameters.
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
constructor({
|
|
|
|
name = null,
|
|
|
|
port = null,
|
|
|
|
verbosity = getVerbosityLevel(),
|
|
|
|
} = {}) {
|
2018-11-09 00:22:26 +09:00
|
|
|
if (port && pdfWorkerPorts.has(port)) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Cannot use more than one PDFWorker per port");
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
2017-06-10 10:07:51 +09:00
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
this.name = name;
|
|
|
|
this.destroyed = false;
|
[api-minor] Remove the `postMessageTransfers` parameter, and thus the ability to manually disable transferring of data, from the API
By transfering, rather than copying, `ArrayBuffer`s between the main- and worker-threads, you can avoid unnecessary allocations by only having *one* copy of the same data.
Hence manually setting `postMessageTransfers: false`, when calling `getDocument`, is a performance footgun[1] which will do nothing but waste memory.
Given that every reasonably modern browser supports `postMessage` transfers[2], I really don't see why it should be possible to force-disable this functionality.
Looking at the browser support, for `postMessage` transfers[2], it's highly unlikely that PDF.js is even usable in browsers without it. However, the feature testing of `postMessage` transfers is kept for the time being just to err on the safe side.
---
[1] This is somewhat similar to the, now removed, `disableWorker` parameter which also provided API users a much too simple way of reducing performance.
[2] See e.g. https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage#Browser_compatibility and https://developer.mozilla.org/en-US/docs/Web/API/Transferable#Browser_compatibility
2019-09-05 17:42:30 +09:00
|
|
|
this.postMessageTransfers = true;
|
2018-11-09 00:22:26 +09:00
|
|
|
this.verbosity = verbosity;
|
2015-01-06 12:45:01 +09:00
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
this._readyCapability = createPromiseCapability();
|
|
|
|
this._port = null;
|
|
|
|
this._webWorker = null;
|
|
|
|
this._messageHandler = null;
|
2017-02-25 04:33:18 +09:00
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
if (port) {
|
|
|
|
pdfWorkerPorts.set(port, this);
|
|
|
|
this._initializeFromPort(port);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._initialize();
|
2017-02-25 04:33:18 +09:00
|
|
|
}
|
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
get promise() {
|
|
|
|
return this._readyCapability.promise;
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
2015-10-28 02:55:15 +09:00
|
|
|
|
|
|
|
get port() {
|
|
|
|
return this._port;
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
2013-05-10 07:35:23 +09:00
|
|
|
|
2015-10-28 02:55:15 +09:00
|
|
|
get messageHandler() {
|
|
|
|
return this._messageHandler;
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
2015-10-28 02:55:15 +09:00
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
_initializeFromPort(port) {
|
2017-02-25 04:33:18 +09:00
|
|
|
this._port = port;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._messageHandler = new MessageHandler("main", "worker", port);
|
2020-04-14 19:28:14 +09:00
|
|
|
this._messageHandler.on("ready", function () {
|
2017-02-25 04:33:18 +09:00
|
|
|
// Ignoring 'ready' event -- MessageHandler shall be already initialized
|
|
|
|
// and ready to accept the messages.
|
|
|
|
});
|
|
|
|
this._readyCapability.resolve();
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
2017-02-25 04:33:18 +09:00
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
_initialize() {
|
2015-10-28 02:55:15 +09:00
|
|
|
// 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.)
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
typeof Worker !== "undefined" &&
|
|
|
|
!isWorkerDisabled &&
|
|
|
|
!getMainThreadWorkerMessageHandler()
|
|
|
|
) {
|
2018-10-07 21:28:16 +09:00
|
|
|
let 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.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev !== "undefined" &&
|
|
|
|
PDFJSDev.test("GENERIC") &&
|
|
|
|
!isSameOrigin(window.location.href, workerSrc)
|
|
|
|
) {
|
2016-10-15 00:57:53 +09:00
|
|
|
workerSrc = createCDNWrapper(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
new URL(workerSrc, window.location).href
|
|
|
|
);
|
2016-10-15 00:57:53 +09:00
|
|
|
}
|
|
|
|
|
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
|
2018-11-09 00:22:26 +09:00
|
|
|
const worker = new Worker(workerSrc);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const messageHandler = new MessageHandler("main", "worker", worker);
|
2018-11-09 00:22:26 +09:00
|
|
|
const terminateEarly = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
worker.removeEventListener("error", onWorkerError);
|
2017-10-07 01:55:28 +09:00
|
|
|
messageHandler.destroy();
|
2015-12-25 21:24:19 +09:00
|
|
|
worker.terminate();
|
2015-10-28 02:55:15 +09:00
|
|
|
if (this.destroyed) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
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
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
const 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
|
|
|
};
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
worker.addEventListener("error", onWorkerError);
|
2015-12-25 21:24:19 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("test", data => {
|
|
|
|
worker.removeEventListener("error", onWorkerError);
|
2015-12-25 21:24:19 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
terminateEarly();
|
2015-10-28 02:55:15 +09:00
|
|
|
return; // worker was destroyed
|
2013-11-12 12:30:26 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (data) {
|
|
|
|
// supportTypedArray
|
2015-10-28 02:55:15 +09:00
|
|
|
this._messageHandler = messageHandler;
|
|
|
|
this._port = worker;
|
|
|
|
this._webWorker = worker;
|
|
|
|
if (!data.supportTransfers) {
|
2017-07-01 02:59:52 +09:00
|
|
|
this.postMessageTransfers = false;
|
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.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.send("configure", {
|
2018-02-15 01:35:08 +09:00
|
|
|
verbosity: this.verbosity,
|
2016-03-04 01:13:37 +09:00
|
|
|
});
|
2015-10-28 02:55:15 +09:00
|
|
|
} else {
|
|
|
|
this._setupFakeWorker();
|
2017-10-07 01:55:28 +09:00
|
|
|
messageHandler.destroy();
|
2015-10-28 02:55:15 +09:00
|
|
|
worker.terminate();
|
|
|
|
}
|
2017-05-03 23:39:54 +09:00
|
|
|
});
|
2015-10-28 02:55:15 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("ready", data => {
|
|
|
|
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
|
|
|
|
2018-02-15 00:53:50 +09:00
|
|
|
const sendTest = () => {
|
2020-01-24 17:48:21 +09:00
|
|
|
const testObj = new Uint8Array([
|
|
|
|
this.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 {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.send("test", testObj, [testObj.buffer]);
|
2015-12-17 09:37:43 +09:00
|
|
|
} catch (ex) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
warn("Cannot use postMessage transfers.");
|
2015-12-17 09:37:43 +09:00
|
|
|
testObj[0] = 0;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.send("test", testObj);
|
2015-12-17 09:37:43 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
info("The worker has been disabled.");
|
2015-10-28 02:55:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Either workers are disabled, not supported or have thrown an exception.
|
|
|
|
// Thus, we fallback to a faked worker.
|
|
|
|
this._setupFakeWorker();
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
_setupFakeWorker() {
|
2018-01-20 02:16:17 +09:00
|
|
|
if (!isWorkerDisabled) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +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
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
setupFakeWorkerGlobal()
|
|
|
|
.then(WorkerMessageHandler => {
|
|
|
|
if (this.destroyed) {
|
|
|
|
this._readyCapability.reject(new Error("Worker was destroyed"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const port = new LoopbackPort();
|
|
|
|
this._port = port;
|
|
|
|
|
|
|
|
// All fake workers use the same port, making id unique.
|
|
|
|
const id = "fake" + nextFakeWorkerId++;
|
|
|
|
|
|
|
|
// If the main thread is our worker, setup the handling for the
|
|
|
|
// messages -- the main thread sends to it self.
|
|
|
|
const workerHandler = new MessageHandler(id + "_worker", id, port);
|
|
|
|
WorkerMessageHandler.setup(workerHandler, port);
|
|
|
|
|
|
|
|
const messageHandler = new MessageHandler(id, id + "_worker", port);
|
|
|
|
this._messageHandler = messageHandler;
|
|
|
|
this._readyCapability.resolve();
|
2020-01-26 20:21:23 +09:00
|
|
|
// Send global setting, e.g. verbosity level.
|
|
|
|
messageHandler.send("configure", {
|
|
|
|
verbosity: this.verbosity,
|
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
})
|
|
|
|
.catch(reason => {
|
|
|
|
this._readyCapability.reject(
|
|
|
|
new Error(`Setting up fake worker failed: "${reason.message}".`)
|
|
|
|
);
|
|
|
|
});
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
2015-10-28 02:55:15 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the worker instance.
|
|
|
|
*/
|
2018-11-09 00:22:26 +09:00
|
|
|
destroy() {
|
2015-10-28 02:55:15 +09:00
|
|
|
this.destroyed = true;
|
|
|
|
if (this._webWorker) {
|
|
|
|
// We need to terminate only web worker created resource.
|
|
|
|
this._webWorker.terminate();
|
|
|
|
this._webWorker = null;
|
|
|
|
}
|
2017-08-03 05:48:42 +09:00
|
|
|
pdfWorkerPorts.delete(this._port);
|
2015-10-28 02:55:15 +09:00
|
|
|
this._port = null;
|
|
|
|
if (this._messageHandler) {
|
2017-10-07 01:55:28 +09:00
|
|
|
this._messageHandler.destroy();
|
2015-10-28 02:55:15 +09:00
|
|
|
this._messageHandler = null;
|
2012-04-12 07:52:15 +09:00
|
|
|
}
|
2017-06-10 10:07:51 +09:00
|
|
|
}
|
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
/**
|
|
|
|
* @param {PDFWorkerParameters} params - The worker initialization
|
2020-08-03 03:24:43 +09:00
|
|
|
* parameters.
|
2018-11-09 00:22:26 +09:00
|
|
|
*/
|
|
|
|
static fromPort(params) {
|
|
|
|
if (!params || !params.port) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("PDFWorker.fromPort - invalid method signature.");
|
2018-11-09 00:22:26 +09:00
|
|
|
}
|
|
|
|
if (pdfWorkerPorts.has(params.port)) {
|
|
|
|
return pdfWorkerPorts.get(params.port);
|
|
|
|
}
|
|
|
|
return new PDFWorker(params);
|
|
|
|
}
|
2018-01-29 23:58:40 +09:00
|
|
|
|
2018-11-09 00:22:26 +09:00
|
|
|
static getWorkerSrc() {
|
|
|
|
return getWorkerSrc();
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*/
|
2018-08-27 01:32:25 +09:00
|
|
|
class WorkerTransport {
|
|
|
|
constructor(messageHandler, loadingTask, networkStream, params) {
|
2015-10-28 02:55:15 +09:00
|
|
|
this.messageHandler = messageHandler;
|
|
|
|
this.loadingTask = loadingTask;
|
2012-10-29 05:10:34 +09:00
|
|
|
this.commonObjs = new PDFObjects();
|
Fallback to the built-in font renderer when font loading fails
After PR 9340 all glyphs are now re-mapped to a Private Use Area (PUA) which means that if a font fails to load, for whatever reason[1], all glyphs in the font will now render as Unicode glyph outlines.
This obviously doesn't look good, to say the least, and might be seen as a "regression" since previously many glyphs were left in their original positions which provided a slightly better fallback[2].
Hence this patch, which implements a *general* fallback to the PDF.js built-in font renderer for fonts that fail to load (i.e. are rejected by the sanitizer). One caveat here is that this only works for the Font Loading API, since it's easy to handle errors in that case[3].
The solution implemented in this patch does *not* in any way delay the loading of valid fonts, which was the problem with my previous attempt at a solution, and will only require a bit of extra work/waiting for those fonts that actually fail to load.
*Please note:* This patch doesn't fix any of the underlying PDF.js font conversion bugs that's responsible for creating corrupt font files, however it does *improve* rendering in a number of cases; refer to this possibly incomplete list:
[Bug 1524888](https://bugzilla.mozilla.org/show_bug.cgi?id=1524888)
Issue 10175
Issue 10232
---
[1] Usually because the PDF.js font conversion code wasn't able to parse the font file correctly.
[2] Glyphs fell back to some default font, which while not accurate was more useful than the current state.
[3] Furthermore I'm not sure how to implement this generally, assuming that's even possible, and don't really have time/interest to look into it either.
2019-02-11 08:47:56 +09:00
|
|
|
this.fontLoader = new FontLoader({
|
|
|
|
docId: loadingTask.docId,
|
|
|
|
onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
|
2020-07-28 02:22:45 +09:00
|
|
|
ownerDocument: params.ownerDocument,
|
Fallback to the built-in font renderer when font loading fails
After PR 9340 all glyphs are now re-mapped to a Private Use Area (PUA) which means that if a font fails to load, for whatever reason[1], all glyphs in the font will now render as Unicode glyph outlines.
This obviously doesn't look good, to say the least, and might be seen as a "regression" since previously many glyphs were left in their original positions which provided a slightly better fallback[2].
Hence this patch, which implements a *general* fallback to the PDF.js built-in font renderer for fonts that fail to load (i.e. are rejected by the sanitizer). One caveat here is that this only works for the Font Loading API, since it's easy to handle errors in that case[3].
The solution implemented in this patch does *not* in any way delay the loading of valid fonts, which was the problem with my previous attempt at a solution, and will only require a bit of extra work/waiting for those fonts that actually fail to load.
*Please note:* This patch doesn't fix any of the underlying PDF.js font conversion bugs that's responsible for creating corrupt font files, however it does *improve* rendering in a number of cases; refer to this possibly incomplete list:
[Bug 1524888](https://bugzilla.mozilla.org/show_bug.cgi?id=1524888)
Issue 10175
Issue 10232
---
[1] Usually because the PDF.js font conversion code wasn't able to parse the font file correctly.
[2] Glyphs fell back to some default font, which while not accurate was more useful than the current state.
[3] Furthermore I'm not sure how to implement this generally, assuming that's even possible, and don't really have time/interest to look into it either.
2019-02-11 08:47:56 +09:00
|
|
|
});
|
2018-02-18 00:57:24 +09:00
|
|
|
this._params = params;
|
2018-06-06 03:30:14 +09:00
|
|
|
this.CMapReaderFactory = new params.CMapReaderFactory({
|
2018-02-18 00:57:24 +09:00
|
|
|
baseUrl: params.cMapUrl,
|
|
|
|
isCompressed: params.cMapPacked,
|
2017-02-12 23:54:41 +09:00
|
|
|
});
|
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
|
|
|
|
2017-07-01 02:59:52 +09:00
|
|
|
this._networkStream = networkStream;
|
|
|
|
this._fullReader = null;
|
|
|
|
this._lastProgress = null;
|
|
|
|
|
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
|
|
|
}
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
destroy() {
|
|
|
|
if (this.destroyCapability) {
|
|
|
|
return this.destroyCapability.promise;
|
|
|
|
}
|
2015-10-21 07:45:55 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
this.destroyed = true;
|
|
|
|
this.destroyCapability = createPromiseCapability();
|
2016-12-31 21:59:07 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this._passwordCapability) {
|
|
|
|
this._passwordCapability.reject(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
new Error("Worker was destroyed during onPassword callback")
|
|
|
|
);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2017-07-01 02:59:52 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
const waitOn = [];
|
|
|
|
// We need to wait for all renderings to be completed, e.g.
|
|
|
|
// timeout/rAF can take a long time.
|
2020-04-14 19:28:14 +09:00
|
|
|
this.pageCache.forEach(function (page) {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (page) {
|
|
|
|
waitOn.push(page._destroy());
|
|
|
|
}
|
|
|
|
});
|
2019-05-30 23:25:48 +09:00
|
|
|
this.pageCache.length = 0;
|
|
|
|
this.pagePromises.length = 0;
|
2018-08-27 01:32:25 +09:00
|
|
|
// We also need to wait for the worker to finish its long running tasks.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const terminated = this.messageHandler.sendWithPromise("Terminate", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
waitOn.push(terminated);
|
|
|
|
Promise.all(waitOn).then(() => {
|
|
|
|
this.fontLoader.clear();
|
|
|
|
if (this._networkStream) {
|
2019-08-01 23:31:32 +09:00
|
|
|
this._networkStream.cancelAllRequests(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
new AbortException("Worker was terminated.")
|
|
|
|
);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2013-08-13 02:48:06 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this.messageHandler) {
|
|
|
|
this.messageHandler.destroy();
|
|
|
|
this.messageHandler = null;
|
|
|
|
}
|
|
|
|
this.destroyCapability.resolve();
|
|
|
|
}, this.destroyCapability.reject);
|
|
|
|
return this.destroyCapability.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
setupMessageHandler() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const { messageHandler, loadingTask } = this;
|
2017-07-01 02:59:52 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("GetReader", (data, sink) => {
|
2020-05-05 19:40:01 +09:00
|
|
|
assert(
|
|
|
|
this._networkStream,
|
|
|
|
"GetReader - no `IPDFStream` instance available."
|
|
|
|
);
|
2018-08-27 01:32:25 +09:00
|
|
|
this._fullReader = this._networkStream.getFullReader();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._fullReader.onProgress = evt => {
|
2018-08-27 01:32:25 +09:00
|
|
|
this._lastProgress = {
|
|
|
|
loaded: evt.loaded,
|
|
|
|
total: evt.total,
|
2017-07-01 02:59:52 +09:00
|
|
|
};
|
2018-08-27 01:32:25 +09:00
|
|
|
};
|
|
|
|
sink.onPull = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._fullReader
|
|
|
|
.read()
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function ({ value, done }) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (done) {
|
|
|
|
sink.close();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-05 19:40:01 +09:00
|
|
|
assert(
|
|
|
|
isArrayBuffer(value),
|
|
|
|
"GetReader - expected an ArrayBuffer."
|
|
|
|
);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
// Enqueue data chunk into sink, and transfer it
|
|
|
|
// to other side as `Transferable` object.
|
|
|
|
sink.enqueue(new Uint8Array(value), 1, [value]);
|
|
|
|
})
|
|
|
|
.catch(reason => {
|
|
|
|
sink.error(reason);
|
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
};
|
2017-07-01 02:59:52 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
sink.onCancel = reason => {
|
2018-08-27 01:32:25 +09:00
|
|
|
this._fullReader.cancel(reason);
|
2020-07-31 01:03:08 +09:00
|
|
|
|
|
|
|
sink.ready.catch(readyReason => {
|
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
throw readyReason;
|
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
};
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("ReaderHeadersReady", data => {
|
2018-08-27 01:32:25 +09:00
|
|
|
const headersCapability = createPromiseCapability();
|
|
|
|
const fullReader = this._fullReader;
|
|
|
|
fullReader.headersReady.then(() => {
|
|
|
|
// If stream or range are disabled, it's our only way to report
|
|
|
|
// loading progress.
|
Ensure that `onProgress` is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired.
From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded).
This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense.
However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls.
The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread.
---
[1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
2018-10-16 20:24:02 +09:00
|
|
|
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
|
|
|
|
if (this._lastProgress && loadingTask.onProgress) {
|
|
|
|
loadingTask.onProgress(this._lastProgress);
|
2017-07-01 02:59:52 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fullReader.onProgress = evt => {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (loadingTask.onProgress) {
|
|
|
|
loadingTask.onProgress({
|
|
|
|
loaded: evt.loaded,
|
|
|
|
total: evt.total,
|
|
|
|
});
|
2017-07-01 02:59:52 +09:00
|
|
|
}
|
2017-04-25 23:17:18 +09:00
|
|
|
};
|
2013-05-10 07:35:23 +09:00
|
|
|
}
|
2012-10-16 19:10:37 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
headersCapability.resolve({
|
|
|
|
isStreamingSupported: fullReader.isStreamingSupported,
|
|
|
|
isRangeSupported: fullReader.isRangeSupported,
|
|
|
|
contentLength: fullReader.contentLength,
|
|
|
|
});
|
|
|
|
}, headersCapability.reject);
|
2013-01-30 03:13:28 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
return headersCapability.promise;
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2014-09-13 23:47:16 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("GetRangeReader", (data, sink) => {
|
2020-05-05 19:40:01 +09:00
|
|
|
assert(
|
|
|
|
this._networkStream,
|
|
|
|
"GetRangeReader - no `IPDFStream` instance available."
|
|
|
|
);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const rangeReader = this._networkStream.getRangeReader(
|
|
|
|
data.begin,
|
|
|
|
data.end
|
|
|
|
);
|
2012-10-16 19:10:37 +09:00
|
|
|
|
2019-03-28 01:54:05 +09:00
|
|
|
// When streaming is enabled, it's possible that the data requested here
|
|
|
|
// has already been fetched via the `_fullRequestReader` implementation.
|
|
|
|
// However, given that the PDF data is loaded asynchronously on the
|
|
|
|
// main-thread and then sent via `postMessage` to the worker-thread,
|
|
|
|
// it may not have been available during parsing (hence the attempt to
|
|
|
|
// use range requests here).
|
|
|
|
//
|
|
|
|
// To avoid wasting time and resources here, we'll thus *not* dispatch
|
|
|
|
// range requests if the data was already loaded but has not been sent to
|
|
|
|
// the worker-thread yet (which will happen via the `_fullRequestReader`).
|
|
|
|
if (!rangeReader) {
|
|
|
|
sink.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
sink.onPull = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
rangeReader
|
|
|
|
.read()
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function ({ value, done }) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (done) {
|
|
|
|
sink.close();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-05 19:40:01 +09:00
|
|
|
assert(
|
|
|
|
isArrayBuffer(value),
|
|
|
|
"GetRangeReader - expected an ArrayBuffer."
|
|
|
|
);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
sink.enqueue(new Uint8Array(value), 1, [value]);
|
|
|
|
})
|
|
|
|
.catch(reason => {
|
|
|
|
sink.error(reason);
|
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
};
|
2012-04-12 07:52:15 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
sink.onCancel = reason => {
|
2018-08-27 01:32:25 +09:00
|
|
|
rangeReader.cancel(reason);
|
2020-07-31 01:03:08 +09:00
|
|
|
|
|
|
|
sink.ready.catch(readyReason => {
|
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
throw readyReason;
|
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
};
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2013-08-01 03:17:36 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("GetDoc", ({ pdfInfo }) => {
|
2019-03-11 20:43:44 +09:00
|
|
|
this._numPages = pdfInfo.numPages;
|
|
|
|
loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
messageHandler.on("DocException", function (ex) {
|
2019-10-19 19:49:30 +09:00
|
|
|
let reason;
|
|
|
|
switch (ex.name) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "PasswordException":
|
2019-10-19 19:49:30 +09:00
|
|
|
reason = new PasswordException(ex.message, ex.code);
|
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "InvalidPDFException":
|
2019-10-19 19:49:30 +09:00
|
|
|
reason = new InvalidPDFException(ex.message);
|
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "MissingPDFException":
|
2019-10-19 19:49:30 +09:00
|
|
|
reason = new MissingPDFException(ex.message);
|
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UnexpectedResponseException":
|
2019-10-19 19:49:30 +09:00
|
|
|
reason = new UnexpectedResponseException(ex.message, ex.status);
|
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "UnknownErrorException":
|
2019-10-19 19:49:30 +09:00
|
|
|
reason = new UnknownErrorException(ex.message, ex.details);
|
|
|
|
break;
|
|
|
|
}
|
2020-08-13 20:17:30 +09:00
|
|
|
if (!(reason instanceof Error)) {
|
|
|
|
const msg = "DocException - expected a valid Error.";
|
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
|
|
|
) {
|
|
|
|
unreachable(msg);
|
|
|
|
} else {
|
|
|
|
warn(msg);
|
|
|
|
}
|
2019-10-19 19:49:30 +09:00
|
|
|
}
|
|
|
|
loadingTask._capability.reject(reason);
|
|
|
|
});
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("PasswordRequest", exception => {
|
2018-08-27 01:32:25 +09:00
|
|
|
this._passwordCapability = createPromiseCapability();
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
if (loadingTask.onPassword) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const updatePassword = password => {
|
2018-08-27 01:32:25 +09:00
|
|
|
this._passwordCapability.resolve({
|
|
|
|
password,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
loadingTask.onPassword(updatePassword, exception.code);
|
|
|
|
} catch (ex) {
|
|
|
|
this._passwordCapability.reject(ex);
|
2015-10-30 03:06:22 +09:00
|
|
|
}
|
2018-08-27 01:32:25 +09:00
|
|
|
} else {
|
|
|
|
this._passwordCapability.reject(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
new PasswordException(exception.message, exception.code)
|
|
|
|
);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
|
|
|
return this._passwordCapability.promise;
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("DataLoaded", data => {
|
Ensure that `onProgress` is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired.
From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded).
This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense.
However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls.
The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread.
---
[1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
2018-10-16 20:24:02 +09:00
|
|
|
// For consistency: Ensure that progress is always reported when the
|
|
|
|
// entire PDF file has been loaded, regardless of how it was fetched.
|
|
|
|
if (loadingTask.onProgress) {
|
|
|
|
loadingTask.onProgress({
|
|
|
|
loaded: data.length,
|
|
|
|
total: data.length,
|
|
|
|
});
|
|
|
|
}
|
2018-08-27 01:32:25 +09:00
|
|
|
this.downloadInfoCapability.resolve(data);
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("StartRenderPage", data => {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
2015-10-30 03:06:22 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
const page = this.pageCache[data.pageIndex];
|
|
|
|
page._startRenderPage(data.transparency, data.intent);
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2012-04-12 07:52:15 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("commonobj", data => {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
2012-10-29 05:10:34 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
const [id, type, exportedData] = data;
|
2018-11-07 22:36:29 +09:00
|
|
|
if (this.commonObjs.has(id)) {
|
2018-08-27 01:32:25 +09:00
|
|
|
return;
|
|
|
|
}
|
2015-10-30 03:06:22 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
switch (type) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "Font":
|
2018-08-27 01:32:25 +09:00
|
|
|
const params = this._params;
|
2012-10-29 05:10:34 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("error" in exportedData) {
|
2018-08-27 01:32:25 +09:00
|
|
|
const exportedError = exportedData.error;
|
|
|
|
warn(`Error during font loading: ${exportedError}`);
|
|
|
|
this.commonObjs.resolve(id, exportedError);
|
2012-04-12 07:52:15 +09:00
|
|
|
break;
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2015-10-30 03:06:22 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
let fontRegistry = null;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
params.pdfBug &&
|
|
|
|
globalThis.FontInspector &&
|
|
|
|
globalThis.FontInspector.enabled
|
|
|
|
) {
|
2018-08-27 01:32:25 +09:00
|
|
|
fontRegistry = {
|
|
|
|
registerFont(font, url) {
|
2019-12-08 21:46:21 +09:00
|
|
|
globalThis.FontInspector.fontAdded(font, url);
|
2018-08-27 01:32:25 +09:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const font = new FontFaceObject(exportedData, {
|
|
|
|
isEvalSupported: params.isEvalSupported,
|
|
|
|
disableFontFace: params.disableFontFace,
|
|
|
|
ignoreErrors: params.ignoreErrors,
|
|
|
|
onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
|
|
|
|
fontRegistry,
|
2013-06-15 23:04:54 +09:00
|
|
|
});
|
2012-06-24 04:48:33 +09:00
|
|
|
|
2020-04-23 20:04:57 +09:00
|
|
|
this.fontLoader
|
|
|
|
.bind(font)
|
|
|
|
.catch(reason => {
|
|
|
|
return messageHandler.sendWithPromise("FontFallback", { id });
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
if (!params.fontExtraProperties && font.data) {
|
|
|
|
// Immediately release the `font.data` property once the font
|
|
|
|
// has been attached to the DOM, since it's no longer needed,
|
|
|
|
// rather than waiting for a `PDFDocumentProxy.cleanup` call.
|
|
|
|
// Since `font.data` could be very large, e.g. in some cases
|
|
|
|
// multiple megabytes, this will help reduce memory usage.
|
|
|
|
font.data = null;
|
|
|
|
}
|
Fallback to the built-in font renderer when font loading fails
After PR 9340 all glyphs are now re-mapped to a Private Use Area (PUA) which means that if a font fails to load, for whatever reason[1], all glyphs in the font will now render as Unicode glyph outlines.
This obviously doesn't look good, to say the least, and might be seen as a "regression" since previously many glyphs were left in their original positions which provided a slightly better fallback[2].
Hence this patch, which implements a *general* fallback to the PDF.js built-in font renderer for fonts that fail to load (i.e. are rejected by the sanitizer). One caveat here is that this only works for the Font Loading API, since it's easy to handle errors in that case[3].
The solution implemented in this patch does *not* in any way delay the loading of valid fonts, which was the problem with my previous attempt at a solution, and will only require a bit of extra work/waiting for those fonts that actually fail to load.
*Please note:* This patch doesn't fix any of the underlying PDF.js font conversion bugs that's responsible for creating corrupt font files, however it does *improve* rendering in a number of cases; refer to this possibly incomplete list:
[Bug 1524888](https://bugzilla.mozilla.org/show_bug.cgi?id=1524888)
Issue 10175
Issue 10232
---
[1] Usually because the PDF.js font conversion code wasn't able to parse the font file correctly.
[2] Glyphs fell back to some default font, which while not accurate was more useful than the current state.
[3] Furthermore I'm not sure how to implement this generally, assuming that's even possible, and don't really have time/interest to look into it either.
2019-02-11 08:47:56 +09:00
|
|
|
this.commonObjs.resolve(id, font);
|
2020-04-23 20:04:57 +09:00
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
break;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "FontPath":
|
Attempt to cache repeated images at the document, rather than the page, level (issue 11878)
Currently image resources, as opposed to e.g. font resources, are handled exclusively on a page-specific basis. Generally speaking this makes sense, since pages are separate from each other, however there's PDF documents where many (or even all) pages actually references exactly the same image resources (through the XRef table). Hence, in some cases, we're decoding the *same* images over and over for every page which is obviously slow and wasting both CPU and memory resources better used elsewhere.[1]
Obviously we cannot simply treat all image resources as-if they're used throughout the entire PDF document, since that would end up increasing memory usage too much.[2]
However, by introducing a `GlobalImageCache` in the worker we can track image resources that appear on more than one page. Hence we can switch image resources from being page-specific to being document-specific, once the image resource has been seen on more than a certain number of pages.
In many cases, such as e.g. the referenced issue, this patch will thus lead to reduced memory usage for image resources. Scrolling through all pages of the document, there's now only a few main-thread copies of the same image data, as opposed to one for each rendered page (i.e. there could theoretically be *twenty* copies of the image data).
While this obviously benefit both CPU and memory usage in this case, for *very* large image data this patch *may* possibly increase persistent main-thread memory usage a tiny bit. Thus to avoid negatively affecting memory usage too much in general, particularly on the main-thread, the `GlobalImageCache` will *only* cache a certain number of image resources at the document level and simply fallback to the default behaviour.
Unfortunately the asynchronous nature of the code, with ranged/streamed loading of data, actually makes all of this much more complicated than if all data could be assumed to be immediately available.[3]
*Please note:* The patch will lead to *small* movement in some existing test-cases, since we're now using the built-in PDF.js JPEG decoder more. This was done in order to simplify the overall implementation, especially on the main-thread, by limiting it to only the `OPS.paintImageXObject` operator.
---
[1] There's e.g. PDF documents that use the same image as background on all pages.
[2] Given that data stored in the `commonObjs`, on the main-thread, are only cleared manually through `PDFDocumentProxy.cleanup`. This as opposed to data stored in the `objs` of each page, which is automatically removed when the page is cleaned-up e.g. by being evicted from the cache in the default viewer.
[3] If the latter case were true, we could simply check for repeat images *before* parsing started and thus avoid handling *any* duplicate image resources.
2020-05-18 21:17:56 +09:00
|
|
|
case "Image":
|
2018-08-27 01:32:25 +09:00
|
|
|
this.commonObjs.resolve(id, exportedData);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error(`Got unknown common object type ${type}`);
|
|
|
|
}
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2015-10-30 03:06:22 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("obj", data => {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this.destroyed) {
|
2019-05-10 19:54:06 +09:00
|
|
|
// Ignore any pending requests if the worker was terminated.
|
|
|
|
return undefined;
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2016-03-11 22:59:09 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
const [id, pageIndex, type, imageData] = data;
|
|
|
|
const pageProxy = this.pageCache[pageIndex];
|
2018-11-07 22:36:29 +09:00
|
|
|
if (pageProxy.objs.has(id)) {
|
2019-05-10 19:54:06 +09:00
|
|
|
return undefined;
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2016-03-11 22:59:09 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
switch (type) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
case "Image":
|
2018-08-27 01:32:25 +09:00
|
|
|
pageProxy.objs.resolve(id, imageData);
|
|
|
|
|
|
|
|
// Heuristic that will allow us not to store large data.
|
|
|
|
const MAX_IMAGE_SIZE_TO_STORE = 8000000;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
imageData &&
|
|
|
|
"data" in imageData &&
|
|
|
|
imageData.data.length > MAX_IMAGE_SIZE_TO_STORE
|
|
|
|
) {
|
2018-08-27 01:32:25 +09:00
|
|
|
pageProxy.cleanupAfterRender = true;
|
2016-03-11 22:59:09 +09:00
|
|
|
}
|
2018-08-27 01:32:25 +09:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error(`Got unknown object type ${type}`);
|
|
|
|
}
|
2019-05-10 19:54:06 +09:00
|
|
|
return undefined;
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2012-04-12 07:52:15 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("DocProgress", data => {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
2015-12-01 05:42:47 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
if (loadingTask.onProgress) {
|
|
|
|
loadingTask.onProgress({
|
|
|
|
loaded: data.loaded,
|
|
|
|
total: data.total,
|
|
|
|
});
|
|
|
|
}
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2015-10-30 03:06:22 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on(
|
|
|
|
"UnsupportedFeature",
|
|
|
|
this._onUnsupportedFeature.bind(this)
|
|
|
|
);
|
2012-04-12 07:52:15 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
messageHandler.on("FetchBuiltInCMap", (data, sink) => {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this.destroyed) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
sink.error(new Error("Worker was destroyed"));
|
Transfer, rather than copy, CMap data to the worker-thread
It recently occurred to me that the CMap data should be an excellent candidate for transfering.
This will help reduce peak memory usage for PDF documents using CMaps, since transfering of data avoids duplicating it on both the main- and worker-threads.
Unfortunately it's not possible to actually transfer data when *returning* data through `sendWithPromise`, and another solution had to be used.
Initially I looked at using one message for requesting the data, and another message for returning the actual CMap data. While that should have worked, it would have meant adding a lot more complexity particularly on the worker-thread.
Hence the simplest solution, at least in my opinion, is to utilize `sendWithStream` since that makes it *really* easy to transfer the CMap data. (This required PR 11115 to land first, since otherwise CMap fetch errors won't propagate correctly to the worker-thread.)
Please note that the patch *purposely* only changes the API to Worker communication, and not the API *itself* since changing the interface of `CMapReaderFactory` would be a breaking change.
Furthermore, given the relatively small size of the `.bcmap` files (the largest one is smaller than the default range-request size) streaming doesn't really seem necessary either.
2019-09-04 18:20:14 +09:00
|
|
|
return;
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
Transfer, rather than copy, CMap data to the worker-thread
It recently occurred to me that the CMap data should be an excellent candidate for transfering.
This will help reduce peak memory usage for PDF documents using CMaps, since transfering of data avoids duplicating it on both the main- and worker-threads.
Unfortunately it's not possible to actually transfer data when *returning* data through `sendWithPromise`, and another solution had to be used.
Initially I looked at using one message for requesting the data, and another message for returning the actual CMap data. While that should have worked, it would have meant adding a lot more complexity particularly on the worker-thread.
Hence the simplest solution, at least in my opinion, is to utilize `sendWithStream` since that makes it *really* easy to transfer the CMap data. (This required PR 11115 to land first, since otherwise CMap fetch errors won't propagate correctly to the worker-thread.)
Please note that the patch *purposely* only changes the API to Worker communication, and not the API *itself* since changing the interface of `CMapReaderFactory` would be a breaking change.
Furthermore, given the relatively small size of the `.bcmap` files (the largest one is smaller than the default range-request size) streaming doesn't really seem necessary either.
2019-09-04 18:20:14 +09:00
|
|
|
let fetched = false;
|
|
|
|
|
|
|
|
sink.onPull = () => {
|
|
|
|
if (fetched) {
|
|
|
|
sink.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fetched = true;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.CMapReaderFactory.fetch(data)
|
2020-04-14 19:28:14 +09:00
|
|
|
.then(function (builtInCMap) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
|
|
|
|
})
|
2020-04-14 19:28:14 +09:00
|
|
|
.catch(function (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
sink.error(reason);
|
|
|
|
});
|
Transfer, rather than copy, CMap data to the worker-thread
It recently occurred to me that the CMap data should be an excellent candidate for transfering.
This will help reduce peak memory usage for PDF documents using CMaps, since transfering of data avoids duplicating it on both the main- and worker-threads.
Unfortunately it's not possible to actually transfer data when *returning* data through `sendWithPromise`, and another solution had to be used.
Initially I looked at using one message for requesting the data, and another message for returning the actual CMap data. While that should have worked, it would have meant adding a lot more complexity particularly on the worker-thread.
Hence the simplest solution, at least in my opinion, is to utilize `sendWithStream` since that makes it *really* easy to transfer the CMap data. (This required PR 11115 to land first, since otherwise CMap fetch errors won't propagate correctly to the worker-thread.)
Please note that the patch *purposely* only changes the API to Worker communication, and not the API *itself* since changing the interface of `CMapReaderFactory` would be a breaking change.
Furthermore, given the relatively small size of the `.bcmap` files (the largest one is smaller than the default range-request size) streaming doesn't really seem necessary either.
2019-09-04 18:20:14 +09:00
|
|
|
};
|
2019-08-31 21:16:06 +09:00
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2013-02-07 08:19:29 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
_onUnsupportedFeature({ featureId }) {
|
2018-08-27 01:32:25 +09:00
|
|
|
if (this.destroyed) {
|
|
|
|
return; // Ignore any pending requests if the worker was terminated.
|
|
|
|
}
|
|
|
|
if (this.loadingTask.onUnsupportedFeature) {
|
|
|
|
this.loadingTask.onUnsupportedFeature(featureId);
|
|
|
|
}
|
|
|
|
}
|
2013-11-15 06:43:38 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getData() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetData", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
getPage(pageNumber) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!Number.isInteger(pageNumber) ||
|
|
|
|
pageNumber <= 0 ||
|
|
|
|
pageNumber > this._numPages
|
|
|
|
) {
|
|
|
|
return Promise.reject(new Error("Invalid page request"));
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const pageIndex = pageNumber - 1;
|
|
|
|
if (pageIndex in this.pagePromises) {
|
|
|
|
return this.pagePromises[pageIndex];
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const promise = this.messageHandler
|
|
|
|
.sendWithPromise("GetPage", {
|
|
|
|
pageIndex,
|
|
|
|
})
|
|
|
|
.then(pageInfo => {
|
|
|
|
if (this.destroyed) {
|
|
|
|
throw new Error("Transport destroyed");
|
|
|
|
}
|
|
|
|
const page = new PDFPageProxy(
|
|
|
|
pageIndex,
|
|
|
|
pageInfo,
|
|
|
|
this,
|
2020-07-28 02:22:45 +09:00
|
|
|
this._params.ownerDocument,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._params.pdfBug
|
|
|
|
);
|
|
|
|
this.pageCache[pageIndex] = page;
|
|
|
|
return page;
|
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
this.pagePromises[pageIndex] = promise;
|
|
|
|
return promise;
|
|
|
|
}
|
2014-10-05 22:56:40 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getPageIndex(ref) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler
|
|
|
|
.sendWithPromise("GetPageIndex", {
|
|
|
|
ref,
|
|
|
|
})
|
2020-04-14 19:28:14 +09:00
|
|
|
.catch(function (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return Promise.reject(new Error(reason));
|
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2015-12-26 05:57:08 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getAnnotations(pageIndex, intent) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetAnnotations", {
|
2018-08-27 01:32:25 +09:00
|
|
|
pageIndex,
|
|
|
|
intent,
|
|
|
|
});
|
|
|
|
}
|
2017-07-18 20:08:02 +09:00
|
|
|
|
2020-08-04 02:44:04 +09:00
|
|
|
saveDocument(annotationStorage) {
|
2020-08-19 05:50:23 +09:00
|
|
|
return this.messageHandler
|
|
|
|
.sendWithPromise("SaveDocument", {
|
|
|
|
numPages: this._numPages,
|
|
|
|
annotationStorage:
|
|
|
|
(annotationStorage && annotationStorage.getAll()) || null,
|
2020-08-20 04:19:59 +09:00
|
|
|
filename: this._fullReader ? this._fullReader.filename : null,
|
2020-08-19 05:50:23 +09:00
|
|
|
})
|
|
|
|
.finally(() => {
|
2020-08-23 01:09:17 +09:00
|
|
|
if (annotationStorage) {
|
|
|
|
annotationStorage.resetModified();
|
|
|
|
}
|
2020-08-19 05:50:23 +09:00
|
|
|
});
|
2020-08-04 02:44:04 +09:00
|
|
|
}
|
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getDestinations() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetDestinations", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2014-03-19 05:32:47 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getDestination(id) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof id !== "string") {
|
|
|
|
return Promise.reject(new Error("Invalid destination request."));
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetDestination", {
|
2018-08-27 01:32:25 +09:00
|
|
|
id,
|
|
|
|
});
|
|
|
|
}
|
2014-05-08 04:15:34 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getPageLabels() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetPageLabels", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2014-05-08 04:06:44 +09:00
|
|
|
|
2019-04-03 20:48:18 +09:00
|
|
|
getPageLayout() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetPageLayout", null);
|
2019-04-03 20:48:18 +09:00
|
|
|
}
|
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getPageMode() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetPageMode", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2014-05-08 04:38:40 +09:00
|
|
|
|
2019-04-14 20:13:59 +09:00
|
|
|
getViewerPreferences() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
|
2019-04-14 20:13:59 +09:00
|
|
|
}
|
|
|
|
|
2020-02-28 22:54:07 +09:00
|
|
|
getOpenAction() {
|
|
|
|
return this.messageHandler.sendWithPromise("GetOpenAction", null);
|
2018-12-06 04:09:15 +09:00
|
|
|
}
|
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getAttachments() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetAttachments", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2014-06-16 23:52:04 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getJavaScript() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetJavaScript", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2018-02-18 06:08:45 +09:00
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getOutline() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetOutline", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
2012-04-12 07:52:15 +09:00
|
|
|
|
2020-07-15 07:17:27 +09:00
|
|
|
getOptionalContentConfig() {
|
|
|
|
return this.messageHandler
|
|
|
|
.sendWithPromise("GetOptionalContentConfig", null)
|
|
|
|
.then(results => {
|
|
|
|
return new OptionalContentConfig(results);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-27 04:37:05 +09:00
|
|
|
getPermissions() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetPermissions", null);
|
2018-08-27 04:37:05 +09:00
|
|
|
}
|
|
|
|
|
2018-08-27 01:32:25 +09:00
|
|
|
getMetadata() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler
|
|
|
|
.sendWithPromise("GetMetadata", null)
|
|
|
|
.then(results => {
|
|
|
|
return {
|
|
|
|
info: results[0],
|
|
|
|
metadata: results[1] ? new Metadata(results[1]) : null,
|
|
|
|
contentDispositionFilename: this._fullReader
|
|
|
|
? this._fullReader.filename
|
|
|
|
: null,
|
|
|
|
};
|
|
|
|
});
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
getStats() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return this.messageHandler.sendWithPromise("GetStats", null);
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
startCleanup() {
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
return this.messageHandler.sendWithPromise("Cleanup", null).then(() => {
|
2018-08-27 01:32:25 +09:00
|
|
|
for (let i = 0, ii = this.pageCache.length; i < ii; i++) {
|
|
|
|
const page = this.pageCache[i];
|
|
|
|
if (page) {
|
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This patch makes the following changes, to improve these API methods:
- Let `PDFPageProxy.cleanup` return a boolean indicating if clean-up actually happened, since ongoing rendering will block clean-up.
Besides being used in other parts of this patch, it seems that an API user may also be interested in the return value given that clean-up isn't *guaranteed* to happen.
- Let `PDFDocumentProxy.cleanup` return the promise indicating when clean-up is finished.
- Improve the JSDoc comment for `PDFDocumentProxy.cleanup` to mention that clean-up is triggered on *both* threads (without going into unnecessary specifics regarding what *exactly* said data actually is).
Add a note in the JSDoc comment about not calling this method when rendering is ongoing.
- Change `WorkerTransport.startCleanup` to throw an `Error` if it's called when rendering is ongoing, to prevent rendering from breaking.
Please note that this won't stop *worker-thread* clean-up from happening (since there's no general "something is rendering"-flag), however I'm not sure if that's really a problem; but please don't quote me on that :-)
All of the caches that's being cleared in `Catalog.cleanup`, on the worker-thread, *should* be re-filled automatically even if cleared *during* parsing/rendering, and the only thing that probably happens is that e.g. font data would have to be re-parsed.
On the main-thread, on the other hand, clearing the caches is more-or-less guaranteed to cause rendering errors, since the rendering code in `src/display/canvas.js` isn't able to re-request any image/font data that's suddenly being pulled out from under it.
- Last, but not least, add a couple of basic unit-tests for the clean-up functionality.
2020-02-07 23:48:58 +09:00
|
|
|
const cleanupSuccessful = page.cleanup();
|
|
|
|
|
|
|
|
if (!cleanupSuccessful) {
|
|
|
|
throw new Error(
|
|
|
|
`startCleanup: Page ${i + 1} is currently rendering.`
|
|
|
|
);
|
|
|
|
}
|
2018-08-27 01:32:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.commonObjs.clear();
|
|
|
|
this.fontLoader.clear();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get loadingParams() {
|
|
|
|
const params = this._params;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return shadow(this, "loadingParams", {
|
2018-08-27 01:32:25 +09:00
|
|
|
disableAutoFetch: params.disableAutoFetch,
|
|
|
|
disableFontFace: params.disableFontFace,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
|
|
|
/**
|
2018-11-07 22:17:14 +09:00
|
|
|
* A PDF document and page is built of many objects. E.g. there are objects for
|
|
|
|
* fonts, images, rendering code, etc. These objects may get processed inside of
|
|
|
|
* a worker. This class implements some basic methods to manage these objects.
|
2014-01-22 04:28:18 +09:00
|
|
|
* @ignore
|
2013-08-13 02:48:06 +09:00
|
|
|
*/
|
2018-11-07 22:17:14 +09:00
|
|
|
class PDFObjects {
|
|
|
|
constructor() {
|
|
|
|
this._objs = Object.create(null);
|
2013-08-13 02:48:06 +09:00
|
|
|
}
|
|
|
|
|
2018-11-07 22:17:14 +09:00
|
|
|
/**
|
|
|
|
* Ensures there is an object defined for `objId`.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_ensureObj(objId) {
|
|
|
|
if (this._objs[objId]) {
|
|
|
|
return this._objs[objId];
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return (this._objs[objId] = {
|
2018-11-07 22:17:14 +09:00
|
|
|
capability: createPromiseCapability(),
|
|
|
|
data: null,
|
|
|
|
resolved: false,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
});
|
2018-11-07 22:17:14 +09:00
|
|
|
}
|
2013-08-13 02:48:06 +09:00
|
|
|
|
2018-11-07 22:17:14 +09:00
|
|
|
/**
|
|
|
|
* If called *without* callback, this returns the data of `objId` but the
|
|
|
|
* object needs to be resolved. If it isn't, this method 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 method
|
|
|
|
* and the object is already resolved, the callback gets called right away.
|
|
|
|
*/
|
|
|
|
get(objId, callback = null) {
|
|
|
|
// If there is a callback, then the get can be async and the object is
|
|
|
|
// not required to be resolved right now.
|
|
|
|
if (callback) {
|
|
|
|
this._ensureObj(objId).capability.promise.then(callback);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// If there isn't a callback, the user expects to get the resolved data
|
|
|
|
// directly.
|
|
|
|
const obj = this._objs[objId];
|
|
|
|
// If there isn't an object yet or the object isn't resolved, then the
|
|
|
|
// data isn't ready yet!
|
|
|
|
if (!obj || !obj.resolved) {
|
|
|
|
throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
|
|
|
|
}
|
|
|
|
return obj.data;
|
|
|
|
}
|
2013-08-13 02:48:06 +09:00
|
|
|
|
2018-11-07 22:36:29 +09:00
|
|
|
has(objId) {
|
|
|
|
const obj = this._objs[objId];
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return obj ? obj.resolved : false;
|
2018-11-07 22:36:29 +09:00
|
|
|
}
|
|
|
|
|
2018-11-07 22:17:14 +09:00
|
|
|
/**
|
|
|
|
* Resolves the object `objId` with optional `data`.
|
|
|
|
*/
|
|
|
|
resolve(objId, data) {
|
|
|
|
const obj = this._ensureObj(objId);
|
2013-08-13 02:48:06 +09:00
|
|
|
|
2018-11-07 22:17:14 +09:00
|
|
|
obj.resolved = true;
|
|
|
|
obj.data = data;
|
|
|
|
obj.capability.resolve(data);
|
|
|
|
}
|
2013-08-13 02:48:06 +09:00
|
|
|
|
2018-11-07 22:17:14 +09:00
|
|
|
clear() {
|
|
|
|
this._objs = Object.create(null);
|
|
|
|
}
|
|
|
|
}
|
2014-01-04 09:17:05 +09:00
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* Allows controlling of the rendering tasks.
|
|
|
|
*/
|
2018-11-08 21:46:02 +09:00
|
|
|
class RenderTask {
|
|
|
|
constructor(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.
|
2020-08-03 03:09:31 +09:00
|
|
|
* @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
|
|
|
}
|
|
|
|
|
2018-11-08 21:46:02 +09:00
|
|
|
/**
|
|
|
|
* Promise for rendering task completion.
|
2020-07-23 05:38:04 +09:00
|
|
|
* @type {Promise<void>}
|
2018-11-08 21:46:02 +09:00
|
|
|
*/
|
|
|
|
get promise() {
|
|
|
|
return this._internalRenderTask.capability.promise;
|
|
|
|
}
|
2014-04-12 02:10:42 +09:00
|
|
|
|
2018-11-08 21:46:02 +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
|
|
|
|
* this object extends will be rejected when cancelled.
|
|
|
|
*/
|
|
|
|
cancel() {
|
|
|
|
this._internalRenderTask.cancel();
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2014-01-22 04:28:18 +09:00
|
|
|
/**
|
|
|
|
* For internal use only.
|
|
|
|
* @ignore
|
|
|
|
*/
|
2018-11-08 22:33:56 +09:00
|
|
|
const InternalRenderTask = (function InternalRenderTaskClosure() {
|
|
|
|
const canvasInRendering = new WeakSet();
|
|
|
|
|
2020-03-25 18:15:50 +09:00
|
|
|
// eslint-disable-next-line no-shadow
|
2018-11-08 22:33:56 +09:00
|
|
|
class InternalRenderTask {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
constructor({
|
|
|
|
callback,
|
|
|
|
params,
|
|
|
|
objs,
|
|
|
|
commonObjs,
|
|
|
|
operatorList,
|
2020-03-19 23:36:09 +09:00
|
|
|
pageIndex,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
canvasFactory,
|
|
|
|
webGLContext,
|
|
|
|
useRequestAnimationFrame = false,
|
|
|
|
pdfBug = false,
|
|
|
|
}) {
|
2018-11-08 22:33:56 +09:00
|
|
|
this.callback = callback;
|
|
|
|
this.params = params;
|
|
|
|
this.objs = objs;
|
|
|
|
this.commonObjs = commonObjs;
|
|
|
|
this.operatorListIdx = null;
|
|
|
|
this.operatorList = operatorList;
|
2020-03-19 23:36:09 +09:00
|
|
|
this._pageIndex = pageIndex;
|
2018-11-08 22:33:56 +09:00
|
|
|
this.canvasFactory = canvasFactory;
|
|
|
|
this.webGLContext = webGLContext;
|
|
|
|
this._pdfBug = pdfBug;
|
2017-11-02 00:32:22 +09:00
|
|
|
|
2018-11-08 22:33:56 +09:00
|
|
|
this.running = false;
|
|
|
|
this.graphicsReadyCallback = null;
|
|
|
|
this.graphicsReady = false;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._useRequestAnimationFrame =
|
|
|
|
useRequestAnimationFrame === true && typeof window !== "undefined";
|
2018-11-08 22:33:56 +09:00
|
|
|
this.cancelled = false;
|
|
|
|
this.capability = createPromiseCapability();
|
|
|
|
this.task = new RenderTask(this);
|
|
|
|
// caching this-bound methods
|
|
|
|
this._continueBound = this._continue.bind(this);
|
|
|
|
this._scheduleNextBound = this._scheduleNext.bind(this);
|
|
|
|
this._nextBound = this._next.bind(this);
|
|
|
|
this._canvas = params.canvasContext.canvas;
|
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2020-06-21 22:38:09 +09:00
|
|
|
get completed() {
|
|
|
|
return this.capability.promise.catch(function () {
|
|
|
|
// Ignoring errors, since we only want to know when rendering is
|
|
|
|
// no longer pending.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-15 07:17:27 +09:00
|
|
|
initializeGraphics({ transparency = false, optionalContentConfig }) {
|
2018-06-29 05:38:09 +09:00
|
|
|
if (this.cancelled) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-13 06:04:35 +09:00
|
|
|
if (this._canvas) {
|
|
|
|
if (canvasInRendering.has(this._canvas)) {
|
|
|
|
throw new Error(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
"Cannot use the same canvas during multiple render() operations. " +
|
|
|
|
"Use different canvas or ensure previous operations were " +
|
|
|
|
"cancelled or completed."
|
|
|
|
);
|
2017-06-13 06:04:35 +09:00
|
|
|
}
|
2018-11-01 02:15:23 +09:00
|
|
|
canvasInRendering.add(this._canvas);
|
2017-06-13 06:04:35 +09:00
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
this._pdfBug &&
|
|
|
|
globalThis.StepperManager &&
|
|
|
|
globalThis.StepperManager.enabled
|
|
|
|
) {
|
2020-03-19 23:36:09 +09:00
|
|
|
this.stepper = globalThis.StepperManager.create(this._pageIndex);
|
2013-08-01 03:17:36 +09:00
|
|
|
this.stepper.init(this.operatorList);
|
|
|
|
this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
|
|
|
|
}
|
2018-11-08 22:33:56 +09:00
|
|
|
const {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
canvasContext,
|
|
|
|
viewport,
|
|
|
|
transform,
|
|
|
|
imageLayer,
|
|
|
|
background,
|
2018-11-08 22:33:56 +09:00
|
|
|
} = this.params;
|
2013-08-01 03:17:36 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.gfx = new CanvasGraphics(
|
|
|
|
canvasContext,
|
|
|
|
this.commonObjs,
|
|
|
|
this.objs,
|
|
|
|
this.canvasFactory,
|
|
|
|
this.webGLContext,
|
2020-07-15 07:17:27 +09:00
|
|
|
imageLayer,
|
|
|
|
optionalContentConfig
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
);
|
2017-05-16 20:01:03 +09:00
|
|
|
this.gfx.beginDrawing({
|
2018-11-08 22:33:56 +09:00
|
|
|
transform,
|
|
|
|
viewport,
|
2017-05-16 20:01:03 +09:00
|
|
|
transparency,
|
2018-11-08 22:33:56 +09:00
|
|
|
background,
|
2017-05-16 20:01:03 +09:00
|
|
|
});
|
2013-08-01 03:17:36 +09:00
|
|
|
this.operatorListIdx = 0;
|
|
|
|
this.graphicsReady = true;
|
|
|
|
if (this.graphicsReadyCallback) {
|
|
|
|
this.graphicsReadyCallback();
|
|
|
|
}
|
2018-11-08 22:33:56 +09:00
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2019-01-26 18:12:32 +09:00
|
|
|
cancel(error = null) {
|
2013-08-01 03:17:36 +09:00
|
|
|
this.running = false;
|
|
|
|
this.cancelled = true;
|
2018-11-01 00:22:17 +09:00
|
|
|
if (this.gfx) {
|
|
|
|
this.gfx.endDrawing();
|
|
|
|
}
|
2017-06-13 06:04:35 +09:00
|
|
|
if (this._canvas) {
|
|
|
|
canvasInRendering.delete(this._canvas);
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.callback(
|
|
|
|
error ||
|
|
|
|
new RenderingCancelledException(
|
2020-03-19 23:36:09 +09:00
|
|
|
`Rendering cancelled, page ${this._pageIndex + 1}`,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
"canvas"
|
|
|
|
)
|
|
|
|
);
|
2018-11-08 22:33:56 +09:00
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2018-11-08 22:33:56 +09:00
|
|
|
operatorListChanged() {
|
2013-08-01 03:17:36 +09:00
|
|
|
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();
|
2018-11-08 22:33:56 +09:00
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2018-11-08 22:33:56 +09:00
|
|
|
_continue() {
|
2013-08-01 03:17:36 +09:00
|
|
|
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
|
|
|
}
|
2018-11-08 22:33:56 +09:00
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
|
2018-11-08 22:33:56 +09:00
|
|
|
_scheduleNext() {
|
|
|
|
if (this._useRequestAnimationFrame) {
|
2018-06-13 18:01:58 +09:00
|
|
|
window.requestAnimationFrame(() => {
|
2019-01-26 18:12:32 +09:00
|
|
|
this._nextBound().catch(this.cancel.bind(this));
|
2018-06-13 18:01:58 +09:00
|
|
|
});
|
2015-05-12 22:44:42 +09:00
|
|
|
} else {
|
2020-04-14 19:28:14 +09:00
|
|
|
Promise.resolve().then(this._nextBound).catch(this.cancel.bind(this));
|
2015-05-12 22:44:42 +09:00
|
|
|
}
|
2018-11-08 22:33:56 +09:00
|
|
|
}
|
2014-05-09 21:00:47 +09:00
|
|
|
|
2018-11-08 22:33:56 +09:00
|
|
|
async _next() {
|
|
|
|
if (this.cancelled) {
|
|
|
|
return;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this.operatorListIdx = this.gfx.executeOperatorList(
|
|
|
|
this.operatorList,
|
|
|
|
this.operatorListIdx,
|
|
|
|
this._continueBound,
|
|
|
|
this.stepper
|
|
|
|
);
|
2018-11-08 22:33:56 +09:00
|
|
|
if (this.operatorListIdx === this.operatorList.argsArray.length) {
|
|
|
|
this.running = false;
|
|
|
|
if (this.operatorList.lastChunk) {
|
|
|
|
this.gfx.endDrawing();
|
|
|
|
if (this._canvas) {
|
|
|
|
canvasInRendering.delete(this._canvas);
|
2017-06-13 06:04:35 +09:00
|
|
|
}
|
2018-11-08 22:33:56 +09:00
|
|
|
this.callback();
|
2013-08-01 03:17:36 +09:00
|
|
|
}
|
2018-11-08 22:33:56 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
return InternalRenderTask;
|
|
|
|
})();
|
2015-12-01 05:42:47 +09:00
|
|
|
|
2020-07-23 05:38:04 +09:00
|
|
|
/** @type {string} */
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const version =
|
|
|
|
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : null;
|
2020-07-23 05:38:04 +09:00
|
|
|
/** @type {string} */
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const build =
|
|
|
|
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : null;
|
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,
|
2018-01-14 08:34:46 +09:00
|
|
|
setPDFNetworkStreamFactory,
|
2017-04-02 21:25:33 +09:00
|
|
|
version,
|
|
|
|
build,
|
|
|
|
};
|