mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-28 23:28:16 +02:00
Merge pull request #7633 from timvandermeij/interactive-forms-tx-flags
Text widget annotations: support read-only/multiline fields and improve testing
This commit is contained in:
commit
f062695d62
13 changed files with 150 additions and 25 deletions
|
@ -33,6 +33,7 @@
|
|||
coreColorSpace, coreObj, coreEvaluator) {
|
||||
|
||||
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
|
||||
var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
|
||||
var AnnotationFlag = sharedUtil.AnnotationFlag;
|
||||
var AnnotationType = sharedUtil.AnnotationType;
|
||||
var OPS = sharedUtil.OPS;
|
||||
|
@ -65,10 +66,14 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
|
|||
/**
|
||||
* @param {XRef} xref
|
||||
* @param {Object} ref
|
||||
* @param {string} uniquePrefix
|
||||
* @param {Object} idCounters
|
||||
* @param {boolean} renderInteractiveForms
|
||||
* @returns {Annotation}
|
||||
*/
|
||||
create: function AnnotationFactory_create(xref, ref,
|
||||
uniquePrefix, idCounters) {
|
||||
uniquePrefix, idCounters,
|
||||
renderInteractiveForms) {
|
||||
var dict = xref.fetchIfRef(ref);
|
||||
if (!isDict(dict)) {
|
||||
return;
|
||||
|
@ -87,6 +92,7 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
|
|||
ref: isRef(ref) ? ref : null,
|
||||
subtype: subtype,
|
||||
id: id,
|
||||
renderInteractiveForms: renderInteractiveForms,
|
||||
};
|
||||
|
||||
switch (subtype) {
|
||||
|
@ -621,9 +627,13 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
|
|||
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
|
||||
var fieldType = Util.getInheritableProperty(dict, 'FT');
|
||||
data.fieldType = isName(fieldType) ? fieldType.name : null;
|
||||
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
|
||||
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
|
||||
|
||||
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
|
||||
if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
|
||||
data.fieldFlags = 0;
|
||||
}
|
||||
|
||||
// Hide signatures because we cannot validate them.
|
||||
if (data.fieldType === 'Sig') {
|
||||
this.setFlags(AnnotationFlag.HIDDEN);
|
||||
|
@ -662,7 +672,22 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
|
|||
data.fullName = fieldName.join('.');
|
||||
}
|
||||
|
||||
Util.inherit(WidgetAnnotation, Annotation, {});
|
||||
Util.inherit(WidgetAnnotation, Annotation, {
|
||||
/**
|
||||
* Check if a provided field flag is set.
|
||||
*
|
||||
* @public
|
||||
* @memberof WidgetAnnotation
|
||||
* @param {number} flag - Bit position, numbered from one instead of
|
||||
* zero, to check
|
||||
* @return {boolean}
|
||||
* @see {@link shared/util.js}
|
||||
*/
|
||||
hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
|
||||
var mask = 1 << (flag - 1);
|
||||
return !!(this.data.fieldFlags & mask);
|
||||
},
|
||||
});
|
||||
|
||||
return WidgetAnnotation;
|
||||
})();
|
||||
|
@ -671,6 +696,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
|
|||
function TextWidgetAnnotation(params) {
|
||||
WidgetAnnotation.call(this, params);
|
||||
|
||||
this.renderInteractiveForms = params.renderInteractiveForms;
|
||||
|
||||
// Determine the alignment of text in the field.
|
||||
var alignment = Util.getInheritableProperty(params.dict, 'Q');
|
||||
if (!isInt(alignment) || alignment < 0 || alignment > 2) {
|
||||
|
@ -684,29 +711,38 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
|
|||
maximumLength = null;
|
||||
}
|
||||
this.data.maxLen = maximumLength;
|
||||
|
||||
// Process field flags for the display layer.
|
||||
this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
|
||||
this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
|
||||
}
|
||||
|
||||
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
|
||||
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
|
||||
task) {
|
||||
var 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 (this.renderInteractiveForms) {
|
||||
return Promise.resolve(operatorList);
|
||||
}
|
||||
|
||||
if (this.appearance) {
|
||||
return Annotation.prototype.getOperatorList.call(this, evaluator, task);
|
||||
}
|
||||
|
||||
var opList = new OperatorList();
|
||||
var data = this.data;
|
||||
|
||||
// Even if there is an appearance stream, ignore it. This is the
|
||||
// behaviour used by Adobe Reader.
|
||||
if (!data.defaultAppearance) {
|
||||
return Promise.resolve(opList);
|
||||
if (!this.data.defaultAppearance) {
|
||||
return Promise.resolve(operatorList);
|
||||
}
|
||||
|
||||
var stream = new Stream(stringToBytes(data.defaultAppearance));
|
||||
return evaluator.getOperatorList(stream, task,
|
||||
this.fieldResources, opList).
|
||||
var stream = new Stream(stringToBytes(this.data.defaultAppearance));
|
||||
return evaluator.getOperatorList(stream, task, this.fieldResources,
|
||||
operatorList).
|
||||
then(function () {
|
||||
return opList;
|
||||
return operatorList;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -205,7 +205,8 @@ var Page = (function PageClosure() {
|
|||
}.bind(this));
|
||||
},
|
||||
|
||||
getOperatorList: function Page_getOperatorList(handler, task, intent) {
|
||||
getOperatorList: function Page_getOperatorList(handler, task, intent,
|
||||
renderInteractiveForms) {
|
||||
var self = this;
|
||||
|
||||
var pdfManager = this.pdfManager;
|
||||
|
@ -245,6 +246,8 @@ var Page = (function PageClosure() {
|
|||
});
|
||||
});
|
||||
|
||||
this.renderInteractiveForms = renderInteractiveForms;
|
||||
|
||||
var annotationsPromise = pdfManager.ensure(this, 'annotations');
|
||||
return Promise.all([pageListPromise, annotationsPromise]).then(
|
||||
function(datas) {
|
||||
|
@ -328,7 +331,8 @@ var Page = (function PageClosure() {
|
|||
var annotationRef = annotationRefs[i];
|
||||
var annotation = annotationFactory.create(this.xref, annotationRef,
|
||||
this.uniquePrefix,
|
||||
this.idCounters);
|
||||
this.idCounters,
|
||||
this.renderInteractiveForms);
|
||||
if (annotation) {
|
||||
annotations.push(annotation);
|
||||
}
|
||||
|
|
|
@ -839,7 +839,8 @@ var WorkerMessageHandler = {
|
|||
var pageNum = pageIndex + 1;
|
||||
var start = Date.now();
|
||||
// Pre compile the pdf page and fetch the fonts/images.
|
||||
page.getOperatorList(handler, task, data.intent).then(
|
||||
page.getOperatorList(handler, task, data.intent,
|
||||
data.renderInteractiveForms).then(
|
||||
function(operatorList) {
|
||||
finishWorkerTask(task);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue