From 98fe094d18a8048d70991e7e95d689fb14933279 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 24 May 2016 17:35:45 +0200 Subject: [PATCH] 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. --- src/core/annotation.js | 62 ++++++++++++++++++++--------- test/pdfs/.gitignore | 1 + test/pdfs/pr7352.pdf | Bin 0 -> 1648 bytes test/test_manifest.json | 8 ++++ test/unit/annotation_layer_spec.js | 50 ++++++++++++++++++----- 5 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 test/pdfs/pr7352.pdf diff --git a/src/core/annotation.js b/src/core/annotation.js index 55c7531a9..99477a984 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -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, {}); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index e2a366caa..f9f1c4102 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -99,6 +99,7 @@ !pr4922.pdf !pr6531_1.pdf !pr6531_2.pdf +!pr7352.pdf !bug900822.pdf !issue918.pdf !issue1905.pdf diff --git a/test/pdfs/pr7352.pdf b/test/pdfs/pr7352.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e98fdb4c6b0ffe595360414e17542181aec35e43 GIT binary patch literal 1648 zcma)6U1%It6qaZaF2x5yQ7QI3G);m{X71gc-9$?@+s#(gHp^y;fe`fW?%my+Oy+K9 z?ly^vNI_9CRv!d|z9<%p2>yWerC2GnSP(@c*oPWW5yU)N5qxRSo#{>{**-Wd3v=e4 zbH4k1-#Pu|VriI;NU6P-T`_?s8jzRpw0*66>Jq z_!=lVaDWKE9%YzwNott~!W=NU#2WW~r9;TXZ-+%)@`74|85;vx#|Gxu*q|ap)d^}M zjJuZ<7Km_^C}g8l?1n#V?rW?bf)f|qM3%;5x*0q(Idcl~=6^OpYk~>d@iL5>&%`RL zcBdVmCDvgWEI!C=nzJ3|P?oisGnDE+=(c1CaRxUx%3ydC&@^-x7h;pj!eqOF_fq%@9;0inn7*H$RUcm=ds2 zgak8&X+z>Y~(T(P9P`bAP0u4@{TXdbAO1)6by=5t157~FoLp){$6 zri8X5Fcz_vGJy#s-xB~O6)YfD>1h#wRr0tNMNw0A1o?#Uo4SSFS&sqAfvQajglVBi zXCviJp-64oz0dSybq?=BtU}@_Itq+M=R+L`zCa#*rGE0EJNoF(;wNn2Q*YqA4^O@K z{v*5k-uQgSm2+Rev@(5p?~m_%d+7NWF17#p^1j!fzVha=6LUq z=Le5fzc~NRtKN&N_h0MWn%@OqU0nL__|9kF(sSz@^W*auH{PB8yY%v@*QP(a`p3Py z9~K*TPmQd@&;@7r)f1JU&we!az@ck9RxejpPOd+-skwA^MQg_?LS3bx!_f#`&Ub94!lmZV$v|=n*E{Jfrq87NHBGyzvmreNSQ|ULs zdQ$r1eki+vt^rMrRFkDZG>8q95<7Vy=QucF4M<`Xi8c@To3T8?+ZJPJ