Implement getOperatorList method in the WidgetAnnotation class to

avoid duplication in subclasses
This commit is contained in:
Tim van der Meij 2017-08-27 00:48:02 +02:00
parent 4f02857394
commit 2512eccbf0
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -646,6 +646,15 @@ class WidgetAnnotation extends Annotation {
hasFieldFlag(flag) {
return !!(this.data.fieldFlags & flag);
}
getOperatorList(evaluator, task, renderForms) {
// Do not render form elements on the canvas when interactive forms are
// enabled. The display layer is responsible for rendering them instead.
if (renderForms) {
return Promise.resolve(new OperatorList());
}
return super.getOperatorList(evaluator, task, renderForms);
}
}
class TextWidgetAnnotation extends WidgetAnnotation {
@ -679,19 +688,12 @@ class TextWidgetAnnotation extends WidgetAnnotation {
}
getOperatorList(evaluator, task, renderForms) {
if (renderForms || this.appearance) {
return super.getOperatorList(evaluator, task, renderForms);
}
let operatorList = new OperatorList();
// Do not render form elements on the canvas when interactive forms are
// enabled. The display layer is responsible for rendering them instead.
if (renderForms) {
return Promise.resolve(operatorList);
}
if (this.appearance) {
return Annotation.prototype.getOperatorList.call(this, evaluator, task,
renderForms);
}
// Even if there is an appearance stream, ignore it. This is the
// behaviour used by Adobe Reader.
if (!this.data.defaultAppearance) {
@ -756,22 +758,6 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}
}
}
getOperatorList(evaluator, task, renderForms) {
let operatorList = new OperatorList();
// Do not render form elements on the canvas when interactive forms are
// enabled. The display layer is responsible for rendering them instead.
if (renderForms) {
return Promise.resolve(operatorList);
}
if (this.appearance) {
return Annotation.prototype.getOperatorList.call(this, evaluator, task,
renderForms);
}
return Promise.resolve(operatorList);
}
}
class ChoiceWidgetAnnotation extends WidgetAnnotation {
@ -814,19 +800,6 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
}
getOperatorList(evaluator, task, renderForms) {
let operatorList = new OperatorList();
// Do not render form elements on the canvas when interactive forms are
// enabled. The display layer is responsible for rendering them instead.
if (renderForms) {
return Promise.resolve(operatorList);
}
return Annotation.prototype.getOperatorList.call(this, evaluator, task,
renderForms);
}
}
class TextAnnotation extends Annotation {