Widget annotations: simplify field flag handling
Directly use the hexadecimal representation, just like the `AnnotationFlags`, to avoid calculations and to improve readability. This allows us to simplify the unit tests for text widget annotations as well.
This commit is contained in:
parent
6100ab4b18
commit
375229d6b9
@ -678,14 +678,13 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
|
|||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @memberof WidgetAnnotation
|
* @memberof WidgetAnnotation
|
||||||
* @param {number} flag - Bit position, numbered from one instead of
|
* @param {number} flag - Hexadecimal representation for an annotation
|
||||||
* zero, to check
|
* field characteristic
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
* @see {@link shared/util.js}
|
* @see {@link shared/util.js}
|
||||||
*/
|
*/
|
||||||
hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
|
hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
|
||||||
var mask = 1 << (flag - 1);
|
return !!(this.data.fieldFlags & flag);
|
||||||
return !!(this.data.fieldFlags & mask);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -94,25 +94,25 @@ var AnnotationFlag = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var AnnotationFieldFlag = {
|
var AnnotationFieldFlag = {
|
||||||
READONLY: 1,
|
READONLY: 0x0000001,
|
||||||
REQUIRED: 2,
|
REQUIRED: 0x0000002,
|
||||||
NOEXPORT: 3,
|
NOEXPORT: 0x0000004,
|
||||||
MULTILINE: 13,
|
MULTILINE: 0x0001000,
|
||||||
PASSWORD: 14,
|
PASSWORD: 0x0002000,
|
||||||
NOTOGGLETOOFF: 15,
|
NOTOGGLETOOFF: 0x0004000,
|
||||||
RADIO: 16,
|
RADIO: 0x0008000,
|
||||||
PUSHBUTTON: 17,
|
PUSHBUTTON: 0x0010000,
|
||||||
COMBO: 18,
|
COMBO: 0x0020000,
|
||||||
EDIT: 19,
|
EDIT: 0x0040000,
|
||||||
SORT: 20,
|
SORT: 0x0080000,
|
||||||
FILESELECT: 21,
|
FILESELECT: 0x0100000,
|
||||||
MULTISELECT: 22,
|
MULTISELECT: 0x0200000,
|
||||||
DONOTSPELLCHECK: 23,
|
DONOTSPELLCHECK: 0x0400000,
|
||||||
DONOTSCROLL: 24,
|
DONOTSCROLL: 0x0800000,
|
||||||
COMB: 25,
|
COMB: 0x1000000,
|
||||||
RICHTEXT: 26,
|
RICHTEXT: 0x2000000,
|
||||||
RADIOSINUNISON: 26,
|
RADIOSINUNISON: 0x2000000,
|
||||||
COMMITONSELCHANGE: 27,
|
COMMITONSELCHANGE: 0x4000000,
|
||||||
};
|
};
|
||||||
|
|
||||||
var AnnotationBorderStyleType = {
|
var AnnotationBorderStyleType = {
|
||||||
|
@ -505,13 +505,10 @@ describe('Annotation layer', function() {
|
|||||||
|
|
||||||
it('should set valid text alignment, maximum length and flags',
|
it('should set valid text alignment, maximum length and flags',
|
||||||
function() {
|
function() {
|
||||||
var flags = 0;
|
|
||||||
flags |= 1 << (AnnotationFieldFlag.READONLY - 1);
|
|
||||||
flags |= 1 << (AnnotationFieldFlag.MULTILINE - 1);
|
|
||||||
|
|
||||||
textWidgetDict.set('Q', 1);
|
textWidgetDict.set('Q', 1);
|
||||||
textWidgetDict.set('MaxLen', 20);
|
textWidgetDict.set('MaxLen', 20);
|
||||||
textWidgetDict.set('Ff', flags);
|
textWidgetDict.set('Ff', AnnotationFieldFlag.READONLY +
|
||||||
|
AnnotationFieldFlag.MULTILINE);
|
||||||
|
|
||||||
var textWidgetRef = new Ref(84, 0);
|
var textWidgetRef = new Ref(84, 0);
|
||||||
var xref = new XRefMock([
|
var xref = new XRefMock([
|
||||||
@ -526,10 +523,7 @@ describe('Annotation layer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should reject comb fields without a maximum length', function() {
|
it('should reject comb fields without a maximum length', function() {
|
||||||
var flags = 0;
|
textWidgetDict.set('Ff', AnnotationFieldFlag.COMB);
|
||||||
flags |= 1 << (AnnotationFieldFlag.COMB - 1);
|
|
||||||
|
|
||||||
textWidgetDict.set('Ff', flags);
|
|
||||||
|
|
||||||
var textWidgetRef = new Ref(46, 0);
|
var textWidgetRef = new Ref(46, 0);
|
||||||
var xref = new XRefMock([
|
var xref = new XRefMock([
|
||||||
@ -541,11 +535,8 @@ describe('Annotation layer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should accept comb fields with a maximum length', 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('MaxLen', 20);
|
||||||
textWidgetDict.set('Ff', flags);
|
textWidgetDict.set('Ff', AnnotationFieldFlag.COMB);
|
||||||
|
|
||||||
var textWidgetRef = new Ref(46, 0);
|
var textWidgetRef = new Ref(46, 0);
|
||||||
var xref = new XRefMock([
|
var xref = new XRefMock([
|
||||||
@ -558,20 +549,16 @@ describe('Annotation layer', function() {
|
|||||||
|
|
||||||
it('should only accept comb fields when the flags are valid', function() {
|
it('should only accept comb fields when the flags are valid', function() {
|
||||||
var invalidFieldFlags = [
|
var invalidFieldFlags = [
|
||||||
AnnotationFieldFlag.MULTILINE,
|
AnnotationFieldFlag.MULTILINE, AnnotationFieldFlag.PASSWORD,
|
||||||
AnnotationFieldFlag.PASSWORD,
|
|
||||||
AnnotationFieldFlag.FILESELECT
|
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++) {
|
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('MaxLen', 20);
|
||||||
textWidgetDict.set('Ff', flags);
|
textWidgetDict.set('Ff', flags);
|
||||||
|
|
||||||
@ -588,7 +575,7 @@ describe('Annotation layer', function() {
|
|||||||
|
|
||||||
// Remove the last invalid flag for the next iteration.
|
// Remove the last invalid flag for the next iteration.
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
invalidFieldFlags.splice(-1, 1);
|
flags -= invalidFieldFlags.splice(-1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user