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

Merge pull request #16029 from calixteman/bug1815196

[api-minor] Don't print hidden annotations (bug 1815196)
This commit is contained in:
calixteman 2023-07-31 20:14:43 +02:00 committed by GitHub
commit 5b8f680480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 124 additions and 18 deletions

View file

@ -628,8 +628,11 @@ class Annotation {
* @private
*/
_isPrintable(flags) {
// In Acrobat, hidden flag cancels the print one
// (see annotation_hidden_print.pdf).
return (
this._hasFlag(flags, AnnotationFlag.PRINT) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
!this._hasFlag(flags, AnnotationFlag.INVISIBLE)
);
}
@ -642,11 +645,13 @@ class Annotation {
* @public
* @memberof Annotation
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
* @param {boolean} [_renderForms] - if true widgets are rendered thanks to
* the annotation layer.
*/
mustBeViewed(annotationStorage) {
const hidden = annotationStorage?.get(this.data.id)?.hidden;
if (hidden !== undefined) {
return !hidden;
mustBeViewed(annotationStorage, _renderForms) {
const noView = annotationStorage?.get(this.data.id)?.noView;
if (noView !== undefined) {
return !noView;
}
return this.viewable && !this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
}
@ -661,9 +666,9 @@ class Annotation {
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
*/
mustBePrinted(annotationStorage) {
const print = annotationStorage?.get(this.data.id)?.print;
if (print !== undefined) {
return print;
const noPrint = annotationStorage?.get(this.data.id)?.noPrint;
if (noPrint !== undefined) {
return !noPrint;
}
return this.printable;
}
@ -1700,7 +1705,9 @@ class WidgetAnnotation extends Annotation {
data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
data.required = this.hasFieldFlag(AnnotationFieldFlag.REQUIRED);
data.hidden = this._hasFlag(data.annotationFlags, AnnotationFlag.HIDDEN);
data.hidden =
this._hasFlag(data.annotationFlags, AnnotationFlag.HIDDEN) ||
this._hasFlag(data.annotationFlags, AnnotationFlag.NOVIEW);
}
/**
@ -1739,6 +1746,26 @@ class WidgetAnnotation extends Annotation {
return !!(this.data.fieldFlags & flag);
}
/** @inheritdoc */
_isViewable(flags) {
// We don't take into account the `NOVIEW` or `HIDDEN` flags here,
// since the visibility can be changed by js code, hence in case
// it's made viewable, we should render it (with visibility set to
// hidden).
return !this._hasFlag(flags, AnnotationFlag.INVISIBLE);
}
/** @inheritdoc */
mustBeViewed(annotationStorage, renderForms) {
if (renderForms) {
return this.viewable;
}
return (
super.mustBeViewed(annotationStorage, renderForms) &&
!this._hasFlag(this.flags, AnnotationFlag.NOVIEW)
);
}
getRotationMatrix(annotationStorage) {
let rotation = annotationStorage?.get(this.data.id)?.rotation;
if (rotation === undefined) {

View file

@ -556,7 +556,8 @@ class Page {
for (const annotation of annotations) {
if (
intentAny ||
(intentDisplay && annotation.mustBeViewed(annotationStorage)) ||
(intentDisplay &&
annotation.mustBeViewed(annotationStorage, renderForms)) ||
(intentPrint && annotation.mustBePrinted(annotationStorage))
) {
opListPromises.push(

View file

@ -342,24 +342,27 @@ class AnnotationElement {
return shadow(this, "_commonActions", {
display: event => {
const hidden = event.detail.display % 2 === 1;
const { display } = event.detail;
// See scripting/constants.js for the values of `Display`.
// 0 = visible, 1 = hidden, 2 = noPrint and 3 = noView.
const hidden = display % 2 === 1;
this.container.style.visibility = hidden ? "hidden" : "visible";
this.annotationStorage.setValue(this.data.id, {
hidden,
print: event.detail.display === 0 || event.detail.display === 3,
noView: hidden,
noPrint: display === 1 || display === 2,
});
},
print: event => {
this.annotationStorage.setValue(this.data.id, {
print: event.detail.print,
noPrint: !event.detail.print,
});
},
hidden: event => {
this.container.style.visibility = event.detail.hidden
? "hidden"
: "visible";
const { hidden } = event.detail;
this.container.style.visibility = hidden ? "hidden" : "visible";
this.annotationStorage.setValue(this.data.id, {
hidden: event.detail.hidden,
noPrint: hidden,
noView: hidden,
});
},
focus: event => {