[api-minor] Include export value for checkboxes
This commit is contained in:
parent
66ffdc4c5b
commit
c31ddf7edc
@ -742,7 +742,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
|
this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
|
||||||
|
|
||||||
if (this.data.checkBox) {
|
if (this.data.checkBox) {
|
||||||
this._processCheckBox();
|
this._processCheckBox(params);
|
||||||
} else if (this.data.radioButton) {
|
} else if (this.data.radioButton) {
|
||||||
this._processRadioButton(params);
|
this._processRadioButton(params);
|
||||||
} else if (this.data.pushButton) {
|
} else if (this.data.pushButton) {
|
||||||
@ -752,11 +752,29 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_processCheckBox() {
|
_processCheckBox(params) {
|
||||||
if (!isName(this.data.fieldValue)) {
|
if (isName(this.data.fieldValue)) {
|
||||||
|
this.data.fieldValue = this.data.fieldValue.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const customAppearance = params.dict.get('AP');
|
||||||
|
if (!isDict(customAppearance)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.data.fieldValue = this.data.fieldValue.name;
|
|
||||||
|
const exportValueOptionsDict = customAppearance.get('D');
|
||||||
|
if (!isDict(exportValueOptionsDict)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportValues = exportValueOptionsDict.getKeys();
|
||||||
|
const hasCorrectOptionCount = exportValues.length === 2;
|
||||||
|
if (!hasCorrectOptionCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.data.exportValue = exportValues[0] === 'Off' ?
|
||||||
|
exportValues[1] : exportValues[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
_processRadioButton(params) {
|
_processRadioButton(params) {
|
||||||
|
@ -979,7 +979,34 @@ describe('annotation', function() {
|
|||||||
buttonWidgetDict = null;
|
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();
|
||||||
|
var exportValueOptionsDict = new Dict();
|
||||||
|
|
||||||
|
exportValueOptionsDict.set('Off', 0);
|
||||||
|
exportValueOptionsDict.set('Checked', 1);
|
||||||
|
appearanceStatesDict.set('D', exportValueOptionsDict);
|
||||||
|
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'));
|
buttonWidgetDict.set('V', Name.get('1'));
|
||||||
|
|
||||||
var buttonWidgetRef = new Ref(124, 0);
|
var buttonWidgetRef = new Ref(124, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user