From a69269fcf9237ecf428d81c3bffae7cd10ab5451 Mon Sep 17 00:00:00 2001 From: bion Date: Fri, 6 Jul 2018 17:51:10 -0700 Subject: [PATCH] Include export value for checkboxes --- src/core/annotation.js | 26 ++++++++++++++++++++++---- test/unit/annotation_spec.js | 25 ++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 5e0dac35b3d380..31672a44a254b2 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -742,7 +742,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON); if (this.data.checkBox) { - this._processCheckBox(); + this._processCheckBox(params); } else if (this.data.radioButton) { this._processRadioButton(params); } else if (this.data.pushButton) { @@ -752,11 +752,29 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { } } - _processCheckBox() { - if (!isName(this.data.fieldValue)) { + _processCheckBox(params) { + if (isName(this.data.fieldValue)) { + this.data.fieldValue = this.data.fieldValue.name; + } + + const customAppearance = params.dict.get('AP'); + if (!isDict(customAppearance)) { + return; + } + + const exportValueOptionsDict = customAppearance.get('D'); + if (!isDict(exportValueOptionsDict)) { return; } - this.data.fieldValue = this.data.fieldValue.name; + + const exportValues = exportValueOptionsDict.getKeys(); + const hasCorrectOptionCount = exportValues.length === 2; + if (!hasCorrectOptionCount) { + return; + } + + this.data.exportValue = exportValues[0] === 'Off' ? + exportValues[1] : exportValues[0]; } _processRadioButton(params) { diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 67e935aefa358c..0d2e5a992d93d0 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -979,7 +979,30 @@ describe('annotation', function() { buttonWidgetDict = null; }); - it('should handle checkboxes', function() { + it('should handle checkboxes with export value', function() { + buttonWidgetDict.set('V', Name.get('1')); + + var appearanceStatesDict = new Dict(); + appearanceStatesDict.set('D', { 'Off': 0, 'Checked': 1, }); + buttonWidgetDict.set('AP', appearanceStatesDict); + + var buttonWidgetRef = new Ref(124, 0); + var xref = new XRefMock([ + { ref: buttonWidgetRef, data: buttonWidgetDict, } + ]); + + var annotation = AnnotationFactory.create(xref, buttonWidgetRef, + pdfManagerMock, idFactoryMock); + var data = annotation.data; + expect(data.annotationType).toEqual(AnnotationType.WIDGET); + + expect(data.checkBox).toEqual(true); + expect(data.fieldValue).toEqual('1'); + expect(data.radioButton).toEqual(false); + expect(data.exportValue).toEqual('Checked'); + }); + + it('should handle checkboxes without export value', function() { buttonWidgetDict.set('V', Name.get('1')); var buttonWidgetRef = new Ref(124, 0);