mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +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
|
@ -158,25 +158,33 @@
|
|||
z-index: 200;
|
||||
max-width: 20em;
|
||||
background-color: #FFFF99;
|
||||
box-shadow: 0px 2px 5px #333;
|
||||
box-shadow: 0px 2px 5px #888;
|
||||
border-radius: 2px;
|
||||
padding: 0.6em;
|
||||
padding: 6px;
|
||||
margin-left: 5px;
|
||||
cursor: pointer;
|
||||
font: message-box;
|
||||
font-size: 9px;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.annotationLayer .popup > * {
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
.annotationLayer .popup h1 {
|
||||
font-size: 1em;
|
||||
border-bottom: 1px solid #000000;
|
||||
margin: 0;
|
||||
padding-bottom: 0.2em;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.annotationLayer .popup span {
|
||||
display: inline-block;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.annotationLayer .popup p {
|
||||
margin: 0;
|
||||
padding-top: 0.2em;
|
||||
border-top: 1px solid #333;
|
||||
margin-top: 2px;
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
.annotationLayer .highlightAnnotation,
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createPromiseCapability, PDFDateString } from 'pdfjs-lib';
|
||||
import {
|
||||
getPageSizeInches, getPDFFileNameFromURL, isPortraitOrientation, NullL10n
|
||||
} from './ui_utils';
|
||||
import { createPromiseCapability } from 'pdfjs-lib';
|
||||
|
||||
const DEFAULT_FIELD_CONTENT = '-';
|
||||
|
||||
|
@ -363,50 +363,14 @@ class PDFDocumentProperties {
|
|||
* @private
|
||||
*/
|
||||
_parseDate(inputDate) {
|
||||
if (!inputDate) {
|
||||
return;
|
||||
const dateObject = PDFDateString.toDateObject(inputDate);
|
||||
if (dateObject) {
|
||||
const dateString = dateObject.toLocaleDateString();
|
||||
const timeString = dateObject.toLocaleTimeString();
|
||||
return this.l10n.get('document_properties_date_string',
|
||||
{ date: dateString, time: timeString, },
|
||||
'{{date}}, {{time}}');
|
||||
}
|
||||
// This is implemented according to the PDF specification, but note that
|
||||
// Adobe Reader doesn't handle changing the date to universal time
|
||||
// and doesn't use the user's time zone (they're effectively ignoring
|
||||
// the HH' and mm' parts of the date string).
|
||||
let dateToParse = inputDate;
|
||||
|
||||
// Remove the D: prefix if it is available.
|
||||
if (dateToParse.substring(0, 2) === 'D:') {
|
||||
dateToParse = dateToParse.substring(2);
|
||||
}
|
||||
|
||||
// Get all elements from the PDF date string.
|
||||
// JavaScript's `Date` object expects the month to be between
|
||||
// 0 and 11 instead of 1 and 12, so we're correcting for this.
|
||||
let year = parseInt(dateToParse.substring(0, 4), 10);
|
||||
let month = parseInt(dateToParse.substring(4, 6), 10) - 1;
|
||||
let day = parseInt(dateToParse.substring(6, 8), 10);
|
||||
let hours = parseInt(dateToParse.substring(8, 10), 10);
|
||||
let minutes = parseInt(dateToParse.substring(10, 12), 10);
|
||||
let seconds = parseInt(dateToParse.substring(12, 14), 10);
|
||||
let utRel = dateToParse.substring(14, 15);
|
||||
let offsetHours = parseInt(dateToParse.substring(15, 17), 10);
|
||||
let offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
|
||||
|
||||
// As per spec, utRel = 'Z' means equal to universal time.
|
||||
// The other cases ('-' and '+') have to be handled here.
|
||||
if (utRel === '-') {
|
||||
hours += offsetHours;
|
||||
minutes += offsetMinutes;
|
||||
} else if (utRel === '+') {
|
||||
hours -= offsetHours;
|
||||
minutes -= offsetMinutes;
|
||||
}
|
||||
|
||||
// Return the new date format from the user's locale.
|
||||
let date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
||||
let dateString = date.toLocaleDateString();
|
||||
let timeString = date.toLocaleTimeString();
|
||||
return this.l10n.get('document_properties_date_string',
|
||||
{ date: dateString, time: timeString, },
|
||||
'{{date}}, {{time}}');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue