diff --git a/test/annotation_layer_test.css b/test/annotation_layer_test.css index df5dea06c..5c6a87be8 100644 --- a/test/annotation_layer_test.css +++ b/test/annotation_layer_test.css @@ -44,7 +44,8 @@ } .annotationLayer .textWidgetAnnotation input, -.annotationLayer .textWidgetAnnotation textarea { +.annotationLayer .textWidgetAnnotation textarea, +.annotationLayer .choiceWidgetAnnotation select { background-color: rgba(0, 54, 255, 0.13); border: 1px solid transparent; box-sizing: border-box; @@ -62,7 +63,8 @@ } .annotationLayer .textWidgetAnnotation input[disabled], -.annotationLayer .textWidgetAnnotation textarea[disabled] { +.annotationLayer .textWidgetAnnotation textarea[disabled], +.annotationLayer .choiceWidgetAnnotation select[disabled] { background: none; border: 1px solid transparent; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index cb7707886..2f21b3329 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -255,4 +255,5 @@ !annotation-highlight.pdf !annotation-fileattachment.pdf !annotation-text-widget.pdf +!annotation-choice-widget.pdf !zero_descent.pdf diff --git a/test/pdfs/annotation-choice-widget.pdf b/test/pdfs/annotation-choice-widget.pdf new file mode 100644 index 000000000..b557d9a85 Binary files /dev/null and b/test/pdfs/annotation-choice-widget.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 531e054fb..d52a68d05 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -3216,6 +3216,20 @@ "type": "eq", "forms": true }, + { "id": "annotation-choice-widget-annotations", + "file": "pdfs/annotation-choice-widget.pdf", + "md5": "7dfb0d743a0da0f4a71b209ab43b0be5", + "rounds": 1, + "type": "eq", + "annotations": true + }, + { "id": "annotation-choice-widget-forms", + "file": "pdfs/annotation-choice-widget.pdf", + "md5": "7dfb0d743a0da0f4a71b209ab43b0be5", + "rounds": 1, + "type": "eq", + "forms": true + }, { "id": "issue6108", "file": "pdfs/issue6108.pdf", "md5": "8961cb55149495989a80bf0487e0f076", diff --git a/test/unit/annotation_layer_spec.js b/test/unit/annotation_layer_spec.js index a1e38168e..16a93b09b 100644 --- a/test/unit/annotation_layer_spec.js +++ b/test/unit/annotation_layer_spec.js @@ -581,6 +581,175 @@ describe('Annotation layer', function() { }); }); + describe('ChoiceWidgetAnnotation', function() { + var choiceWidgetDict; + + beforeEach(function (done) { + choiceWidgetDict = new Dict(); + choiceWidgetDict.set('Type', Name.get('Annot')); + choiceWidgetDict.set('Subtype', Name.get('Widget')); + choiceWidgetDict.set('FT', Name.get('Ch')); + + done(); + }); + + afterEach(function () { + choiceWidgetDict = null; + }); + + it('should handle missing option arrays', function() { + var choiceWidgetRef = new Ref(122, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.options).toEqual([]); + }); + + it('should handle option arrays with array elements', function() { + var options = [['foo_export', 'Foo'], ['bar_export', 'Bar']]; + var expected = [ + { + exportValue: 'foo_export', + displayValue: 'Foo' + }, + { + exportValue: 'bar_export', + displayValue: 'Bar' + } + ]; + + choiceWidgetDict.set('Opt', options); + + var choiceWidgetRef = new Ref(123, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.options).toEqual(expected); + }); + + it('should handle option arrays with string elements', function() { + var options = ['Foo', 'Bar']; + var expected = [ + { + exportValue: 'Foo', + displayValue: 'Foo' + }, + { + exportValue: 'Bar', + displayValue: 'Bar' + } + ]; + + choiceWidgetDict.set('Opt', options); + + var choiceWidgetRef = new Ref(981, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.options).toEqual(expected); + }); + + it('should handle array field values', function() { + var fieldValue = ['Foo', 'Bar']; + + choiceWidgetDict.set('V', fieldValue); + + var choiceWidgetRef = new Ref(968, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.fieldValue).toEqual(fieldValue); + }); + + it('should handle string field values', function() { + var fieldValue = 'Foo'; + + choiceWidgetDict.set('V', fieldValue); + + var choiceWidgetRef = new Ref(978, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.fieldValue).toEqual([fieldValue]); + }); + + it('should handle unknown flags', function() { + var choiceWidgetRef = new Ref(166, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.readOnly).toEqual(false); + expect(data.combo).toEqual(false); + expect(data.multiSelect).toEqual(false); + }); + + it('should not set invalid flags', function() { + choiceWidgetDict.set('Ff', 'readonly'); + + var choiceWidgetRef = new Ref(165, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.readOnly).toEqual(false); + expect(data.combo).toEqual(false); + expect(data.multiSelect).toEqual(false); + }); + + it('should set valid flags', function() { + choiceWidgetDict.set('Ff', AnnotationFieldFlag.READONLY + + AnnotationFieldFlag.COMBO + + AnnotationFieldFlag.MULTISELECT); + + var choiceWidgetRef = new Ref(512, 0); + var xref = new XRefMock([ + { ref: choiceWidgetRef, data: choiceWidgetDict, } + ]); + + var choiceWidgetAnnotation = annotationFactory.create(xref, + choiceWidgetRef); + var data = choiceWidgetAnnotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + expect(data.readOnly).toEqual(true); + expect(data.combo).toEqual(true); + expect(data.multiSelect).toEqual(true); + }); + }); + describe('FileAttachmentAnnotation', function() { var loadingTask; var annotations;