Skip to content

Commit adf0972

Browse files
committed
Text widget annotations: improve unit and reference tests
This patch improves the unit tests by testing the support for read-only and multiline fields. Moreover, we add a reference test to ensure that the text widgets are not only rendered, but also that their contents are styled properly. Finally, we perform minor improvements in `src/core/annotation.js`, for example adding missing comments.
1 parent f6965fa commit adf0972

File tree

6 files changed

+45
-12
lines changed

6 files changed

+45
-12
lines changed

src/core/annotation.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
6666
/**
6767
* @param {XRef} xref
6868
* @param {Object} ref
69+
* @param {string} uniquePrefix
70+
* @param {Object} idCounters
6971
* @returns {Annotation}
7072
*/
7173
create: function AnnotationFactory_create(xref, ref,
@@ -717,20 +719,19 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
717719
return Annotation.prototype.getOperatorList.call(this, evaluator, task);
718720
}
719721

720-
var opList = new OperatorList();
721-
var data = this.data;
722+
var operatorList = new OperatorList();
722723

723724
// Even if there is an appearance stream, ignore it. This is the
724725
// behaviour used by Adobe Reader.
725-
if (!data.defaultAppearance) {
726-
return Promise.resolve(opList);
726+
if (!this.data.defaultAppearance) {
727+
return Promise.resolve(operatorList);
727728
}
728729

729-
var stream = new Stream(stringToBytes(data.defaultAppearance));
730-
return evaluator.getOperatorList(stream, task,
731-
this.fieldResources, opList).
730+
var stream = new Stream(stringToBytes(this.data.defaultAppearance));
731+
return evaluator.getOperatorList(stream, task, this.fieldResources,
732+
operatorList).
732733
then(function () {
733-
return opList;
734+
return operatorList;
734735
});
735736
}
736737
});

test/annotation_layer_test.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
position: absolute;
4444
}
4545

46-
.annotationLayer .textWidgetAnnotation input {
46+
.annotationLayer .textWidgetAnnotation input,
47+
.annotationLayer .textWidgetAnnotation textarea {
4748
background-color: rgba(0, 54, 255, 0.13);
4849
border: 1px solid transparent;
4950
box-sizing: border-box;
@@ -54,6 +55,18 @@
5455
width: 100%;
5556
}
5657

58+
.annotationLayer .textWidgetAnnotation textarea {
59+
font: message-box;
60+
font-size: 9px;
61+
resize: none;
62+
}
63+
64+
.annotationLayer .textWidgetAnnotation input[disabled],
65+
.annotationLayer .textWidgetAnnotation textarea[disabled] {
66+
background: none;
67+
border: 1px solid transparent;
68+
}
69+
5770
.annotationLayer .popupAnnotation {
5871
display: block !important;
5972
}

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,5 @@
249249
!annotation-squiggly.pdf
250250
!annotation-highlight.pdf
251251
!annotation-fileattachment.pdf
252+
!annotation-text-widget.pdf
252253
!zero_descent.pdf

test/pdfs/annotation-text-widget.pdf

89.1 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,13 @@
31373137
"type": "eq",
31383138
"annotations": true
31393139
},
3140+
{ "id": "annotation-text-widget-forms",
3141+
"file": "pdfs/annotation-text-widget.pdf",
3142+
"md5": "cc9672539ad5b837152a9c6961e5f106",
3143+
"rounds": 1,
3144+
"type": "eq",
3145+
"forms": true
3146+
},
31403147
{ "id": "issue6108",
31413148
"file": "pdfs/issue6108.pdf",
31423149
"md5": "8961cb55149495989a80bf0487e0f076",

test/unit/annotation_layer_spec.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ describe('Annotation layer', function() {
469469
textWidgetDict = null;
470470
});
471471

472-
it('should handle unknown text alignment and maximum length', function() {
472+
it('should handle unknown text alignment, maximum length and flags',
473+
function() {
473474
var textWidgetRef = new Ref(124, 0);
474475
var xref = new XRefMock([
475476
{ ref: textWidgetRef, data: textWidgetDict, }
@@ -478,11 +479,15 @@ describe('Annotation layer', function() {
478479
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef);
479480
expect(textWidgetAnnotation.data.textAlignment).toEqual(null);
480481
expect(textWidgetAnnotation.data.maxLen).toEqual(null);
482+
expect(textWidgetAnnotation.data.readOnly).toEqual(false);
483+
expect(textWidgetAnnotation.data.multiLine).toEqual(false);
481484
});
482485

483-
it('should not set invalid text alignment and maximum length', function() {
486+
it('should not set invalid text alignment, maximum length and flags',
487+
function() {
484488
textWidgetDict.set('Q', 'center');
485489
textWidgetDict.set('MaxLen', 'five');
490+
textWidgetDict.set('Ff', 'readonly');
486491

487492
var textWidgetRef = new Ref(43, 0);
488493
var xref = new XRefMock([
@@ -492,11 +497,15 @@ describe('Annotation layer', function() {
492497
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef);
493498
expect(textWidgetAnnotation.data.textAlignment).toEqual(null);
494499
expect(textWidgetAnnotation.data.maxLen).toEqual(null);
500+
expect(textWidgetAnnotation.data.readOnly).toEqual(false);
501+
expect(textWidgetAnnotation.data.multiLine).toEqual(false);
495502
});
496503

497-
it('should set valid text alignment and maximum length', function() {
504+
it('should set valid text alignment, maximum length and flags',
505+
function() {
498506
textWidgetDict.set('Q', 1);
499507
textWidgetDict.set('MaxLen', 20);
508+
textWidgetDict.set('Ff', 4097);
500509

501510
var textWidgetRef = new Ref(84, 0);
502511
var xref = new XRefMock([
@@ -506,6 +515,8 @@ describe('Annotation layer', function() {
506515
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef);
507516
expect(textWidgetAnnotation.data.textAlignment).toEqual(1);
508517
expect(textWidgetAnnotation.data.maxLen).toEqual(20);
518+
expect(textWidgetAnnotation.data.readOnly).toEqual(true);
519+
expect(textWidgetAnnotation.data.multiLine).toEqual(true);
509520
});
510521
});
511522

0 commit comments

Comments
 (0)