1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Let non-viewable Popup Annotations inherit the parent's Annotation Flags if the parent is viewable

Fixes http://www.pdf-archive.com/2013/09/30/file2/file2.pdf.

Note how it's not possible to show the various Popup Annotations in the above document.
To fix that, this patch lets the Popup inherit the flags of the parent, in the special case where the parent is `viewable` *and* the Popup is not.
In general, I don't think that a Popup must have the same flags set as the parent. However, it seems very strange to have a `viewable` parent annotation, and then not being able to view the Popup.

Annoyingly the PDF specification doesn't, as far as I can find, mention anything about how this case should be handled, but this patch seem consistent with the actual behaviour in Adobe Reader.
This commit is contained in:
Jonas Jenwald 2016-05-24 17:35:45 +02:00
parent 47b929be26
commit 98fe094d18
5 changed files with 91 additions and 30 deletions

View file

@ -190,28 +190,49 @@ var Annotation = (function AnnotationClosure() {
}
Annotation.prototype = {
/**
* @private
*/
_hasFlag: function Annotation_hasFlag(flags, flag) {
return !!(flags & flag);
},
/**
* @private
*/
_isViewable: function Annotation_isViewable(flags) {
return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
!this._hasFlag(flags, AnnotationFlag.NOVIEW);
},
/**
* @private
*/
_isPrintable: function AnnotationFlag_isPrintable(flags) {
return this._hasFlag(flags, AnnotationFlag.PRINT) &&
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN);
},
/**
* @return {boolean}
*/
get viewable() {
if (this.flags) {
return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
!this.hasFlag(AnnotationFlag.HIDDEN) &&
!this.hasFlag(AnnotationFlag.NOVIEW);
if (this.flags === 0) {
return true;
}
return true;
return this._isViewable(this.flags);
},
/**
* @return {boolean}
*/
get printable() {
if (this.flags) {
return this.hasFlag(AnnotationFlag.PRINT) &&
!this.hasFlag(AnnotationFlag.INVISIBLE) &&
!this.hasFlag(AnnotationFlag.HIDDEN);
if (this.flags === 0) {
return false;
}
return false;
return this._isPrintable(this.flags);
},
/**
@ -224,11 +245,7 @@ var Annotation = (function AnnotationClosure() {
* @see {@link shared/util.js}
*/
setFlags: function Annotation_setFlags(flags) {
if (isInt(flags)) {
this.flags = flags;
} else {
this.flags = 0;
}
this.flags = (isInt(flags) && flags > 0) ? flags : 0;
},
/**
@ -242,10 +259,7 @@ var Annotation = (function AnnotationClosure() {
* @see {@link shared/util.js}
*/
hasFlag: function Annotation_hasFlag(flag) {
if (this.flags) {
return (this.flags & flag) > 0;
}
return false;
return this._hasFlag(this.flags, flag);
},
/**
@ -823,6 +837,16 @@ var PopupAnnotation = (function PopupAnnotationClosure() {
this.setColor(parentItem.getArray('C'));
this.data.color = this.color;
}
// If the Popup annotation is not viewable, but the parent annotation is,
// that is most likely a bug. Fallback to inherit the flags from the parent
// annotation (this is consistent with the behaviour in Adobe Reader).
if (!this.viewable) {
var parentFlags = parentItem.get('F');
if (this._isViewable(parentFlags)) {
this.setFlags(parentFlags);
}
}
}
Util.inherit(PopupAnnotation, Annotation, {});