mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Implement creation/modification date for annotations
This includes the information in the core and display layers. The date parsing logic from the document properties is rewritten according to the specification and now includes unit tests. Moreover, missing unit tests for the color of a popup annotation have been added. Finally the styling of the popup is changed slightly to make the text a bit smaller (it's currently quite large in comparison to other viewers) and to make the drop shadow a bit more subtle. The former is done to be able to easily include the modification date in the popup similar to how other viewers do this.
This commit is contained in:
parent
6cfb1e1a63
commit
be1d6626a7
11 changed files with 343 additions and 59 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
import {
|
||||
AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag,
|
||||
AnnotationType, OPS, stringToBytes, stringToPDFString, Util, warn
|
||||
AnnotationType, isString, OPS, stringToBytes, stringToPDFString, Util, warn
|
||||
} from '../shared/util';
|
||||
import { Catalog, FileSpec, ObjectLoader } from './obj';
|
||||
import { Dict, isDict, isName, isRef, isStream } from './primitives';
|
||||
|
@ -176,6 +176,8 @@ class Annotation {
|
|||
constructor(params) {
|
||||
let dict = params.dict;
|
||||
|
||||
this.setCreationDate(dict.get('CreationDate'));
|
||||
this.setModificationDate(dict.get('M'));
|
||||
this.setFlags(dict.get('F'));
|
||||
this.setRectangle(dict.getArray('Rect'));
|
||||
this.setColor(dict.getArray('C'));
|
||||
|
@ -187,8 +189,10 @@ class Annotation {
|
|||
annotationFlags: this.flags,
|
||||
borderStyle: this.borderStyle,
|
||||
color: this.color,
|
||||
creationDate: this.creationDate,
|
||||
hasAppearance: !!this.appearance,
|
||||
id: params.id,
|
||||
modificationDate: this.modificationDate,
|
||||
rect: this.rectangle,
|
||||
subtype: params.subtype,
|
||||
};
|
||||
|
@ -239,6 +243,31 @@ class Annotation {
|
|||
return this._isPrintable(this.flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @public
|
||||
* @memberof Annotation
|
||||
* @param {string} modificationDate - PDF date string that indicates when the
|
||||
* annotation was last modified
|
||||
*/
|
||||
setModificationDate(modificationDate) {
|
||||
this.modificationDate = isString(modificationDate) ?
|
||||
modificationDate : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the flags.
|
||||
*
|
||||
|
@ -947,6 +976,20 @@ 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;
|
||||
}
|
||||
|
||||
if (!parentItem.has('M')) {
|
||||
this.data.modificationDate = null;
|
||||
} else {
|
||||
this.setModificationDate(parentItem.get('M'));
|
||||
this.data.modificationDate = this.modificationDate;
|
||||
}
|
||||
|
||||
if (!parentItem.has('C')) {
|
||||
// Fall back to the default background color.
|
||||
this.data.color = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue