Skip to content

Commit f6965fa

Browse files
committed
Text widget annotations: support multiline and read-only fields
Moreover, this patch provides us with a framework for handling field flags in general for all types of widget annotations.
1 parent a7c3502 commit f6965fa

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

src/core/annotation.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
coreColorSpace, coreObj, coreEvaluator) {
3434

3535
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
36+
var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
3637
var AnnotationFlag = sharedUtil.AnnotationFlag;
3738
var AnnotationType = sharedUtil.AnnotationType;
3839
var OPS = sharedUtil.OPS;
@@ -621,9 +622,13 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
621622
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
622623
var fieldType = Util.getInheritableProperty(dict, 'FT');
623624
data.fieldType = isName(fieldType) ? fieldType.name : null;
624-
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
625625
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
626626

627+
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
628+
if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
629+
data.fieldFlags = 0;
630+
}
631+
627632
// Hide signatures because we cannot validate them.
628633
if (data.fieldType === 'Sig') {
629634
this.setFlags(AnnotationFlag.HIDDEN);
@@ -662,7 +667,22 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
662667
data.fullName = fieldName.join('.');
663668
}
664669

665-
Util.inherit(WidgetAnnotation, Annotation, {});
670+
Util.inherit(WidgetAnnotation, Annotation, {
671+
/**
672+
* Check if a provided field flag is set.
673+
*
674+
* @public
675+
* @memberof WidgetAnnotation
676+
* @param {number} flag - Bit position, numbered from one instead of
677+
* zero, to check
678+
* @return {boolean}
679+
* @see {@link shared/util.js}
680+
*/
681+
hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
682+
var mask = 1 << (flag - 1);
683+
return !!(this.data.fieldFlags & mask);
684+
},
685+
});
666686

667687
return WidgetAnnotation;
668688
})();
@@ -684,6 +704,10 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
684704
maximumLength = null;
685705
}
686706
this.data.maxLen = maximumLength;
707+
708+
// Process field flags for the display layer.
709+
this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
710+
this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
687711
}
688712

689713
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {

src/display/annotation_layer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,15 @@ var TextWidgetAnnotationElement = (
446446

447447
var element = null;
448448
if (this.renderInteractiveForms) {
449-
element = document.createElement('input');
450-
element.type = 'text';
449+
if (this.data.multiLine) {
450+
element = document.createElement('textarea');
451+
} else {
452+
element = document.createElement('input');
453+
element.type = 'text';
454+
}
455+
451456
element.value = this.data.fieldValue;
457+
element.disabled = this.data.readOnly;
452458

453459
if (this.data.maxLen !== null) {
454460
element.maxLength = this.data.maxLen;

src/shared/util.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,28 @@ var AnnotationFlag = {
9393
LOCKEDCONTENTS: 0x200
9494
};
9595

96+
var AnnotationFieldFlag = {
97+
READONLY: 1,
98+
REQUIRED: 2,
99+
NOEXPORT: 3,
100+
MULTILINE: 13,
101+
PASSWORD: 14,
102+
NOTOGGLETOOFF: 15,
103+
RADIO: 16,
104+
PUSHBUTTON: 17,
105+
COMBO: 18,
106+
EDIT: 19,
107+
SORT: 20,
108+
FILESELECT: 21,
109+
MULTISELECT: 22,
110+
DONOTSPELLCHECK: 23,
111+
DONOTSCROLL: 24,
112+
COMB: 25,
113+
RICHTEXT: 26,
114+
RADIOSINUNISON: 26,
115+
COMMITONSELCHANGE: 27,
116+
};
117+
96118
var AnnotationBorderStyleType = {
97119
SOLID: 1,
98120
DASHED: 2,
@@ -2364,6 +2386,7 @@ exports.OPS = OPS;
23642386
exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
23652387
exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
23662388
exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
2389+
exports.AnnotationFieldFlag = AnnotationFieldFlag;
23672390
exports.AnnotationFlag = AnnotationFlag;
23682391
exports.AnnotationType = AnnotationType;
23692392
exports.FontType = FontType;

web/annotation_layer_builder.css

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
cursor: pointer;
4242
}
4343

44-
.annotationLayer .textWidgetAnnotation input {
44+
.annotationLayer .textWidgetAnnotation input,
45+
.annotationLayer .textWidgetAnnotation textarea {
4546
background-color: rgba(0, 54, 255, 0.13);
4647
border: 1px solid transparent;
4748
box-sizing: border-box;
@@ -52,11 +53,26 @@
5253
width: 100%;
5354
}
5455

55-
.annotationLayer .textWidgetAnnotation input:hover {
56+
.annotationLayer .textWidgetAnnotation textarea {
57+
font: message-box;
58+
font-size: 9px;
59+
resize: none;
60+
}
61+
62+
.annotationLayer .textWidgetAnnotation input[disabled],
63+
.annotationLayer .textWidgetAnnotation textarea[disabled] {
64+
background: none;
65+
border: 1px solid transparent;
66+
cursor: not-allowed;
67+
}
68+
69+
.annotationLayer .textWidgetAnnotation input:hover,
70+
.annotationLayer .textWidgetAnnotation textarea:hover {
5671
border: 1px solid #000;
5772
}
5873

59-
.annotationLayer .textWidgetAnnotation input:focus {
74+
.annotationLayer .textWidgetAnnotation input:focus,
75+
.annotationLayer .textWidgetAnnotation textarea:focus {
6076
background: none;
6177
border: 1px solid transparent;
6278
}

0 commit comments

Comments
 (0)