2012-09-01 07:48:21 +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.
|
|
|
|
*/
|
2011-10-25 10:13:12 +09:00
|
|
|
|
2017-04-02 23:14:30 +09:00
|
|
|
import { Catalog, ObjectLoader, XRef } from './obj';
|
|
|
|
import { Dict, isDict, isName, isStream } from './primitives';
|
2017-07-20 21:04:54 +09:00
|
|
|
import {
|
2017-09-02 03:27:13 +09:00
|
|
|
info, isArrayBuffer, isNum, isSpace, isString, MissingDataException, OPS,
|
|
|
|
shadow, stringToBytes, stringToPDFString, Util, warn
|
2017-07-20 21:04:54 +09:00
|
|
|
} from '../shared/util';
|
2017-04-02 23:14:30 +09:00
|
|
|
import { NullStream, Stream, StreamsSequenceStream } from './stream';
|
|
|
|
import { OperatorList, PartialEvaluator } from './evaluator';
|
|
|
|
import { AnnotationFactory } from './annotation';
|
|
|
|
import { calculateMD5 } from './crypto';
|
|
|
|
import { Linearization } from './parser';
|
2017-09-19 20:49:30 +09:00
|
|
|
import { PDFFunctionFactory } from './function';
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2011-12-09 07:18:43 +09:00
|
|
|
var Page = (function PageClosure() {
|
2013-03-14 04:24:55 +09:00
|
|
|
|
2016-11-22 06:39:04 +09:00
|
|
|
var DEFAULT_USER_UNIT = 1.0;
|
2014-03-14 22:39:35 +09:00
|
|
|
var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
|
|
|
|
2017-02-16 07:52:15 +09:00
|
|
|
function isAnnotationRenderable(annotation, intent) {
|
|
|
|
return (intent === 'display' && annotation.viewable) ||
|
|
|
|
(intent === 'print' && annotation.printable);
|
|
|
|
}
|
|
|
|
|
2017-09-19 20:49:30 +09:00
|
|
|
function Page({ pdfManager, xref, pageIndex, pageDict, ref, fontCache,
|
|
|
|
builtInCMapCache, pdfFunctionFactory, }) {
|
2013-04-09 07:14:56 +09:00
|
|
|
this.pdfManager = pdfManager;
|
2012-10-29 05:10:34 +09:00
|
|
|
this.pageIndex = pageIndex;
|
2011-10-25 10:13:12 +09:00
|
|
|
this.pageDict = pageDict;
|
|
|
|
this.xref = xref;
|
|
|
|
this.ref = ref;
|
2013-11-15 06:43:38 +09:00
|
|
|
this.fontCache = fontCache;
|
2017-02-14 22:28:31 +09:00
|
|
|
this.builtInCMapCache = builtInCMapCache;
|
2017-09-19 20:49:30 +09:00
|
|
|
this.pdfFunctionFactory = pdfFunctionFactory;
|
2016-03-03 09:48:21 +09:00
|
|
|
this.evaluatorOptions = pdfManager.evaluatorOptions;
|
2013-06-05 09:57:52 +09:00
|
|
|
this.resourcesPromise = null;
|
2017-01-09 00:51:30 +09:00
|
|
|
|
|
|
|
var uniquePrefix = 'p' + this.pageIndex + '_';
|
|
|
|
var idCounters = {
|
|
|
|
obj: 0,
|
|
|
|
};
|
|
|
|
this.idFactory = {
|
2017-04-27 19:58:44 +09:00
|
|
|
createObjId() {
|
2017-01-09 00:51:30 +09:00
|
|
|
return uniquePrefix + (++idCounters.obj);
|
|
|
|
},
|
|
|
|
};
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
|
|
|
|
2011-12-09 07:18:43 +09:00
|
|
|
Page.prototype = {
|
2012-04-05 05:43:26 +09:00
|
|
|
getPageProp: function Page_getPageProp(key) {
|
2012-04-05 03:43:04 +09:00
|
|
|
return this.pageDict.get(key);
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2016-12-06 18:21:42 +09:00
|
|
|
getInheritedPageProp: function Page_getInheritedPageProp(key, getArray) {
|
2015-05-20 22:08:55 +09:00
|
|
|
var dict = this.pageDict, valueArray = null, loopCount = 0;
|
|
|
|
var MAX_LOOP_COUNT = 100;
|
2016-12-06 18:21:42 +09:00
|
|
|
getArray = getArray || false;
|
2015-05-20 22:08:55 +09:00
|
|
|
// Always walk up the entire parent chain, to be able to find
|
|
|
|
// e.g. \Resources placed on multiple levels of the tree.
|
|
|
|
while (dict) {
|
2016-12-06 18:21:42 +09:00
|
|
|
var value = getArray ? dict.getArray(key) : dict.get(key);
|
2017-03-03 20:22:55 +09:00
|
|
|
if (value !== undefined) {
|
2015-05-20 22:08:55 +09:00
|
|
|
if (!valueArray) {
|
|
|
|
valueArray = [];
|
|
|
|
}
|
|
|
|
valueArray.push(value);
|
|
|
|
}
|
|
|
|
if (++loopCount > MAX_LOOP_COUNT) {
|
2017-03-04 20:34:29 +09:00
|
|
|
warn('getInheritedPageProp: maximum loop count exceeded for ' + key);
|
|
|
|
return valueArray ? valueArray[0] : undefined;
|
2014-03-14 22:39:35 +09:00
|
|
|
}
|
2015-05-20 22:08:55 +09:00
|
|
|
dict = dict.get('Parent');
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
2015-05-20 22:08:55 +09:00
|
|
|
if (!valueArray) {
|
2017-03-04 20:34:29 +09:00
|
|
|
return undefined;
|
2015-05-20 22:08:55 +09:00
|
|
|
}
|
2017-03-04 20:34:29 +09:00
|
|
|
if (valueArray.length === 1 || !isDict(valueArray[0])) {
|
2015-05-20 22:08:55 +09:00
|
|
|
return valueArray[0];
|
|
|
|
}
|
|
|
|
return Dict.merge(this.xref, valueArray);
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2011-10-25 10:13:12 +09:00
|
|
|
get content() {
|
2013-04-20 05:07:08 +09:00
|
|
|
return this.getPageProp('Contents');
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2011-10-25 10:13:12 +09:00
|
|
|
get resources() {
|
2014-03-14 22:39:17 +09:00
|
|
|
// For robustness: The spec states that a \Resources entry has to be
|
2015-05-20 22:08:55 +09:00
|
|
|
// present, but can be empty. Some document omit it still, in this case
|
|
|
|
// we return an empty dictionary.
|
2017-03-04 20:34:29 +09:00
|
|
|
return shadow(this, 'resources',
|
|
|
|
this.getInheritedPageProp('Resources') || Dict.empty);
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2011-10-25 10:13:12 +09:00
|
|
|
get mediaBox() {
|
2016-12-06 09:00:12 +09:00
|
|
|
var mediaBox = this.getInheritedPageProp('MediaBox', true);
|
2011-10-25 10:13:12 +09:00
|
|
|
// Reset invalid media box to letter size.
|
2017-09-02 03:27:13 +09:00
|
|
|
if (!Array.isArray(mediaBox) || mediaBox.length !== 4) {
|
2016-12-06 09:00:12 +09:00
|
|
|
return shadow(this, 'mediaBox', LETTER_SIZE_MEDIABOX);
|
2014-03-14 22:39:35 +09:00
|
|
|
}
|
2016-12-06 09:00:12 +09:00
|
|
|
return shadow(this, 'mediaBox', mediaBox);
|
|
|
|
},
|
|
|
|
|
|
|
|
get cropBox() {
|
|
|
|
var cropBox = this.getInheritedPageProp('CropBox', true);
|
|
|
|
// Reset invalid crop box to media box.
|
2017-09-02 03:27:13 +09:00
|
|
|
if (!Array.isArray(cropBox) || cropBox.length !== 4) {
|
2016-12-06 09:00:12 +09:00
|
|
|
return shadow(this, 'cropBox', this.mediaBox);
|
|
|
|
}
|
|
|
|
return shadow(this, 'cropBox', cropBox);
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2016-11-22 06:39:04 +09:00
|
|
|
get userUnit() {
|
|
|
|
var obj = this.getPageProp('UserUnit');
|
|
|
|
if (!isNum(obj) || obj <= 0) {
|
|
|
|
obj = DEFAULT_USER_UNIT;
|
|
|
|
}
|
|
|
|
return shadow(this, 'userUnit', obj);
|
|
|
|
},
|
|
|
|
|
2011-10-25 10:13:12 +09:00
|
|
|
get view() {
|
2012-02-15 04:48:58 +09:00
|
|
|
// From the spec, 6th ed., p.963:
|
|
|
|
// "The crop, bleed, trim, and art boxes should not ordinarily
|
|
|
|
// extend beyond the boundaries of the media box. If they do, they are
|
|
|
|
// effectively reduced to their intersection with the media box."
|
2016-12-06 09:00:12 +09:00
|
|
|
var mediaBox = this.mediaBox, cropBox = this.cropBox;
|
|
|
|
if (mediaBox === cropBox) {
|
2012-04-12 00:29:44 +09:00
|
|
|
return shadow(this, 'view', mediaBox);
|
2014-03-14 22:39:35 +09:00
|
|
|
}
|
2016-12-06 09:00:12 +09:00
|
|
|
var intersection = Util.intersect(cropBox, mediaBox);
|
|
|
|
return shadow(this, 'view', intersection || mediaBox);
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2011-10-25 10:13:12 +09:00
|
|
|
get rotate() {
|
2014-03-14 22:39:35 +09:00
|
|
|
var rotate = this.getInheritedPageProp('Rotate') || 0;
|
2011-10-25 10:13:12 +09:00
|
|
|
// Normalize rotation so it's a multiple of 90 and between 0 and 270
|
2013-02-01 08:31:11 +09:00
|
|
|
if (rotate % 90 !== 0) {
|
2011-10-25 10:13:12 +09:00
|
|
|
rotate = 0;
|
|
|
|
} else if (rotate >= 360) {
|
|
|
|
rotate = rotate % 360;
|
|
|
|
} else if (rotate < 0) {
|
|
|
|
// The spec doesn't cover negatives, assume its counterclockwise
|
|
|
|
// rotation. The following is the other implementation of modulo.
|
|
|
|
rotate = ((rotate % 360) + 360) % 360;
|
|
|
|
}
|
|
|
|
return shadow(this, 'rotate', rotate);
|
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2012-10-29 05:10:34 +09:00
|
|
|
getContentStream: function Page_getContentStream() {
|
2012-04-05 03:43:04 +09:00
|
|
|
var content = this.content;
|
2013-04-20 05:07:08 +09:00
|
|
|
var stream;
|
2017-09-02 03:27:13 +09:00
|
|
|
if (Array.isArray(content)) {
|
2011-10-25 10:13:12 +09:00
|
|
|
// fetching items
|
2012-10-29 05:10:34 +09:00
|
|
|
var xref = this.xref;
|
2011-10-25 10:13:12 +09:00
|
|
|
var i, n = content.length;
|
2011-12-11 08:24:54 +09:00
|
|
|
var streams = [];
|
2014-03-23 04:36:35 +09:00
|
|
|
for (i = 0; i < n; ++i) {
|
2012-04-17 06:46:26 +09:00
|
|
|
streams.push(xref.fetchIfRef(content[i]));
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2013-04-20 05:07:08 +09:00
|
|
|
stream = new StreamsSequenceStream(streams);
|
2012-04-17 06:46:26 +09:00
|
|
|
} else if (isStream(content)) {
|
2013-04-20 05:07:08 +09:00
|
|
|
stream = content;
|
|
|
|
} else {
|
2012-01-10 11:08:22 +09:00
|
|
|
// replacing non-existent page content with empty one
|
2013-04-20 05:07:08 +09:00
|
|
|
stream = new NullStream();
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
2013-04-20 05:07:08 +09:00
|
|
|
return stream;
|
2012-10-29 05:10:34 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
2014-05-02 07:17:30 +09:00
|
|
|
loadResources: function Page_loadResources(keys) {
|
2013-06-05 09:57:52 +09:00
|
|
|
if (!this.resourcesPromise) {
|
2014-03-14 22:39:35 +09:00
|
|
|
// TODO: add async getInheritedPageProp and remove this.
|
2013-06-05 09:57:52 +09:00
|
|
|
this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
|
|
|
|
}
|
2017-05-02 18:14:53 +09:00
|
|
|
return this.resourcesPromise.then(() => {
|
2017-06-13 17:22:11 +09:00
|
|
|
let objectLoader = new ObjectLoader(this.resources, keys, this.xref);
|
|
|
|
|
2014-05-02 07:17:30 +09:00
|
|
|
return objectLoader.load();
|
2017-05-02 18:14:53 +09:00
|
|
|
});
|
2013-06-05 09:57:52 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
getOperatorList({ handler, task, intent, renderInteractiveForms, }) {
|
|
|
|
var contentStreamPromise = this.pdfManager.ensure(this,
|
|
|
|
'getContentStream');
|
2013-06-05 09:57:52 +09:00
|
|
|
var resourcesPromise = this.loadResources([
|
|
|
|
'ExtGState',
|
|
|
|
'ColorSpace',
|
|
|
|
'Pattern',
|
|
|
|
'Shading',
|
|
|
|
'XObject',
|
2014-03-14 22:39:35 +09:00
|
|
|
'Font'
|
2013-06-05 09:57:52 +09:00
|
|
|
// ProcSet
|
|
|
|
// Properties
|
|
|
|
]);
|
2013-04-23 06:20:49 +09:00
|
|
|
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
var partialEvaluator = new PartialEvaluator({
|
|
|
|
pdfManager: this.pdfManager,
|
|
|
|
xref: this.xref,
|
|
|
|
handler,
|
|
|
|
pageIndex: this.pageIndex,
|
|
|
|
idFactory: this.idFactory,
|
|
|
|
fontCache: this.fontCache,
|
|
|
|
builtInCMapCache: this.builtInCMapCache,
|
|
|
|
options: this.evaluatorOptions,
|
2017-09-19 20:49:30 +09:00
|
|
|
pdfFunctionFactory: this.pdfFunctionFactory,
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
});
|
2013-04-23 06:20:49 +09:00
|
|
|
|
2014-05-10 10:21:15 +09:00
|
|
|
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
2017-05-02 18:14:53 +09:00
|
|
|
var pageListPromise = dataPromises.then(([contentStream]) => {
|
|
|
|
var opList = new OperatorList(intent, handler, this.pageIndex);
|
2013-08-01 03:17:36 +09:00
|
|
|
|
|
|
|
handler.send('StartRenderPage', {
|
2017-05-02 18:14:53 +09:00
|
|
|
transparency: partialEvaluator.hasBlendModes(this.resources),
|
|
|
|
pageIndex: this.pageIndex,
|
2017-04-27 19:58:44 +09:00
|
|
|
intent,
|
2013-08-01 03:17:36 +09:00
|
|
|
});
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
return partialEvaluator.getOperatorList({
|
|
|
|
stream: contentStream,
|
|
|
|
task,
|
|
|
|
resources: this.resources,
|
|
|
|
operatorList: opList,
|
|
|
|
}).then(function () {
|
|
|
|
return opList;
|
|
|
|
});
|
2013-04-09 07:14:56 +09:00
|
|
|
});
|
|
|
|
|
2017-02-16 07:52:15 +09:00
|
|
|
// Fetch the page's annotations and add their operator lists to the
|
|
|
|
// page's operator list to render them.
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
var annotationsPromise = this.pdfManager.ensure(this, 'annotations');
|
2014-05-10 10:21:15 +09:00
|
|
|
return Promise.all([pageListPromise, annotationsPromise]).then(
|
2017-05-02 18:14:53 +09:00
|
|
|
function ([pageOpList, annotations]) {
|
2013-05-29 07:12:35 +09:00
|
|
|
if (annotations.length === 0) {
|
2013-08-01 03:17:36 +09:00
|
|
|
pageOpList.flush(true);
|
2014-05-10 10:21:15 +09:00
|
|
|
return pageOpList;
|
2013-04-09 07:14:56 +09:00
|
|
|
}
|
|
|
|
|
2017-02-16 07:52:15 +09:00
|
|
|
// Collect the operator list promises for the annotations. Each promise
|
|
|
|
// is resolved with the complete operator list for a single annotation.
|
|
|
|
var i, ii, opListPromises = [];
|
|
|
|
for (i = 0, ii = annotations.length; i < ii; i++) {
|
|
|
|
if (isAnnotationRenderable(annotations[i], intent)) {
|
|
|
|
opListPromises.push(annotations[i].getOperatorList(
|
|
|
|
partialEvaluator, task, renderInteractiveForms));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all(opListPromises).then(function(opLists) {
|
|
|
|
pageOpList.addOp(OPS.beginAnnotations, []);
|
|
|
|
for (i = 0, ii = opLists.length; i < ii; i++) {
|
|
|
|
pageOpList.addOpList(opLists[i]);
|
|
|
|
}
|
|
|
|
pageOpList.addOp(OPS.endAnnotations, []);
|
|
|
|
|
2013-08-01 03:17:36 +09:00
|
|
|
pageOpList.flush(true);
|
2014-05-10 10:21:15 +09:00
|
|
|
return pageOpList;
|
|
|
|
});
|
|
|
|
});
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2014-03-14 22:39:35 +09:00
|
|
|
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
extractTextContent({ handler, task, normalizeWhitespace,
|
2017-04-17 21:46:53 +09:00
|
|
|
sink, combineTextItems, }) {
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
var contentStreamPromise = this.pdfManager.ensure(this,
|
|
|
|
'getContentStream');
|
2013-06-05 09:57:52 +09:00
|
|
|
var resourcesPromise = this.loadResources([
|
|
|
|
'ExtGState',
|
|
|
|
'XObject',
|
|
|
|
'Font'
|
|
|
|
]);
|
2013-04-09 07:14:56 +09:00
|
|
|
|
2017-05-02 18:14:53 +09:00
|
|
|
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
|
|
|
return dataPromises.then(([contentStream]) => {
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
var partialEvaluator = new PartialEvaluator({
|
|
|
|
pdfManager: this.pdfManager,
|
|
|
|
xref: this.xref,
|
|
|
|
handler,
|
|
|
|
pageIndex: this.pageIndex,
|
|
|
|
idFactory: this.idFactory,
|
|
|
|
fontCache: this.fontCache,
|
|
|
|
builtInCMapCache: this.builtInCMapCache,
|
|
|
|
options: this.evaluatorOptions,
|
2017-09-19 20:49:30 +09:00
|
|
|
pdfFunctionFactory: this.pdfFunctionFactory,
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
return partialEvaluator.getTextContent({
|
|
|
|
stream: contentStream,
|
|
|
|
task,
|
|
|
|
resources: this.resources,
|
|
|
|
normalizeWhitespace,
|
|
|
|
combineTextItems,
|
2017-04-17 21:46:53 +09:00
|
|
|
sink,
|
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).
Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.
With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.
*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.
---
[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-04-30 06:13:51 +09:00
|
|
|
});
|
2013-04-09 07:14:56 +09:00
|
|
|
});
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
2013-03-14 04:24:55 +09:00
|
|
|
|
2015-11-22 21:56:52 +09:00
|
|
|
getAnnotationsData: function Page_getAnnotationsData(intent) {
|
2013-03-21 17:04:44 +09:00
|
|
|
var annotations = this.annotations;
|
|
|
|
var annotationsData = [];
|
|
|
|
for (var i = 0, n = annotations.length; i < n; ++i) {
|
2017-02-16 07:52:15 +09:00
|
|
|
if (!intent || isAnnotationRenderable(annotations[i], intent)) {
|
|
|
|
annotationsData.push(annotations[i].data);
|
2015-11-22 21:56:52 +09:00
|
|
|
}
|
2013-03-14 04:24:55 +09:00
|
|
|
}
|
2013-03-21 17:04:44 +09:00
|
|
|
return annotationsData;
|
2013-03-14 04:24:55 +09:00
|
|
|
},
|
|
|
|
|
2013-03-21 17:04:44 +09:00
|
|
|
get annotations() {
|
|
|
|
var annotations = [];
|
2015-07-19 00:52:03 +09:00
|
|
|
var annotationRefs = this.getInheritedPageProp('Annots') || [];
|
2013-03-21 17:04:44 +09:00
|
|
|
for (var i = 0, n = annotationRefs.length; i < n; ++i) {
|
|
|
|
var annotationRef = annotationRefs[i];
|
2017-08-27 07:30:00 +09:00
|
|
|
var annotation = AnnotationFactory.create(this.xref, annotationRef,
|
2016-10-01 19:05:07 +09:00
|
|
|
this.pdfManager,
|
2017-01-09 00:51:30 +09:00
|
|
|
this.idFactory);
|
2015-11-22 21:56:52 +09:00
|
|
|
if (annotation) {
|
2013-03-21 17:04:44 +09:00
|
|
|
annotations.push(annotation);
|
2013-03-14 04:24:55 +09:00
|
|
|
}
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
2013-03-21 17:04:44 +09:00
|
|
|
return shadow(this, 'annotations', annotations);
|
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 18:16:24 +09:00
|
|
|
},
|
2011-10-25 10:13:12 +09:00
|
|
|
};
|
|
|
|
|
2011-12-09 07:18:43 +09:00
|
|
|
return Page;
|
2011-10-25 10:13:12 +09:00
|
|
|
})();
|
|
|
|
|
|
|
|
/**
|
2012-04-13 04:11:22 +09:00
|
|
|
* The `PDFDocument` holds all the data of the PDF file. Compared to the
|
2011-10-25 10:13:12 +09:00
|
|
|
* `PDFDoc`, this one doesn't have any job management code.
|
2012-04-13 04:11:22 +09:00
|
|
|
* Right now there exists one PDFDocument on the main thread + one object
|
2011-10-25 10:13:12 +09:00
|
|
|
* for each worker. If there is no worker support enabled, there are two
|
2012-04-13 04:11:22 +09:00
|
|
|
* `PDFDocument` objects on the main thread created.
|
2011-10-25 10:13:12 +09:00
|
|
|
*/
|
2012-04-13 04:11:22 +09:00
|
|
|
var PDFDocument = (function PDFDocumentClosure() {
|
2014-08-02 22:19:55 +09:00
|
|
|
var FINGERPRINT_FIRST_BYTES = 1024;
|
|
|
|
var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
|
|
|
|
'\x00\x00\x00\x00\x00\x00\x00\x00\x00';
|
2014-12-30 23:43:04 +09:00
|
|
|
|
2017-01-03 20:39:38 +09:00
|
|
|
function PDFDocument(pdfManager, arg) {
|
|
|
|
var stream;
|
2014-03-23 04:36:35 +09:00
|
|
|
if (isStream(arg)) {
|
2017-01-03 20:39:38 +09:00
|
|
|
stream = arg;
|
2014-03-23 04:36:35 +09:00
|
|
|
} else if (isArrayBuffer(arg)) {
|
2017-01-03 20:39:38 +09:00
|
|
|
stream = new Stream(arg);
|
2014-03-23 04:36:35 +09:00
|
|
|
} else {
|
2017-06-29 05:51:31 +09:00
|
|
|
throw new Error('PDFDocument: Unknown argument type');
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2017-07-20 21:04:54 +09:00
|
|
|
if (stream.length <= 0) {
|
|
|
|
throw new Error('PDFDocument: stream must have data');
|
|
|
|
}
|
2017-01-03 20:39:38 +09:00
|
|
|
|
2013-04-09 07:14:56 +09:00
|
|
|
this.pdfManager = pdfManager;
|
2011-10-25 10:13:12 +09:00
|
|
|
this.stream = stream;
|
2017-01-03 20:39:38 +09:00
|
|
|
this.xref = new XRef(stream, pdfManager);
|
2017-09-19 20:49:30 +09:00
|
|
|
|
|
|
|
let evaluatorOptions = pdfManager.evaluatorOptions;
|
|
|
|
this.pdfFunctionFactory = new PDFFunctionFactory({
|
|
|
|
xref: this.xref,
|
|
|
|
isEvalSupported: evaluatorOptions.isEvalSupported,
|
|
|
|
});
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function find(stream, needle, limit, backwards) {
|
|
|
|
var pos = stream.pos;
|
|
|
|
var end = stream.end;
|
2014-07-23 04:17:57 +09:00
|
|
|
var strBuf = [];
|
2014-03-23 04:36:35 +09:00
|
|
|
if (pos + limit > end) {
|
2011-10-25 10:13:12 +09:00
|
|
|
limit = end - pos;
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2014-07-23 04:17:57 +09:00
|
|
|
for (var n = 0; n < limit; ++n) {
|
|
|
|
strBuf.push(String.fromCharCode(stream.getByte()));
|
|
|
|
}
|
|
|
|
var str = strBuf.join('');
|
2011-10-25 10:13:12 +09:00
|
|
|
stream.pos = pos;
|
|
|
|
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
|
2014-08-02 01:24:51 +09:00
|
|
|
if (index === -1) {
|
2011-10-25 10:13:12 +09:00
|
|
|
return false; /* not found */
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2011-10-25 10:13:12 +09:00
|
|
|
stream.pos += index;
|
|
|
|
return true; /* found */
|
|
|
|
}
|
|
|
|
|
2012-08-07 06:32:54 +09:00
|
|
|
var DocumentInfoValidators = {
|
2012-08-04 08:11:43 +09:00
|
|
|
get entries() {
|
|
|
|
// Lazily build this since all the validation functions below are not
|
|
|
|
// defined until after this file loads.
|
|
|
|
return shadow(this, 'entries', {
|
|
|
|
Title: isString,
|
|
|
|
Author: isString,
|
|
|
|
Subject: isString,
|
|
|
|
Keywords: isString,
|
|
|
|
Creator: isString,
|
|
|
|
Producer: isString,
|
|
|
|
CreationDate: isString,
|
|
|
|
ModDate: isString,
|
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 18:16:24 +09:00
|
|
|
Trapped: isName,
|
2012-08-04 08:11:43 +09:00
|
|
|
});
|
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 18:16:24 +09:00
|
|
|
},
|
2012-08-04 08:11:43 +09:00
|
|
|
};
|
|
|
|
|
2012-04-13 04:11:22 +09:00
|
|
|
PDFDocument.prototype = {
|
2013-02-07 08:19:29 +09:00
|
|
|
parse: function PDFDocument_parse(recoveryMode) {
|
|
|
|
this.setup(recoveryMode);
|
2015-05-25 11:45:20 +09:00
|
|
|
var version = this.catalog.catDict.get('Version');
|
|
|
|
if (isName(version)) {
|
|
|
|
this.pdfFormatVersion = version.name;
|
|
|
|
}
|
2013-08-16 23:53:05 +09:00
|
|
|
try {
|
|
|
|
// checking if AcroForm is present
|
|
|
|
this.acroForm = this.catalog.catDict.get('AcroForm');
|
|
|
|
if (this.acroForm) {
|
|
|
|
this.xfa = this.acroForm.get('XFA');
|
|
|
|
var fields = this.acroForm.get('Fields');
|
2017-09-02 03:27:13 +09:00
|
|
|
if ((!fields || !Array.isArray(fields) || fields.length === 0) &&
|
2013-08-16 23:53:05 +09:00
|
|
|
!this.xfa) {
|
|
|
|
// no fields and no XFA -- not a form (?)
|
|
|
|
this.acroForm = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
2017-03-22 22:55:59 +09:00
|
|
|
if (ex instanceof MissingDataException) {
|
|
|
|
throw ex;
|
|
|
|
}
|
2013-08-16 23:53:05 +09:00
|
|
|
info('Something wrong with AcroForm entry');
|
|
|
|
this.acroForm = null;
|
|
|
|
}
|
2013-02-07 08:19:29 +09:00
|
|
|
},
|
|
|
|
|
2011-10-25 10:13:12 +09:00
|
|
|
get linearization() {
|
2014-07-02 19:48:09 +09:00
|
|
|
var linearization = null;
|
|
|
|
if (this.stream.length) {
|
2012-07-14 00:00:55 +09:00
|
|
|
try {
|
2014-07-02 19:48:09 +09:00
|
|
|
linearization = Linearization.create(this.stream);
|
2012-07-14 00:00:55 +09:00
|
|
|
} catch (err) {
|
2013-02-07 08:19:29 +09:00
|
|
|
if (err instanceof MissingDataException) {
|
|
|
|
throw err;
|
|
|
|
}
|
2014-07-02 19:48:09 +09:00
|
|
|
info(err);
|
2012-07-13 23:41:20 +09:00
|
|
|
}
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
|
|
|
// shadow the prototype getter with a data property
|
|
|
|
return shadow(this, 'linearization', linearization);
|
|
|
|
},
|
|
|
|
get startXRef() {
|
|
|
|
var stream = this.stream;
|
|
|
|
var startXRef = 0;
|
|
|
|
var linearization = this.linearization;
|
|
|
|
if (linearization) {
|
|
|
|
// Find end of first obj.
|
|
|
|
stream.reset();
|
2014-03-23 04:36:35 +09:00
|
|
|
if (find(stream, 'endobj', 1024)) {
|
2011-10-25 10:13:12 +09:00
|
|
|
startXRef = stream.pos + 6;
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2011-10-25 10:13:12 +09:00
|
|
|
} else {
|
2011-12-05 07:00:22 +09:00
|
|
|
// Find startxref by jumping backward from the end of the file.
|
|
|
|
var step = 1024;
|
2011-12-03 07:33:00 +09:00
|
|
|
var found = false, pos = stream.end;
|
2011-12-05 07:00:22 +09:00
|
|
|
while (!found && pos > 0) {
|
|
|
|
pos -= step - 'startxref'.length;
|
2014-03-23 04:36:35 +09:00
|
|
|
if (pos < 0) {
|
2011-12-03 07:33:00 +09:00
|
|
|
pos = 0;
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2011-12-03 07:33:00 +09:00
|
|
|
stream.pos = pos;
|
2011-12-05 07:00:22 +09:00
|
|
|
found = find(stream, 'startxref', step, true);
|
2011-12-03 07:33:00 +09:00
|
|
|
}
|
|
|
|
if (found) {
|
2011-10-25 10:13:12 +09:00
|
|
|
stream.skip(9);
|
|
|
|
var ch;
|
|
|
|
do {
|
2013-07-01 05:45:15 +09:00
|
|
|
ch = stream.getByte();
|
2016-06-06 16:11:33 +09:00
|
|
|
} while (isSpace(ch));
|
2011-10-25 10:13:12 +09:00
|
|
|
var str = '';
|
2013-07-01 05:45:15 +09:00
|
|
|
while (ch >= 0x20 && ch <= 0x39) { // < '9'
|
|
|
|
str += String.fromCharCode(ch);
|
|
|
|
ch = stream.getByte();
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
|
|
|
startXRef = parseInt(str, 10);
|
2014-03-23 04:36:35 +09:00
|
|
|
if (isNaN(startXRef)) {
|
2011-10-25 10:13:12 +09:00
|
|
|
startXRef = 0;
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2011-10-25 10:13:12 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// shadow the prototype getter with a data property
|
|
|
|
return shadow(this, 'startXRef', startXRef);
|
|
|
|
},
|
|
|
|
get mainXRefEntriesOffset() {
|
|
|
|
var mainXRefEntriesOffset = 0;
|
|
|
|
var linearization = this.linearization;
|
2014-03-23 04:36:35 +09:00
|
|
|
if (linearization) {
|
2011-10-25 10:13:12 +09:00
|
|
|
mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
|
2014-03-23 04:36:35 +09:00
|
|
|
}
|
2011-10-25 10:13:12 +09:00
|
|
|
// shadow the prototype getter with a data property
|
|
|
|
return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
|
|
|
|
},
|
|
|
|
// Find the header, remove leading garbage and setup the stream
|
|
|
|
// starting from the header.
|
2012-04-13 04:11:22 +09:00
|
|
|
checkHeader: function PDFDocument_checkHeader() {
|
2011-10-25 10:13:12 +09:00
|
|
|
var stream = this.stream;
|
|
|
|
stream.reset();
|
|
|
|
if (find(stream, '%PDF-', 1024)) {
|
|
|
|
// Found the header, trim off any garbage before it.
|
|
|
|
stream.moveStart();
|
2012-11-06 02:12:17 +09:00
|
|
|
// Reading file format version
|
|
|
|
var MAX_VERSION_LENGTH = 12;
|
|
|
|
var version = '', ch;
|
2013-07-01 05:45:15 +09:00
|
|
|
while ((ch = stream.getByte()) > 0x20) { // SPACE
|
2012-11-06 02:12:17 +09:00
|
|
|
if (version.length >= MAX_VERSION_LENGTH) {
|
|
|
|
break;
|
|
|
|
}
|
2013-07-01 05:45:15 +09:00
|
|
|
version += String.fromCharCode(ch);
|
2012-11-06 02:12:17 +09:00
|
|
|
}
|
2015-05-25 11:45:20 +09:00
|
|
|
if (!this.pdfFormatVersion) {
|
|
|
|
// removing "%PDF-"-prefix
|
|
|
|
this.pdfFormatVersion = version.substring(5);
|
|
|
|
}
|
2011-10-25 10:13:12 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// May not be a PDF file, continue anyway.
|
|
|
|
},
|
2013-02-07 08:19:29 +09:00
|
|
|
parseStartXRef: function PDFDocument_parseStartXRef() {
|
|
|
|
var startXRef = this.startXRef;
|
|
|
|
this.xref.setStartXRef(startXRef);
|
|
|
|
},
|
|
|
|
setup: function PDFDocument_setup(recoveryMode) {
|
|
|
|
this.xref.parse(recoveryMode);
|
2015-11-22 01:32:47 +09:00
|
|
|
var pageFactory = {
|
2017-04-27 19:58:44 +09:00
|
|
|
createPage: (pageIndex, dict, ref, fontCache, builtInCMapCache) => {
|
2017-09-19 20:49:30 +09:00
|
|
|
return new Page({
|
|
|
|
pdfManager: this.pdfManager,
|
|
|
|
xref: this.xref,
|
|
|
|
pageIndex,
|
|
|
|
pageDict: dict,
|
|
|
|
ref,
|
|
|
|
fontCache,
|
|
|
|
builtInCMapCache,
|
|
|
|
pdfFunctionFactory: this.pdfFunctionFactory,
|
|
|
|
});
|
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 18:16:24 +09:00
|
|
|
},
|
2015-11-22 01:32:47 +09:00
|
|
|
};
|
|
|
|
this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
|
2011-10-25 10:13:12 +09:00
|
|
|
},
|
|
|
|
get numPages() {
|
|
|
|
var linearization = this.linearization;
|
|
|
|
var num = linearization ? linearization.numPages : this.catalog.numPages;
|
|
|
|
// shadow the prototype getter
|
|
|
|
return shadow(this, 'numPages', num);
|
|
|
|
},
|
2013-02-07 08:19:29 +09:00
|
|
|
get documentInfo() {
|
2012-12-01 08:36:39 +09:00
|
|
|
var docInfo = {
|
2013-02-01 06:46:44 +09:00
|
|
|
PDFFormatVersion: this.pdfFormatVersion,
|
2013-08-16 23:53:05 +09:00
|
|
|
IsAcroFormPresent: !!this.acroForm,
|
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 18:16:24 +09:00
|
|
|
IsXFAPresent: !!this.xfa,
|
2012-12-01 08:36:39 +09:00
|
|
|
};
|
2013-08-09 02:02:11 +09:00
|
|
|
var infoDict;
|
|
|
|
try {
|
|
|
|
infoDict = this.xref.trailer.get('Info');
|
|
|
|
} catch (err) {
|
2017-03-22 22:02:34 +09:00
|
|
|
if (err instanceof MissingDataException) {
|
|
|
|
throw err;
|
|
|
|
}
|
2013-08-09 02:02:11 +09:00
|
|
|
info('The document information dictionary is invalid.');
|
|
|
|
}
|
|
|
|
if (infoDict) {
|
2012-08-07 06:32:54 +09:00
|
|
|
var validEntries = DocumentInfoValidators.entries;
|
2012-08-04 08:11:43 +09:00
|
|
|
// Only fill the document info with valid entries from the spec.
|
|
|
|
for (var key in validEntries) {
|
|
|
|
if (infoDict.has(key)) {
|
|
|
|
var value = infoDict.get(key);
|
|
|
|
// Make sure the value conforms to the spec.
|
|
|
|
if (validEntries[key](value)) {
|
2014-03-23 04:36:35 +09:00
|
|
|
docInfo[key] = (typeof value !== 'string' ?
|
|
|
|
value : stringToPDFString(value));
|
2012-08-04 08:11:43 +09:00
|
|
|
} else {
|
|
|
|
info('Bad value in document info for "' + key + '"');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-06 00:40:37 +09:00
|
|
|
}
|
2013-02-07 08:19:29 +09:00
|
|
|
return shadow(this, 'documentInfo', docInfo);
|
2012-03-27 06:48:04 +09:00
|
|
|
},
|
2013-02-07 08:19:29 +09:00
|
|
|
get fingerprint() {
|
2015-09-08 00:41:13 +09:00
|
|
|
var xref = this.xref, hash, fileID = '';
|
|
|
|
var idArray = xref.trailer.get('ID');
|
2013-10-03 17:09:06 +09:00
|
|
|
|
2017-09-02 03:27:13 +09:00
|
|
|
if (Array.isArray(idArray) && idArray[0] && isString(idArray[0]) &&
|
2015-09-08 00:41:13 +09:00
|
|
|
idArray[0] !== EMPTY_FINGERPRINT) {
|
2014-12-30 23:43:04 +09:00
|
|
|
hash = stringToBytes(idArray[0]);
|
2011-12-23 07:44:42 +09:00
|
|
|
} else {
|
2014-08-02 22:19:55 +09:00
|
|
|
if (this.stream.ensureRange) {
|
|
|
|
this.stream.ensureRange(0,
|
|
|
|
Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
|
|
|
|
}
|
|
|
|
hash = calculateMD5(this.stream.bytes.subarray(0,
|
|
|
|
FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
|
2013-10-03 17:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0, n = hash.length; i < n; i++) {
|
2014-08-02 22:19:55 +09:00
|
|
|
var hex = hash[i].toString(16);
|
|
|
|
fileID += hex.length === 1 ? '0' + hex : hex;
|
2011-12-23 07:44:42 +09:00
|
|
|
}
|
2012-03-27 07:14:59 +09:00
|
|
|
|
2013-02-07 08:19:29 +09:00
|
|
|
return shadow(this, 'fingerprint', fileID);
|
2011-12-23 07:44:42 +09:00
|
|
|
},
|
2013-02-07 08:19:29 +09:00
|
|
|
|
|
|
|
getPage: function PDFDocument_getPage(pageIndex) {
|
|
|
|
return this.catalog.getPage(pageIndex);
|
2013-11-15 06:43:38 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
cleanup: function PDFDocument_cleanup() {
|
|
|
|
return this.catalog.cleanup();
|
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 18:16:24 +09:00
|
|
|
},
|
2011-10-25 10:13:12 +09:00
|
|
|
};
|
|
|
|
|
2012-04-13 04:11:22 +09:00
|
|
|
return PDFDocument;
|
2011-10-25 10:13:12 +09:00
|
|
|
})();
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2017-04-02 23:14:30 +09:00
|
|
|
export {
|
|
|
|
Page,
|
|
|
|
PDFDocument,
|
|
|
|
};
|