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.
|
|
|
|
*/
|
|
|
|
|
2021-12-15 07:59:17 +09:00
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
/** @typedef {import("../src/display/optional_content_config").OptionalContentConfig} OptionalContentConfig */
|
2021-12-15 21:54:29 +09:00
|
|
|
/** @typedef {import("./event_utils").EventBus} EventBus */
|
2021-12-15 07:59:17 +09:00
|
|
|
/** @typedef {import("./interfaces").IL10n} IL10n */
|
Fix Viewer API definitions and include in CI
The Viewer API definitions do not compile because of missing imports and
anonymous objects are typed as `Object`. These issues were not caught
during CI because the test project was not compiling anything from the
Viewer API.
As an example of the first problem:
```
/**
* @implements MyInterface
*/
export class MyClass {
...
}
```
will generate a broken definition that doesn’t import MyInterface:
```
/**
* @implements MyInterface
*/
export class MyClass implements MyInterface {
...
}
```
This can be fixed by adding a typedef jsdoc to specify the import:
```
/** @typedef {import("./otherFile").MyInterface} MyInterface */
```
See https://github.com/jsdoc/jsdoc/issues/1537 and
https://github.com/microsoft/TypeScript/issues/22160 for more details.
As an example of the second problem:
```
/**
* Gets the size of the specified page, converted from PDF units to inches.
* @param {Object} An Object containing the properties: {Array} `view`,
* {number} `userUnit`, and {number} `rotate`.
*/
function getPageSizeInches({ view, userUnit, rotate }) {
...
}
```
generates the broken definition:
```
function getPageSizeInches({ view, userUnit, rotate }: Object) {
...
}
```
The jsdoc should specify the type of each nested property:
```
/**
* Gets the size of the specified page, converted from PDF units to inches.
* @param {Object} options An object containing the properties: {Array} `view`,
* {number} `userUnit`, and {number} `rotate`.
* @param {number[]} options.view
* @param {number} options.userUnit
* @param {number} options.rotate
*/
```
2021-08-26 07:44:06 +09:00
|
|
|
/** @typedef {import("./interfaces").IRenderableView} IRenderableView */
|
2021-12-15 07:59:17 +09:00
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */
|
Fix Viewer API definitions and include in CI
The Viewer API definitions do not compile because of missing imports and
anonymous objects are typed as `Object`. These issues were not caught
during CI because the test project was not compiling anything from the
Viewer API.
As an example of the first problem:
```
/**
* @implements MyInterface
*/
export class MyClass {
...
}
```
will generate a broken definition that doesn’t import MyInterface:
```
/**
* @implements MyInterface
*/
export class MyClass implements MyInterface {
...
}
```
This can be fixed by adding a typedef jsdoc to specify the import:
```
/** @typedef {import("./otherFile").MyInterface} MyInterface */
```
See https://github.com/jsdoc/jsdoc/issues/1537 and
https://github.com/microsoft/TypeScript/issues/22160 for more details.
As an example of the second problem:
```
/**
* Gets the size of the specified page, converted from PDF units to inches.
* @param {Object} An Object containing the properties: {Array} `view`,
* {number} `userUnit`, and {number} `rotate`.
*/
function getPageSizeInches({ view, userUnit, rotate }) {
...
}
```
generates the broken definition:
```
function getPageSizeInches({ view, userUnit, rotate }: Object) {
...
}
```
The jsdoc should specify the type of each nested property:
```
/**
* Gets the size of the specified page, converted from PDF units to inches.
* @param {Object} options An object containing the properties: {Array} `view`,
* {number} `userUnit`, and {number} `rotate`.
* @param {number[]} options.view
* @param {number} options.userUnit
* @param {number} options.rotate
*/
```
2021-08-26 07:44:06 +09:00
|
|
|
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
import {
|
2022-11-22 01:15:39 +09:00
|
|
|
AbortException,
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
AnnotationMode,
|
|
|
|
createPromiseCapability,
|
2021-09-20 17:10:57 +09:00
|
|
|
PixelsPerInch,
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
RenderingCancelledException,
|
2022-11-22 02:48:37 +09:00
|
|
|
setLayerDimensions,
|
2022-12-14 21:19:41 +09:00
|
|
|
shadow,
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
SVGGraphics,
|
|
|
|
} from "pdfjs-lib";
|
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,
|
|
|
|
DEFAULT_SCALE,
|
2022-02-19 00:38:25 +09:00
|
|
|
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
|
|
|
RendererType,
|
2021-12-15 21:54:29 +09:00
|
|
|
RenderingStates,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
roundToDivide,
|
|
|
|
TextLayerMode,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "./ui_utils.js";
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
import { AnnotationEditorLayerBuilder } from "./annotation_editor_layer_builder.js";
|
[api-minor] Remove the `annotationLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:34:55 +09:00
|
|
|
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
|
2021-07-27 19:23:33 +09:00
|
|
|
import { compatibilityParams } from "./app_options.js";
|
2021-02-22 20:43:16 +09:00
|
|
|
import { NullL10n } from "./l10n_utils.js";
|
2023-02-06 00:13:18 +09:00
|
|
|
import { SimpleLinkService } from "./pdf_link_service.js";
|
[api-minor] Remove the `structTreeLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `structTreeLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:43:09 +09:00
|
|
|
import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
|
2022-07-29 00:59:03 +09:00
|
|
|
import { TextAccessibilityManager } from "./text_accessibility.js";
|
[api-minor] Remove the `textHighlighterFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `textHighlighterFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:55:23 +09:00
|
|
|
import { TextHighlighter } from "./text_highlighter.js";
|
[api-minor] Remove the `textLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `textLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 08:09:14 +09:00
|
|
|
import { TextLayerBuilder } from "./text_layer_builder.js";
|
[api-minor] Remove the `xfaLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `xfaLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 08:13:44 +09:00
|
|
|
import { XfaLayerBuilder } from "./xfa_layer_builder.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
|
2021-10-28 18:57:27 +09:00
|
|
|
* @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).
|
2022-08-26 01:36:05 +09:00
|
|
|
* @property {number} [scale] - The page scale display.
|
2014-09-28 03:03:28 +09:00
|
|
|
* @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`.
|
2022-08-26 01:36:05 +09:00
|
|
|
* @property {PDFRenderingQueue} [renderingQueue] - The rendering queue object.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {number} [textLayerMode] - Controls if the text layer used for
|
2022-01-19 02:09:12 +09:00
|
|
|
* selection and searching is created. The constants from {TextLayerMode}
|
|
|
|
* should be used. The default value is `TextLayerMode.ENABLE`.
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
* @property {number} [annotationMode] - Controls if the annotation layer is
|
|
|
|
* created, and if interactive form elements or `AnnotationStorage`-data are
|
|
|
|
* being rendered. The constants from {@link AnnotationMode} should be used;
|
|
|
|
* see also {@link RenderParameters} and {@link GetOperatorListParameters}.
|
|
|
|
* The default value is `AnnotationMode.ENABLE_FORMS`.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
|
|
|
* for annotation icons. Include trailing slash.
|
|
|
|
* @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default
|
|
|
|
* value is `false`.
|
2022-11-22 01:15:39 +09:00
|
|
|
* @property {boolean} [isOffscreenCanvasSupported] - Allows to use an
|
|
|
|
* OffscreenCanvas if needed.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @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).
|
2022-05-04 22:37:13 +09:00
|
|
|
* @property {Object} [pageColors] - Overwrites background and foreground colors
|
|
|
|
* with user defined ones in order to improve readability in high contrast
|
|
|
|
* mode.
|
2022-08-26 01:36:05 +09:00
|
|
|
* @property {IL10n} [l10n] - Localization service.
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
* @property {function} [layerProperties] - The function that is used to lookup
|
|
|
|
* the necessary layer-properties.
|
2014-09-28 03:03:28 +09:00
|
|
|
*/
|
|
|
|
|
2021-07-27 19:23:33 +09:00
|
|
|
const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216;
|
2018-02-13 21:02:15 +09:00
|
|
|
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
const DEFAULT_LAYER_PROPERTIES = () => {
|
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("COMPONENTS")) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
annotationEditorUIManager: null,
|
[api-minor] Remove the `annotationLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:34:55 +09:00
|
|
|
annotationStorage: null,
|
|
|
|
downloadManager: null,
|
|
|
|
enableScripting: false,
|
|
|
|
fieldObjectsPromise: null,
|
[api-minor] Remove the `textHighlighterFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `textHighlighterFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:55:23 +09:00
|
|
|
findController: null,
|
[api-minor] Remove the `annotationLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:34:55 +09:00
|
|
|
hasJSActionsPromise: null,
|
2022-12-19 09:04:04 +09:00
|
|
|
get linkService() {
|
|
|
|
return new SimpleLinkService();
|
|
|
|
},
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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 {
|
2021-12-12 00:53:59 +09:00
|
|
|
#annotationMode = AnnotationMode.ENABLE_FORMS;
|
|
|
|
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
#layerProperties = null;
|
|
|
|
|
2023-01-30 01:53:01 +09:00
|
|
|
#loadingId = null;
|
|
|
|
|
2022-12-12 22:24:27 +09:00
|
|
|
#previousRotation = null;
|
|
|
|
|
2022-12-26 23:00:22 +09:00
|
|
|
#renderingState = RenderingStates.INITIAL;
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
#useThumbnailCanvas = {
|
|
|
|
initialOptionalContent: true,
|
|
|
|
regularAnnotations: true,
|
|
|
|
};
|
2022-07-24 20:14:58 +09:00
|
|
|
|
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;
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
|
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;
|
[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 =
|
|
|
|
options.optionalContentConfigPromise || null;
|
2014-09-28 03:03:28 +09:00
|
|
|
this.hasRestrictedScaling = false;
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
2021-12-12 00:53:59 +09:00
|
|
|
this.#annotationMode =
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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.imageResourcesPath = options.imageResourcesPath || "";
|
2018-02-13 20:52:42 +09:00
|
|
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
2022-11-22 01:15:39 +09:00
|
|
|
this.isOffscreenCanvasSupported =
|
|
|
|
options.isOffscreenCanvasSupported ?? true;
|
2018-02-13 21:02:15 +09:00
|
|
|
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
2022-05-04 22:37:13 +09:00
|
|
|
this.pageColors = options.pageColors || null;
|
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;
|
2022-07-19 20:41:01 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
|
|
) {
|
|
|
|
this.renderer = options.renderer || RendererType.CANVAS;
|
|
|
|
}
|
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.resume = null;
|
2020-09-23 21:29:21 +09:00
|
|
|
this._renderError = null;
|
2022-07-24 22:43:31 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
|
|
) {
|
|
|
|
this._isStandalone = !this.renderingQueue?.hasViewer();
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2021-11-07 02:36:49 +09:00
|
|
|
this._annotationCanvasMap = null;
|
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
this.annotationLayer = null;
|
2022-06-01 17:38:08 +09:00
|
|
|
this.annotationEditorLayer = null;
|
2014-09-28 03:03:28 +09:00
|
|
|
this.textLayer = null;
|
2013-10-03 01:05:46 +09:00
|
|
|
this.zoomLayer = null;
|
2021-03-19 18:11:40 +09:00
|
|
|
this.xfaLayer = null;
|
2021-04-01 07:07:02 +09:00
|
|
|
this.structTreeLayer = 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.setAttribute("data-page-number", this.id);
|
2021-03-19 08:10:54 +09:00
|
|
|
div.setAttribute("role", "region");
|
|
|
|
this.l10n.get("page_landmark", { page: this.id }).then(msg => {
|
|
|
|
div.setAttribute("aria-label", msg);
|
|
|
|
});
|
2014-09-28 03:03:28 +09:00
|
|
|
this.div = div;
|
|
|
|
|
2022-11-22 02:48:37 +09:00
|
|
|
this.#setDimensions();
|
2022-06-12 19:20:25 +09:00
|
|
|
container?.append(div);
|
2022-07-24 20:14:58 +09:00
|
|
|
|
2022-07-24 22:43:31 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
|
this._isStandalone
|
|
|
|
) {
|
2022-12-09 22:30:12 +09:00
|
|
|
// Ensure that the various layers always get the correct initial size,
|
|
|
|
// see issue 15795.
|
2023-01-17 03:38:33 +09:00
|
|
|
container?.style.setProperty(
|
2022-12-09 22:30:12 +09:00
|
|
|
"--scale-factor",
|
|
|
|
this.scale * PixelsPerInch.PDF_TO_CSS_UNITS
|
|
|
|
);
|
|
|
|
|
2022-07-24 20:14:58 +09:00
|
|
|
const { optionalContentConfigPromise } = options;
|
|
|
|
if (optionalContentConfigPromise) {
|
|
|
|
// Ensure that the thumbnails always display the *initial* document
|
2022-06-27 18:41:37 +09:00
|
|
|
// state, for documents with optional content.
|
2022-07-24 20:14:58 +09:00
|
|
|
optionalContentConfigPromise.then(optionalContentConfig => {
|
|
|
|
if (
|
|
|
|
optionalContentConfigPromise !== this._optionalContentConfigPromise
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
2022-06-27 18:41:37 +09:00
|
|
|
this.#useThumbnailCanvas.initialOptionalContent =
|
|
|
|
optionalContentConfig.hasInitialVisibility;
|
2022-07-24 20:14:58 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
}
|
|
|
|
|
2022-12-26 23:00:22 +09:00
|
|
|
get renderingState() {
|
|
|
|
return this.#renderingState;
|
|
|
|
}
|
|
|
|
|
|
|
|
set renderingState(state) {
|
2023-01-30 01:53:01 +09:00
|
|
|
if (state === this.#renderingState) {
|
|
|
|
return;
|
|
|
|
}
|
2022-12-26 23:00:22 +09:00
|
|
|
this.#renderingState = state;
|
|
|
|
|
2023-01-30 01:53:01 +09:00
|
|
|
if (this.#loadingId) {
|
|
|
|
clearTimeout(this.#loadingId);
|
|
|
|
this.#loadingId = null;
|
|
|
|
}
|
|
|
|
|
2022-12-26 23:00:22 +09:00
|
|
|
switch (state) {
|
|
|
|
case RenderingStates.PAUSED:
|
2023-01-30 01:53:01 +09:00
|
|
|
this.div.classList.remove("loading");
|
2022-12-26 23:00:22 +09:00
|
|
|
break;
|
|
|
|
case RenderingStates.RUNNING:
|
2023-01-30 01:53:01 +09:00
|
|
|
this.div.classList.add("loadingIcon");
|
|
|
|
this.#loadingId = setTimeout(() => {
|
|
|
|
// Adding the loading class is slightly postponed in order to not have
|
|
|
|
// it with loadingIcon.
|
|
|
|
// If we don't do that the visibility of the background is changed but
|
|
|
|
// the transition isn't triggered.
|
|
|
|
this.div.classList.add("loading");
|
|
|
|
this.#loadingId = null;
|
|
|
|
}, 0);
|
2022-12-26 23:00:22 +09:00
|
|
|
break;
|
2023-02-03 05:17:49 +09:00
|
|
|
case RenderingStates.INITIAL:
|
2022-12-26 23:00:22 +09:00
|
|
|
case RenderingStates.FINISHED:
|
2023-01-30 01:53:01 +09:00
|
|
|
this.div.classList.remove("loadingIcon", "loading");
|
2022-12-26 23:00:22 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 02:48:37 +09:00
|
|
|
#setDimensions() {
|
2022-12-12 22:24:27 +09:00
|
|
|
const { viewport } = this;
|
2022-12-27 20:14:42 +09:00
|
|
|
if (this.pdfPage) {
|
|
|
|
if (this.#previousRotation === viewport.rotation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.#previousRotation = viewport.rotation;
|
2022-12-12 22:24:27 +09:00
|
|
|
}
|
|
|
|
|
2022-11-22 02:48:37 +09:00
|
|
|
setLayerDimensions(
|
2022-12-12 22:24:27 +09:00
|
|
|
this.div,
|
2022-11-22 02:48:37 +09:00
|
|
|
viewport,
|
|
|
|
/* mustFlip = */ true,
|
|
|
|
/* mustRotate = */ false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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({
|
2021-09-20 17:10:57 +09:00
|
|
|
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
rotation: totalRotation,
|
|
|
|
});
|
2022-12-12 22:24:27 +09:00
|
|
|
this.#setDimensions();
|
2017-05-29 05:44:00 +09:00
|
|
|
this.reset();
|
|
|
|
}
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
destroy() {
|
|
|
|
this.reset();
|
2022-09-05 22:36:04 +09:00
|
|
|
this.pdfPage?.cleanup();
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2022-12-14 21:19:41 +09:00
|
|
|
get _textHighlighter() {
|
|
|
|
return shadow(
|
|
|
|
this,
|
|
|
|
"_textHighlighter",
|
[api-minor] Remove the `textHighlighterFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `textHighlighterFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:55:23 +09:00
|
|
|
new TextHighlighter({
|
2022-12-14 21:19:41 +09:00
|
|
|
pageIndex: this.id - 1,
|
|
|
|
eventBus: this.eventBus,
|
[api-minor] Remove the `textHighlighterFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `textHighlighterFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:55:23 +09:00
|
|
|
findController: this.#layerProperties().findController,
|
2022-12-14 21:19:41 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-14 21:12:49 +09:00
|
|
|
async #renderAnnotationLayer() {
|
2020-08-18 05:19:03 +09:00
|
|
|
let error = null;
|
|
|
|
try {
|
|
|
|
await this.annotationLayer.render(this.viewport, "display");
|
|
|
|
} catch (ex) {
|
2022-12-14 21:12:49 +09:00
|
|
|
console.error(`#renderAnnotationLayer: "${ex}".`);
|
2020-08-18 05:19:03 +09:00
|
|
|
error = ex;
|
|
|
|
} finally {
|
|
|
|
this.eventBus.dispatch("annotationlayerrendered", {
|
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 21:12:49 +09:00
|
|
|
async #renderAnnotationEditorLayer() {
|
2022-06-01 17:38:08 +09:00
|
|
|
let error = null;
|
|
|
|
try {
|
|
|
|
await this.annotationEditorLayer.render(this.viewport, "display");
|
|
|
|
} catch (ex) {
|
2022-12-14 21:12:49 +09:00
|
|
|
console.error(`#renderAnnotationEditorLayer: "${ex}".`);
|
2022-06-01 17:38:08 +09:00
|
|
|
error = ex;
|
|
|
|
} finally {
|
|
|
|
this.eventBus.dispatch("annotationeditorlayerrendered", {
|
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 21:12:49 +09:00
|
|
|
async #renderXfaLayer() {
|
2021-03-19 18:11:40 +09:00
|
|
|
let error = null;
|
|
|
|
try {
|
2021-08-19 09:02:29 +09:00
|
|
|
const result = await this.xfaLayer.render(this.viewport, "display");
|
2022-12-14 21:19:41 +09:00
|
|
|
if (result?.textDivs && this._textHighlighter) {
|
2022-12-14 21:12:49 +09:00
|
|
|
this.#buildXfaTextContentItems(result.textDivs);
|
2021-08-19 09:02:29 +09:00
|
|
|
}
|
2021-03-19 18:11:40 +09:00
|
|
|
} catch (ex) {
|
2022-12-14 21:12:49 +09:00
|
|
|
console.error(`#renderXfaLayer: "${ex}".`);
|
2021-03-19 18:11:40 +09:00
|
|
|
error = ex;
|
|
|
|
} finally {
|
|
|
|
this.eventBus.dispatch("xfalayerrendered", {
|
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 01:15:39 +09:00
|
|
|
async #renderTextLayer() {
|
|
|
|
const { pdfPage, textLayer, viewport } = this;
|
|
|
|
if (!textLayer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let error = null;
|
|
|
|
try {
|
|
|
|
if (!textLayer.renderingDone) {
|
|
|
|
const readableStream = pdfPage.streamTextContent({
|
|
|
|
includeMarkedContent: true,
|
|
|
|
});
|
2022-12-05 01:42:24 +09:00
|
|
|
textLayer.setTextContentSource(readableStream);
|
2022-11-22 01:15:39 +09:00
|
|
|
}
|
|
|
|
await textLayer.render(viewport);
|
|
|
|
} catch (ex) {
|
|
|
|
if (ex instanceof AbortException) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.error(`#renderTextLayer: "${ex}".`);
|
|
|
|
error = ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.eventBus.dispatch("textlayerrendered", {
|
|
|
|
source: this,
|
|
|
|
pageNumber: this.id,
|
|
|
|
numTextDivs: textLayer.numTextDivs,
|
|
|
|
error,
|
|
|
|
});
|
2022-12-04 08:27:44 +09:00
|
|
|
|
[api-minor] Remove the `structTreeLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `structTreeLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:43:09 +09:00
|
|
|
this.#renderStructTreeLayer();
|
2022-12-04 08:27:44 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The structure tree is currently only supported when the text layer is
|
|
|
|
* enabled and a canvas is used for rendering.
|
|
|
|
*
|
|
|
|
* The structure tree must be generated after the text layer for the
|
|
|
|
* aria-owns to work.
|
|
|
|
*/
|
|
|
|
async #renderStructTreeLayer() {
|
|
|
|
if (!this.textLayer) {
|
|
|
|
return;
|
|
|
|
}
|
[api-minor] Remove the `structTreeLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `structTreeLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:43:09 +09:00
|
|
|
this.structTreeLayer ||= new StructTreeLayerBuilder();
|
2022-12-04 08:27:44 +09:00
|
|
|
|
|
|
|
const tree = await (!this.structTreeLayer.renderingDone
|
|
|
|
? this.pdfPage.getStructTree()
|
|
|
|
: null);
|
|
|
|
const treeDom = this.structTreeLayer?.render(tree);
|
|
|
|
if (treeDom) {
|
|
|
|
this.canvas?.append(treeDom);
|
|
|
|
}
|
2023-02-07 22:38:32 +09:00
|
|
|
this.structTreeLayer?.show();
|
2022-11-22 01:15:39 +09:00
|
|
|
}
|
|
|
|
|
2022-12-14 21:12:49 +09:00
|
|
|
async #buildXfaTextContentItems(textDivs) {
|
2021-08-19 09:02:29 +09:00
|
|
|
const text = await this.pdfPage.getTextContent();
|
|
|
|
const items = [];
|
|
|
|
for (const item of text.items) {
|
|
|
|
items.push(item.str);
|
|
|
|
}
|
2022-12-14 21:19:41 +09:00
|
|
|
this._textHighlighter.setTextMapping(textDivs, items);
|
|
|
|
this._textHighlighter.enable();
|
2021-08-19 09:02:29 +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
|
|
|
|
2021-07-23 18:37:38 +09:00
|
|
|
reset({
|
|
|
|
keepZoomLayer = false,
|
|
|
|
keepAnnotationLayer = false,
|
2022-06-01 17:38:08 +09:00
|
|
|
keepAnnotationEditorLayer = false,
|
2021-07-23 18:37:38 +09:00
|
|
|
keepXfaLayer = false,
|
2022-11-22 01:15:39 +09:00
|
|
|
keepTextLayer = false,
|
2021-07-23 18:37:38 +09:00
|
|
|
} = {}) {
|
2022-06-01 17:38:08 +09:00
|
|
|
this.cancelRendering({
|
|
|
|
keepAnnotationLayer,
|
|
|
|
keepAnnotationEditorLayer,
|
|
|
|
keepXfaLayer,
|
2022-11-22 01:15:39 +09:00
|
|
|
keepTextLayer,
|
2022-06-01 17:38:08 +09:00
|
|
|
});
|
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;
|
2013-10-03 01:05:46 +09:00
|
|
|
|
2021-07-23 18:37:38 +09:00
|
|
|
const childNodes = div.childNodes,
|
|
|
|
zoomLayerNode = (keepZoomLayer && this.zoomLayer) || null,
|
|
|
|
annotationLayerNode =
|
|
|
|
(keepAnnotationLayer && this.annotationLayer?.div) || null,
|
2022-06-01 17:38:08 +09:00
|
|
|
annotationEditorLayerNode =
|
|
|
|
(keepAnnotationEditorLayer && this.annotationEditorLayer?.div) || null,
|
2022-11-22 01:15:39 +09:00
|
|
|
xfaLayerNode = (keepXfaLayer && this.xfaLayer?.div) || null,
|
|
|
|
textLayerNode = (keepTextLayer && this.textLayer?.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];
|
2021-07-23 18:37:38 +09:00
|
|
|
switch (node) {
|
|
|
|
case zoomLayerNode:
|
|
|
|
case annotationLayerNode:
|
2022-06-01 17:38:08 +09:00
|
|
|
case annotationEditorLayerNode:
|
2021-07-23 18:37:38 +09:00
|
|
|
case xfaLayerNode:
|
2022-11-22 01:15:39 +09:00
|
|
|
case textLayerNode:
|
2021-07-23 18:37:38 +09:00
|
|
|
continue;
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2021-11-16 20:36:22 +09:00
|
|
|
node.remove();
|
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.removeAttribute("data-loaded");
|
2017-05-29 05:44:00 +09:00
|
|
|
|
2021-07-23 18:37:38 +09:00
|
|
|
if (annotationLayerNode) {
|
2017-05-29 05:44:00 +09:00
|
|
|
// Hide the annotation layer until all elements are resized
|
|
|
|
// so they are not displayed on the already resized page.
|
|
|
|
this.annotationLayer.hide();
|
|
|
|
}
|
2022-06-01 17:38:08 +09:00
|
|
|
if (annotationEditorLayerNode) {
|
|
|
|
this.annotationEditorLayer.hide();
|
|
|
|
}
|
2021-07-23 18:37:38 +09:00
|
|
|
if (xfaLayerNode) {
|
|
|
|
// Hide the XFA layer until all elements are resized
|
|
|
|
// so they are not displayed on the already resized page.
|
|
|
|
this.xfaLayer.hide();
|
|
|
|
}
|
2022-11-22 01:15:39 +09:00
|
|
|
if (textLayerNode) {
|
|
|
|
this.textLayer.hide();
|
|
|
|
}
|
2023-02-07 22:38:32 +09:00
|
|
|
this.structTreeLayer?.hide();
|
2022-11-22 01:15:39 +09:00
|
|
|
|
2021-07-23 18:37:38 +09:00
|
|
|
if (!zoomLayerNode) {
|
2017-05-29 05:44:00 +09:00
|
|
|
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();
|
|
|
|
}
|
2022-07-16 17:31:25 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
|
this.svg
|
|
|
|
) {
|
2017-05-29 05:44:00 +09:00
|
|
|
this.paintedViewportMap.delete(this.svg);
|
|
|
|
delete this.svg;
|
|
|
|
}
|
|
|
|
}
|
2013-10-03 01:05:46 +09:00
|
|
|
|
2022-12-12 22:24:27 +09:00
|
|
|
update({
|
|
|
|
scale = 0,
|
|
|
|
rotation = null,
|
|
|
|
optionalContentConfigPromise = null,
|
|
|
|
drawingDelay = -1,
|
|
|
|
}) {
|
2017-05-29 05:44:00 +09:00
|
|
|
this.scale = scale || this.scale;
|
2021-09-01 00:08:43 +09:00
|
|
|
if (typeof rotation === "number") {
|
|
|
|
this.rotation = rotation; // The rotation may be zero.
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
[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 (optionalContentConfigPromise instanceof Promise) {
|
|
|
|
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
2022-07-24 20:14:58 +09:00
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
// Ensure that the thumbnails always display the *initial* document state,
|
|
|
|
// for documents with optional content.
|
2022-07-24 20:14:58 +09:00
|
|
|
optionalContentConfigPromise.then(optionalContentConfig => {
|
|
|
|
if (
|
|
|
|
optionalContentConfigPromise !== this._optionalContentConfigPromise
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
2022-06-27 18:41:37 +09:00
|
|
|
this.#useThumbnailCanvas.initialOptionalContent =
|
|
|
|
optionalContentConfig.hasInitialVisibility;
|
2022-07-24 20:14:58 +09:00
|
|
|
});
|
[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
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
|
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({
|
2022-04-14 19:43:44 +09:00
|
|
|
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
2017-05-29 05:44:00 +09:00
|
|
|
rotation: totalRotation,
|
|
|
|
});
|
2022-12-12 22:24:27 +09:00
|
|
|
this.#setDimensions();
|
2017-05-29 05:44:00 +09:00
|
|
|
|
2022-07-24 22:43:31 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
|
this._isStandalone
|
|
|
|
) {
|
2023-01-17 03:38:33 +09:00
|
|
|
this.div.parentNode?.style.setProperty(
|
|
|
|
"--scale-factor",
|
|
|
|
this.viewport.scale
|
|
|
|
);
|
2021-11-07 02:36:49 +09:00
|
|
|
}
|
|
|
|
|
2022-07-16 17:31:25 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
|
|
this.svg
|
|
|
|
) {
|
2021-07-23 18:37:38 +09:00
|
|
|
this.cssTransform({
|
|
|
|
target: this.svg,
|
|
|
|
redrawAnnotationLayer: true,
|
2022-06-01 17:38:08 +09:00
|
|
|
redrawAnnotationEditorLayer: true,
|
2021-07-23 18:37:38 +09:00
|
|
|
redrawXfaLayer: true,
|
2022-11-22 01:15:39 +09:00
|
|
|
redrawTextLayer: true,
|
2021-07-23 18:37:38 +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
|
|
|
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(),
|
2020-09-23 21:29:21 +09:00
|
|
|
error: this._renderError,
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-03-29 17:31:54 +09:00
|
|
|
const onlyCssZoom =
|
|
|
|
this.useOnlyCssZoom || (this.hasRestrictedScaling && isScalingRestricted);
|
|
|
|
const postponeDrawing =
|
|
|
|
!onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
|
2022-12-12 22:24:27 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
if (this.canvas) {
|
2023-03-29 17:31:54 +09:00
|
|
|
if (postponeDrawing || onlyCssZoom) {
|
2022-12-12 22:24:27 +09:00
|
|
|
if (
|
|
|
|
postponeDrawing &&
|
|
|
|
this.renderingState !== RenderingStates.FINISHED
|
|
|
|
) {
|
|
|
|
this.cancelRendering({
|
|
|
|
keepZoomLayer: true,
|
|
|
|
keepAnnotationLayer: true,
|
|
|
|
keepAnnotationEditorLayer: true,
|
|
|
|
keepXfaLayer: true,
|
|
|
|
keepTextLayer: true,
|
|
|
|
cancelExtraDelay: drawingDelay,
|
|
|
|
});
|
|
|
|
// It isn't really finished, but once we have finished
|
|
|
|
// to postpone, we'll call this.reset(...) which will set
|
|
|
|
// the rendering state to INITIAL, hence the next call to
|
|
|
|
// PDFViewer.update() will trigger a redraw (if it's mandatory).
|
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
|
|
|
}
|
|
|
|
|
2021-07-23 18:37:38 +09:00
|
|
|
this.cssTransform({
|
|
|
|
target: this.canvas,
|
|
|
|
redrawAnnotationLayer: true,
|
2022-06-01 17:38:08 +09:00
|
|
|
redrawAnnotationEditorLayer: true,
|
2021-07-23 18:37:38 +09:00
|
|
|
redrawXfaLayer: true,
|
2022-12-12 22:24:27 +09:00
|
|
|
redrawTextLayer: !postponeDrawing,
|
|
|
|
hideTextLayer: postponeDrawing,
|
2021-07-23 18:37:38 +09:00
|
|
|
});
|
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(),
|
2020-09-23 21:29:21 +09:00
|
|
|
error: this._renderError,
|
2016-11-19 04:03:49 +09:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-02-08 08:21:49 +09:00
|
|
|
if (!this.zoomLayer && !this.canvas.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) {
|
2021-07-23 18:37:38 +09:00
|
|
|
this.cssTransform({ target: this.zoomLayer.firstChild });
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2021-07-23 18:37:38 +09:00
|
|
|
this.reset({
|
|
|
|
keepZoomLayer: true,
|
|
|
|
keepAnnotationLayer: true,
|
2022-06-01 17:38:08 +09:00
|
|
|
keepAnnotationEditorLayer: true,
|
2021-07-23 18:37:38 +09:00
|
|
|
keepXfaLayer: true,
|
2022-11-22 01:15:39 +09:00
|
|
|
keepTextLayer: true,
|
2021-07-23 18:37:38 +09:00
|
|
|
});
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
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.
|
|
|
|
*/
|
2022-06-01 17:38:08 +09:00
|
|
|
cancelRendering({
|
|
|
|
keepAnnotationLayer = false,
|
|
|
|
keepAnnotationEditorLayer = false,
|
|
|
|
keepXfaLayer = false,
|
2022-11-22 01:15:39 +09:00
|
|
|
keepTextLayer = false,
|
2022-12-12 22:24:27 +09:00
|
|
|
cancelExtraDelay = 0,
|
2022-06-01 17:38:08 +09:00
|
|
|
} = {}) {
|
2017-05-29 05:44:00 +09:00
|
|
|
if (this.paintTask) {
|
2022-12-12 22:24:27 +09:00
|
|
|
this.paintTask.cancel(cancelExtraDelay);
|
2017-05-29 05:44:00 +09:00
|
|
|
this.paintTask = null;
|
|
|
|
}
|
|
|
|
this.resume = null;
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2022-11-22 01:15:39 +09:00
|
|
|
if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
|
2017-05-29 05:44:00 +09:00
|
|
|
this.textLayer.cancel();
|
|
|
|
this.textLayer = null;
|
|
|
|
}
|
2022-12-04 08:27:44 +09:00
|
|
|
if (this.structTreeLayer && !this.textLayer) {
|
|
|
|
this.structTreeLayer = null;
|
|
|
|
}
|
2021-07-23 21:14:42 +09:00
|
|
|
if (
|
|
|
|
this.annotationLayer &&
|
|
|
|
(!keepAnnotationLayer || !this.annotationLayer.div)
|
|
|
|
) {
|
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.annotationLayer.cancel();
|
|
|
|
this.annotationLayer = null;
|
2021-11-07 02:36:49 +09:00
|
|
|
this._annotationCanvasMap = 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
|
|
|
}
|
2022-06-01 17:38:08 +09:00
|
|
|
if (
|
|
|
|
this.annotationEditorLayer &&
|
|
|
|
(!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)
|
|
|
|
) {
|
|
|
|
this.annotationEditorLayer.cancel();
|
|
|
|
this.annotationEditorLayer = null;
|
|
|
|
}
|
2021-07-23 21:14:42 +09:00
|
|
|
if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
|
2021-07-23 18:37:38 +09:00
|
|
|
this.xfaLayer.cancel();
|
|
|
|
this.xfaLayer = null;
|
2022-12-14 21:19:41 +09:00
|
|
|
this._textHighlighter?.disable();
|
2021-07-23 18:37:38 +09:00
|
|
|
}
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2016-07-30 03:51:37 +09:00
|
|
|
|
2021-07-23 18:37:38 +09:00
|
|
|
cssTransform({
|
|
|
|
target,
|
|
|
|
redrawAnnotationLayer = false,
|
2022-06-01 17:38:08 +09:00
|
|
|
redrawAnnotationEditorLayer = false,
|
2021-07-23 18:37:38 +09:00
|
|
|
redrawXfaLayer = false,
|
2022-11-22 01:15:39 +09:00
|
|
|
redrawTextLayer = false,
|
2022-12-12 22:24:27 +09:00
|
|
|
hideTextLayer = false,
|
2021-07-23 18:37:38 +09:00
|
|
|
}) {
|
2017-05-29 05:44:00 +09:00
|
|
|
// Scale target (canvas or svg), its wrapper and page container.
|
2022-12-12 22:24:27 +09:00
|
|
|
|
|
|
|
if (target instanceof HTMLCanvasElement) {
|
|
|
|
if (!target.hasAttribute("zooming")) {
|
|
|
|
target.setAttribute("zooming", true);
|
|
|
|
const { style } = target;
|
|
|
|
style.width = style.height = "";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const div = this.div;
|
|
|
|
const { width, height } = this.viewport;
|
|
|
|
|
|
|
|
target.style.width =
|
|
|
|
target.parentNode.style.width =
|
|
|
|
div.style.width =
|
|
|
|
Math.floor(width) + "px";
|
|
|
|
target.style.height =
|
|
|
|
target.parentNode.style.height =
|
|
|
|
div.style.height =
|
|
|
|
Math.floor(height) + "px";
|
|
|
|
}
|
|
|
|
|
|
|
|
const originalViewport = this.paintedViewportMap.get(target);
|
|
|
|
if (this.viewport !== originalViewport) {
|
|
|
|
// The canvas may have been originally rotated; rotate relative to that.
|
|
|
|
const relativeRotation =
|
|
|
|
this.viewport.rotation - originalViewport.rotation;
|
|
|
|
const absRotation = Math.abs(relativeRotation);
|
|
|
|
let scaleX = 1,
|
|
|
|
scaleY = 1;
|
|
|
|
if (absRotation === 90 || absRotation === 270) {
|
|
|
|
const { width, height } = this.viewport;
|
|
|
|
// Scale x and y because of the rotation.
|
|
|
|
scaleX = height / width;
|
|
|
|
scaleY = width / height;
|
|
|
|
}
|
2023-03-29 17:04:20 +09:00
|
|
|
target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
|
2021-07-23 18:37:38 +09:00
|
|
|
if (redrawAnnotationLayer && this.annotationLayer) {
|
2022-12-14 21:12:49 +09:00
|
|
|
this.#renderAnnotationLayer();
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2022-06-01 17:38:08 +09:00
|
|
|
if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
|
2022-12-14 21:12:49 +09:00
|
|
|
this.#renderAnnotationEditorLayer();
|
2022-06-01 17:38:08 +09:00
|
|
|
}
|
2021-07-23 18:37:38 +09:00
|
|
|
if (redrawXfaLayer && this.xfaLayer) {
|
2022-12-14 21:12:49 +09:00
|
|
|
this.#renderXfaLayer();
|
2021-03-19 18:11:40 +09:00
|
|
|
}
|
2022-12-12 22:24:27 +09:00
|
|
|
|
|
|
|
if (this.textLayer) {
|
|
|
|
if (hideTextLayer) {
|
|
|
|
this.textLayer.hide();
|
2023-02-07 22:38:32 +09:00
|
|
|
this.structTreeLayer?.hide();
|
2022-12-12 22:24:27 +09:00
|
|
|
} else if (redrawTextLayer) {
|
|
|
|
this.#renderTextLayer();
|
|
|
|
}
|
2022-11-22 01:15:39 +09:00
|
|
|
}
|
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
|
|
|
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");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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");
|
2022-12-23 05:55:25 +09:00
|
|
|
div.append(canvasWrapper);
|
2014-09-28 03:03:28 +09:00
|
|
|
|
2022-11-22 01:15:39 +09:00
|
|
|
if (
|
|
|
|
!this.textLayer &&
|
|
|
|
this.textLayerMode !== TextLayerMode.DISABLE &&
|
[api-minor] Remove the `textLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `textLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 08:09:14 +09:00
|
|
|
!pdfPage.isPureXfa
|
2022-11-22 01:15:39 +09:00
|
|
|
) {
|
|
|
|
this._accessibilityManager ||= new TextAccessibilityManager();
|
|
|
|
|
[api-minor] Remove the `textLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `textLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 08:09:14 +09:00
|
|
|
this.textLayer = new TextLayerBuilder({
|
2022-12-14 21:19:41 +09:00
|
|
|
highlighter: this._textHighlighter,
|
2022-07-29 00:59:03 +09:00
|
|
|
accessibilityManager: this._accessibilityManager,
|
2022-11-22 01:15:39 +09:00
|
|
|
isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
2022-07-29 21:47:57 +09:00
|
|
|
});
|
2022-12-23 05:55:25 +09:00
|
|
|
div.append(this.textLayer.div);
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
|
2021-11-07 02:36:49 +09:00
|
|
|
if (
|
[api-minor] Remove the `annotationLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:34:55 +09:00
|
|
|
!this.annotationLayer &&
|
|
|
|
this.#annotationMode !== AnnotationMode.DISABLE
|
2021-11-07 02:36:49 +09:00
|
|
|
) {
|
[api-minor] Remove the `annotationLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:34:55 +09:00
|
|
|
const {
|
|
|
|
annotationStorage,
|
|
|
|
downloadManager,
|
|
|
|
enableScripting,
|
|
|
|
fieldObjectsPromise,
|
|
|
|
hasJSActionsPromise,
|
|
|
|
linkService,
|
|
|
|
} = this.#layerProperties();
|
|
|
|
|
2021-11-07 02:36:49 +09:00
|
|
|
this._annotationCanvasMap ||= new Map();
|
[api-minor] Remove the `annotationLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 07:34:55 +09:00
|
|
|
this.annotationLayer = new AnnotationLayerBuilder({
|
|
|
|
pageDiv: div,
|
|
|
|
pdfPage,
|
|
|
|
annotationStorage,
|
|
|
|
imageResourcesPath: this.imageResourcesPath,
|
|
|
|
renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS,
|
|
|
|
linkService,
|
|
|
|
downloadManager,
|
|
|
|
l10n: this.l10n,
|
|
|
|
enableScripting,
|
|
|
|
hasJSActionsPromise,
|
|
|
|
fieldObjectsPromise,
|
|
|
|
annotationCanvasMap: this._annotationCanvasMap,
|
|
|
|
accessibilityManager: this._accessibilityManager,
|
|
|
|
});
|
2021-11-07 02:36:49 +09:00
|
|
|
}
|
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
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
|
|
|
|
2020-09-23 21:29:21 +09:00
|
|
|
const finishPaintTask = async (error = null) => {
|
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) {
|
2020-09-23 21:29:21 +09:00
|
|
|
this._renderError = null;
|
2019-01-26 18:12:32 +09:00
|
|
|
return;
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
2020-09-23 21:29:21 +09:00
|
|
|
this._renderError = error;
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2017-05-29 05:44:00 +09:00
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
|
|
|
this._resetZoomLayer(/* removeFromDOM = */ true);
|
2013-09-20 16:25:41 +09:00
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
// Ensure that the thumbnails won't become partially (or fully) blank,
|
|
|
|
// for documents that contain interactive form elements.
|
|
|
|
this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *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(),
|
2020-09-23 21:29:21 +09:00
|
|
|
error: this._renderError,
|
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 =
|
2022-07-16 17:31:25 +09:00
|
|
|
(typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || 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
|
|
|
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(
|
2021-04-01 07:07:02 +09:00
|
|
|
() => {
|
2022-12-08 01:27:02 +09:00
|
|
|
return finishPaintTask(null).then(async () => {
|
2022-11-22 01:15:39 +09:00
|
|
|
this.#renderTextLayer();
|
2021-11-07 02:36:49 +09:00
|
|
|
|
|
|
|
if (this.annotationLayer) {
|
2022-12-08 01:27:02 +09:00
|
|
|
await this.#renderAnnotationLayer();
|
|
|
|
}
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
|
|
|
|
if (!this.annotationEditorLayer) {
|
|
|
|
const { annotationEditorUIManager } = this.#layerProperties();
|
|
|
|
|
|
|
|
if (!annotationEditorUIManager) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.annotationEditorLayer = new AnnotationEditorLayerBuilder({
|
|
|
|
uiManager: annotationEditorUIManager,
|
|
|
|
pageDiv: div,
|
|
|
|
pdfPage,
|
|
|
|
l10n: this.l10n,
|
|
|
|
accessibilityManager: this._accessibilityManager,
|
|
|
|
});
|
2021-11-07 02:36:49 +09:00
|
|
|
}
|
[api-minor] Remove the `annotationEditorLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-06 22:21:51 +09:00
|
|
|
this.#renderAnnotationEditorLayer();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
});
|
|
|
|
},
|
2020-04-14 19:28:14 +09:00
|
|
|
function (reason) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return finishPaintTask(reason);
|
|
|
|
}
|
|
|
|
);
|
2017-05-29 05:44:00 +09:00
|
|
|
|
[api-minor] Remove the `xfaLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `xfaLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 08:13:44 +09:00
|
|
|
if (pdfPage.isPureXfa) {
|
|
|
|
if (!this.xfaLayer) {
|
|
|
|
const { annotationStorage, linkService } = this.#layerProperties();
|
|
|
|
|
|
|
|
this.xfaLayer = new XfaLayerBuilder({
|
|
|
|
pageDiv: div,
|
|
|
|
pdfPage,
|
|
|
|
annotationStorage,
|
|
|
|
linkService,
|
|
|
|
});
|
2023-02-14 20:52:03 +09:00
|
|
|
} else if (this.xfaLayer.div) {
|
|
|
|
// The xfa layer needs to stay on top.
|
|
|
|
div.append(this.xfaLayer.div);
|
[api-minor] Remove the `xfaLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `xfaLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 08:13:44 +09:00
|
|
|
}
|
2022-12-14 21:12:49 +09:00
|
|
|
this.#renderXfaLayer();
|
2021-03-19 18:11:40 +09:00
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
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();
|
|
|
|
},
|
2022-12-12 22:24:27 +09:00
|
|
|
cancel(extraDelay = 0) {
|
|
|
|
renderTask.cancel(extraDelay);
|
2017-05-29 05:44:00 +09:00
|
|
|
},
|
2022-06-27 18:41:37 +09:00
|
|
|
get separateAnnots() {
|
|
|
|
return renderTask.separateAnnots;
|
|
|
|
},
|
2017-05-29 05:44:00 +09:00
|
|
|
};
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const viewport = this.viewport;
|
2022-12-12 22:24:27 +09:00
|
|
|
const { width, height } = viewport;
|
2019-12-27 08:22:32 +09:00
|
|
|
const canvas = document.createElement("canvas");
|
2022-06-08 01:56:30 +09:00
|
|
|
canvas.setAttribute("role", "presentation");
|
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.
|
2021-02-08 08:21:49 +09:00
|
|
|
canvas.hidden = true;
|
2017-05-29 05:44:00 +09:00
|
|
|
let isCanvasHidden = true;
|
2023-03-07 03:09:56 +09:00
|
|
|
const hasHCM = !!(
|
|
|
|
this.pageColors?.background && this.pageColors?.foreground
|
|
|
|
);
|
|
|
|
const showCanvas = function (isLastShow) {
|
|
|
|
// In HCM, a final filter is applied on the canvas which means that
|
|
|
|
// before it's applied we've normal colors. Consequently, to avoid to have
|
|
|
|
// a final flash we just display it once all the drawing is done.
|
|
|
|
if (isCanvasHidden && (!hasHCM || isLastShow)) {
|
2021-02-08 08:21:49 +09:00
|
|
|
canvas.hidden = false;
|
2017-05-29 05:44:00 +09:00
|
|
|
isCanvasHidden = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-12 19:20:25 +09:00
|
|
|
canvasWrapper.append(canvas);
|
2017-05-29 05:44:00 +09:00
|
|
|
this.canvas = canvas;
|
|
|
|
|
2019-12-27 08:22:32 +09:00
|
|
|
const ctx = canvas.getContext("2d", { alpha: false });
|
2022-02-19 00:38:25 +09:00
|
|
|
const outputScale = (this.outputScale = new OutputScale());
|
2017-05-29 05:44:00 +09:00
|
|
|
|
2018-02-13 20:52:42 +09:00
|
|
|
if (this.useOnlyCssZoom) {
|
2021-09-20 17:10:57 +09:00
|
|
|
const actualSizeViewport = viewport.clone({
|
|
|
|
scale: PixelsPerInch.PDF_TO_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.
|
2022-12-12 22:24:27 +09:00
|
|
|
outputScale.sx *= actualSizeViewport.width / width;
|
|
|
|
outputScale.sy *= actualSizeViewport.height / height;
|
2017-05-29 05:44:00 +09:00
|
|
|
}
|
|
|
|
|
2018-02-13 21:02:15 +09:00
|
|
|
if (this.maxCanvasPixels > 0) {
|
2022-12-12 22:24:27 +09:00
|
|
|
const pixelsInViewport = width * height;
|
2019-12-27 08:22:32 +09:00
|
|
|
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;
|
|
|
|
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);
|
2022-11-22 01:15:39 +09:00
|
|
|
|
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]);
|
2022-11-22 01:15:39 +09:00
|
|
|
const { style } = canvas;
|
|
|
|
style.width = roundToDivide(viewport.width, sfx[1]) + "px";
|
|
|
|
style.height = roundToDivide(viewport.height, sfy[1]) + "px";
|
2021-11-07 02:36:49 +09:00
|
|
|
|
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
|
2022-02-18 06:21:59 +09:00
|
|
|
const transform = outputScale.scaled
|
|
|
|
? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
|
|
|
|
: null;
|
2019-12-27 08:22:32 +09:00
|
|
|
const renderContext = {
|
2017-05-29 05:44:00 +09:00
|
|
|
canvasContext: ctx,
|
|
|
|
transform,
|
2022-12-12 22:24:27 +09:00
|
|
|
viewport,
|
2021-12-12 00:53:59 +09:00
|
|
|
annotationMode: this.#annotationMode,
|
[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,
|
2021-11-07 02:36:49 +09:00
|
|
|
annotationCanvasMap: this._annotationCanvasMap,
|
2022-05-04 22:37:13 +09:00
|
|
|
pageColors: this.pageColors,
|
2017-05-29 05:44:00 +09:00
|
|
|
};
|
2019-12-27 08:22:32 +09:00
|
|
|
const renderTask = this.pdfPage.render(renderContext);
|
2020-04-14 19:28:14 +09:00
|
|
|
renderTask.onContinue = function (cont) {
|
2023-03-07 03:09:56 +09:00
|
|
|
showCanvas(false);
|
2017-05-29 05:44:00 +09:00
|
|
|
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(
|
2020-04-14 19:28:14 +09:00
|
|
|
function () {
|
2023-03-07 03:09:56 +09:00
|
|
|
showCanvas(true);
|
2021-10-03 22:32:33 +09:00
|
|
|
renderCapability.resolve();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
},
|
2020-04-14 19:28:14 +09:00
|
|
|
function (error) {
|
2023-01-15 07:15:15 +09:00
|
|
|
// When zooming with a `drawingDelay` set, avoid temporarily showing
|
|
|
|
// a black canvas if rendering was cancelled before the `onContinue`-
|
|
|
|
// callback had been invoked at least once.
|
|
|
|
if (!(error instanceof RenderingCancelledException)) {
|
2023-03-07 03:09:56 +09:00
|
|
|
showCanvas(true);
|
2023-01-15 07:15:15 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
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 (
|
2022-06-16 23:11:47 +09:00
|
|
|
!(
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || 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
|
|
|
) {
|
2022-06-16 23:11:47 +09:00
|
|
|
throw new Error("Not implemented: paintOnSvg");
|
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;
|
2021-09-20 17:10:57 +09:00
|
|
|
const actualSizeViewport = this.viewport.clone({
|
|
|
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
|
|
});
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
const promise = pdfPage
|
|
|
|
.getOperatorList({
|
2021-12-12 00:53:59 +09:00
|
|
|
annotationMode: this.#annotationMode,
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
})
|
|
|
|
.then(opList => {
|
2017-01-10 10:13:36 +09:00
|
|
|
ensureNotCancelled();
|
[api-minor] Remove support for browsers/environments without fully working `URL.createObjectURL` implementations
This `disableCreateObjectURL` option was originally introduced all the way back in PR 4103 (eight years ago), in order to work-around `URL.createObjectURL()`-bugs specific to Internet Explorer.
In PR 8081 (five years ago) the `disableCreateObjectURL` option was extended to cover Google Chrome on iOS-devices as well, since that configuration apparently also suffered from `URL.createObjectURL()`-bugs.[1]
At this point in time, I thus think that it makes sense to re-evaluate if we should still keep the `disableCreateObjectURL` option.
- For Internet Explorer, support was explicitly removed in PDF.js version `2.7.570` which was released one year ago and all IE-specific compatibility code (and polyfills) have since been removed.
- For Google Chrome on iOS-devices, while we still "support" such configurations, it's *not* the focus of any development and platform-specific bugs are thus often closed as WONTFIX.
Note here that at this point in time, the `disableCreateObjectURL` option is *only* being used in the viewer and any `URL.createObjectURL()`-bugs browser/platform bugs will thus not affect the main PDF.js library. Furthermore, given where the `disableCreateObjectURL` option is being used in the viewer the basic functionality should also remain unaffected by these changes.[2]
Furthermore, it's also possible that the `URL.createObjectURL()`-bugs have been fixed in *browser* itself since PR 8081 was submitted.[3]
Obviously you could argue that this isn't a lot of code, w.r.t. number of lines, and you'd be technically correct. However, it does add additional complexity in a few different viewer components which thus add overhead when reading and working with this code.
Finally, assuming the `URL.createObjectURL()`-bugs are still present in Google Chrome on iOS-devices, I think that we should ask ourselves if it's reasonable for the PDF.js project (and its contributors) to keep attempting to support a configuration if the *browser* developers still haven't fixed these kind of bugs!?
---
[1] According to https://groups.google.com/a/chromium.org/forum/#!topic/chromium-html5/RKQ0ZJIj7c4, which is linked in PR 8081, that bug was mentioned/reported as early as the 2014 (eight years ago).
[2] Viewer functionality such as e.g. downloading and printing may be affected.
[3] I don't have access to any iOS-devices to test with.
2022-01-02 21:18:18 +09:00
|
|
|
const svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
|
|
|
|
ensureNotCancelled();
|
|
|
|
this.svg = svg;
|
|
|
|
this.paintedViewportMap.set(svg, actualSizeViewport);
|
|
|
|
|
|
|
|
svg.style.width = wrapper.style.width;
|
|
|
|
svg.style.height = wrapper.style.height;
|
|
|
|
this.renderingState = RenderingStates.FINISHED;
|
2022-06-12 19:20:25 +09:00
|
|
|
wrapper.append(svg);
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
});
|
2017-05-29 05:44:00 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
promise,
|
|
|
|
onRenderContinue(cont) {
|
|
|
|
cont();
|
|
|
|
},
|
|
|
|
cancel() {
|
|
|
|
cancelled = true;
|
|
|
|
},
|
2022-06-27 18:41:37 +09:00
|
|
|
get separateAnnots() {
|
|
|
|
return false;
|
|
|
|
},
|
2017-05-29 05:44:00 +09:00
|
|
|
};
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2022-07-24 20:14:58 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For use by the `PDFThumbnailView.setImage`-method.
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
get thumbnailCanvas() {
|
2022-06-27 18:41:37 +09:00
|
|
|
const { initialOptionalContent, regularAnnotations } =
|
|
|
|
this.#useThumbnailCanvas;
|
|
|
|
return initialOptionalContent && regularAnnotations ? this.canvas : null;
|
2022-07-24 20:14:58 +09:00
|
|
|
}
|
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 };
|