1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58: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:
Tim van der Meij 2019-04-21 21:21:01 +02:00
parent 6cfb1e1a63
commit be1d6626a7
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
11 changed files with 343 additions and 59 deletions

View file

@ -15,7 +15,8 @@
/* eslint no-var: error */
import {
DOMCanvasFactory, DOMSVGFactory, getFilenameFromUrl, isValidFetchUrl
DOMCanvasFactory, DOMSVGFactory, getFilenameFromUrl, isValidFetchUrl,
PDFDateString
} from '../../src/display/display_utils';
import isNodeJS from '../../src/shared/is_node';
@ -220,4 +221,70 @@ describe('display_utils', function() {
expect(isValidFetchUrl('https://www.example.com')).toEqual(true);
});
});
describe('PDFDateString', function() {
describe('toDateObject', function() {
it('converts PDF date strings to JavaScript `Date` objects', function() {
const expectations = {
undefined: null,
null: null,
42: null,
'2019': null,
'D2019': null,
'D:': null,
'D:201': null,
'D:2019': new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
'D:20190': new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
'D:201900': new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
'D:201913': new Date(Date.UTC(2019, 0, 1, 0, 0, 0)),
'D:201902': new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
'D:2019020': new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
'D:20190200': new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
'D:20190232': new Date(Date.UTC(2019, 1, 1, 0, 0, 0)),
'D:20190203': new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
// Invalid dates like the 31th of April are handled by JavaScript:
'D:20190431': new Date(Date.UTC(2019, 4, 1, 0, 0, 0)),
'D:201902030': new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
'D:2019020300': new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
'D:2019020324': new Date(Date.UTC(2019, 1, 3, 0, 0, 0)),
'D:2019020304': new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
'D:20190203040': new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
'D:201902030400': new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
'D:201902030460': new Date(Date.UTC(2019, 1, 3, 4, 0, 0)),
'D:201902030405': new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
'D:2019020304050': new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
'D:20190203040500': new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
'D:20190203040560': new Date(Date.UTC(2019, 1, 3, 4, 5, 0)),
'D:20190203040506': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506F': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506Z': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506-': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506+': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506+\'': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506+0': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506+01': new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
'D:20190203040506+00\'': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506+24\'': new Date(Date.UTC(2019, 1, 3, 4, 5, 6)),
'D:20190203040506+01\'': new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
'D:20190203040506+01\'0': new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
'D:20190203040506+01\'00': new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
'D:20190203040506+01\'60': new Date(Date.UTC(2019, 1, 3, 3, 5, 6)),
'D:20190203040506+0102': new Date(Date.UTC(2019, 1, 3, 3, 3, 6)),
'D:20190203040506+01\'02': new Date(Date.UTC(2019, 1, 3, 3, 3, 6)),
'D:20190203040506+01\'02\'': new Date(Date.UTC(2019, 1, 3, 3, 3, 6)),
// Offset hour and minute that result in a day change:
'D:20190203040506+05\'07': new Date(Date.UTC(2019, 1, 2, 22, 58, 6)),
};
for (const [input, expectation] of Object.entries(expectations)) {
const result = PDFDateString.toDateObject(input);
if (result) {
expect(result.getTime()).toEqual(expectation.getTime());
} else {
expect(result).toEqual(expectation);
}
}
});
});
});
});