Skip to content

Commit

Permalink
Implement creation date only for markup annotations
Browse files Browse the repository at this point in the history
The specification states that `CreationDate` is only available for
markup annotations instead of for all annotation types.

(Note that the creation date logic is still tested in e.g. the popup
annotation unit tests, even though the generic setter is now removed.)
  • Loading branch information
timvandermeij committed May 18, 2019
1 parent cf07918 commit 95ace1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
27 changes: 6 additions & 21 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ class Annotation {
const dict = params.dict;

this.setContents(dict.get('Contents'));
this.setCreationDate(dict.get('CreationDate'));
this.setModificationDate(dict.get('M'));
this.setFlags(dict.get('F'));
this.setRectangle(dict.getArray('Rect'));
Expand All @@ -190,7 +189,6 @@ class Annotation {
borderStyle: this.borderStyle,
color: this.color,
contents: this.contents,
creationDate: this.creationDate,
hasAppearance: !!this.appearance,
id: params.id,
modificationDate: this.modificationDate,
Expand Down Expand Up @@ -257,18 +255,6 @@ class Annotation {
this.contents = stringToPDFString(contents || '');
}

/**
* Set the creation date.
*
* @public
* @memberof Annotation
* @param {string} creationDate - PDF date string that indicates when the
* annotation was originally created
*/
setCreationDate(creationDate) {
this.creationDate = isString(creationDate) ? creationDate : null;
}

/**
* Set the modification date.
*
Expand Down Expand Up @@ -629,13 +615,16 @@ class AnnotationBorderStyle {
class MarkupAnnotation extends Annotation {
constructor(parameters) {
super(parameters);
const dict = parameters.dict;

const dict = parameters.dict;
if (!dict.has('C')) {
// Fall back to the default background color.
this.data.color = null;
}

const creationDate = dict.get('CreationDate');
this.data.creationDate = isString(creationDate) ? creationDate : null;

this.data.hasPopup = dict.has('Popup');
this.data.title = stringToPDFString(dict.get('T') || '');
}
Expand Down Expand Up @@ -989,12 +978,8 @@ class PopupAnnotation extends Annotation {
this.data.title = stringToPDFString(parentItem.get('T') || '');
this.data.contents = stringToPDFString(parentItem.get('Contents') || '');

if (!parentItem.has('CreationDate')) {
this.data.creationDate = null;
} else {
this.setCreationDate(parentItem.get('CreationDate'));
this.data.creationDate = this.creationDate;
}
const creationDate = parentItem.get('CreationDate');
this.data.creationDate = isString(creationDate) ? creationDate : null;

if (!parentItem.has('M')) {
this.data.modificationDate = null;
Expand Down
16 changes: 1 addition & 15 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,14 @@ describe('annotation', function() {
expect(annotation.contents).toEqual('');
});

it('should set and get a valid creation date', function() {
const annotation = new Annotation({ dict, ref, });
annotation.setCreationDate('D:20190422');

expect(annotation.creationDate).toEqual('D:20190422');
});

it('should set and get an invalid creation date', function() {
const annotation = new Annotation({ dict, ref, });
annotation.setCreationDate(undefined);

expect(annotation.creationDate).toEqual(null);
});

it('should set and get a valid modification date', function() {
const annotation = new Annotation({ dict, ref, });
annotation.setModificationDate('D:20190422');

expect(annotation.modificationDate).toEqual('D:20190422');
});

it('should set and get an invalid modification date', function() {
it('should not set and get an invalid modification date', function() {
const annotation = new Annotation({ dict, ref, });
annotation.setModificationDate(undefined);

Expand Down

0 comments on commit 95ace1f

Please sign in to comment.