-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor annotation flags code #6672
Merged
+107
−44
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ | |
/* globals PDFJS, Util, isDict, isName, stringToPDFString, warn, Dict, Stream, | ||
stringToBytes, Promise, isArray, ObjectLoader, OperatorList, | ||
isValidUrl, OPS, createPromiseCapability, AnnotationType, | ||
stringToUTF8String, AnnotationBorderStyleType, ColorSpace */ | ||
stringToUTF8String, AnnotationBorderStyleType, ColorSpace, | ||
AnnotationFlag, isInt */ | ||
|
||
'use strict'; | ||
|
||
|
@@ -121,7 +122,8 @@ var Annotation = (function AnnotationClosure() { | |
var data = this.data = {}; | ||
|
||
data.subtype = dict.get('Subtype').name; | ||
data.annotationFlags = dict.get('F'); | ||
|
||
this.setFlags(dict.get('F')); | ||
|
||
this.setRectangle(dict.get('Rect')); | ||
data.rect = this.rectangle; | ||
|
@@ -138,6 +140,64 @@ var Annotation = (function AnnotationClosure() { | |
} | ||
|
||
Annotation.prototype = { | ||
/** | ||
* @return {boolean} | ||
*/ | ||
get viewable() { | ||
if (this.flags) { | ||
return !this.hasFlag(AnnotationFlag.INVISIBLE) && | ||
!this.hasFlag(AnnotationFlag.HIDDEN) && | ||
!this.hasFlag(AnnotationFlag.NOVIEW); | ||
} | ||
return true; | ||
}, | ||
|
||
/** | ||
* @return {boolean} | ||
*/ | ||
get printable() { | ||
if (this.flags) { | ||
return this.hasFlag(AnnotationFlag.PRINT) && | ||
!this.hasFlag(AnnotationFlag.INVISIBLE) && | ||
!this.hasFlag(AnnotationFlag.HIDDEN); | ||
} | ||
return false; | ||
}, | ||
|
||
/** | ||
* Set the flags. | ||
* | ||
* @public | ||
* @memberof Annotation | ||
* @param {number} flags - Unsigned 32-bit integer specifying annotation | ||
* characteristics | ||
* @see {@link shared/util.js} | ||
*/ | ||
setFlags: function Annotation_setFlags(flags) { | ||
if (isInt(flags)) { | ||
this.flags = flags; | ||
} else { | ||
this.flags = 0; | ||
} | ||
}, | ||
|
||
/** | ||
* Check if a provided flag is set. | ||
* | ||
* @public | ||
* @memberof Annotation | ||
* @param {number} flag - Hexadecimal representation for an annotation | ||
* characteristic | ||
* @return {boolean} | ||
* @see {@link shared/util.js} | ||
*/ | ||
hasFlag: function Annotation_hasFlag(flag) { | ||
if (this.flags) { | ||
return (this.flags & flag) > 0; | ||
} | ||
return false; | ||
}, | ||
|
||
/** | ||
* Set the rectangle. | ||
* | ||
|
@@ -237,32 +297,6 @@ var Annotation = (function AnnotationClosure() { | |
} | ||
}, | ||
|
||
isInvisible: function Annotation_isInvisible() { | ||
var data = this.data; | ||
return !!(data && | ||
data.annotationFlags && // Default: not invisible | ||
data.annotationFlags & 0x1); // Invisible | ||
}, | ||
|
||
isViewable: function Annotation_isViewable() { | ||
var data = this.data; | ||
return !!(!this.isInvisible() && | ||
data && | ||
(!data.annotationFlags || | ||
!(data.annotationFlags & 0x22)) && // Hidden or NoView | ||
data.rect); // rectangle is necessary | ||
}, | ||
|
||
isPrintable: function Annotation_isPrintable() { | ||
var data = this.data; | ||
return !!(!this.isInvisible() && | ||
data && | ||
data.annotationFlags && // Default: not printable | ||
data.annotationFlags & 0x4 && // Print | ||
!(data.annotationFlags & 0x2) && // Hidden | ||
data.rect); // rectangle is necessary | ||
}, | ||
|
||
loadResources: function Annotation_loadResources(keys) { | ||
return new Promise(function (resolve, reject) { | ||
this.appearance.dict.getAsync('Resources').then(function (resources) { | ||
|
@@ -329,8 +363,8 @@ var Annotation = (function AnnotationClosure() { | |
|
||
var annotationPromises = []; | ||
for (var i = 0, n = annotations.length; i < n; ++i) { | ||
if (intent === 'display' && annotations[i].isViewable() || | ||
intent === 'print' && annotations[i].isPrintable()) { | ||
if (intent === 'display' && annotations[i].viewable || | ||
intent === 'print' && annotations[i].printable) { | ||
annotationPromises.push( | ||
annotations[i].getOperatorList(partialEvaluator, task)); | ||
} | ||
|
@@ -506,6 +540,12 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { | |
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0; | ||
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty; | ||
|
||
// Hide unsupported Widget signatures. | ||
if (data.fieldType === 'Sig') { | ||
warn('unimplemented annotation type: Widget signature'); | ||
this.setFlags(AnnotationFlag.HIDDEN); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice simplification, compared to the previous code! |
||
|
||
// Building the full field name by collecting the field and | ||
// its ancestors 'T' data and joining them using '.'. | ||
var fieldName = []; | ||
|
@@ -539,17 +579,7 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { | |
data.fullName = fieldName.join('.'); | ||
} | ||
|
||
var parent = Annotation.prototype; | ||
Util.inherit(WidgetAnnotation, Annotation, { | ||
isViewable: function WidgetAnnotation_isViewable() { | ||
if (this.data.fieldType === 'Sig') { | ||
warn('unimplemented annotation type: Widget signature'); | ||
return false; | ||
} | ||
|
||
return parent.isViewable.call(this); | ||
} | ||
}); | ||
Util.inherit(WidgetAnnotation, Annotation, {}); | ||
|
||
return WidgetAnnotation; | ||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
this.flags
instead ofthis.data.flags
?Only the data object is exposed with
Page.getAnnotationsData
method so this will remove the ability to read annotation flags from viewer/third-party code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be addressed by #6677.