2013-09-20 16:25:41 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-03-28 08:07:27 +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
|
|
|
approximateFraction,
|
|
|
|
CSS_UNITS,
|
|
|
|
DEFAULT_SCALE,
|
|
|
|
getOutputScale,
|
|
|
|
NullL10n,
|
|
|
|
RendererType,
|
|
|
|
roundToDivide,
|
|
|
|
TextLayerMode,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./ui_utils.js";
|
2017-03-28 17:15:02 +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
|
|
|
createPromiseCapability,
|
|
|
|
RenderingCancelledException,
|
|
|
|
SVGGraphics,
|
|
|
|
} from "pdfjs-lib";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { RenderingStates } from "./pdf_rendering_queue.js";
|
|
|
|
import { viewerCompatibilityParams } from "./viewer_compatibility.js";
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2014-09-28 03:03:28 +09:00
|
|
|
* @typedef {Object} PDFPageViewOptions
|
|
|
|
* @property {HTMLDivElement} container - The viewer element.
|
2016-04-26 07:57:15 +09:00
|
|
|
* @property {EventBus} eventBus - The application event bus.
|
2014-09-28 03:03:28 +09:00
|
|
|
* @property {number} id - The page unique ID (normally its number).
|
|
|
|
* @property {number} scale - The page scale display.
|
|
|
|
* @property {PageViewport} defaultViewport - The page viewport.
|
|
|
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
2014-09-28 23:35:33 +09:00
|
|
|
* @property {IPDFTextLayerFactory} textLayerFactory
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {number} [textLayerMode] - Controls if the text layer used for
|
|
|
|
* selection and searching is created, and if the improved text selection
|
2018-02-13 23:01:55 +09:00
|
|
|
* behaviour is enabled. The constants from {TextLayerMode} should be used.
|
|
|
|
* The default value is `TextLayerMode.ENABLE`.
|
2015-12-17 20:54:53 +09:00
|
|
|
* @property {IPDFAnnotationLayerFactory} annotationLayerFactory
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
|
|
|
* for annotation icons. Include trailing slash.
|
2016-09-18 02:44:25 +09:00
|
|
|
* @property {boolean} renderInteractiveForms - Turns on rendering of
|
|
|
|
* interactive form elements. The default is `false`.
|
2016-11-19 04:03:49 +09:00
|
|
|
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {boolean} [enableWebGL] - Enables WebGL accelerated rendering for
|
|
|
|
* some operations. The default value is `false`.
|
|
|
|
* @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default
|
|
|
|
* value is `false`.
|
|
|
|
* @property {number} [maxCanvasPixels] - The maximum supported canvas size in
|
|
|
|
* total pixels, i.e. width * height. Use -1 for no limit. The default value
|
|
|
|
* is 4096 * 4096 (16 mega-pixels).
|
2017-05-04 10:05:53 +09:00
|
|
|
* @property {IL10n} l10n - Localization service.
|
2014-09-28 03:03:28 +09:00
|
|
|
*/
|
|
|
|
|
2018-02-13 21:02:15 +09:00
|
|
|
const MAX_CANVAS_PIXELS = viewerCompatibilityParams.maxCanvasPixels || 16777216;
|
|
|
|
|
2014-09-28 03:03:28 +09:00
|
|
|
/**
|
2014-09-21 02:21:49 +09:00
|
|
|
* @implements {IRenderableView}
|
|
|
|
*/
|
2017-05-29 05:44:00 +09:00
|
|
|
class PDFPageView {
|
2014-09-28 03:03:28 +09:00
|
|
|
/**
|
|
|
|
* @param {PDFPageViewOptions} options
|
|
|
|
*/
|
2017-05-29 05:44:00 +09:00
|
|
|
constructor(options) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const container = options.container;
|
|
|
|
const defaultViewport = options.defaultViewport;
|
2017-05-29 05:44:00 +09:00
|
|
|
|
|
|
|
this.id = options.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
|
|
|
this.renderingId = "page" + this.id;
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-08-04 07:24:19 +09:00
|
|
|
this.pdfPage = null;
|
2017-05-29 05:44:00 +09:00
|
|
|
this.pageLabel = null;
|
2014-09-28 03:03:28 +09:00
|
|
|
this.rotation = 0;
|
2017-05-29 05:44:00 +09:00
|
|
|
this.scale = options.scale || DEFAULT_SCALE;
|
2014-09-28 03:03:28 +09:00
|
|
|
this.viewport = defaultViewport;
|
|
|
|
this.pdfPageRotate = defaultViewport.rotation;
|
|
|
|
this.hasRestrictedScaling = 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.textLayerMode = Number.isInteger(options.textLayerMode)
|
|
|
|
? options.textLayerMode
|
|
|
|
: TextLayerMode.ENABLE;
|
|
|
|
this.imageResourcesPath = options.imageResourcesPath || "";
|
2017-05-29 05:44:00 +09:00
|
|
|
this.renderInteractiveForms = options.renderInteractiveForms || false;
|
2018-02-13 20:52:42 +09:00
|
|
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
2018-02-13 21:02:15 +09:00
|
|
|
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2020-02-27 23:02:03 +09:00
|
|
|
this.eventBus = options.eventBus;
|
2017-05-29 05:44:00 +09:00
|
|
|
this.renderingQueue = options.renderingQueue;
|
|
|
|
this.textLayerFactory = options.textLayerFactory;
|
|
|
|
this.annotationLayerFactory = options.annotationLayerFactory;
|
2016-11-19 04:03:49 +09:00
|
|
|
this.renderer = options.renderer || RendererType.CANVAS;
|
2018-02-13 22:16:10 +09:00
|
|
|
this.enableWebGL = options.enableWebGL || false;
|
2017-05-04 10:05:53 +09:00
|
|
|
this.l10n = options.l10n || NullL10n;
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2016-10-19 23:16:57 +09:00
|
|
|
this.paintTask = null;
|
Ensure that we use the *correct* `paintedViewport` in `PDFPageView.cssTransform`, to avoid visual glitches on quick rotations (PR 7738 follow-up)
*This fixes a regression from commit https://github.com/mozilla/pdf.js/pull/7738/commits/c9a0955c9c7ed857c98696732c6edeb6f4901f43, i.e. PR 7738.*
Currently if you quickly rotate a document at least *twice*,[1] such that rendering of a page hasn't finished for the first rotation before the last rotation is triggered, the `cssTransform` method can fail to update the page correctly leading to it looking temporarily distorted.
The reason why things break is that previously we stored the `viewport` on the canvas DOM element, meaning that when it was accessed in `cssTransform` is was guaranteed to point to the `viewport` of the `zoomLayer` canvas.
Generally you want to avoid storing data on DOM elements this way, and during the `PDFPageView` refactoring needed to support SVG rendering, the previous `viewport` was instead stored directly on `PDFPageView`.
However, the problem is first of all that the `paintedViewport` only stores the *last* `viewport` computed, and second of all that there're no guarantees that it actually applies to the current `zoomLayer` canvas.
If a document is rotated slowly enough that rendering finishes *before* the next rotation then this problem doesn't exist, but for sufficiently quick rotations rendering will be cancelled at least once and the `paintedViewport` could thus be bogus.
The solution for the above problems is to ensure that we track the correct `viewport` for each DOM element (canvas or svg),[2] which seemed easist to do with a `WeakMap`.[3]
---
[1] I'm able to reproduce this using the `tracemonkey` file, but please note that for pages with few operations, i.e. that render very quickly, the effect may be hard to spot.
[2] One other possible solution that I briefly considered, was to wait until rendering finished before storing the current `viewport`. However, that would have caused issues with rotating a page before the *first* rendering operation had finished.
[3] This regression took me way longer to both figure out, and fix, than I'd like to admit :-)
2017-01-21 20:27:57 +09:00
|
|
|
this.paintedViewportMap = new WeakMap();
|
2014-09-28 03:03:28 +09:00
|
|
|
this.renderingState = RenderingStates.INITIAL;
|
|
|
|
this.resume = null;
|
2016-10-19 23:16:57 +09:00
|
|
|
this.error = null;
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
this.annotationLayer = null;
|
2014-09-28 03:03:28 +09:00
|
|
|
this.textLayer = null;
|
2013-10-03 01:05:46 +09:00
|
|
|
this.zoomLayer = null;
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const div = document.createElement("div");
|
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
|
|
|
div.className = "page";
|
|
|
|
div.style.width = Math.floor(this.viewport.width) + "px";
|
|
|
|
div.style.height = Math.floor(this.viewport.height) + "px";
|
|
|
|
div.setAttribute("data-page-number", this.id);
|
2014-09-28 03:03:28 +09:00
|
|
|
this.div = div;
|
|
|
|
|
|
|
|
container.appendChild(div);
|
|
|
|
}
|
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
setPdfPage(pdfPage) {
|
|
|
|
this.pdfPage = pdfPage;
|
|
|
|
this.pdfPageRotate = pdfPage.rotate;
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
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.viewport = pdfPage.getViewport({
|
|
|
|
scale: this.scale * CSS_UNITS,
|
|
|
|
rotation: totalRotation,
|
|
|
|
});
|
2017-05-29 05:44:00 +09:00
|
|
|
this.stats = pdfPage.stats;
|
|
|
|
this.reset();
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
destroy() {
|
|
|
|
this.reset();
|
|
|
|
if (this.pdfPage) {
|
|
|
|
this.pdfPage.cleanup();
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_resetZoomLayer(removeFromDOM = false) {
|
|
|
|
if (!this.zoomLayer) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const zoomLayerCanvas = this.zoomLayer.firstChild;
|
2017-05-29 05:44:00 +09:00
|
|
|
this.paintedViewportMap.delete(zoomLayerCanvas);
|
|
|
|
// Zeroing the width and height causes Firefox to release graphics
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
zoomLayerCanvas.width = 0;
|
|
|
|
zoomLayerCanvas.height = 0;
|
|
|
|
|
|
|
|
if (removeFromDOM) {
|
|
|
|
// Note: `ChildNode.remove` doesn't throw if the parent node is undefined.
|
|
|
|
this.zoomLayer.remove();
|
|
|
|
}
|
|
|
|
this.zoomLayer = null;
|
|
|
|
}
|
2013-10-03 01:05:46 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
reset(keepZoomLayer = false, keepAnnotations = false) {
|
Prevent the `annotationLayer` from, in some cases, becoming duplicated on the first page when the document loads
I don't know if this is a regression, but I noticed earlier today that depending on the initial scale *and* sidebar state, the `annotationLayer` of the first rendered page may end up duplicated; please see screen-shot below.
[screen-shot]
I can reproduce this reliable with e.g. https://arxiv.org/pdf/1112.0542v1.pdf#zoom=page-width&pagemode=bookmarks.
When the document loads, rendering of the first page begins immediately. When the sidebar is then opened, that forces re-rendering which thus aborts rendering of the first page.
Note that calling `PDFPageView.draw()` will always, provided an `AnnotationLayerFactory` instance exists, call `AnnotationLayerBuilder.render()`. Hence the events described above will result in *two* such calls, where the actual annotation rendering/updating happens asynchronously.
For reasons that I don't (at all) understand, when multiple `pdfPage.getAnnotations()` promises are handled back-to-back (in `AnnotationLayerBuilder.render()`), the `this.div` property seems to not update in time for the subsequent calls.
This thus, at least in Firefox, result in double rendering of all annotations on the first page.
Obviously it'd be good to find out why it breaks, since it *really* shouldn't, but this patch at least provides a (hopefully) acceptable work-around by ignoring `getAnnotations()` calls for `AnnotationLayerBuilder` instances that we're destroying (in `PDFPageView.reset()`).
2017-10-07 00:26:54 +09:00
|
|
|
this.cancelRendering(keepAnnotations);
|
2019-02-15 02:47:32 +09:00
|
|
|
this.renderingState = RenderingStates.INITIAL;
|
2013-10-03 01:05:46 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const div = this.div;
|
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
|
|
|
div.style.width = Math.floor(this.viewport.width) + "px";
|
|
|
|
div.style.height = Math.floor(this.viewport.height) + "px";
|
2013-10-03 01:05:46 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const childNodes = div.childNodes;
|
|
|
|
const currentZoomLayerNode = (keepZoomLayer && this.zoomLayer) || null;
|
|
|
|
const currentAnnotationNode =
|
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
|
|
|
(keepAnnotations && this.annotationLayer && this.annotationLayer.div) ||
|
|
|
|
null;
|
2017-05-29 05:44:00 +09:00
|
|
|
for (let i = childNodes.length - 1; i >= 0; i--) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const node = childNodes[i];
|
2017-05-29 05:44:00 +09:00
|
|
|
if (currentZoomLayerNode === node || currentAnnotationNode === node) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
div.removeChild(node);
|
|
|
|
}
|
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
|
|
|
div.removeAttribute("data-loaded");
|
2017-05-29 05:44:00 +09:00
|
|
|
|
|
|
|
if (currentAnnotationNode) {
|
|
|
|
// Hide the annotation layer until all elements are resized
|
|
|
|
// so they are not displayed on the already resized page.
|
|
|
|
this.annotationLayer.hide();
|
Prevent the `annotationLayer` from, in some cases, becoming duplicated on the first page when the document loads
I don't know if this is a regression, but I noticed earlier today that depending on the initial scale *and* sidebar state, the `annotationLayer` of the first rendered page may end up duplicated; please see screen-shot below.
[screen-shot]
I can reproduce this reliable with e.g. https://arxiv.org/pdf/1112.0542v1.pdf#zoom=page-width&pagemode=bookmarks.
When the document loads, rendering of the first page begins immediately. When the sidebar is then opened, that forces re-rendering which thus aborts rendering of the first page.
Note that calling `PDFPageView.draw()` will always, provided an `AnnotationLayerFactory` instance exists, call `AnnotationLayerBuilder.render()`. Hence the events described above will result in *two* such calls, where the actual annotation rendering/updating happens asynchronously.
For reasons that I don't (at all) understand, when multiple `pdfPage.getAnnotations()` promises are handled back-to-back (in `AnnotationLayerBuilder.render()`), the `this.div` property seems to not update in time for the subsequent calls.
This thus, at least in Firefox, result in double rendering of all annotations on the first page.
Obviously it'd be good to find out why it breaks, since it *really* shouldn't, but this patch at least provides a (hopefully) acceptable work-around by ignoring `getAnnotations()` calls for `AnnotationLayerBuilder` instances that we're destroying (in `PDFPageView.reset()`).
2017-10-07 00:26:54 +09:00
|
|
|
} else if (this.annotationLayer) {
|
|
|
|
this.annotationLayer.cancel();
|
2017-05-29 05:44:00 +09:00
|
|
|
this.annotationLayer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!currentZoomLayerNode) {
|
|
|
|
if (this.canvas) {
|
|
|
|
this.paintedViewportMap.delete(this.canvas);
|
|
|
|
// Zeroing the width and height causes Firefox to release graphics
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
this.canvas.width = 0;
|
|
|
|
this.canvas.height = 0;
|
|
|
|
delete this.canvas;
|
2014-05-24 10:43:43 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
this._resetZoomLayer();
|
|
|
|
}
|
|
|
|
if (this.svg) {
|
|
|
|
this.paintedViewportMap.delete(this.svg);
|
|
|
|
delete this.svg;
|
|
|
|
}
|
|
|
|
|
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.loadingIconDiv = document.createElement("div");
|
|
|
|
this.loadingIconDiv.className = "loadingIcon";
|
2017-05-29 05:44:00 +09:00
|
|
|
div.appendChild(this.loadingIconDiv);
|
|
|
|
}
|
2013-10-03 01:05:46 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
update(scale, rotation) {
|
|
|
|
this.scale = scale || this.scale;
|
2019-12-26 04:03:46 +09:00
|
|
|
// The rotation may be zero.
|
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 rotation !== "undefined") {
|
2017-05-29 05:44:00 +09:00
|
|
|
this.rotation = rotation;
|
|
|
|
}
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
2017-05-29 05:44:00 +09:00
|
|
|
this.viewport = this.viewport.clone({
|
|
|
|
scale: this.scale * CSS_UNITS,
|
|
|
|
rotation: totalRotation,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.svg) {
|
|
|
|
this.cssTransform(this.svg, 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.eventBus.dispatch("pagerendered", {
|
2017-05-29 05:44:00 +09:00
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
cssTransform: true,
|
2019-07-13 06:08:23 +09:00
|
|
|
timestamp: performance.now(),
|
2014-09-28 03:03:28 +09:00
|
|
|
});
|
2017-05-29 05:44:00 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let isScalingRestricted = false;
|
2018-02-13 21:02:15 +09:00
|
|
|
if (this.canvas && this.maxCanvasPixels > 0) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const outputScale = this.outputScale;
|
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 (
|
|
|
|
((Math.floor(this.viewport.width) * outputScale.sx) | 0) *
|
2017-05-29 05:44:00 +09:00
|
|
|
((Math.floor(this.viewport.height) * outputScale.sy) | 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
|
|
|
this.maxCanvasPixels
|
|
|
|
) {
|
2017-05-29 05:44:00 +09:00
|
|
|
isScalingRestricted = true;
|
|
|
|
}
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
if (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
|
|
|
if (
|
|
|
|
this.useOnlyCssZoom ||
|
|
|
|
(this.hasRestrictedScaling && isScalingRestricted)
|
|
|
|
) {
|
2017-05-29 05:44:00 +09:00
|
|
|
this.cssTransform(this.canvas, true);
|
2016-11-19 04:03:49 +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.eventBus.dispatch("pagerendered", {
|
2016-11-19 04:03:49 +09:00
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
cssTransform: true,
|
2019-07-13 06:08:23 +09:00
|
|
|
timestamp: performance.now(),
|
2016-11-19 04:03:49 +09:00
|
|
|
});
|
|
|
|
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
|
|
|
if (!this.zoomLayer && !this.canvas.hasAttribute("hidden")) {
|
2017-05-29 05:44:00 +09:00
|
|
|
this.zoomLayer = this.canvas.parentNode;
|
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.zoomLayer.style.position = "absolute";
|
2014-09-28 03:03:28 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
if (this.zoomLayer) {
|
|
|
|
this.cssTransform(this.zoomLayer.firstChild);
|
|
|
|
}
|
|
|
|
this.reset(/* keepZoomLayer = */ true, /* keepAnnotations = */ true);
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2019-02-15 02:47:32 +09:00
|
|
|
/**
|
|
|
|
* PLEASE NOTE: Most likely you want to use the `this.reset()` method,
|
|
|
|
* rather than calling this one directly.
|
|
|
|
*/
|
Prevent the `annotationLayer` from, in some cases, becoming duplicated on the first page when the document loads
I don't know if this is a regression, but I noticed earlier today that depending on the initial scale *and* sidebar state, the `annotationLayer` of the first rendered page may end up duplicated; please see screen-shot below.
[screen-shot]
I can reproduce this reliable with e.g. https://arxiv.org/pdf/1112.0542v1.pdf#zoom=page-width&pagemode=bookmarks.
When the document loads, rendering of the first page begins immediately. When the sidebar is then opened, that forces re-rendering which thus aborts rendering of the first page.
Note that calling `PDFPageView.draw()` will always, provided an `AnnotationLayerFactory` instance exists, call `AnnotationLayerBuilder.render()`. Hence the events described above will result in *two* such calls, where the actual annotation rendering/updating happens asynchronously.
For reasons that I don't (at all) understand, when multiple `pdfPage.getAnnotations()` promises are handled back-to-back (in `AnnotationLayerBuilder.render()`), the `this.div` property seems to not update in time for the subsequent calls.
This thus, at least in Firefox, result in double rendering of all annotations on the first page.
Obviously it'd be good to find out why it breaks, since it *really* shouldn't, but this patch at least provides a (hopefully) acceptable work-around by ignoring `getAnnotations()` calls for `AnnotationLayerBuilder` instances that we're destroying (in `PDFPageView.reset()`).
2017-10-07 00:26:54 +09:00
|
|
|
cancelRendering(keepAnnotations = false) {
|
2017-05-29 05:44:00 +09:00
|
|
|
if (this.paintTask) {
|
|
|
|
this.paintTask.cancel();
|
|
|
|
this.paintTask = null;
|
|
|
|
}
|
|
|
|
this.resume = null;
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
if (this.textLayer) {
|
|
|
|
this.textLayer.cancel();
|
|
|
|
this.textLayer = null;
|
|
|
|
}
|
Prevent the `annotationLayer` from, in some cases, becoming duplicated on the first page when the document loads
I don't know if this is a regression, but I noticed earlier today that depending on the initial scale *and* sidebar state, the `annotationLayer` of the first rendered page may end up duplicated; please see screen-shot below.
[screen-shot]
I can reproduce this reliable with e.g. https://arxiv.org/pdf/1112.0542v1.pdf#zoom=page-width&pagemode=bookmarks.
When the document loads, rendering of the first page begins immediately. When the sidebar is then opened, that forces re-rendering which thus aborts rendering of the first page.
Note that calling `PDFPageView.draw()` will always, provided an `AnnotationLayerFactory` instance exists, call `AnnotationLayerBuilder.render()`. Hence the events described above will result in *two* such calls, where the actual annotation rendering/updating happens asynchronously.
For reasons that I don't (at all) understand, when multiple `pdfPage.getAnnotations()` promises are handled back-to-back (in `AnnotationLayerBuilder.render()`), the `this.div` property seems to not update in time for the subsequent calls.
This thus, at least in Firefox, result in double rendering of all annotations on the first page.
Obviously it'd be good to find out why it breaks, since it *really* shouldn't, but this patch at least provides a (hopefully) acceptable work-around by ignoring `getAnnotations()` calls for `AnnotationLayerBuilder` instances that we're destroying (in `PDFPageView.reset()`).
2017-10-07 00:26:54 +09:00
|
|
|
if (!keepAnnotations && this.annotationLayer) {
|
|
|
|
this.annotationLayer.cancel();
|
|
|
|
this.annotationLayer = null;
|
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2016-07-30 03:51:37 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
cssTransform(target, redrawAnnotations = false) {
|
|
|
|
// Scale target (canvas or svg), its wrapper and page container.
|
2019-12-27 08:22:32 +09:00
|
|
|
const width = this.viewport.width;
|
|
|
|
const height = this.viewport.height;
|
|
|
|
const div = this.div;
|
2017-05-29 05:44:00 +09:00
|
|
|
target.style.width = target.parentNode.style.width = div.style.width =
|
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
|
|
|
Math.floor(width) + "px";
|
2017-05-29 05:44:00 +09:00
|
|
|
target.style.height = target.parentNode.style.height = div.style.height =
|
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
|
|
|
Math.floor(height) + "px";
|
2017-05-29 05:44:00 +09:00
|
|
|
// The canvas may have been originally rotated; rotate relative to that.
|
2019-12-27 08:22:32 +09:00
|
|
|
const relativeRotation =
|
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.viewport.rotation - this.paintedViewportMap.get(target).rotation;
|
2019-12-27 08:22:32 +09:00
|
|
|
const absRotation = Math.abs(relativeRotation);
|
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 scaleX = 1,
|
|
|
|
scaleY = 1;
|
2017-05-29 05:44:00 +09:00
|
|
|
if (absRotation === 90 || absRotation === 270) {
|
|
|
|
// Scale x and y because of the rotation.
|
|
|
|
scaleX = height / width;
|
|
|
|
scaleY = width / height;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const cssTransform =
|
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
|
|
|
"rotate(" +
|
|
|
|
relativeRotation +
|
|
|
|
"deg) " +
|
|
|
|
"scale(" +
|
|
|
|
scaleX +
|
|
|
|
"," +
|
|
|
|
scaleY +
|
|
|
|
")";
|
2017-12-31 21:51:51 +09:00
|
|
|
target.style.transform = cssTransform;
|
2017-05-29 05:44:00 +09:00
|
|
|
|
|
|
|
if (this.textLayer) {
|
|
|
|
// Rotating the text layer is more complicated since the divs inside the
|
|
|
|
// the text layer are rotated.
|
|
|
|
// TODO: This could probably be simplified by drawing the text layer in
|
|
|
|
// one orientation and then rotating overall.
|
2019-12-27 08:22:32 +09:00
|
|
|
const textLayerViewport = this.textLayer.viewport;
|
|
|
|
const textRelativeRotation =
|
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.viewport.rotation - textLayerViewport.rotation;
|
2019-12-27 08:22:32 +09:00
|
|
|
const textAbsRotation = Math.abs(textRelativeRotation);
|
2017-05-29 05:44:00 +09:00
|
|
|
let scale = width / textLayerViewport.width;
|
|
|
|
if (textAbsRotation === 90 || textAbsRotation === 270) {
|
|
|
|
scale = width / textLayerViewport.height;
|
2014-09-28 03:03:28 +09:00
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const textLayerDiv = this.textLayer.textLayerDiv;
|
2017-05-29 05:44:00 +09:00
|
|
|
let transX, transY;
|
|
|
|
switch (textAbsRotation) {
|
|
|
|
case 0:
|
|
|
|
transX = transY = 0;
|
|
|
|
break;
|
|
|
|
case 90:
|
|
|
|
transX = 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
|
|
|
transY = "-" + textLayerDiv.style.height;
|
2017-05-29 05:44:00 +09:00
|
|
|
break;
|
|
|
|
case 180:
|
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
|
|
|
transX = "-" + textLayerDiv.style.width;
|
|
|
|
transY = "-" + textLayerDiv.style.height;
|
2017-05-29 05:44:00 +09:00
|
|
|
break;
|
|
|
|
case 270:
|
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
|
|
|
transX = "-" + textLayerDiv.style.width;
|
2017-05-29 05:44:00 +09:00
|
|
|
transY = 0;
|
|
|
|
break;
|
|
|
|
default:
|
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
|
|
|
console.error("Bad rotation value.");
|
2017-05-29 05:44:00 +09:00
|
|
|
break;
|
2014-09-28 03:03:28 +09:00
|
|
|
}
|
2017-12-31 21:51:51 +09:00
|
|
|
|
|
|
|
textLayerDiv.style.transform =
|
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
|
|
|
"rotate(" +
|
|
|
|
textAbsRotation +
|
|
|
|
"deg) " +
|
|
|
|
"scale(" +
|
|
|
|
scale +
|
|
|
|
", " +
|
|
|
|
scale +
|
|
|
|
") " +
|
|
|
|
"translate(" +
|
|
|
|
transX +
|
|
|
|
", " +
|
|
|
|
transY +
|
|
|
|
")";
|
|
|
|
textLayerDiv.style.transformOrigin = "0% 0%";
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (redrawAnnotations && this.annotationLayer) {
|
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.annotationLayer.render(this.viewport, "display");
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
get width() {
|
|
|
|
return this.viewport.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
get height() {
|
|
|
|
return this.viewport.height;
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
getPagePoint(x, y) {
|
|
|
|
return this.viewport.convertToPdfPoint(x, y);
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
draw() {
|
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
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
|
|
|
console.error("Must be in new state before drawing");
|
2017-05-29 05:44:00 +09:00
|
|
|
this.reset(); // Ensure that we reset all state to prevent issues.
|
|
|
|
}
|
2020-02-09 01:43:53 +09:00
|
|
|
const { div, pdfPage } = this;
|
2017-05-29 05:44:00 +09:00
|
|
|
|
2020-02-09 01:43:53 +09:00
|
|
|
if (!pdfPage) {
|
2017-08-04 07:24:19 +09:00
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
2020-02-09 01:43:53 +09:00
|
|
|
|
|
|
|
if (this.loadingIconDiv) {
|
|
|
|
div.removeChild(this.loadingIconDiv);
|
|
|
|
delete this.loadingIconDiv;
|
|
|
|
}
|
|
|
|
return Promise.reject(new Error("pdfPage is not loaded"));
|
2017-08-04 07:24:19 +09:00
|
|
|
}
|
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
this.renderingState = RenderingStates.RUNNING;
|
|
|
|
|
|
|
|
// Wrap the canvas so that if it has a CSS transform for high DPI the
|
|
|
|
// overflow will be hidden in Firefox.
|
2019-12-27 08:22:32 +09:00
|
|
|
const canvasWrapper = document.createElement("div");
|
2017-05-29 05:44:00 +09:00
|
|
|
canvasWrapper.style.width = div.style.width;
|
|
|
|
canvasWrapper.style.height = div.style.height;
|
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
|
|
|
canvasWrapper.classList.add("canvasWrapper");
|
2017-05-29 05:44:00 +09:00
|
|
|
|
|
|
|
if (this.annotationLayer && this.annotationLayer.div) {
|
|
|
|
// The annotation layer needs to stay on top.
|
|
|
|
div.insertBefore(canvasWrapper, this.annotationLayer.div);
|
|
|
|
} else {
|
|
|
|
div.appendChild(canvasWrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
let textLayer = null;
|
2018-02-13 23:01:55 +09:00
|
|
|
if (this.textLayerMode !== TextLayerMode.DISABLE && this.textLayerFactory) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const textLayerDiv = document.createElement("div");
|
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
|
|
|
textLayerDiv.className = "textLayer";
|
2017-05-29 05:44:00 +09:00
|
|
|
textLayerDiv.style.width = canvasWrapper.style.width;
|
|
|
|
textLayerDiv.style.height = canvasWrapper.style.height;
|
2015-09-24 02:34:11 +09:00
|
|
|
if (this.annotationLayer && this.annotationLayer.div) {
|
2017-05-29 05:44:00 +09:00
|
|
|
// The annotation layer needs to stay on top.
|
|
|
|
div.insertBefore(textLayerDiv, this.annotationLayer.div);
|
2014-04-01 20:45:00 +09:00
|
|
|
} else {
|
2017-05-29 05:44:00 +09:00
|
|
|
div.appendChild(textLayerDiv);
|
2014-04-01 20:45:00 +09:00
|
|
|
}
|
2014-09-28 03:03:28 +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
|
|
|
textLayer = this.textLayerFactory.createTextLayerBuilder(
|
|
|
|
textLayerDiv,
|
|
|
|
this.id - 1,
|
|
|
|
this.viewport,
|
2020-02-27 01:16:30 +09:00
|
|
|
this.textLayerMode === TextLayerMode.ENABLE_ENHANCE,
|
|
|
|
this.eventBus
|
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-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
this.textLayer = textLayer;
|
|
|
|
|
|
|
|
let renderContinueCallback = null;
|
|
|
|
if (this.renderingQueue) {
|
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
|
|
|
renderContinueCallback = cont => {
|
2017-05-29 05:44:00 +09:00
|
|
|
if (!this.renderingQueue.isHighestPriority(this)) {
|
|
|
|
this.renderingState = RenderingStates.PAUSED;
|
|
|
|
this.resume = () => {
|
|
|
|
this.renderingState = RenderingStates.RUNNING;
|
|
|
|
cont();
|
|
|
|
};
|
|
|
|
return;
|
2014-09-28 03:03:28 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
cont();
|
|
|
|
};
|
|
|
|
}
|
2013-09-20 16:25:41 +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 finishPaintTask = async error => {
|
2017-05-29 05:44:00 +09:00
|
|
|
// The paintTask may have been replaced by a new one, so only remove
|
|
|
|
// the reference to the paintTask if it matches the one that is
|
|
|
|
// triggering this callback.
|
|
|
|
if (paintTask === this.paintTask) {
|
|
|
|
this.paintTask = null;
|
2016-10-19 23:16:57 +09:00
|
|
|
}
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2017-10-05 01:13:40 +09:00
|
|
|
if (error instanceof RenderingCancelledException) {
|
2017-05-29 05:44:00 +09:00
|
|
|
this.error = null;
|
2019-01-26 18:12:32 +09:00
|
|
|
return;
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
2016-10-19 23:16:57 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
if (this.loadingIconDiv) {
|
|
|
|
div.removeChild(this.loadingIconDiv);
|
|
|
|
delete this.loadingIconDiv;
|
2014-09-28 03:03:28 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
this._resetZoomLayer(/* removeFromDOM = */ true);
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
this.error = error;
|
|
|
|
this.stats = pdfPage.stats;
|
2019-07-19 19:40:49 +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.eventBus.dispatch("pagerendered", {
|
2017-05-29 05:44:00 +09:00
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
cssTransform: false,
|
2019-07-13 06:08:23 +09:00
|
|
|
timestamp: performance.now(),
|
2017-05-29 05:44:00 +09:00
|
|
|
});
|
2016-10-19 23:16:57 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
if (error) {
|
2019-01-26 18:12:32 +09:00
|
|
|
throw error;
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const paintTask =
|
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.renderer === RendererType.SVG
|
|
|
|
? this.paintOnSvg(canvasWrapper)
|
|
|
|
: this.paintOnCanvas(canvasWrapper);
|
2017-05-29 05:44:00 +09:00
|
|
|
paintTask.onRenderContinue = renderContinueCallback;
|
|
|
|
this.paintTask = paintTask;
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const resultPromise = paintTask.promise.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
|
|
|
function() {
|
|
|
|
return finishPaintTask(null).then(function() {
|
|
|
|
if (textLayer) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const readableStream = pdfPage.streamTextContent({
|
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: true,
|
|
|
|
});
|
|
|
|
textLayer.setTextContentStream(readableStream);
|
|
|
|
textLayer.render();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function(reason) {
|
|
|
|
return finishPaintTask(reason);
|
|
|
|
}
|
|
|
|
);
|
2017-05-29 05:44:00 +09:00
|
|
|
|
|
|
|
if (this.annotationLayerFactory) {
|
|
|
|
if (!this.annotationLayer) {
|
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.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(
|
|
|
|
div,
|
|
|
|
pdfPage,
|
|
|
|
this.imageResourcesPath,
|
|
|
|
this.renderInteractiveForms,
|
|
|
|
this.l10n
|
|
|
|
);
|
2014-12-18 05:47:14 +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.annotationLayer.render(this.viewport, "display");
|
2017-05-29 05:44:00 +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
|
|
|
div.setAttribute("data-loaded", true);
|
2017-05-29 05:44:00 +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.eventBus.dispatch("pagerender", {
|
2019-07-19 19:40:49 +09:00
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
});
|
2017-05-29 05:44:00 +09:00
|
|
|
return resultPromise;
|
|
|
|
}
|
2014-12-18 05:47:14 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
paintOnCanvas(canvasWrapper) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const renderCapability = createPromiseCapability();
|
|
|
|
const result = {
|
2017-05-29 05:44:00 +09:00
|
|
|
promise: renderCapability.promise,
|
|
|
|
onRenderContinue(cont) {
|
|
|
|
cont();
|
|
|
|
},
|
|
|
|
cancel() {
|
|
|
|
renderTask.cancel();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const viewport = this.viewport;
|
|
|
|
const canvas = document.createElement("canvas");
|
2020-01-11 21:55:13 +09:00
|
|
|
this.l10n
|
|
|
|
.get("page_canvas", { page: this.id }, "Page {{page}}")
|
|
|
|
.then(msg => {
|
|
|
|
canvas.setAttribute("aria-label", msg);
|
|
|
|
});
|
2017-05-29 05:44:00 +09:00
|
|
|
|
|
|
|
// Keep the canvas hidden until the first draw callback, or until drawing
|
|
|
|
// is complete when `!this.renderingQueue`, to prevent black flickering.
|
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.setAttribute("hidden", "hidden");
|
2017-05-29 05:44:00 +09:00
|
|
|
let isCanvasHidden = true;
|
2019-12-27 08:22:32 +09:00
|
|
|
const showCanvas = function() {
|
2017-05-29 05:44:00 +09:00
|
|
|
if (isCanvasHidden) {
|
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.removeAttribute("hidden");
|
2017-05-29 05:44:00 +09:00
|
|
|
isCanvasHidden = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
canvasWrapper.appendChild(canvas);
|
|
|
|
this.canvas = 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
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
2020-01-08 21:57:31 +09:00
|
|
|
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
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-29 05:44:00 +09:00
|
|
|
canvas.mozOpaque = true;
|
|
|
|
}
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const ctx = canvas.getContext("2d", { alpha: false });
|
|
|
|
const outputScale = getOutputScale(ctx);
|
2017-05-29 05:44:00 +09:00
|
|
|
this.outputScale = outputScale;
|
|
|
|
|
2018-02-13 20:52:42 +09:00
|
|
|
if (this.useOnlyCssZoom) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const actualSizeViewport = viewport.clone({ scale: CSS_UNITS });
|
2017-05-29 05:44:00 +09:00
|
|
|
// Use a scale that makes the canvas have the originally intended size
|
|
|
|
// of the page.
|
|
|
|
outputScale.sx *= actualSizeViewport.width / viewport.width;
|
|
|
|
outputScale.sy *= actualSizeViewport.height / viewport.height;
|
|
|
|
outputScale.scaled = true;
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:02:15 +09:00
|
|
|
if (this.maxCanvasPixels > 0) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const pixelsInViewport = viewport.width * viewport.height;
|
|
|
|
const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
|
2017-05-29 05:44:00 +09:00
|
|
|
if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
|
|
|
|
outputScale.sx = maxScale;
|
|
|
|
outputScale.sy = maxScale;
|
2016-10-19 23:16:57 +09:00
|
|
|
outputScale.scaled = true;
|
2017-05-29 05:44:00 +09:00
|
|
|
this.hasRestrictedScaling = true;
|
|
|
|
} else {
|
|
|
|
this.hasRestrictedScaling = false;
|
2016-10-19 23:16:57 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const sfx = approximateFraction(outputScale.sx);
|
|
|
|
const sfy = approximateFraction(outputScale.sy);
|
2017-05-29 05:44:00 +09:00
|
|
|
canvas.width = roundToDivide(viewport.width * outputScale.sx, sfx[0]);
|
|
|
|
canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[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
|
|
|
canvas.style.width = roundToDivide(viewport.width, sfx[1]) + "px";
|
|
|
|
canvas.style.height = roundToDivide(viewport.height, sfy[1]) + "px";
|
2017-05-29 05:44:00 +09:00
|
|
|
// Add the viewport so it's known what it was originally drawn with.
|
|
|
|
this.paintedViewportMap.set(canvas, viewport);
|
|
|
|
|
|
|
|
// Rendering area
|
2019-12-27 08:22:32 +09:00
|
|
|
const transform = !outputScale.scaled
|
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
|
|
|
? null
|
|
|
|
: [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
|
2019-12-27 08:22:32 +09:00
|
|
|
const renderContext = {
|
2017-05-29 05:44:00 +09:00
|
|
|
canvasContext: ctx,
|
|
|
|
transform,
|
|
|
|
viewport: this.viewport,
|
2018-02-13 22:16:10 +09:00
|
|
|
enableWebGL: this.enableWebGL,
|
2017-05-29 05:44:00 +09:00
|
|
|
renderInteractiveForms: this.renderInteractiveForms,
|
|
|
|
};
|
2019-12-27 08:22:32 +09:00
|
|
|
const renderTask = this.pdfPage.render(renderContext);
|
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
|
|
|
renderTask.onContinue = function(cont) {
|
2017-05-29 05:44:00 +09:00
|
|
|
showCanvas();
|
|
|
|
if (result.onRenderContinue) {
|
|
|
|
result.onRenderContinue(cont);
|
|
|
|
} else {
|
|
|
|
cont();
|
2016-10-19 23:16:57 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +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
|
|
|
renderTask.promise.then(
|
|
|
|
function() {
|
|
|
|
showCanvas();
|
|
|
|
renderCapability.resolve(undefined);
|
|
|
|
},
|
|
|
|
function(error) {
|
|
|
|
showCanvas();
|
|
|
|
renderCapability.reject(error);
|
|
|
|
}
|
|
|
|
);
|
2017-05-29 05:44:00 +09:00
|
|
|
return result;
|
|
|
|
}
|
2016-10-19 23:16:57 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
paintOnSvg(wrapper) {
|
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" &&
|
2020-01-08 21:57:31 +09:00
|
|
|
PDFJSDev.test("MOZCENTRAL || CHROME")
|
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-29 05:44:00 +09:00
|
|
|
// Return a mock object, to prevent errors such as e.g.
|
|
|
|
// "TypeError: paintTask.promise is undefined".
|
|
|
|
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
|
|
|
promise: Promise.reject(new Error("SVG rendering is not supported.")),
|
|
|
|
onRenderContinue(cont) {},
|
|
|
|
cancel() {},
|
2013-09-20 16:25:41 +09:00
|
|
|
};
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
let cancelled = false;
|
2019-12-27 08:22:32 +09:00
|
|
|
const ensureNotCancelled = () => {
|
2017-05-29 05:44:00 +09:00
|
|
|
if (cancelled) {
|
2017-10-05 01:13:40 +09:00
|
|
|
throw new RenderingCancelledException(
|
2020-03-19 23:36:09 +09:00
|
|
|
`Rendering cancelled, page ${this.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
|
|
|
"svg"
|
|
|
|
);
|
2017-01-10 10:13:36 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
};
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const pdfPage = this.pdfPage;
|
|
|
|
const actualSizeViewport = this.viewport.clone({ scale: CSS_UNITS });
|
|
|
|
const promise = pdfPage.getOperatorList().then(opList => {
|
2017-05-29 05:44:00 +09:00
|
|
|
ensureNotCancelled();
|
2019-12-27 08:22:32 +09:00
|
|
|
const svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
|
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 svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
|
2017-01-10 10:13:36 +09:00
|
|
|
ensureNotCancelled();
|
2017-05-29 05:44:00 +09:00
|
|
|
this.svg = svg;
|
|
|
|
this.paintedViewportMap.set(svg, actualSizeViewport);
|
2016-01-27 22:27:01 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
svg.style.width = wrapper.style.width;
|
|
|
|
svg.style.height = wrapper.style.height;
|
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
|
|
|
wrapper.appendChild(svg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
promise,
|
|
|
|
onRenderContinue(cont) {
|
|
|
|
cont();
|
|
|
|
},
|
|
|
|
cancel() {
|
|
|
|
cancelled = true;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
/**
|
|
|
|
* @param {string|null} label
|
|
|
|
*/
|
|
|
|
setPageLabel(label) {
|
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.pageLabel = typeof label === "string" ? label : null;
|
2017-05-29 05:44:00 +09:00
|
|
|
|
|
|
|
if (this.pageLabel !== 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
|
|
|
this.div.setAttribute("data-page-label", this.pageLabel);
|
2017-05-29 05:44:00 +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
|
|
|
this.div.removeAttribute("data-page-label");
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +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
|
|
|
export { PDFPageView };
|