2013-08-07 05:19:03 +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.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 20:00:16 +09:00
|
|
|
import { getOutputScale, NullL10n } from "./ui_utils.js";
|
2020-09-24 01:08:32 +09:00
|
|
|
import { RenderingCancelledException } from "pdfjs-lib";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { RenderingStates } from "./pdf_rendering_queue.js";
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
const MAX_NUM_SCALING_STEPS = 3;
|
|
|
|
const THUMBNAIL_CANVAS_BORDER_WIDTH = 1; // px
|
|
|
|
const THUMBNAIL_WIDTH = 98; // px
|
2014-09-16 05:46:01 +09:00
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2015-01-25 00:27:31 +09:00
|
|
|
* @typedef {Object} PDFThumbnailViewOptions
|
|
|
|
* @property {HTMLDivElement} container - The viewer element.
|
|
|
|
* @property {number} id - The thumbnail's unique ID (normally its number).
|
|
|
|
* @property {PageViewport} defaultViewport - The page viewport.
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
* @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
|
|
|
|
* A promise that is resolved with an {@link OptionalContentConfig} instance.
|
|
|
|
* The default value is `null`.
|
2015-01-25 00:27:31 +09:00
|
|
|
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
|
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
* @property {function} checkSetImageDisabled
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {boolean} [disableCanvasToImageConversion] - Don't convert the
|
|
|
|
* canvas thumbnails to images. This prevents `toDataURL` calls, but
|
|
|
|
* increases the overall memory usage. The default value is `false`.
|
2017-05-04 10:05:53 +09:00
|
|
|
* @property {IL10n} l10n - Localization service.
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
2013-08-07 05:19:03 +09:00
|
|
|
|
2017-05-30 22:50:37 +09:00
|
|
|
const TempImageFactory = (function TempImageFactoryClosure() {
|
|
|
|
let tempCanvasCache = null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
getCanvas(width, height) {
|
|
|
|
let tempCanvas = tempCanvasCache;
|
|
|
|
if (!tempCanvas) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
tempCanvas = document.createElement("canvas");
|
2017-05-30 22:50:37 +09:00
|
|
|
tempCanvasCache = tempCanvas;
|
|
|
|
}
|
|
|
|
tempCanvas.width = width;
|
|
|
|
tempCanvas.height = height;
|
|
|
|
|
|
|
|
// Since this is a temporary canvas, we need to fill it with a white
|
|
|
|
// background ourselves. `_getPageDrawContext` uses CSS rules for this.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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-30 22:50:37 +09:00
|
|
|
tempCanvas.mozOpaque = true;
|
|
|
|
}
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const ctx = tempCanvas.getContext("2d", { alpha: false });
|
2017-05-30 22:50:37 +09:00
|
|
|
ctx.save();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
ctx.fillStyle = "rgb(255, 255, 255)";
|
2017-05-30 22:50:37 +09:00
|
|
|
ctx.fillRect(0, 0, width, height);
|
|
|
|
ctx.restore();
|
|
|
|
return tempCanvas;
|
|
|
|
},
|
|
|
|
|
|
|
|
destroyCanvas() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const tempCanvas = tempCanvasCache;
|
2017-05-30 22:50:37 +09:00
|
|
|
if (tempCanvas) {
|
|
|
|
// Zeroing the width and height causes Firefox to release graphics
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
tempCanvas.width = 0;
|
|
|
|
tempCanvas.height = 0;
|
|
|
|
}
|
|
|
|
tempCanvasCache = null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
/**
|
|
|
|
* @implements {IRenderableView}
|
|
|
|
*/
|
2017-06-05 02:45:28 +09:00
|
|
|
class PDFThumbnailView {
|
2015-01-25 00:27:31 +09:00
|
|
|
/**
|
|
|
|
* @param {PDFThumbnailViewOptions} options
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
constructor({
|
|
|
|
container,
|
|
|
|
id,
|
|
|
|
defaultViewport,
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
optionalContentConfigPromise,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
linkService,
|
|
|
|
renderingQueue,
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
checkSetImageDisabled,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
disableCanvasToImageConversion = false,
|
|
|
|
l10n = NullL10n,
|
|
|
|
}) {
|
2015-01-25 21:27:11 +09:00
|
|
|
this.id = 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 = "thumbnail" + id;
|
2016-01-27 22:27:01 +09:00
|
|
|
this.pageLabel = null;
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.pdfPage = null;
|
|
|
|
this.rotation = 0;
|
2015-01-25 00:27:31 +09:00
|
|
|
this.viewport = defaultViewport;
|
|
|
|
this.pdfPageRotate = defaultViewport.rotation;
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.linkService = linkService;
|
|
|
|
this.renderingQueue = renderingQueue;
|
|
|
|
|
2016-07-30 03:39:22 +09:00
|
|
|
this.renderTask = null;
|
2015-01-25 21:27:11 +09:00
|
|
|
this.renderingState = RenderingStates.INITIAL;
|
2016-07-30 03:39:22 +09:00
|
|
|
this.resume = null;
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
this._checkSetImageDisabled =
|
|
|
|
checkSetImageDisabled ||
|
|
|
|
function () {
|
|
|
|
return false;
|
|
|
|
};
|
2015-09-12 18:32:18 +09:00
|
|
|
this.disableCanvasToImageConversion = disableCanvasToImageConversion;
|
2015-01-25 21:27:11 +09:00
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
this.pageWidth = this.viewport.width;
|
|
|
|
this.pageHeight = this.viewport.height;
|
|
|
|
this.pageRatio = this.pageWidth / this.pageHeight;
|
|
|
|
|
2015-01-25 21:27:11 +09:00
|
|
|
this.canvasWidth = THUMBNAIL_WIDTH;
|
2015-01-25 00:27:31 +09:00
|
|
|
this.canvasHeight = (this.canvasWidth / this.pageRatio) | 0;
|
|
|
|
this.scale = this.canvasWidth / this.pageWidth;
|
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
this.l10n = l10n;
|
2017-05-04 10:05:53 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const anchor = document.createElement("a");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
anchor.href = linkService.getAnchorUrl("#page=" + id);
|
2020-01-11 22:28:29 +09:00
|
|
|
this._thumbPageTitle.then(msg => {
|
|
|
|
anchor.title = msg;
|
|
|
|
});
|
2020-04-14 19:28:14 +09:00
|
|
|
anchor.onclick = function () {
|
2020-10-04 01:08:30 +09:00
|
|
|
linkService.goToPage(id);
|
2015-01-25 21:27:11 +09:00
|
|
|
return false;
|
|
|
|
};
|
2016-01-27 22:27:01 +09:00
|
|
|
this.anchor = anchor;
|
2015-01-25 21:27:11 +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 = "thumbnail";
|
|
|
|
div.setAttribute("data-page-number", this.id);
|
2015-01-25 00:27:31 +09:00
|
|
|
this.div = div;
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const ring = 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
|
|
|
ring.className = "thumbnailSelectionRing";
|
2019-12-27 08:22:32 +09:00
|
|
|
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_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
|
|
|
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
|
|
|
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
2015-01-25 00:27:31 +09:00
|
|
|
this.ring = ring;
|
|
|
|
|
|
|
|
div.appendChild(ring);
|
|
|
|
anchor.appendChild(div);
|
|
|
|
container.appendChild(anchor);
|
|
|
|
}
|
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
setPdfPage(pdfPage) {
|
|
|
|
this.pdfPage = pdfPage;
|
|
|
|
this.pdfPageRotate = pdfPage.rotate;
|
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: 1, rotation: totalRotation });
|
2017-06-05 02:45:28 +09:00
|
|
|
this.reset();
|
|
|
|
}
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
reset() {
|
|
|
|
this.cancelRendering();
|
2019-02-15 02:47:32 +09:00
|
|
|
this.renderingState = RenderingStates.INITIAL;
|
2015-01-25 21:27:11 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
this.pageWidth = this.viewport.width;
|
|
|
|
this.pageHeight = this.viewport.height;
|
|
|
|
this.pageRatio = this.pageWidth / this.pageHeight;
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
this.canvasHeight = (this.canvasWidth / this.pageRatio) | 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.scale = this.canvasWidth / this.pageWidth;
|
2015-01-25 00:27:31 +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.div.removeAttribute("data-loaded");
|
2019-12-27 08:22:32 +09:00
|
|
|
const ring = this.ring;
|
|
|
|
const childNodes = ring.childNodes;
|
2017-06-05 02:45:28 +09:00
|
|
|
for (let i = childNodes.length - 1; i >= 0; i--) {
|
|
|
|
ring.removeChild(childNodes[i]);
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_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
|
|
|
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
|
|
|
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
2015-01-25 21:27:11 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
if (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;
|
|
|
|
}
|
|
|
|
if (this.image) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.image.removeAttribute("src");
|
2017-06-05 02:45:28 +09:00
|
|
|
delete this.image;
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
update(rotation) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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-06-05 02:45:28 +09:00
|
|
|
this.rotation = rotation;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
2017-06-05 02:45:28 +09:00
|
|
|
this.viewport = this.viewport.clone({
|
|
|
|
scale: 1,
|
|
|
|
rotation: totalRotation,
|
|
|
|
});
|
|
|
|
this.reset();
|
|
|
|
}
|
2015-01-25 00:27:31 +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.
|
|
|
|
*/
|
2017-06-05 02:45:28 +09:00
|
|
|
cancelRendering() {
|
|
|
|
if (this.renderTask) {
|
|
|
|
this.renderTask.cancel();
|
|
|
|
this.renderTask = null;
|
|
|
|
}
|
|
|
|
this.resume = null;
|
|
|
|
}
|
2016-07-30 03:39:22 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_getPageDrawContext(noCtxScale = false) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const canvas = document.createElement("canvas");
|
2017-06-05 02:45:28 +09:00
|
|
|
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
|
|
|
// until rendering/image conversion is complete, to avoid display issues.
|
|
|
|
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-06-05 02:45:28 +09:00
|
|
|
canvas.mozOpaque = true;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const ctx = canvas.getContext("2d", { alpha: false });
|
|
|
|
const outputScale = getOutputScale(ctx);
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
canvas.width = (this.canvasWidth * outputScale.sx) | 0;
|
|
|
|
canvas.height = (this.canvasHeight * 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
|
|
|
canvas.style.width = this.canvasWidth + "px";
|
|
|
|
canvas.style.height = this.canvasHeight + "px";
|
2015-09-11 20:11:49 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
if (!noCtxScale && outputScale.scaled) {
|
|
|
|
ctx.scale(outputScale.sx, outputScale.sy);
|
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
2015-09-11 20:11:49 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_convertCanvasToImage() {
|
|
|
|
if (!this.canvas) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const className = "thumbnailImage";
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
if (this.disableCanvasToImageConversion) {
|
|
|
|
this.canvas.className = className;
|
2020-01-11 22:28:29 +09:00
|
|
|
this._thumbPageCanvas.then(msg => {
|
|
|
|
this.canvas.setAttribute("aria-label", msg);
|
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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-loaded", true);
|
2017-06-05 02:45:28 +09:00
|
|
|
this.ring.appendChild(this.canvas);
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const image = document.createElement("img");
|
2017-06-05 02:45:28 +09:00
|
|
|
image.className = className;
|
2020-01-11 22:28:29 +09:00
|
|
|
this._thumbPageCanvas.then(msg => {
|
|
|
|
image.setAttribute("aria-label", msg);
|
|
|
|
});
|
2015-09-12 18:51:25 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
image.style.width = this.canvasWidth + "px";
|
|
|
|
image.style.height = this.canvasHeight + "px";
|
2015-09-11 20:11:49 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
image.src = this.canvas.toDataURL();
|
|
|
|
this.image = image;
|
2016-02-26 00:47:51 +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.div.setAttribute("data-loaded", true);
|
2017-06-05 02:45:28 +09:00
|
|
|
this.ring.appendChild(image);
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-05 02:45:28 +09:00
|
|
|
return Promise.resolve(undefined);
|
|
|
|
}
|
2020-02-09 01:43:53 +09:00
|
|
|
const { pdfPage } = this;
|
|
|
|
|
|
|
|
if (!pdfPage) {
|
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
|
|
|
return Promise.reject(new Error("pdfPage is not loaded"));
|
|
|
|
}
|
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
this.renderingState = RenderingStates.RUNNING;
|
|
|
|
|
2020-09-24 01:08:32 +09:00
|
|
|
const finishRenderTask = async (error = null) => {
|
2017-06-05 02:45:28 +09:00
|
|
|
// The renderTask may have been replaced by a new one, so only remove
|
|
|
|
// the reference to the renderTask if it matches the one that is
|
|
|
|
// triggering this callback.
|
|
|
|
if (renderTask === this.renderTask) {
|
|
|
|
this.renderTask = null;
|
2016-02-26 00:47:51 +09:00
|
|
|
}
|
2017-06-05 02:45:28 +09:00
|
|
|
|
2017-10-05 01:13:40 +09:00
|
|
|
if (error instanceof RenderingCancelledException) {
|
2015-01-25 00:27:31 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-02-26 00:47:51 +09:00
|
|
|
|
2015-01-25 00:27:31 +09:00
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
2017-06-05 02:45:28 +09:00
|
|
|
this._convertCanvasToImage();
|
2015-01-25 21:27:11 +09:00
|
|
|
|
2020-09-24 01:08:32 +09:00
|
|
|
if (error) {
|
|
|
|
throw error;
|
2017-06-05 02:45:28 +09:00
|
|
|
}
|
|
|
|
};
|
2015-01-25 00:27:31 +09:00
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const ctx = this._getPageDrawContext();
|
|
|
|
const drawViewport = this.viewport.clone({ scale: this.scale });
|
|
|
|
const renderContinueCallback = cont => {
|
2017-06-05 02:45:28 +09:00
|
|
|
if (!this.renderingQueue.isHighestPriority(this)) {
|
|
|
|
this.renderingState = RenderingStates.PAUSED;
|
|
|
|
this.resume = () => {
|
|
|
|
this.renderingState = RenderingStates.RUNNING;
|
|
|
|
cont();
|
|
|
|
};
|
2015-01-25 21:27:11 +09:00
|
|
|
return;
|
2015-01-25 00:27:31 +09:00
|
|
|
}
|
2017-06-05 02:45:28 +09:00
|
|
|
cont();
|
|
|
|
};
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const renderContext = {
|
2017-06-05 02:45:28 +09:00
|
|
|
canvasContext: ctx,
|
|
|
|
viewport: drawViewport,
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
optionalContentConfigPromise: this._optionalContentConfigPromise,
|
2017-06-05 02:45:28 +09:00
|
|
|
};
|
2020-02-09 01:43:53 +09:00
|
|
|
const renderTask = (this.renderTask = pdfPage.render(renderContext));
|
2017-06-05 02:45:28 +09:00
|
|
|
renderTask.onContinue = renderContinueCallback;
|
|
|
|
|
2020-09-24 01:08:32 +09:00
|
|
|
const resultPromise = renderTask.promise.then(
|
2020-04-14 19:28:14 +09:00
|
|
|
function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
finishRenderTask(null);
|
|
|
|
},
|
2020-04-14 19:28:14 +09:00
|
|
|
function (error) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
finishRenderTask(error);
|
|
|
|
}
|
|
|
|
);
|
2020-09-24 01:08:32 +09:00
|
|
|
return resultPromise;
|
2017-06-05 02:45:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
setImage(pageView) {
|
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)
By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.
Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)
Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.
To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
- Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
- Uses a slightly different formatting, compared to the "regular" headings.
- Is localizable.
Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-07 04:01:03 +09:00
|
|
|
if (this._checkSetImageDisabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-05 02:45:28 +09:00
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const img = pageView.canvas;
|
2017-06-05 02:45:28 +09:00
|
|
|
if (!img) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this.pdfPage) {
|
|
|
|
this.setPdfPage(pageView.pdfPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const ctx = this._getPageDrawContext(true);
|
|
|
|
const canvas = ctx.canvas;
|
2017-06-05 02:45:28 +09:00
|
|
|
if (img.width <= 2 * canvas.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
|
|
|
ctx.drawImage(
|
|
|
|
img,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
img.width,
|
|
|
|
img.height,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
canvas.width,
|
|
|
|
canvas.height
|
|
|
|
);
|
2015-09-11 20:11:49 +09:00
|
|
|
this._convertCanvasToImage();
|
2017-06-05 02:45:28 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-01-27 22:27:01 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
|
|
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
|
|
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
2019-12-27 08:22:32 +09:00
|
|
|
const reducedImage = TempImageFactory.getCanvas(
|
|
|
|
reducedWidth,
|
|
|
|
reducedHeight
|
|
|
|
);
|
|
|
|
const reducedImageCtx = reducedImage.getContext("2d");
|
2016-01-27 22:27:01 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
|
|
reducedWidth >>= 1;
|
|
|
|
reducedHeight >>= 1;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
reducedImageCtx.drawImage(
|
|
|
|
img,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
img.width,
|
|
|
|
img.height,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
reducedWidth,
|
|
|
|
reducedHeight
|
|
|
|
);
|
2017-06-05 02:45:28 +09:00
|
|
|
while (reducedWidth > 2 * canvas.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
|
|
|
reducedImageCtx.drawImage(
|
|
|
|
reducedImage,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
reducedWidth,
|
|
|
|
reducedHeight,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
reducedWidth >> 1,
|
|
|
|
reducedHeight >> 1
|
|
|
|
);
|
2017-06-05 02:45:28 +09:00
|
|
|
reducedWidth >>= 1;
|
|
|
|
reducedHeight >>= 1;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
ctx.drawImage(
|
|
|
|
reducedImage,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
reducedWidth,
|
|
|
|
reducedHeight,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
canvas.width,
|
|
|
|
canvas.height
|
|
|
|
);
|
2017-06-05 02:45:28 +09:00
|
|
|
this._convertCanvasToImage();
|
|
|
|
}
|
2016-01-27 22:27:01 +09:00
|
|
|
|
2020-01-11 22:28:29 +09:00
|
|
|
get _thumbPageTitle() {
|
|
|
|
return this.l10n.get(
|
|
|
|
"thumb_page_title",
|
2020-06-12 22:08:51 +09:00
|
|
|
{ page: this.pageLabel ?? this.id },
|
2020-01-11 22:28:29 +09:00
|
|
|
"Page {{page}}"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get _thumbPageCanvas() {
|
|
|
|
return this.l10n.get(
|
|
|
|
"thumb_page_canvas",
|
2020-06-12 22:08:51 +09:00
|
|
|
{ page: this.pageLabel ?? this.id },
|
2020-01-11 22:28:29 +09:00
|
|
|
"Thumbnail of Page {{page}}"
|
|
|
|
);
|
2017-06-05 02:45:28 +09:00
|
|
|
}
|
2016-01-27 22:27:01 +09:00
|
|
|
|
2017-06-05 02:45:28 +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-04 10:05:53 +09:00
|
|
|
|
2020-01-11 22:28:29 +09:00
|
|
|
this._thumbPageTitle.then(msg => {
|
|
|
|
this.anchor.title = msg;
|
|
|
|
});
|
2014-06-13 00:28:42 +09:00
|
|
|
|
2017-06-05 02:45:28 +09:00
|
|
|
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-30 22:50:37 +09:00
|
|
|
|
2020-01-11 22:28:29 +09:00
|
|
|
this._thumbPageCanvas.then(msg => {
|
|
|
|
if (this.image) {
|
|
|
|
this.image.setAttribute("aria-label", msg);
|
|
|
|
} else if (this.disableCanvasToImageConversion && this.canvas) {
|
|
|
|
this.canvas.setAttribute("aria-label", msg);
|
|
|
|
}
|
|
|
|
});
|
2017-06-05 02:45:28 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static cleanup() {
|
|
|
|
TempImageFactory.destroyCanvas();
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 00:27:31 +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 { PDFThumbnailView };
|