diff --git a/src/core/annotation.js b/src/core/annotation.js index bf4a5a716..1bcab54b4 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -678,14 +678,13 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { * * @public * @memberof WidgetAnnotation - * @param {number} flag - Bit position, numbered from one instead of - * zero, to check + * @param {number} flag - Hexadecimal representation for an annotation + * field characteristic * @return {boolean} * @see {@link shared/util.js} */ hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) { - var mask = 1 << (flag - 1); - return !!(this.data.fieldFlags & mask); + return !!(this.data.fieldFlags & flag); }, }); diff --git a/src/shared/util.js b/src/shared/util.js index 853cc1a34..48876dad3 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -94,25 +94,25 @@ var AnnotationFlag = { }; var AnnotationFieldFlag = { - READONLY: 1, - REQUIRED: 2, - NOEXPORT: 3, - MULTILINE: 13, - PASSWORD: 14, - NOTOGGLETOOFF: 15, - RADIO: 16, - PUSHBUTTON: 17, - COMBO: 18, - EDIT: 19, - SORT: 20, - FILESELECT: 21, - MULTISELECT: 22, - DONOTSPELLCHECK: 23, - DONOTSCROLL: 24, - COMB: 25, - RICHTEXT: 26, - RADIOSINUNISON: 26, - COMMITONSELCHANGE: 27, + READONLY: 0x0000001, + REQUIRED: 0x0000002, + NOEXPORT: 0x0000004, + MULTILINE: 0x0001000, + PASSWORD: 0x0002000, + NOTOGGLETOOFF: 0x0004000, + RADIO: 0x0008000, + PUSHBUTTON: 0x0010000, + COMBO: 0x0020000, + EDIT: 0x0040000, + SORT: 0x0080000, + FILESELECT: 0x0100000, + MULTISELECT: 0x0200000, + DONOTSPELLCHECK: 0x0400000, + DONOTSCROLL: 0x0800000, + COMB: 0x1000000, + RICHTEXT: 0x2000000, + RADIOSINUNISON: 0x2000000, + COMMITONSELCHANGE: 0x4000000, }; var AnnotationBorderStyleType = { diff --git a/test/unit/annotation_layer_spec.js b/test/unit/annotation_layer_spec.js index fb34b2423..a1e38168e 100644 --- a/test/unit/annotation_layer_spec.js +++ b/test/unit/annotation_layer_spec.js @@ -505,13 +505,10 @@ describe('Annotation layer', function() { it('should set valid text alignment, maximum length and flags', function() { - var flags = 0; - flags |= 1 << (AnnotationFieldFlag.READONLY - 1); - flags |= 1 << (AnnotationFieldFlag.MULTILINE - 1); - textWidgetDict.set('Q', 1); textWidgetDict.set('MaxLen', 20); - textWidgetDict.set('Ff', flags); + textWidgetDict.set('Ff', AnnotationFieldFlag.READONLY + + AnnotationFieldFlag.MULTILINE); var textWidgetRef = new Ref(84, 0); var xref = new XRefMock([ @@ -526,10 +523,7 @@ describe('Annotation layer', function() { }); it('should reject comb fields without a maximum length', function() { - var flags = 0; - flags |= 1 << (AnnotationFieldFlag.COMB - 1); - - textWidgetDict.set('Ff', flags); + textWidgetDict.set('Ff', AnnotationFieldFlag.COMB); var textWidgetRef = new Ref(46, 0); var xref = new XRefMock([ @@ -541,11 +535,8 @@ describe('Annotation layer', function() { }); it('should accept comb fields with a maximum length', function() { - var flags = 0; - flags |= 1 << (AnnotationFieldFlag.COMB - 1); - textWidgetDict.set('MaxLen', 20); - textWidgetDict.set('Ff', flags); + textWidgetDict.set('Ff', AnnotationFieldFlag.COMB); var textWidgetRef = new Ref(46, 0); var xref = new XRefMock([ @@ -558,20 +549,16 @@ describe('Annotation layer', function() { it('should only accept comb fields when the flags are valid', function() { var invalidFieldFlags = [ - AnnotationFieldFlag.MULTILINE, - AnnotationFieldFlag.PASSWORD, + AnnotationFieldFlag.MULTILINE, AnnotationFieldFlag.PASSWORD, AnnotationFieldFlag.FILESELECT ]; - // The field may not use combs until all invalid flags are unset. + // Start with all invalid flags set and remove them one by one. + // The field may only use combs when all invalid flags are unset. + var flags = AnnotationFieldFlag.COMB + AnnotationFieldFlag.MULTILINE + + AnnotationFieldFlag.PASSWORD + AnnotationFieldFlag.FILESELECT; + for (var i = 0, ii = invalidFieldFlags.length; i <= ii; i++) { - var flags = 0; - flags |= 1 << (AnnotationFieldFlag.COMB - 1); - - for (var j = 0, jj = invalidFieldFlags.length; j < jj; j++) { - flags |= 1 << (invalidFieldFlags[j] - 1); - } - textWidgetDict.set('MaxLen', 20); textWidgetDict.set('Ff', flags); @@ -588,7 +575,7 @@ describe('Annotation layer', function() { // Remove the last invalid flag for the next iteration. if (!valid) { - invalidFieldFlags.splice(-1, 1); + flags -= invalidFieldFlags.splice(-1, 1); } } });