2014-01-22 08:07:07 +09:00
|
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-03-20 01:27:04 +09:00
|
|
|
|
import {
|
|
|
|
|
cloneObj, getPageSizeInches, getPDFFileNameFromURL, NullL10n
|
|
|
|
|
} from './ui_utils';
|
2017-05-31 10:38:22 +09:00
|
|
|
|
import { createPromiseCapability } from 'pdfjs-lib';
|
2016-04-09 02:34:27 +09:00
|
|
|
|
|
2017-05-05 21:04:08 +09:00
|
|
|
|
const DEFAULT_FIELD_CONTENT = '-';
|
|
|
|
|
|
2018-03-20 21:51:56 +09:00
|
|
|
|
// See https://en.wikibooks.org/wiki/Lentis/Conversion_to_the_Metric_Standard_in_the_United_States
|
|
|
|
|
const NON_METRIC_LOCALES = ['en-us', 'en-lr', 'my'];
|
|
|
|
|
|
2015-04-25 04:01:03 +09:00
|
|
|
|
/**
|
|
|
|
|
* @typedef {Object} PDFDocumentPropertiesOptions
|
2015-04-25 04:19:58 +09:00
|
|
|
|
* @property {string} overlayName - Name/identifier for the overlay.
|
|
|
|
|
* @property {Object} fields - Names and elements of the overlay's fields.
|
2017-04-16 23:42:57 +09:00
|
|
|
|
* @property {HTMLDivElement} container - Div container for the overlay.
|
2015-04-25 04:19:58 +09:00
|
|
|
|
* @property {HTMLButtonElement} closeButton - Button for closing the overlay.
|
2015-04-25 04:01:03 +09:00
|
|
|
|
*/
|
|
|
|
|
|
2017-04-16 23:42:57 +09:00
|
|
|
|
class PDFDocumentProperties {
|
2015-04-25 03:47:38 +09:00
|
|
|
|
/**
|
|
|
|
|
* @param {PDFDocumentPropertiesOptions} options
|
2017-05-26 21:52:23 +09:00
|
|
|
|
* @param {OverlayManager} overlayManager - Manager for the viewer overlays.
|
2018-03-18 02:50:34 +09:00
|
|
|
|
* @param {EventBus} eventBus - The application event bus.
|
2017-05-04 10:05:53 +09:00
|
|
|
|
* @param {IL10n} l10n - Localization service.
|
2015-04-25 03:47:38 +09:00
|
|
|
|
*/
|
2017-05-26 21:52:23 +09:00
|
|
|
|
constructor({ overlayName, fields, container, closeButton, },
|
2018-03-18 02:50:34 +09:00
|
|
|
|
overlayManager, eventBus, l10n = NullL10n) {
|
2017-05-05 21:04:08 +09:00
|
|
|
|
this.overlayName = overlayName;
|
|
|
|
|
this.fields = fields;
|
|
|
|
|
this.container = container;
|
2017-05-26 21:52:23 +09:00
|
|
|
|
this.overlayManager = overlayManager;
|
2017-05-04 10:05:53 +09:00
|
|
|
|
this.l10n = l10n;
|
2015-04-25 04:19:58 +09:00
|
|
|
|
|
2017-05-05 21:04:08 +09:00
|
|
|
|
this._reset();
|
2014-01-22 08:07:07 +09:00
|
|
|
|
|
2017-05-05 21:04:08 +09:00
|
|
|
|
if (closeButton) { // Bind the event listener for the Close button.
|
|
|
|
|
closeButton.addEventListener('click', this.close.bind(this));
|
2014-01-22 08:07:07 +09:00
|
|
|
|
}
|
2017-05-26 21:52:23 +09:00
|
|
|
|
this.overlayManager.register(this.overlayName, this.container,
|
|
|
|
|
this.close.bind(this));
|
2018-03-18 02:50:34 +09:00
|
|
|
|
|
|
|
|
|
if (eventBus) {
|
|
|
|
|
eventBus.on('pagechanging', (evt) => {
|
|
|
|
|
this._currentPageNumber = evt.pageNumber;
|
|
|
|
|
});
|
2018-03-20 21:37:19 +09:00
|
|
|
|
eventBus.on('rotationchanging', (evt) => {
|
|
|
|
|
this._pagesRotation = evt.pagesRotation;
|
|
|
|
|
});
|
2018-03-18 02:50:34 +09:00
|
|
|
|
}
|
2018-03-20 21:51:56 +09:00
|
|
|
|
|
|
|
|
|
this._isNonMetricLocale = true; // The default viewer locale is 'en-us'.
|
|
|
|
|
l10n.getLanguage().then((locale) => {
|
|
|
|
|
this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
|
|
|
|
|
});
|
2015-04-25 03:47:38 +09:00
|
|
|
|
}
|
2014-01-22 08:07:07 +09:00
|
|
|
|
|
2017-04-16 23:42:57 +09:00
|
|
|
|
/**
|
|
|
|
|
* Open the document properties overlay.
|
|
|
|
|
*/
|
|
|
|
|
open() {
|
2017-05-05 21:04:08 +09:00
|
|
|
|
let freezeFieldData = (data) => {
|
|
|
|
|
Object.defineProperty(this, 'fieldData', {
|
|
|
|
|
value: Object.freeze(data),
|
|
|
|
|
writable: false,
|
|
|
|
|
enumerable: true,
|
|
|
|
|
configurable: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-26 21:52:23 +09:00
|
|
|
|
Promise.all([this.overlayManager.open(this.overlayName),
|
2017-04-16 23:42:57 +09:00
|
|
|
|
this._dataAvailableCapability.promise]).then(() => {
|
2018-03-18 02:50:34 +09:00
|
|
|
|
const currentPageNumber = this._currentPageNumber;
|
2018-03-20 21:37:19 +09:00
|
|
|
|
const pagesRotation = this._pagesRotation;
|
2018-03-18 02:50:34 +09:00
|
|
|
|
|
2017-05-05 21:04:08 +09:00
|
|
|
|
// If the document properties were previously fetched (for this PDF file),
|
|
|
|
|
// just update the dialog immediately to avoid redundant lookups.
|
2018-03-18 02:50:34 +09:00
|
|
|
|
if (this.fieldData &&
|
2018-03-20 21:37:19 +09:00
|
|
|
|
currentPageNumber === this.fieldData['_currentPageNumber'] &&
|
|
|
|
|
pagesRotation === this.fieldData['_pagesRotation']) {
|
2017-05-05 21:04:08 +09:00
|
|
|
|
this._updateUI();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-03-18 02:50:34 +09:00
|
|
|
|
|
2017-05-05 21:04:08 +09:00
|
|
|
|
// Get the document properties.
|
2018-01-17 00:24:36 +09:00
|
|
|
|
this.pdfDocument.getMetadata().then(
|
|
|
|
|
({ info, metadata, contentDispositionFilename, }) => {
|
2017-05-04 10:05:53 +09:00
|
|
|
|
return Promise.all([
|
|
|
|
|
info,
|
|
|
|
|
metadata,
|
2018-01-17 00:24:36 +09:00
|
|
|
|
contentDispositionFilename || getPDFFileNameFromURL(this.url),
|
2017-05-04 10:05:53 +09:00
|
|
|
|
this._parseFileSize(this.maybeFileSize),
|
|
|
|
|
this._parseDate(info.CreationDate),
|
2018-03-09 02:23:47 +09:00
|
|
|
|
this._parseDate(info.ModDate),
|
2018-03-18 02:50:34 +09:00
|
|
|
|
this.pdfDocument.getPage(currentPageNumber).then((pdfPage) => {
|
2018-03-20 21:37:19 +09:00
|
|
|
|
return this._parsePageSize(getPageSizeInches(pdfPage),
|
|
|
|
|
pagesRotation);
|
2018-03-09 02:23:47 +09:00
|
|
|
|
}),
|
2017-05-04 10:05:53 +09:00
|
|
|
|
]);
|
2018-03-18 01:10:37 +09:00
|
|
|
|
}).then(([info, metadata, fileName, fileSize, creationDate, modDate,
|
2018-03-20 21:51:56 +09:00
|
|
|
|
pageSize]) => {
|
2017-05-05 21:04:08 +09:00
|
|
|
|
freezeFieldData({
|
2018-01-17 00:24:36 +09:00
|
|
|
|
'fileName': fileName,
|
2017-05-04 10:05:53 +09:00
|
|
|
|
'fileSize': fileSize,
|
2017-05-05 21:04:08 +09:00
|
|
|
|
'title': info.Title,
|
|
|
|
|
'author': info.Author,
|
|
|
|
|
'subject': info.Subject,
|
|
|
|
|
'keywords': info.Keywords,
|
2017-05-04 10:05:53 +09:00
|
|
|
|
'creationDate': creationDate,
|
2018-01-17 00:24:36 +09:00
|
|
|
|
'modificationDate': modDate,
|
2017-05-05 21:04:08 +09:00
|
|
|
|
'creator': info.Creator,
|
|
|
|
|
'producer': info.Producer,
|
|
|
|
|
'version': info.PDFFormatVersion,
|
|
|
|
|
'pageCount': this.pdfDocument.numPages,
|
2018-03-20 21:51:56 +09:00
|
|
|
|
'pageSize': pageSize,
|
2018-03-18 02:50:34 +09:00
|
|
|
|
'_currentPageNumber': currentPageNumber,
|
2018-03-20 21:37:19 +09:00
|
|
|
|
'_pagesRotation': pagesRotation,
|
2017-05-05 21:04:08 +09:00
|
|
|
|
});
|
|
|
|
|
this._updateUI();
|
|
|
|
|
|
|
|
|
|
// Get the correct fileSize, since it may not have been set (if
|
|
|
|
|
// `this.setFileSize` wasn't called) or may be incorrectly set.
|
|
|
|
|
return this.pdfDocument.getDownloadInfo();
|
|
|
|
|
}).then(({ length, }) => {
|
2018-03-18 01:53:13 +09:00
|
|
|
|
this.maybeFileSize = length;
|
2017-05-04 10:05:53 +09:00
|
|
|
|
return this._parseFileSize(length);
|
|
|
|
|
}).then((fileSize) => {
|
2018-03-18 01:53:13 +09:00
|
|
|
|
if (fileSize === this.fieldData['fileSize']) {
|
|
|
|
|
return; // The fileSize has already been correctly set.
|
|
|
|
|
}
|
2017-05-05 21:04:08 +09:00
|
|
|
|
let data = cloneObj(this.fieldData);
|
2017-05-04 10:05:53 +09:00
|
|
|
|
data['fileSize'] = fileSize;
|
2017-05-05 21:04:08 +09:00
|
|
|
|
|
|
|
|
|
freezeFieldData(data);
|
|
|
|
|
this._updateUI();
|
|
|
|
|
});
|
2017-04-16 23:42:57 +09:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Close the document properties overlay.
|
|
|
|
|
*/
|
|
|
|
|
close() {
|
2017-05-26 21:52:23 +09:00
|
|
|
|
this.overlayManager.close(this.overlayName);
|
2017-04-16 23:42:57 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a reference to the PDF document and the URL in order
|
|
|
|
|
* to populate the overlay fields with the document properties.
|
|
|
|
|
* Note that the overlay will contain no information if this method
|
|
|
|
|
* is not called.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} pdfDocument - A reference to the PDF document.
|
|
|
|
|
* @param {string} url - The URL of the document.
|
|
|
|
|
*/
|
2017-05-05 21:04:08 +09:00
|
|
|
|
setDocument(pdfDocument, url) {
|
|
|
|
|
if (this.pdfDocument) {
|
|
|
|
|
this._reset();
|
|
|
|
|
this._updateUI(true);
|
|
|
|
|
}
|
|
|
|
|
if (!pdfDocument) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-16 23:42:57 +09:00
|
|
|
|
this.pdfDocument = pdfDocument;
|
|
|
|
|
this.url = url;
|
2017-05-05 21:04:08 +09:00
|
|
|
|
|
2017-04-16 23:42:57 +09:00
|
|
|
|
this._dataAvailableCapability.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-05-05 21:04:08 +09:00
|
|
|
|
* Set the file size of the PDF document. This method is used to
|
|
|
|
|
* update the file size in the document properties overlay once it
|
|
|
|
|
* is known so we do not have to wait until the entire file is loaded.
|
|
|
|
|
*
|
|
|
|
|
* @param {number} fileSize - The file size of the PDF document.
|
2017-04-16 23:42:57 +09:00
|
|
|
|
*/
|
2017-05-05 21:04:08 +09:00
|
|
|
|
setFileSize(fileSize) {
|
2018-03-18 01:53:13 +09:00
|
|
|
|
if (Number.isInteger(fileSize) && fileSize > 0) {
|
2017-05-05 21:04:08 +09:00
|
|
|
|
this.maybeFileSize = fileSize;
|
2017-04-16 23:42:57 +09:00
|
|
|
|
}
|
2017-05-05 21:04:08 +09:00
|
|
|
|
}
|
2017-04-16 23:42:57 +09:00
|
|
|
|
|
2017-05-05 21:04:08 +09:00
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_reset() {
|
|
|
|
|
this.pdfDocument = null;
|
|
|
|
|
this.url = null;
|
|
|
|
|
|
|
|
|
|
this.maybeFileSize = 0;
|
|
|
|
|
delete this.fieldData;
|
|
|
|
|
this._dataAvailableCapability = createPromiseCapability();
|
2018-03-18 02:50:34 +09:00
|
|
|
|
this._currentPageNumber = 1;
|
2018-03-20 21:37:19 +09:00
|
|
|
|
this._pagesRotation = 0;
|
2017-04-16 23:42:57 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-05-05 21:04:08 +09:00
|
|
|
|
* Always updates all of the dialog fields, to prevent inconsistent UI state.
|
|
|
|
|
* NOTE: If the contents of a particular field is neither a non-empty string,
|
|
|
|
|
* nor a number, it will fall back to `DEFAULT_FIELD_CONTENT`.
|
2017-04-16 23:42:57 +09:00
|
|
|
|
* @private
|
|
|
|
|
*/
|
2017-05-05 21:04:08 +09:00
|
|
|
|
_updateUI(reset = false) {
|
|
|
|
|
if (reset || !this.fieldData) {
|
|
|
|
|
for (let id in this.fields) {
|
|
|
|
|
this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-26 21:52:23 +09:00
|
|
|
|
if (this.overlayManager.active !== this.overlayName) {
|
2017-05-05 21:04:08 +09:00
|
|
|
|
// Don't bother updating the dialog if has already been closed,
|
|
|
|
|
// since it will be updated the next time `this.open` is called.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (let id in this.fields) {
|
|
|
|
|
let content = this.fieldData[id];
|
|
|
|
|
this.fields[id].textContent = (content || content === 0) ?
|
|
|
|
|
content : DEFAULT_FIELD_CONTENT;
|
2017-04-16 23:42:57 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2017-05-05 21:04:08 +09:00
|
|
|
|
_parseFileSize(fileSize = 0) {
|
|
|
|
|
let kb = fileSize / 1024;
|
2017-04-16 23:42:57 +09:00
|
|
|
|
if (!kb) {
|
2017-05-04 10:05:53 +09:00
|
|
|
|
return Promise.resolve(undefined);
|
2017-04-16 23:42:57 +09:00
|
|
|
|
} else if (kb < 1024) {
|
2017-05-04 10:05:53 +09:00
|
|
|
|
return this.l10n.get('document_properties_kb', {
|
2017-04-16 23:42:57 +09:00
|
|
|
|
size_kb: (+kb.toPrecision(3)).toLocaleString(),
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
|
size_b: fileSize.toLocaleString(),
|
2017-04-16 23:42:57 +09:00
|
|
|
|
}, '{{size_kb}} KB ({{size_b}} bytes)');
|
|
|
|
|
}
|
2017-05-04 10:05:53 +09:00
|
|
|
|
return this.l10n.get('document_properties_mb', {
|
2017-04-16 23:42:57 +09:00
|
|
|
|
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
|
size_b: fileSize.toLocaleString(),
|
2017-04-16 23:42:57 +09:00
|
|
|
|
}, '{{size_mb}} MB ({{size_b}} bytes)');
|
|
|
|
|
}
|
2014-01-22 08:07:07 +09:00
|
|
|
|
|
2018-03-09 02:23:47 +09:00
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2018-03-20 21:37:19 +09:00
|
|
|
|
_parsePageSize(pageSizeInches, pagesRotation) {
|
2018-03-09 02:23:47 +09:00
|
|
|
|
if (!pageSizeInches) {
|
2018-03-20 21:51:56 +09:00
|
|
|
|
return Promise.resolve(undefined);
|
2018-03-09 02:23:47 +09:00
|
|
|
|
}
|
2018-03-20 21:37:19 +09:00
|
|
|
|
// Take the viewer rotation into account as well; compare with Adobe Reader.
|
|
|
|
|
if (pagesRotation % 180 !== 0) {
|
|
|
|
|
pageSizeInches = {
|
|
|
|
|
width: pageSizeInches.height,
|
|
|
|
|
height: pageSizeInches.width,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-03-20 21:51:56 +09:00
|
|
|
|
|
|
|
|
|
const sizeInches = {
|
|
|
|
|
width: Math.round(pageSizeInches.width * 100) / 100,
|
|
|
|
|
height: Math.round(pageSizeInches.height * 100) / 100,
|
|
|
|
|
};
|
|
|
|
|
// 1in == 25.4mm; no need to round to 2 decimals for millimeters.
|
|
|
|
|
const sizeMillimeters = {
|
|
|
|
|
width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
|
|
|
|
|
height: Math.round(pageSizeInches.height * 25.4 * 10) / 10,
|
|
|
|
|
};
|
2018-03-18 01:10:37 +09:00
|
|
|
|
|
2018-03-09 02:23:47 +09:00
|
|
|
|
return Promise.all([
|
2018-03-20 21:51:56 +09:00
|
|
|
|
(this._isNonMetricLocale ? sizeInches : sizeMillimeters),
|
|
|
|
|
this.l10n.get('document_properties_page_size_unit_' +
|
|
|
|
|
(this._isNonMetricLocale ? 'inches' : 'millimeters'), null,
|
|
|
|
|
this._isNonMetricLocale ? 'in' : 'mm'),
|
|
|
|
|
]).then(([{ width, height, }, unit]) => {
|
|
|
|
|
return this.l10n.get('document_properties_page_size_dimension_string', {
|
|
|
|
|
width: width.toLocaleString(),
|
|
|
|
|
height: height.toLocaleString(),
|
|
|
|
|
unit,
|
|
|
|
|
}, '{{width}} × {{height}} {{unit}}');
|
2018-03-09 02:23:47 +09:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 23:42:57 +09:00
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_parseDate(inputDate) {
|
2017-05-05 21:04:08 +09:00
|
|
|
|
if (!inputDate) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-16 23:42:57 +09:00
|
|
|
|
// 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).
|
2017-05-05 21:04:08 +09:00
|
|
|
|
let dateToParse = inputDate;
|
2014-01-22 08:07:07 +09:00
|
|
|
|
|
2017-04-16 23:42:57 +09:00
|
|
|
|
// Remove the D: prefix if it is available.
|
|
|
|
|
if (dateToParse.substring(0, 2) === 'D:') {
|
|
|
|
|
dateToParse = dateToParse.substring(2);
|
|
|
|
|
}
|
2014-01-22 08:07:07 +09:00
|
|
|
|
|
2017-04-16 23:42:57 +09:00
|
|
|
|
// 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.
|
2017-06-30 19:55:22 +09:00
|
|
|
|
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);
|
2017-04-16 23:42:57 +09:00
|
|
|
|
|
|
|
|
|
// 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;
|
2014-01-22 08:07:07 +09:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 23:42:57 +09:00
|
|
|
|
// Return the new date format from the user's locale.
|
2017-06-30 19:55:22 +09:00
|
|
|
|
let date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
|
|
|
|
let dateString = date.toLocaleDateString();
|
|
|
|
|
let timeString = date.toLocaleTimeString();
|
2017-05-04 10:05:53 +09:00
|
|
|
|
return this.l10n.get('document_properties_date_string',
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
|
{ date: dateString, time: timeString, },
|
2017-05-04 10:05:53 +09:00
|
|
|
|
'{{date}}, {{time}}');
|
2017-04-16 23:42:57 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
|
export {
|
|
|
|
|
PDFDocumentProperties,
|
|
|
|
|
};
|