1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Group popup creation code and apply it to more annotation types

This commit is contained in:
Tim van der Meij 2016-02-23 00:21:28 +01:00
parent 41efb92d3a
commit ad31e52a26
5 changed files with 102 additions and 59 deletions

View file

@ -346,6 +346,24 @@ var Annotation = (function AnnotationClosure() {
}
},
/**
* Prepare the annotation for working with a popup in the display layer.
*
* @private
* @memberof Annotation
* @param {Dict} dict - The annotation's data dictionary
*/
_preparePopup: function Annotation_preparePopup(dict) {
if (!dict.has('C')) {
// Fall back to the default background color.
this.data.color = null;
}
this.data.hasPopup = dict.has('Popup');
this.data.title = stringToPDFString(dict.get('T') || '');
this.data.contents = stringToPDFString(dict.get('Contents') || '');
},
loadResources: function Annotation_loadResources(keys) {
return new Promise(function (resolve, reject) {
this.appearance.dict.getAsync('Resources').then(function (resources) {
@ -663,23 +681,15 @@ var TextAnnotation = (function TextAnnotationClosure() {
this.data.annotationType = AnnotationType.TEXT;
var dict = parameters.dict;
if (this.data.hasAppearance) {
this.data.name = 'NoIcon';
} else {
this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
this.data.name = parameters.dict.has('Name') ?
parameters.dict.get('Name').name : 'Note';
}
if (!dict.has('C')) {
// Fall back to the default background color.
this.data.color = null;
}
this.data.hasPopup = dict.has('Popup');
this.data.title = stringToPDFString(dict.get('T') || '');
this.data.contents = stringToPDFString(dict.get('Contents') || '');
this._preparePopup(parameters.dict);
}
Util.inherit(TextAnnotation, Annotation, {});
@ -798,7 +808,7 @@ var HighlightAnnotation = (function HighlightAnnotationClosure() {
Annotation.call(this, parameters);
this.data.annotationType = AnnotationType.HIGHLIGHT;
this.data.hasPopup = parameters.dict.has('Popup');
this._preparePopup(parameters.dict);
// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
@ -814,7 +824,7 @@ var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
Annotation.call(this, parameters);
this.data.annotationType = AnnotationType.UNDERLINE;
this.data.hasPopup = parameters.dict.has('Popup');
this._preparePopup(parameters.dict);
// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
@ -830,7 +840,7 @@ var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
Annotation.call(this, parameters);
this.data.annotationType = AnnotationType.SQUIGGLY;
this.data.hasPopup = parameters.dict.has('Popup');
this._preparePopup(parameters.dict);
// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
@ -846,7 +856,7 @@ var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
Annotation.call(this, parameters);
this.data.annotationType = AnnotationType.STRIKEOUT;
this.data.hasPopup = parameters.dict.has('Popup');
this._preparePopup(parameters.dict);
// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
@ -861,20 +871,11 @@ var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
function FileAttachmentAnnotation(parameters) {
Annotation.call(this, parameters);
var dict = parameters.dict;
var file = new FileSpec(dict.get('FS'), parameters.xref);
var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
this.data.annotationType = AnnotationType.FILEATTACHMENT;
this.data.file = file.serializable;
if (!dict.has('C')) {
// Fall back to the default background color.
this.data.color = null;
}
this.data.hasPopup = dict.has('Popup');
this.data.title = stringToPDFString(dict.get('T') || '');
this.data.contents = stringToPDFString(dict.get('Contents') || '');
this._preparePopup(parameters.dict);
}
Util.inherit(FileAttachmentAnnotation, Annotation, {});