Implement contents for every annotation type
The specification states that `Contents` can be available for every annotation types instead of only for markup annotations.
This commit is contained in:
parent
1421b2f205
commit
cf07918ccb
@ -173,8 +173,9 @@ function getTransformMatrix(rect, bbox, matrix) {
|
|||||||
|
|
||||||
class Annotation {
|
class Annotation {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
let dict = params.dict;
|
const dict = params.dict;
|
||||||
|
|
||||||
|
this.setContents(dict.get('Contents'));
|
||||||
this.setCreationDate(dict.get('CreationDate'));
|
this.setCreationDate(dict.get('CreationDate'));
|
||||||
this.setModificationDate(dict.get('M'));
|
this.setModificationDate(dict.get('M'));
|
||||||
this.setFlags(dict.get('F'));
|
this.setFlags(dict.get('F'));
|
||||||
@ -188,6 +189,7 @@ class Annotation {
|
|||||||
annotationFlags: this.flags,
|
annotationFlags: this.flags,
|
||||||
borderStyle: this.borderStyle,
|
borderStyle: this.borderStyle,
|
||||||
color: this.color,
|
color: this.color,
|
||||||
|
contents: this.contents,
|
||||||
creationDate: this.creationDate,
|
creationDate: this.creationDate,
|
||||||
hasAppearance: !!this.appearance,
|
hasAppearance: !!this.appearance,
|
||||||
id: params.id,
|
id: params.id,
|
||||||
@ -242,6 +244,19 @@ class Annotation {
|
|||||||
return this._isPrintable(this.flags);
|
return this._isPrintable(this.flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the contents.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @memberof Annotation
|
||||||
|
* @param {string} contents - Text to display for the annotation or, if the
|
||||||
|
* type of annotation does not display text, a
|
||||||
|
* description of the annotation's contents
|
||||||
|
*/
|
||||||
|
setContents(contents) {
|
||||||
|
this.contents = stringToPDFString(contents || '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the creation date.
|
* Set the creation date.
|
||||||
*
|
*
|
||||||
@ -623,7 +638,6 @@ class MarkupAnnotation extends Annotation {
|
|||||||
|
|
||||||
this.data.hasPopup = dict.has('Popup');
|
this.data.hasPopup = dict.has('Popup');
|
||||||
this.data.title = stringToPDFString(dict.get('T') || '');
|
this.data.title = stringToPDFString(dict.get('T') || '');
|
||||||
this.data.contents = stringToPDFString(dict.get('Contents') || '');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +131,20 @@ describe('annotation', function() {
|
|||||||
dict = ref = null;
|
dict = ref = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set and get valid contents', function() {
|
||||||
|
const annotation = new Annotation({ dict, ref, });
|
||||||
|
annotation.setContents('Foo bar baz');
|
||||||
|
|
||||||
|
expect(annotation.contents).toEqual('Foo bar baz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not set and get invalid contents', function() {
|
||||||
|
const annotation = new Annotation({ dict, ref, });
|
||||||
|
annotation.setContents(undefined);
|
||||||
|
|
||||||
|
expect(annotation.contents).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
it('should set and get a valid creation date', function() {
|
it('should set and get a valid creation date', function() {
|
||||||
const annotation = new Annotation({ dict, ref, });
|
const annotation = new Annotation({ dict, ref, });
|
||||||
annotation.setCreationDate('D:20190422');
|
annotation.setCreationDate('D:20190422');
|
||||||
|
Loading…
Reference in New Issue
Block a user