mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Improve the structure for widget annotations
Currently, we only support text widget annotations (field type 'Tx') partially. However, the current code does not make this entirely clear and does not provide a warning when an unsupported field type is encountered, making it harder to determine why rendering fails. Moreover, in the display layer we make no distinction between the various types of widget annotations, causing the code for text widget annotations to also be executed for other types of widget annotations in a fallback situation. This patch improves the structure of the widget annotation code. In the core layer, we use the same structure we use for non-widget annotations in the factory and provide a clear warning when an unsupported type is encountered. In the display layer, we do the same and split the `WidgetAnnotationElement` class into two classes, namely `TextWidgetAnnotationElement` for text widget annotations and `WidgetAnnotationElement` for other unsupported annotations as a fallback. From this it clear that we only support text widget annotations and nothing else.
This commit is contained in:
parent
38c85039d1
commit
576f742047
2 changed files with 46 additions and 11 deletions
|
@ -98,9 +98,14 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
|
|||
|
||||
case 'Widget':
|
||||
var fieldType = Util.getInheritableProperty(dict, 'FT');
|
||||
if (isName(fieldType, 'Tx')) {
|
||||
return new TextWidgetAnnotation(parameters);
|
||||
fieldType = isName(fieldType) ? fieldType.name : null;
|
||||
|
||||
switch (fieldType) {
|
||||
case 'Tx':
|
||||
return new TextWidgetAnnotation(parameters);
|
||||
}
|
||||
warn('Unimplemented widget field type "' + fieldType + '", ' +
|
||||
'falling back to base field type.');
|
||||
return new WidgetAnnotation(parameters);
|
||||
|
||||
case 'Popup':
|
||||
|
@ -615,13 +620,12 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
|
|||
data.alternativeText = stringToPDFString(dict.get('TU') || '');
|
||||
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
|
||||
var fieldType = Util.getInheritableProperty(dict, 'FT');
|
||||
data.fieldType = isName(fieldType) ? fieldType.name : '';
|
||||
data.fieldType = isName(fieldType) ? fieldType.name : null;
|
||||
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
|
||||
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
|
||||
|
||||
// Hide unsupported Widget signatures.
|
||||
// Hide signatures because we cannot validate them.
|
||||
if (data.fieldType === 'Sig') {
|
||||
warn('unimplemented annotation type: Widget signature');
|
||||
this.setFlags(AnnotationFlag.HIDDEN);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue