2013-02-06 15:19:29 -08: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.
|
|
|
|
*/
|
|
|
|
|
2017-04-02 16:14:30 +02:00
|
|
|
import {
|
2018-06-23 21:34:31 +02:00
|
|
|
createValidAbsoluteUrl, MissingDataException, shadow, unreachable, warn
|
2017-04-02 16:14:30 +02:00
|
|
|
} from '../shared/util';
|
|
|
|
import { ChunkedStreamManager } from './chunked_stream';
|
|
|
|
import { PDFDocument } from './document';
|
|
|
|
import { Stream } from './stream';
|
2015-11-21 10:32:47 -06:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
class BasePdfManager {
|
|
|
|
constructor() {
|
|
|
|
if (this.constructor === BasePdfManager) {
|
|
|
|
unreachable('Cannot initialize BasePdfManager.');
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
}
|
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
get docId() {
|
|
|
|
return this._docId;
|
|
|
|
}
|
2015-10-27 17:48:10 -05:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
get password() {
|
|
|
|
return this._password;
|
|
|
|
}
|
2017-01-03 12:39:38 +01:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
get docBaseUrl() {
|
|
|
|
let docBaseUrl = null;
|
|
|
|
if (this._docBaseUrl) {
|
|
|
|
const absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
|
|
|
|
if (absoluteUrl) {
|
|
|
|
docBaseUrl = absoluteUrl.href;
|
|
|
|
} else {
|
|
|
|
warn(`Invalid absolute docBaseUrl: "${this._docBaseUrl}".`);
|
2016-10-01 12:05:07 +02:00
|
|
|
}
|
2018-06-23 21:34:31 +02:00
|
|
|
}
|
|
|
|
return shadow(this, 'docBaseUrl', docBaseUrl);
|
|
|
|
}
|
2016-10-01 12:05:07 +02:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
onLoadedStream() {
|
|
|
|
unreachable('Abstract method `onLoadedStream` called');
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
ensureDoc(prop, args) {
|
|
|
|
return this.ensure(this.pdfDocument, prop, args);
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
ensureXRef(prop, args) {
|
|
|
|
return this.ensure(this.pdfDocument.xref, prop, args);
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
ensureCatalog(prop, args) {
|
|
|
|
return this.ensure(this.pdfDocument.catalog, prop, args);
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
getPage(pageIndex) {
|
|
|
|
return this.pdfDocument.getPage(pageIndex);
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
cleanup() {
|
|
|
|
return this.pdfDocument.cleanup();
|
|
|
|
}
|
2013-11-14 13:43:38 -08:00
|
|
|
|
2018-07-30 13:58:09 +02:00
|
|
|
async ensure(obj, prop, args) {
|
2018-06-23 21:34:31 +02:00
|
|
|
unreachable('Abstract method `ensure` called');
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
requestRange(begin, end) {
|
|
|
|
unreachable('Abstract method `requestRange` called');
|
|
|
|
}
|
2013-04-18 10:41:33 -07:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
requestLoadedStream() {
|
|
|
|
unreachable('Abstract method `requestLoadedStream` called');
|
|
|
|
}
|
2013-05-09 17:35:23 -05:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
sendProgressiveData(chunk) {
|
|
|
|
unreachable('Abstract method `sendProgressiveData` called');
|
|
|
|
}
|
2014-09-05 20:02:54 -05:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
updatePassword(password) {
|
|
|
|
this._password = password;
|
|
|
|
}
|
2014-05-02 01:38:49 +02:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
terminate() {
|
|
|
|
unreachable('Abstract method `terminate` called');
|
|
|
|
}
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
class LocalPdfManager extends BasePdfManager {
|
|
|
|
constructor(docId, data, password, evaluatorOptions, docBaseUrl) {
|
|
|
|
super();
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2015-10-27 17:48:10 -05:00
|
|
|
this._docId = docId;
|
2017-01-03 12:39:38 +01:00
|
|
|
this._password = password;
|
2016-10-01 12:05:07 +02:00
|
|
|
this._docBaseUrl = docBaseUrl;
|
2016-03-02 18:48:21 -06:00
|
|
|
this.evaluatorOptions = evaluatorOptions;
|
2018-06-23 21:34:31 +02:00
|
|
|
|
|
|
|
const stream = new Stream(data);
|
2017-01-03 12:39:38 +01:00
|
|
|
this.pdfDocument = new PDFDocument(this, stream);
|
2018-06-23 21:34:31 +02:00
|
|
|
this._loadedStreamPromise = Promise.resolve(stream);
|
2013-02-06 15:19:29 -08:00
|
|
|
}
|
|
|
|
|
2018-07-30 13:58:09 +02:00
|
|
|
async ensure(obj, prop, args) {
|
|
|
|
const value = obj[prop];
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
return value.apply(obj, args);
|
|
|
|
}
|
|
|
|
return value;
|
2018-06-23 21:34:31 +02:00
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
requestRange(begin, end) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
2013-04-18 10:41:33 -07:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
requestLoadedStream() {}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
onLoadedStream() {
|
|
|
|
return this._loadedStreamPromise;
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
terminate() {}
|
|
|
|
}
|
2013-09-25 16:25:41 -05:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
class NetworkPdfManager extends BasePdfManager {
|
|
|
|
constructor(docId, pdfNetworkStream, args, evaluatorOptions, docBaseUrl) {
|
|
|
|
super();
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2015-10-27 17:48:10 -05:00
|
|
|
this._docId = docId;
|
2017-01-03 12:39:38 +01:00
|
|
|
this._password = args.password;
|
2016-10-01 12:05:07 +02:00
|
|
|
this._docBaseUrl = docBaseUrl;
|
2016-02-09 14:55:11 -06:00
|
|
|
this.msgHandler = args.msgHandler;
|
2016-03-02 18:48:21 -06:00
|
|
|
this.evaluatorOptions = evaluatorOptions;
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
this.streamManager = new ChunkedStreamManager(pdfNetworkStream, {
|
2016-02-09 14:55:11 -06:00
|
|
|
msgHandler: args.msgHandler,
|
|
|
|
length: args.length,
|
2013-11-18 11:17:26 -08:00
|
|
|
disableAutoFetch: args.disableAutoFetch,
|
Fix inconsistent spacing and trailing commas in objects in `src/core/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
*Unfortunately this patch is fairly big, even though it only covers the `src/core` folder, but splitting it even further seemed difficult.*
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 *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/src/core/evaluator.js b/src/core/evaluator.js
index abab9027..dcd3594b 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -2785,7 +2785,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false, };
t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false, };
t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false, };
- t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false, };
+ t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1,
+ variableArgs: false, };
t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false, };
t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false, };
t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false, };
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 5a17d482..71671541 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -123,19 +123,22 @@ var Jbig2Image = (function Jbig2ImageClosure() {
{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -2, y: 0, },
{ x: -1, y: 0, }],
[{ x: -3, y: -1, }, { x: -2, y: -1, }, { x: -1, y: -1, }, { x: 0, y: -1, },
- { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, }, { x: -1, y: 0, }]
+ { x: 1, y: -1, }, { x: -4, y: 0, }, { x: -3, y: 0, }, { x: -2, y: 0, },
+ { x: -1, y: 0, }]
];
var RefinementTemplates = [
{
coding: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
- { x: 1, y: 0, }, { x: -1, y: 1, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
+ reference: [{ x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, },
+ { x: 0, y: 0, }, { x: 1, y: 0, }, { x: -1, y: 1, },
+ { x: 0, y: 1, }, { x: 1, y: 1, }],
},
{
- coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, }, { x: -1, y: 0, }],
- reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, }, { x: 1, y: 0, },
- { x: 0, y: 1, }, { x: 1, y: 1, }],
+ coding: [{ x: -1, y: -1, }, { x: 0, y: -1, }, { x: 1, y: -1, },
+ { x: -1, y: 0, }],
+ reference: [{ x: 0, y: -1, }, { x: -1, y: 0, }, { x: 0, y: 0, },
+ { x: 1, y: 0, }, { x: 0, y: 1, }, { x: 1, y: 1, }],
}
];
```
2017-06-02 11:16:24 +02:00
|
|
|
rangeChunkSize: args.rangeChunkSize,
|
2018-06-23 21:34:31 +02:00
|
|
|
});
|
2017-01-03 12:39:38 +01:00
|
|
|
this.pdfDocument = new PDFDocument(this, this.streamManager.getStream());
|
2013-02-06 15:19:29 -08:00
|
|
|
}
|
|
|
|
|
2018-07-30 13:58:09 +02:00
|
|
|
async ensure(obj, prop, args) {
|
|
|
|
try {
|
|
|
|
const value = obj[prop];
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
return value.apply(obj, args);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
} catch (ex) {
|
|
|
|
if (!(ex instanceof MissingDataException)) {
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
await this.requestRange(ex.begin, ex.end);
|
|
|
|
return this.ensure(obj, prop, args);
|
|
|
|
}
|
2018-06-23 21:34:31 +02:00
|
|
|
}
|
2013-04-18 10:41:33 -07:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
requestRange(begin, end) {
|
|
|
|
return this.streamManager.requestRange(begin, end);
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
requestLoadedStream() {
|
|
|
|
this.streamManager.requestAllChunks();
|
|
|
|
}
|
2014-09-05 20:02:54 -05:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
sendProgressiveData(chunk) {
|
|
|
|
this.streamManager.onReceiveData({ chunk, });
|
|
|
|
}
|
2013-02-06 15:19:29 -08:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
onLoadedStream() {
|
|
|
|
return this.streamManager.onLoadedStream();
|
|
|
|
}
|
2013-09-25 16:25:41 -05:00
|
|
|
|
2018-06-23 21:34:31 +02:00
|
|
|
terminate() {
|
|
|
|
this.streamManager.abort();
|
|
|
|
}
|
|
|
|
}
|
2015-11-21 10:32:47 -06:00
|
|
|
|
2017-04-02 16:14:30 +02:00
|
|
|
export {
|
|
|
|
LocalPdfManager,
|
|
|
|
NetworkPdfManager,
|
|
|
|
};
|