1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

JS - Add support for display property

- in annotation_layer, move common properties treatment in a common method instead having duplicated code in each widget.
This commit is contained in:
Calixte Denizet 2021-05-03 18:03:16 +02:00
parent afb8c4fd25
commit af125cd299
6 changed files with 197 additions and 141 deletions

View file

@ -439,13 +439,40 @@ class Annotation {
);
}
isHidden(annotationStorage) {
/**
* Check if the annotation must be displayed by taking into account
* the value found in the annotationStorage which may have been set
* through JS.
*
* @public
* @memberof Annotation
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
*/
mustBeViewed(annotationStorage) {
const storageEntry =
annotationStorage && annotationStorage.get(this.data.id);
if (storageEntry && storageEntry.hidden !== undefined) {
return storageEntry.hidden;
return !storageEntry.hidden;
}
return this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
return this.viewable && !this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
}
/**
* Check if the annotation must be printed by taking into account
* the value found in the annotationStorage which may have been set
* through JS.
*
* @public
* @memberof Annotation
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
*/
mustBePrinted(annotationStorage) {
const storageEntry =
annotationStorage && annotationStorage.get(this.data.id);
if (storageEntry && storageEntry.print !== undefined) {
return storageEntry.print;
}
return this.printable;
}
/**

View file

@ -68,13 +68,6 @@ import { XRef } from "./xref.js";
const DEFAULT_USER_UNIT = 1.0;
const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
function isAnnotationRenderable(annotation, intent) {
return (
(intent === "display" && annotation.viewable) ||
(intent === "print" && annotation.printable)
);
}
class Page {
constructor({
pdfManager,
@ -274,7 +267,7 @@ class Page {
return this._parsedAnnotations.then(function (annotations) {
const newRefsPromises = [];
for (const annotation of annotations) {
if (!isAnnotationRenderable(annotation, "print")) {
if (!annotation.mustBePrinted(annotationStorage)) {
continue;
}
newRefsPromises.push(
@ -377,8 +370,9 @@ class Page {
const opListPromises = [];
for (const annotation of annotations) {
if (
isAnnotationRenderable(annotation, intent) &&
!annotation.isHidden(annotationStorage)
(intent === "display" &&
annotation.mustBeViewed(annotationStorage)) ||
(intent === "print" && annotation.mustBePrinted(annotationStorage))
) {
opListPromises.push(
annotation
@ -482,7 +476,13 @@ class Page {
return this._parsedAnnotations.then(function (annotations) {
const annotationsData = [];
for (let i = 0, ii = annotations.length; i < ii; i++) {
if (!intent || isAnnotationRenderable(annotations[i], intent)) {
// Get the annotation even if it's hidden because
// JS can change its display.
if (
!intent ||
(intent === "display" && annotations[i].viewable) ||
(intent === "print" && annotations[i].printable)
) {
annotationsData.push(annotations[i].data);
}
}