Merge pull request #7053 from yurydelendik/rm-pdfjs-core

Removes global PDFJS usage from the src/core/.
This commit is contained in:
Brendan Dahl 2016-03-25 13:19:43 -07:00
commit df7afcf004
28 changed files with 485 additions and 394 deletions

View File

@ -17,17 +17,14 @@
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/core/bidi', ['exports', 'pdfjs/shared/global'], factory); define('pdfjs/core/bidi', ['exports'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/global.js')); factory(exports);
} else { } else {
factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal); factory((root.pdfjsCoreBidi = {}));
} }
}(this, function (exports, sharedGlobal) { }(this, function (exports) {
var PDFJS = sharedGlobal.PDFJS;
var bidi = PDFJS.bidi = (function bidiClosure() {
// Character types for symbols from 0000 to 00FF. // Character types for symbols from 0000 to 00FF.
var baseTypes = [ var baseTypes = [
'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
@ -430,8 +427,5 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
return createBidiText(chars.join(''), isLTR); return createBidiText(chars.join(''), isLTR);
} }
return bidi;
})();
exports.bidi = bidi; exports.bidi = bidi;
})); }));

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS */
'use strict'; 'use strict';
@ -35,7 +34,6 @@ var assert = sharedUtil.assert;
var error = sharedUtil.error; var error = sharedUtil.error;
var isInt = sharedUtil.isInt; var isInt = sharedUtil.isInt;
var isString = sharedUtil.isString; var isString = sharedUtil.isString;
var warn = sharedUtil.warn;
var isName = corePrimitives.isName; var isName = corePrimitives.isName;
var isCmd = corePrimitives.isCmd; var isCmd = corePrimitives.isCmd;
var isStream = corePrimitives.isStream; var isStream = corePrimitives.isStream;

View File

@ -79,6 +79,7 @@ var Page = (function PageClosure() {
this.idCounters = { this.idCounters = {
obj: 0 obj: 0
}; };
this.evaluatorOptions = pdfManager.evaluatorOptions;
this.resourcesPromise = null; this.resourcesPromise = null;
} }
@ -224,7 +225,8 @@ var Page = (function PageClosure() {
handler, this.pageIndex, handler, this.pageIndex,
'p' + this.pageIndex + '_', 'p' + this.pageIndex + '_',
this.idCounters, this.idCounters,
this.fontCache); this.fontCache,
this.evaluatorOptions);
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]); var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
var pageListPromise = dataPromises.then(function(data) { var pageListPromise = dataPromises.then(function(data) {
@ -289,7 +291,8 @@ var Page = (function PageClosure() {
handler, self.pageIndex, handler, self.pageIndex,
'p' + self.pageIndex + '_', 'p' + self.pageIndex + '_',
self.idCounters, self.idCounters,
self.fontCache); self.fontCache,
self.evaluatorOptions);
return partialEvaluator.getTextContent(contentStream, return partialEvaluator.getTextContent(contentStream,
task, task,

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS */
'use strict'; 'use strict';
@ -108,8 +107,15 @@ var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode; var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
var PartialEvaluator = (function PartialEvaluatorClosure() { var PartialEvaluator = (function PartialEvaluatorClosure() {
var DefaultPartialEvaluatorOptions = {
forceDataSchema: false,
maxImageSize: -1,
disableFontFace: false,
cMapOptions: { url: null, packed: false }
};
function PartialEvaluator(pdfManager, xref, handler, pageIndex, function PartialEvaluator(pdfManager, xref, handler, pageIndex,
uniquePrefix, idCounters, fontCache) { uniquePrefix, idCounters, fontCache, options) {
this.pdfManager = pdfManager; this.pdfManager = pdfManager;
this.xref = xref; this.xref = xref;
this.handler = handler; this.handler = handler;
@ -117,6 +123,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
this.uniquePrefix = uniquePrefix; this.uniquePrefix = uniquePrefix;
this.idCounters = idCounters; this.idCounters = idCounters;
this.fontCache = fontCache; this.fontCache = fontCache;
this.options = options || DefaultPartialEvaluatorOptions;
} }
// Trying to minimize Date.now() usage and check every 100 time // Trying to minimize Date.now() usage and check every 100 time
@ -275,7 +282,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
warn('Image dimensions are missing, or not numbers.'); warn('Image dimensions are missing, or not numbers.');
return; return;
} }
if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) { var maxImageSize = this.options.maxImageSize;
if (maxImageSize !== -1 && w * h > maxImageSize) {
warn('Image exceeded maximum allowed size and was removed.'); warn('Image exceeded maximum allowed size and was removed.');
return; return;
} }
@ -339,11 +347,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// These JPEGs don't need any more processing so we can just send it. // These JPEGs don't need any more processing so we can just send it.
operatorList.addOp(OPS.paintJpegXObject, args); operatorList.addOp(OPS.paintJpegXObject, args);
this.handler.send('obj', this.handler.send('obj',
[objId, this.pageIndex, 'JpegStream', image.getIR()]); [objId, this.pageIndex, 'JpegStream',
image.getIR(this.options.forceDataSchema)]);
return; return;
} }
PDFImage.buildImage(self.handler, self.xref, resources, image, inline). PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
this.options.forceDataSchema).
then(function(imageObj) { then(function(imageObj) {
var imgData = imageObj.createImageData(/* forceRGBA = */ false); var imgData = imageObj.createImageData(/* forceRGBA = */ false);
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData], self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
@ -451,7 +461,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var glyphs = font.charsToGlyphs(chars); var glyphs = font.charsToGlyphs(chars);
var isAddToPathSet = !!(state.textRenderingMode & var isAddToPathSet = !!(state.textRenderingMode &
TextRenderingMode.ADD_TO_PATH_FLAG); TextRenderingMode.ADD_TO_PATH_FLAG);
if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) { if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
var buildPath = function (fontChar) { var buildPath = function (fontChar) {
if (!font.renderer.hasBuiltPath(fontChar)) { if (!font.renderer.hasBuiltPath(fontChar)) {
var path = font.renderer.getPathJs(fontChar); var path = font.renderer.getPathJs(fontChar);
@ -1174,7 +1184,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
function runBidiTransform(textChunk) { function runBidiTransform(textChunk) {
var str = textChunk.str.join(''); var str = textChunk.str.join('');
var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical); var bidiResult = bidi(str, -1, textChunk.vertical);
return { return {
str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) : str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
bidiResult.str), bidiResult.str),
@ -1757,8 +1767,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2'); var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
// d) Obtain the CMap with the name constructed in step (c) (available // d) Obtain the CMap with the name constructed in step (c) (available
// from the ASN Web site; see the Bibliography). // from the ASN Web site; see the Bibliography).
return CMapFactory.create(ucs2CMapName, return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then( null).then(
function (ucs2CMap) { function (ucs2CMap) {
var cMap = properties.cMap; var cMap = properties.cMap;
toUnicode = []; toUnicode = [];
@ -1785,8 +1795,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) { readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
var cmapObj = toUnicode; var cmapObj = toUnicode;
if (isName(cmapObj)) { if (isName(cmapObj)) {
return CMapFactory.create(cmapObj, return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
function (cmap) { function (cmap) {
if (cmap instanceof IdentityCMap) { if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xFFFF); return new IdentityToUnicodeMap(0, 0xFFFF);
@ -1794,8 +1803,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return new ToUnicodeMap(cmap.getMap()); return new ToUnicodeMap(cmap.getMap());
}); });
} else if (isStream(cmapObj)) { } else if (isStream(cmapObj)) {
return CMapFactory.create(cmapObj, return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
function (cmap) { function (cmap) {
if (cmap instanceof IdentityCMap) { if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xFFFF); return new IdentityToUnicodeMap(0, 0xFFFF);
@ -2086,6 +2094,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var descriptor = preEvaluatedFont.descriptor; var descriptor = preEvaluatedFont.descriptor;
var type = preEvaluatedFont.type; var type = preEvaluatedFont.type;
var maxCharIndex = (composite ? 0xFFFF : 0xFF); var maxCharIndex = (composite ? 0xFFFF : 0xFF);
var cMapOptions = this.options.cMapOptions;
var properties; var properties;
if (!descriptor) { if (!descriptor) {
@ -2213,8 +2222,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (isName(cidEncoding)) { if (isName(cidEncoding)) {
properties.cidEncoding = cidEncoding.name; properties.cidEncoding = cidEncoding.name;
} }
cMapPromise = CMapFactory.create(cidEncoding, cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
function (cMap) { function (cMap) {
properties.cMap = cMap; properties.cMap = cMap;
properties.vertical = properties.cMap.vertical; properties.vertical = properties.cMap.vertical;

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS */
'use strict'; 'use strict';
@ -20,24 +19,24 @@
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/core/fonts', ['exports', 'pdfjs/shared/util', define('pdfjs/core/fonts', ['exports', 'pdfjs/shared/util',
'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser', 'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser',
'pdfjs/core/cmap', 'pdfjs/core/glyphlist', 'pdfjs/core/charsets', 'pdfjs/core/glyphlist', 'pdfjs/core/charsets',
'pdfjs/core/font_renderer', 'pdfjs/core/encodings', 'pdfjs/core/font_renderer', 'pdfjs/core/encodings',
'pdfjs/core/standard_fonts', 'pdfjs/core/unicode'], factory); 'pdfjs/core/standard_fonts', 'pdfjs/core/unicode'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), require('./primitives.js'), factory(exports, require('../shared/util.js'), require('./primitives.js'),
require('./stream.js'), require('./parser.js'), require('./cmap.js'), require('./stream.js'), require('./parser.js'),
require('./glyphlist.js'), require('./charsets.js'), require('./glyphlist.js'), require('./charsets.js'),
require('./font_renderer.js'), require('./encodings.js'), require('./font_renderer.js'), require('./encodings.js'),
require('./standard_fonts'), require('./unicode.js')); require('./standard_fonts'), require('./unicode.js'));
} else { } else {
factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil, factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode); root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode);
} }
}(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
coreCMap, coreGlyphList, coreCharsets, coreFontRenderer, coreGlyphList, coreCharsets, coreFontRenderer,
coreEncodings, coreStandardFonts, coreUnicode) { coreEncodings, coreStandardFonts, coreUnicode) {
var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX; var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
@ -55,11 +54,8 @@ var shadow = sharedUtil.shadow;
var stringToBytes = sharedUtil.stringToBytes; var stringToBytes = sharedUtil.stringToBytes;
var string32 = sharedUtil.string32; var string32 = sharedUtil.string32;
var warn = sharedUtil.warn; var warn = sharedUtil.warn;
var Name = corePrimitives.Name;
var Stream = coreStream.Stream; var Stream = coreStream.Stream;
var Lexer = coreParser.Lexer; var Lexer = coreParser.Lexer;
var CMapFactory = coreCMap.CMapFactory;
var IdentityCMap = coreCMap.IdentityCMap;
var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode; var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode; var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
var ISOAdobeCharset = coreCharsets.ISOAdobeCharset; var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;

View File

@ -51,7 +51,7 @@ var PDFImage = (function PDFImageClosure() {
* Decode the image in the main thread if it supported. Resovles the promise * Decode the image in the main thread if it supported. Resovles the promise
* when the image data is ready. * when the image data is ready.
*/ */
function handleImageData(handler, xref, res, image) { function handleImageData(handler, xref, res, image, forceDataSchema) {
if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) { if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
// For natively supported jpegs send them to the main thread for decoding. // For natively supported jpegs send them to the main thread for decoding.
var dict = image.dict; var dict = image.dict;
@ -59,7 +59,8 @@ var PDFImage = (function PDFImageClosure() {
colorSpace = ColorSpace.parse(colorSpace, xref, res); colorSpace = ColorSpace.parse(colorSpace, xref, res);
var numComps = colorSpace.numComps; var numComps = colorSpace.numComps;
var decodePromise = handler.sendWithPromise('JpegDecode', var decodePromise = handler.sendWithPromise('JpegDecode',
[image.getIR(), numComps]); [image.getIR(forceDataSchema),
numComps]);
return decodePromise.then(function (message) { return decodePromise.then(function (message) {
var data = message.data; var data = message.data;
return new Stream(data, 0, data.length, image.dict); return new Stream(data, 0, data.length, image.dict);
@ -184,8 +185,10 @@ var PDFImage = (function PDFImageClosure() {
* with a PDFImage when the image is ready to be used. * with a PDFImage when the image is ready to be used.
*/ */
PDFImage.buildImage = function PDFImage_buildImage(handler, xref, PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
res, image, inline) { res, image, inline,
var imagePromise = handleImageData(handler, xref, res, image); forceDataSchema) {
var imagePromise = handleImageData(handler, xref, res, image,
forceDataSchema);
var smaskPromise; var smaskPromise;
var maskPromise; var maskPromise;
@ -193,13 +196,15 @@ var PDFImage = (function PDFImageClosure() {
var mask = image.dict.get('Mask'); var mask = image.dict.get('Mask');
if (smask) { if (smask) {
smaskPromise = handleImageData(handler, xref, res, smask); smaskPromise = handleImageData(handler, xref, res, smask,
forceDataSchema);
maskPromise = Promise.resolve(null); maskPromise = Promise.resolve(null);
} else { } else {
smaskPromise = Promise.resolve(null); smaskPromise = Promise.resolve(null);
if (mask) { if (mask) {
if (isStream(mask)) { if (isStream(mask)) {
maskPromise = handleImageData(handler, xref, res, mask); maskPromise = handleImageData(handler, xref, res, mask,
forceDataSchema);
} else if (isArray(mask)) { } else if (isArray(mask)) {
maskPromise = Promise.resolve(mask); maskPromise = Promise.resolve(mask);
} else { } else {

View File

@ -110,8 +110,9 @@ var BasePdfManager = (function BasePdfManagerClosure() {
})(); })();
var LocalPdfManager = (function LocalPdfManagerClosure() { var LocalPdfManager = (function LocalPdfManagerClosure() {
function LocalPdfManager(docId, data, password) { function LocalPdfManager(docId, data, password, evaluatorOptions) {
this._docId = docId; this._docId = docId;
this.evaluatorOptions = evaluatorOptions;
var stream = new Stream(data); var stream = new Stream(data);
this.pdfDocument = new PDFDocument(this, stream, password); this.pdfDocument = new PDFDocument(this, stream, password);
this._loadedStreamCapability = createPromiseCapability(); this._loadedStreamCapability = createPromiseCapability();
@ -157,9 +158,10 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
})(); })();
var NetworkPdfManager = (function NetworkPdfManagerClosure() { var NetworkPdfManager = (function NetworkPdfManagerClosure() {
function NetworkPdfManager(docId, pdfNetworkStream, args) { function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
this._docId = docId; this._docId = docId;
this.msgHandler = args.msgHandler; this.msgHandler = args.msgHandler;
this.evaluatorOptions = evaluatorOptions;
var params = { var params = {
msgHandler: args.msgHandler, msgHandler: args.msgHandler,

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS */
'use strict'; 'use strict';
@ -36,6 +35,7 @@ var Util = sharedUtil.Util;
var error = sharedUtil.error; var error = sharedUtil.error;
var info = sharedUtil.info; var info = sharedUtil.info;
var isArray = sharedUtil.isArray; var isArray = sharedUtil.isArray;
var createObjectURL = sharedUtil.createObjectURL;
var shadow = sharedUtil.shadow; var shadow = sharedUtil.shadow;
var warn = sharedUtil.warn; var warn = sharedUtil.warn;
var Dict = corePrimitives.Dict; var Dict = corePrimitives.Dict;
@ -959,8 +959,8 @@ var JpegStream = (function JpegStreamClosure() {
return this.buffer; return this.buffer;
}; };
JpegStream.prototype.getIR = function JpegStream_getIR() { JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
return PDFJS.createObjectURL(this.bytes, 'image/jpeg'); return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
}; };
/** /**
* Checks if the image can be decoded and displayed by the browser without any * Checks if the image can be decoded and displayed by the browser without any

View File

@ -19,18 +19,16 @@
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/core/worker', ['exports', 'pdfjs/shared/util', define('pdfjs/core/worker', ['exports', 'pdfjs/shared/util',
'pdfjs/core/primitives', 'pdfjs/core/pdf_manager', 'pdfjs/shared/global'], 'pdfjs/core/primitives', 'pdfjs/core/pdf_manager'],
factory); factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), require('./primitives.js'), factory(exports, require('../shared/util.js'), require('./primitives.js'),
require('./pdf_manager.js'), require('../shared/global.js')); require('./pdf_manager.js'));
} else { } else {
factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil, factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
root.pdfjsCorePrimitives, root.pdfjsCorePdfManager, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
root.pdfjsSharedGlobal);
} }
}(this, function (exports, sharedUtil, corePrimitives, corePdfManager, }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
sharedGlobal) {
var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES; var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
var InvalidPDFException = sharedUtil.InvalidPDFException; var InvalidPDFException = sharedUtil.InvalidPDFException;
@ -48,11 +46,11 @@ var createPromiseCapability = sharedUtil.createPromiseCapability;
var error = sharedUtil.error; var error = sharedUtil.error;
var info = sharedUtil.info; var info = sharedUtil.info;
var warn = sharedUtil.warn; var warn = sharedUtil.warn;
var setVerbosityLevel = sharedUtil.setVerbosityLevel;
var Ref = corePrimitives.Ref; var Ref = corePrimitives.Ref;
var LocalPdfManager = corePdfManager.LocalPdfManager; var LocalPdfManager = corePdfManager.LocalPdfManager;
var NetworkPdfManager = corePdfManager.NetworkPdfManager; var NetworkPdfManager = corePdfManager.NetworkPdfManager;
var globalScope = sharedGlobal.globalScope; var globalScope = sharedUtil.globalScope;
var PDFJS = sharedGlobal.PDFJS;
var WorkerTask = (function WorkerTaskClosure() { var WorkerTask = (function WorkerTaskClosure() {
function WorkerTask(name) { function WorkerTask(name) {
@ -428,7 +426,7 @@ function setPDFNetworkStreamClass(cls) {
PDFNetworkStream = cls; PDFNetworkStream = cls;
} }
var WorkerMessageHandler = PDFJS.WorkerMessageHandler = { var WorkerMessageHandler = {
setup: function wphSetup(handler, port) { setup: function wphSetup(handler, port) {
var testMessageProcessed = false; var testMessageProcessed = false;
handler.on('test', function wphSetupTest(data) { handler.on('test', function wphSetupTest(data) {
@ -464,6 +462,10 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}); });
}); });
handler.on('configure', function wphConfigure(data) {
setVerbosityLevel(data.verbosity);
});
handler.on('GetDocRequest', function wphSetupDoc(data) { handler.on('GetDocRequest', function wphSetupDoc(data) {
return WorkerMessageHandler.createDocumentHandler(data, port); return WorkerMessageHandler.createDocumentHandler(data, port);
}); });
@ -533,14 +535,15 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
return loadDocumentCapability.promise; return loadDocumentCapability.promise;
} }
function getPdfManager(data) { function getPdfManager(data, evaluatorOptions) {
var pdfManagerCapability = createPromiseCapability(); var pdfManagerCapability = createPromiseCapability();
var pdfManager; var pdfManager;
var source = data.source; var source = data.source;
if (source.data) { if (source.data) {
try { try {
pdfManager = new LocalPdfManager(docId, source.data, source.password); pdfManager = new LocalPdfManager(docId, source.data, source.password,
evaluatorOptions);
pdfManagerCapability.resolve(pdfManager); pdfManagerCapability.resolve(pdfManager);
} catch (ex) { } catch (ex) {
pdfManagerCapability.reject(ex); pdfManagerCapability.reject(ex);
@ -589,7 +592,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
length: fullRequest.contentLength, length: fullRequest.contentLength,
disableAutoFetch: disableAutoFetch, disableAutoFetch: disableAutoFetch,
rangeChunkSize: source.rangeChunkSize rangeChunkSize: source.rangeChunkSize
}); }, evaluatorOptions);
pdfManagerCapability.resolve(pdfManager); pdfManagerCapability.resolve(pdfManager);
cancelXHRs = null; cancelXHRs = null;
}).catch(function (reason) { }).catch(function (reason) {
@ -605,7 +608,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
} }
// the data is array, instantiating directly from it // the data is array, instantiating directly from it
try { try {
pdfManager = new LocalPdfManager(docId, pdfFile, source.password); pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
evaluatorOptions);
pdfManagerCapability.resolve(pdfManager); pdfManagerCapability.resolve(pdfManager);
} catch (ex) { } catch (ex) {
pdfManagerCapability.reject(ex); pdfManagerCapability.reject(ex);
@ -685,16 +689,18 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
ensureNotTerminated(); ensureNotTerminated();
PDFJS.maxImageSize = data.maxImageSize === undefined ? var cMapOptions = {
-1 : data.maxImageSize; url: data.cMapUrl === undefined ? null : data.cMapUrl,
PDFJS.disableFontFace = data.disableFontFace; packed: data.cMapPacked === true
PDFJS.disableCreateObjectURL = data.disableCreateObjectURL; };
PDFJS.verbosity = data.verbosity; var evaluatorOptions = {
PDFJS.cMapUrl = data.cMapUrl === undefined ? forceDataSchema: data.disableCreateObjectURL,
null : data.cMapUrl; maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
PDFJS.cMapPacked = data.cMapPacked === true; disableFontFace: data.disableFontFace,
cMapOptions: cMapOptions
};
getPdfManager(data).then(function (newPdfManager) { getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
if (terminated) { if (terminated) {
// We were in a process of setting up the manager, but it got // We were in a process of setting up the manager, but it got
// terminated in the middle. // terminated in the middle.

View File

@ -31,8 +31,8 @@
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType; var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
var AnnotationType = sharedUtil.AnnotationType; var AnnotationType = sharedUtil.AnnotationType;
var Util = sharedUtil.Util; var Util = sharedUtil.Util;
var addLinkAttributes = sharedUtil.addLinkAttributes; var addLinkAttributes = displayDOMUtils.addLinkAttributes;
var getFilenameFromUrl = sharedUtil.getFilenameFromUrl; var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
var warn = sharedUtil.warn; var warn = sharedUtil.warn;
var CustomStyle = displayDOMUtils.CustomStyle; var CustomStyle = displayDOMUtils.CustomStyle;

View File

@ -20,18 +20,20 @@
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/api', ['exports', 'pdfjs/shared/util', define('pdfjs/display/api', ['exports', 'pdfjs/shared/util',
'pdfjs/display/font_loader', 'pdfjs/display/canvas', 'pdfjs/display/font_loader', 'pdfjs/display/canvas',
'pdfjs/display/metadata', 'pdfjs/shared/global', 'require'], factory); 'pdfjs/display/metadata', 'pdfjs/display/dom_utils',
'pdfjs/display/global', 'require'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), require('./font_loader.js'), factory(exports, require('../shared/util.js'), require('./font_loader.js'),
require('./canvas.js'), require('./metadata.js'), require('./canvas.js'), require('./metadata.js'),
require('../shared/global.js')); require('./dom_utils.js'), require('./global.js'));
} else { } else {
factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil, factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas, root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
root.pdfjsDisplayMetadata, root.pdfjsSharedGlobal); root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils,
root.pdfjsDisplayGlobal);
} }
}(this, function (exports, sharedUtil, displayFontLoader, displayCanvas, }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
displayMetadata, sharedGlobal, amdRequire) { displayMetadata, displayDOMUtils, displayGlobal, amdRequire) {
var InvalidPDFException = sharedUtil.InvalidPDFException; var InvalidPDFException = sharedUtil.InvalidPDFException;
var MessageHandler = sharedUtil.MessageHandler; var MessageHandler = sharedUtil.MessageHandler;
@ -46,6 +48,7 @@ var createPromiseCapability = sharedUtil.createPromiseCapability;
var combineUrl = sharedUtil.combineUrl; var combineUrl = sharedUtil.combineUrl;
var error = sharedUtil.error; var error = sharedUtil.error;
var deprecated = sharedUtil.deprecated; var deprecated = sharedUtil.deprecated;
var getVerbosityLevel = sharedUtil.getVerbosityLevel;
var info = sharedUtil.info; var info = sharedUtil.info;
var isArrayBuffer = sharedUtil.isArrayBuffer; var isArrayBuffer = sharedUtil.isArrayBuffer;
var isSameOrigin = sharedUtil.isSameOrigin; var isSameOrigin = sharedUtil.isSameOrigin;
@ -57,8 +60,8 @@ var FontLoader = displayFontLoader.FontLoader;
var CanvasGraphics = displayCanvas.CanvasGraphics; var CanvasGraphics = displayCanvas.CanvasGraphics;
var createScratchCanvas = displayCanvas.createScratchCanvas; var createScratchCanvas = displayCanvas.createScratchCanvas;
var Metadata = displayMetadata.Metadata; var Metadata = displayMetadata.Metadata;
var PDFJS = sharedGlobal.PDFJS; var PDFJS = displayGlobal.PDFJS;
var globalScope = sharedGlobal.globalScope; var globalScope = displayGlobal.globalScope;
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536 var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
@ -198,17 +201,6 @@ PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ? PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
false : PDFJS.useOnlyCssZoom); false : PDFJS.useOnlyCssZoom);
/**
* Controls the logging level.
* The constants from PDFJS.VERBOSITY_LEVELS should be used:
* - errors
* - warnings [default]
* - infos
* @var {number}
*/
PDFJS.verbosity = (PDFJS.verbosity === undefined ?
PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
/** /**
* The maximum supported canvas size in total pixels e.g. width * height. * The maximum supported canvas size in total pixels e.g. width * height.
* The default value is 4096 * 4096. Use -1 for no limit. * The default value is 4096 * 4096. Use -1 for no limit.
@ -454,7 +446,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
cMapPacked: PDFJS.cMapPacked, cMapPacked: PDFJS.cMapPacked,
disableFontFace: PDFJS.disableFontFace, disableFontFace: PDFJS.disableFontFace,
disableCreateObjectURL: PDFJS.disableCreateObjectURL, disableCreateObjectURL: PDFJS.disableCreateObjectURL,
verbosity: PDFJS.verbosity,
postMessageTransfers: PDFJS.postMessageTransfers, postMessageTransfers: PDFJS.postMessageTransfers,
}).then(function (workerId) { }).then(function (workerId) {
if (worker.destroyed) { if (worker.destroyed) {
@ -1213,38 +1204,45 @@ var PDFWorker = (function PDFWorkerClosure() {
error('No PDFJS.workerSrc specified'); error('No PDFJS.workerSrc specified');
} }
var fakeWorkerFilesLoadedCapability;
// Loads worker code into main thread. // Loads worker code into main thread.
function setupFakeWorkerGlobal() { function setupFakeWorkerGlobal() {
if (!PDFJS.fakeWorkerFilesLoadedCapability) { var WorkerMessageHandler;
PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability(); if (!fakeWorkerFilesLoadedCapability) {
fakeWorkerFilesLoadedCapability = createPromiseCapability();
// In the developer build load worker_loader which in turn loads all the // In the developer build load worker_loader which in turn loads all the
// other files and resolves the promise. In production only the // other files and resolves the promise. In production only the
// pdf.worker.js file is needed. // pdf.worker.js file is needed.
//#if !PRODUCTION //#if !PRODUCTION
if (typeof amdRequire === 'function') { if (typeof amdRequire === 'function') {
amdRequire(['pdfjs/core/network', 'pdfjs/core/worker'], function () { amdRequire(['pdfjs/core/network', 'pdfjs/core/worker'],
PDFJS.fakeWorkerFilesLoadedCapability.resolve(); function (network, worker) {
WorkerMessageHandler = worker.WorkerMessageHandler;
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
}); });
} else if (typeof require === 'function') { } else if (typeof require === 'function') {
require('../core/worker.js'); var worker = require('../core/worker.js');
PDFJS.fakeWorkerFilesLoadedCapability.resolve(); WorkerMessageHandler = worker.WorkerMessageHandler;
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
} else { } else {
throw new Error('AMD or CommonJS must be used to load fake worker.'); throw new Error('AMD or CommonJS must be used to load fake worker.');
} }
//#endif //#endif
//#if PRODUCTION && SINGLE_FILE //#if PRODUCTION && SINGLE_FILE
// PDFJS.fakeWorkerFilesLoadedCapability.resolve(); // WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
// fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
//#endif //#endif
//#if PRODUCTION && !SINGLE_FILE //#if PRODUCTION && !SINGLE_FILE
// var loader = fakeWorkerFilesLoader || function (callback) { // var loader = fakeWorkerFilesLoader || function (callback) {
// Util.loadScript(getWorkerSrc(), callback); // Util.loadScript(getWorkerSrc(), function () {
// callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
// });
// }; // };
// loader(function () { // loader(fakeWorkerFilesLoadedCapability.resolve);
// PDFJS.fakeWorkerFilesLoadedCapability.resolve();
// });
//#endif //#endif
} }
return PDFJS.fakeWorkerFilesLoadedCapability.promise; return fakeWorkerFilesLoadedCapability.promise;
} }
function createCDNWrapper(url) { function createCDNWrapper(url) {
@ -1318,6 +1316,10 @@ var PDFWorker = (function PDFWorkerClosure() {
PDFJS.postMessageTransfers = false; PDFJS.postMessageTransfers = false;
} }
this._readyCapability.resolve(); this._readyCapability.resolve();
// Send global PDFJS setting, e.g. verbosity level.
messageHandler.send('configure', {
verbosity: getVerbosityLevel()
});
} else { } else {
this._setupFakeWorker(); this._setupFakeWorker();
messageHandler.destroy(); messageHandler.destroy();
@ -1383,7 +1385,7 @@ var PDFWorker = (function PDFWorkerClosure() {
globalScope.PDFJS.disableWorker = true; globalScope.PDFJS.disableWorker = true;
} }
setupFakeWorkerGlobal().then(function () { setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
if (this.destroyed) { if (this.destroyed) {
this._readyCapability.reject(new Error('Worker was destroyed')); this._readyCapability.reject(new Error('Worker was destroyed'));
return; return;
@ -1415,7 +1417,7 @@ var PDFWorker = (function PDFWorkerClosure() {
// If the main thread is our worker, setup the handling for the // If the main thread is our worker, setup the handling for the
// messages -- the main thread sends to it self. // messages -- the main thread sends to it self.
var workerHandler = new MessageHandler(id + '_worker', id, port); var workerHandler = new MessageHandler(id + '_worker', id, port);
PDFJS.WorkerMessageHandler.setup(workerHandler, port); WorkerMessageHandler.setup(workerHandler, port);
var messageHandler = new MessageHandler(id, id + '_worker', port); var messageHandler = new MessageHandler(id, id + '_worker', port);
this._messageHandler = messageHandler; this._messageHandler = messageHandler;

View File

@ -19,15 +19,18 @@
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/canvas', ['exports', 'pdfjs/shared/util', define('pdfjs/display/canvas', ['exports', 'pdfjs/shared/util',
'pdfjs/display/pattern_helper', 'pdfjs/display/webgl'], factory); 'pdfjs/display/dom_utils', 'pdfjs/display/pattern_helper',
'pdfjs/display/webgl'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), factory(exports, require('../shared/util.js'), require('./dom_utils.js'),
require('./pattern_helper.js'), require('./webgl.js')); require('./pattern_helper.js'), require('./webgl.js'));
} else { } else {
factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil, factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL); root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper,
root.pdfjsDisplayWebGL);
} }
}(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) { }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper,
displayWebGL) {
var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX; var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX; var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;

View File

@ -17,16 +17,21 @@
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/dom_utils', ['exports', 'pdfjs/shared/global'], define('pdfjs/display/dom_utils', ['exports', 'pdfjs/shared/util',
factory); 'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/global.js')); factory(exports, require('../shared/util.js'), require('./global.js'));
} else { } else {
factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal); factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayGlobal);
} }
}(this, function (exports, sharedGlobal) { }(this, function (exports, sharedUtil, displayGlobal) {
var PDFJS = sharedGlobal.PDFJS; var deprecated = sharedUtil.deprecated;
var removeNullCharacters = sharedUtil.removeNullCharacters;
var shadow = sharedUtil.shadow;
var warn = sharedUtil.warn;
var PDFJS = displayGlobal.PDFJS;
/** /**
* Optimised CSS custom property getter/setter. * Optimised CSS custom property getter/setter.
@ -84,5 +89,106 @@ var CustomStyle = (function CustomStyleClosure() {
PDFJS.CustomStyle = CustomStyle; PDFJS.CustomStyle = CustomStyle;
//#if !(FIREFOX || MOZCENTRAL || CHROME)
//// Lazy test if the userAgent support CanvasTypedArrays
function hasCanvasTypedArrays() {
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
var ctx = canvas.getContext('2d');
var imageData = ctx.createImageData(1, 1);
return (typeof imageData.data.buffer !== 'undefined');
}
Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
configurable: true,
get: function PDFJS_hasCanvasTypedArrays() {
return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
}
});
//#else
//PDFJS.hasCanvasTypedArrays = true;
//#endif
var LinkTarget = {
NONE: 0, // Default value.
SELF: 1,
BLANK: 2,
PARENT: 3,
TOP: 4,
};
PDFJS.LinkTarget = LinkTarget;
var LinkTargetStringMap = [
'',
'_self',
'_blank',
'_parent',
'_top'
];
function isExternalLinkTargetSet() {
//#if !MOZCENTRAL
if (PDFJS.openExternalLinksInNewWindow) {
deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
'"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
PDFJS.externalLinkTarget = LinkTarget.BLANK;
}
// Reset the deprecated parameter, to suppress further warnings.
PDFJS.openExternalLinksInNewWindow = false;
}
//#endif
switch (PDFJS.externalLinkTarget) {
case LinkTarget.NONE:
return false;
case LinkTarget.SELF:
case LinkTarget.BLANK:
case LinkTarget.PARENT:
case LinkTarget.TOP:
return true;
}
warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
// Reset the external link target, to suppress further warnings.
PDFJS.externalLinkTarget = LinkTarget.NONE;
return false;
}
PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
/**
* Adds various attributes (href, title, target, rel) to hyperlinks.
* @param {HTMLLinkElement} link - The link element.
* @param {Object} params - An object with the properties:
* @param {string} params.url - An absolute URL.
*/
function addLinkAttributes(link, params) {
var url = params && params.url;
link.href = link.title = (url ? removeNullCharacters(url) : '');
if (url) {
if (isExternalLinkTargetSet()) {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
}
// Strip referrer from the URL.
link.rel = PDFJS.externalLinkRel;
}
}
PDFJS.addLinkAttributes = addLinkAttributes;
// Gets the file name from a given URL.
function getFilenameFromUrl(url) {
var anchor = url.indexOf('#');
var query = url.indexOf('?');
var end = Math.min(
anchor > 0 ? anchor : url.length,
query > 0 ? query : url.length);
return url.substring(url.lastIndexOf('/', end) + 1, end);
}
PDFJS.getFilenameFromUrl = getFilenameFromUrl;
exports.CustomStyle = CustomStyle; exports.CustomStyle = CustomStyle;
exports.addLinkAttributes = addLinkAttributes;
exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
exports.getFilenameFromUrl = getFilenameFromUrl;
exports.LinkTarget = LinkTarget;
})); }));

View File

@ -19,15 +19,14 @@
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/font_loader', ['exports', 'pdfjs/shared/util', define('pdfjs/display/font_loader', ['exports', 'pdfjs/shared/util',
'pdfjs/shared/global'], factory); 'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), factory(exports, require('../shared/util.js'), require('./global.js'));
require('../shared/global.js'));
} else { } else {
factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil, factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
root.pdfjsSharedGlobal); root.pdfjsDisplayGlobal);
} }
}(this, function (exports, sharedUtil, sharedGlobal) { }(this, function (exports, sharedUtil, displayGlobal) {
var assert = sharedUtil.assert; var assert = sharedUtil.assert;
var bytesToString = sharedUtil.bytesToString; var bytesToString = sharedUtil.bytesToString;
@ -35,9 +34,9 @@ var string32 = sharedUtil.string32;
var shadow = sharedUtil.shadow; var shadow = sharedUtil.shadow;
var warn = sharedUtil.warn; var warn = sharedUtil.warn;
var PDFJS = sharedGlobal.PDFJS; var PDFJS = displayGlobal.PDFJS;
var globalScope = sharedGlobal.globalScope; var globalScope = displayGlobal.globalScope;
var isWorker = sharedGlobal.isWorker; var isWorker = displayGlobal.isWorker;
function FontLoader(docId) { function FontLoader(docId) {
this.docId = docId; this.docId = docId;

92
src/display/global.js Normal file
View File

@ -0,0 +1,92 @@
/* Copyright 2015 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.
*/
/* globals pdfjsVersion, pdfjsBuild */
'use strict';
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs/display/global', ['exports', 'pdfjs/shared/util'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'));
} else {
factory((root.pdfjsDisplayGlobal = {}), root.pdfjsSharedUtil);
}
}(this, function (exports, sharedUtil) {
var globalScope = sharedUtil.globalScope;
var isWorker = (typeof window === 'undefined');
// The global PDFJS object exposes the API
// In production, it will be declared outside a global wrapper
// In development, it will be declared here
if (!globalScope.PDFJS) {
globalScope.PDFJS = {};
}
var PDFJS = globalScope.PDFJS;
if (typeof pdfjsVersion !== 'undefined') {
PDFJS.version = pdfjsVersion;
}
if (typeof pdfjsBuild !== 'undefined') {
PDFJS.build = pdfjsBuild;
}
PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) {
sharedUtil.setVerbosityLevel(PDFJS.verbosity);
}
delete PDFJS.verbosity;
Object.defineProperty(PDFJS, 'verbosity', {
get: function () { return sharedUtil.getVerbosityLevel(); },
set: function (level) { sharedUtil.setVerbosityLevel(level); },
enumerable: true,
configurable: true
});
PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
PDFJS.OPS = sharedUtil.OPS;
PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
PDFJS.isValidUrl = sharedUtil.isValidUrl;
PDFJS.shadow = sharedUtil.shadow;
PDFJS.createBlob = sharedUtil.createBlob;
PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
return sharedUtil.createObjectURL(data, contentType,
PDFJS.disableCreateObjectURL);
};
Object.defineProperty(PDFJS, 'isLittleEndian', {
configurable: true,
get: function PDFJS_isLittleEndian() {
var value = sharedUtil.isLittleEndian();
return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
}
});
PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
PDFJS.PasswordException = sharedUtil.PasswordException;
PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
PDFJS.Util = sharedUtil.Util;
PDFJS.PageViewport = sharedUtil.PageViewport;
PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
exports.globalScope = globalScope;
exports.isWorker = isWorker;
exports.PDFJS = globalScope.PDFJS;
}));

View File

@ -12,21 +12,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS, Document */ /* globals Document */
'use strict'; 'use strict';
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/metadata', ['exports', 'pdfjs/shared/util'], factory); define('pdfjs/display/metadata', ['exports', 'pdfjs/shared/util',
'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js')); factory(exports, require('../shared/util.js'), require('./global.js'));
} else { } else {
factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil); factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayGlobal);
} }
}(this, function (exports, sharedUtil) { }(this, function (exports, sharedUtil, displayGlobal) {
var error = sharedUtil.error; var error = sharedUtil.error;
var PDFJS = displayGlobal.PDFJS;
var Metadata = PDFJS.Metadata = (function MetadataClosure() { var Metadata = PDFJS.Metadata = (function MetadataClosure() {
function fixMetadata(meta) { function fixMetadata(meta) {

View File

@ -12,20 +12,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS */
'use strict'; 'use strict';
//#if (GENERIC || SINGLE_FILE) //#if (GENERIC || SINGLE_FILE)
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/svg', ['exports', 'pdfjs/shared/util'], factory); define('pdfjs/display/svg', ['exports', 'pdfjs/shared/util',
'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js')); factory(exports, require('../shared/util.js'), require('./global.js'));
} else { } else {
factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil); factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayGlobal);
} }
}(this, function (exports, sharedUtil) { }(this, function (exports, sharedUtil, displayGlobal) {
var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX; var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX; var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
@ -35,6 +36,7 @@ var Util = sharedUtil.Util;
var isNum = sharedUtil.isNum; var isNum = sharedUtil.isNum;
var isArray = sharedUtil.isArray; var isArray = sharedUtil.isArray;
var warn = sharedUtil.warn; var warn = sharedUtil.warn;
var PDFJS = displayGlobal.PDFJS;
var SVG_DEFAULTS = { var SVG_DEFAULTS = {
fontStyle: 'normal', fontStyle: 'normal',

View File

@ -18,20 +18,20 @@
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/text_layer', ['exports', 'pdfjs/shared/util', define('pdfjs/display/text_layer', ['exports', 'pdfjs/shared/util',
'pdfjs/display/dom_utils', 'pdfjs/shared/global'], factory); 'pdfjs/display/dom_utils', 'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), require('./dom_utils.js'), factory(exports, require('../shared/util.js'), require('./dom_utils.js'),
require('../shared/global.js')); require('./global.js'));
} else { } else {
factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil, factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayDOMUtils, root.pdfjsSharedGlobal); root.pdfjsDisplayDOMUtils, root.pdfjsDisplayGlobal);
} }
}(this, function (exports, sharedUtil, displayDOMUtils, sharedGlobal) { }(this, function (exports, sharedUtil, displayDOMUtils, displayGlobal) {
var Util = sharedUtil.Util; var Util = sharedUtil.Util;
var createPromiseCapability = sharedUtil.createPromiseCapability; var createPromiseCapability = sharedUtil.createPromiseCapability;
var CustomStyle = displayDOMUtils.CustomStyle; var CustomStyle = displayDOMUtils.CustomStyle;
var PDFJS = sharedGlobal.PDFJS; var PDFJS = displayGlobal.PDFJS;
/** /**
* Text layer render parameters. * Text layer render parameters.

View File

@ -12,22 +12,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS */
/* jshint -W043 */ /* jshint -W043 */
'use strict'; 'use strict';
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/display/webgl', ['exports', 'pdfjs/shared/util'], factory); define('pdfjs/display/webgl', ['exports', 'pdfjs/shared/util',
'pdfjs/display/global'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js')); factory(exports, require('../shared/util.js'), require('./global.js'));
} else { } else {
factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil); factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil,
root.pdfjsDisplayGlobal);
} }
}(this, function (exports, sharedUtil) { }(this, function (exports, sharedUtil, displayGlobal) {
var shadow = sharedUtil.shadow; var shadow = sharedUtil.shadow;
var PDFJS = displayGlobal.PDFJS;
var WebGLUtils = (function WebGLUtilsClosure() { var WebGLUtils = (function WebGLUtilsClosure() {
function loadShader(gl, code, shaderType) { function loadShader(gl, code, shaderType) {

View File

@ -27,6 +27,16 @@ function PDFJS() {
// Mock class constructor. See src/display/api.js. // Mock class constructor. See src/display/api.js.
} }
/**
* Controls the logging level.
* The constants from PDFJS.VERBOSITY_LEVELS should be used:
* - errors
* - warnings [default]
* - infos
* @var {number}
*/
PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.warnings;
/** /**
* Represents the eventual result of an asynchronous operation. * Represents the eventual result of an asynchronous operation.
* @external Promise * @external Promise

View File

@ -37,11 +37,11 @@ if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
} }
var fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) { var fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) {
require.ensure([], function () { require.ensure([], function () {
require('./pdf.worker.js'); var worker = require('./pdf.worker.js');
callback(); callback(worker.WorkerMessageHandler);
}); });
}) : (typeof requirejs !== 'undefined') ? (function (callback) { }) : (typeof requirejs !== 'undefined') ? (function (callback) {
requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) { requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
callback(); callback(worker.WorkerMessageHandler);
}); });
}) : null; }) : null;

View File

@ -19,23 +19,24 @@
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/main_loader', ['exports', 'pdfjs/display/api', define('pdfjs/main_loader', ['exports', 'pdfjs/display/api',
'pdfjs/display/annotation_layer', 'pdfjs/display/text_layer', 'pdfjs/display/annotation_layer', 'pdfjs/display/text_layer',
'pdfjs/display/dom_utils', 'pdfjs/shared/util', 'pdfjs/shared/global'], 'pdfjs/display/dom_utils', 'pdfjs/shared/util', 'pdfjs/display/global'],
factory); factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('./display/api.js'), factory(exports, require('./display/api.js'),
require('./display/annotation_layer.js'), require('./display/annotation_layer.js'),
require('./display/text_layer.js'), require('./display/dom_utils.js'), require('./display/text_layer.js'), require('./display/dom_utils.js'),
require('./shared/util.js'), require('./shared/global.js')); require('./shared/util.js'), require('./display/global.js'));
} else { } else {
factory((root.pdfjsMainLoader = {}), root.pdfjsDisplayAPI, factory((root.pdfjsMainLoader = {}), root.pdfjsDisplayAPI,
root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer, root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer,
root.pdfjsDisplayDOMUtils, root.pdfjsSharedUtil, root.pdfjsSharedGlobal); root.pdfjsDisplayDOMUtils, root.pdfjsSharedUtil, root.pdfjsDisplayGlobal);
} }
}(this, function (exports, displayAPI, displayAnnotationLayer, }(this, function (exports, displayAPI, displayAnnotationLayer,
displayTextLayer, displayDOMUtils, sharedUtil, sharedGlobal) { displayTextLayer, displayDOMUtils, sharedUtil,
displayGlobal) {
// Sync the exports below with ./pdf.js file/template. // Sync the exports below with ./pdf.js file/template.
exports.PDFJS = sharedGlobal.PDFJS; exports.PDFJS = displayGlobal.PDFJS;
exports.getDocument = displayAPI.getDocument; exports.getDocument = displayAPI.getDocument;
exports.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport; exports.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;

View File

@ -43,9 +43,8 @@
}).call(pdfjsLibs); }).call(pdfjsLibs);
exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
//#if MAIN_FILE //#if MAIN_FILE
exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument; exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
exports.PDFDataRangeTransport = exports.PDFDataRangeTransport =
pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport; pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
@ -58,5 +57,7 @@
exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException; exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
exports.UnexpectedResponseException = exports.UnexpectedResponseException =
pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException; pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
//#else
exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
//#endif //#endif
})); }));

View File

@ -1,54 +0,0 @@
/* Copyright 2015 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.
*/
/* globals global, pdfjsVersion, pdfjsBuild */
'use strict';
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs/shared/global', ['exports'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports);
} else {
factory((root.pdfjsSharedGlobal = {}));
}
}(this, function (exports) {
var globalScope = (typeof window !== 'undefined') ? window :
(typeof global !== 'undefined') ? global :
(typeof self !== 'undefined') ? self : this;
var isWorker = (typeof window === 'undefined');
// The global PDFJS object exposes the API
// In production, it will be declared outside a global wrapper
// In development, it will be declared here
if (!globalScope.PDFJS) {
globalScope.PDFJS = {};
}
if (typeof pdfjsVersion !== 'undefined') {
globalScope.PDFJS.version = pdfjsVersion;
}
if (typeof pdfjsVersion !== 'undefined') {
globalScope.PDFJS.build = pdfjsBuild;
}
globalScope.PDFJS.pdfBug = false;
exports.globalScope = globalScope;
exports.isWorker = isWorker;
exports.PDFJS = globalScope.PDFJS;
}));

View File

@ -12,22 +12,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals MozBlobBuilder, URL */ /* globals MozBlobBuilder, URL, global */
'use strict'; 'use strict';
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs/shared/util', ['exports', 'pdfjs/shared/global'], factory); define('pdfjs/shared/util', ['exports'], factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('./global.js')); factory(exports);
} else { } else {
factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal); factory((root.pdfjsSharedUtil = {}));
} }
}(this, function (exports, sharedGlobal) { }(this, function (exports) {
var PDFJS = sharedGlobal.PDFJS; var globalScope = (typeof window !== 'undefined') ? window :
var globalScope = sharedGlobal.globalScope; (typeof global !== 'undefined') ? global :
(typeof self !== 'undefined') ? self : this;
var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
@ -127,14 +128,14 @@ var FontType = {
MMTYPE1: 10 MMTYPE1: 10
}; };
PDFJS.VERBOSITY_LEVELS = { var VERBOSITY_LEVELS = {
errors: 0, errors: 0,
warnings: 1, warnings: 1,
infos: 5 infos: 5
}; };
// All the possible operations for an operator list. // All the possible operations for an operator list.
var OPS = PDFJS.OPS = { var OPS = {
// Intentionally start from 1 so it is easy to spot bad operators that will be // Intentionally start from 1 so it is easy to spot bad operators that will be
// 0's. // 0's.
dependency: 1, dependency: 1,
@ -230,18 +231,28 @@ var OPS = PDFJS.OPS = {
constructPath: 91 constructPath: 91
}; };
var verbosity = VERBOSITY_LEVELS.warnings;
function setVerbosityLevel(level) {
verbosity = level;
}
function getVerbosityLevel() {
return verbosity;
}
// A notice for devs. These are good for things that are helpful to devs, such // A notice for devs. These are good for things that are helpful to devs, such
// as warning that Workers were disabled, which is important to devs but not // as warning that Workers were disabled, which is important to devs but not
// end users. // end users.
function info(msg) { function info(msg) {
if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) { if (verbosity >= VERBOSITY_LEVELS.infos) {
console.log('Info: ' + msg); console.log('Info: ' + msg);
} }
} }
// Non-fatal warnings. // Non-fatal warnings.
function warn(msg) { function warn(msg) {
if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) { if (verbosity >= VERBOSITY_LEVELS.warnings) {
console.log('Warning: ' + msg); console.log('Warning: ' + msg);
} }
} }
@ -254,7 +265,7 @@ function deprecated(details) {
// Fatal errors that should trigger the fallback UI and halt execution by // Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception. // throwing an exception.
function error(msg) { function error(msg) {
if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) { if (verbosity >= VERBOSITY_LEVELS.errors) {
console.log('Error: ' + msg); console.log('Error: ' + msg);
console.log(backtrace()); console.log(backtrace());
} }
@ -275,7 +286,7 @@ function assert(cond, msg) {
} }
} }
var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = { var UNSUPPORTED_FEATURES = {
unknown: 'unknown', unknown: 'unknown',
forms: 'forms', forms: 'forms',
javaScript: 'javaScript', javaScript: 'javaScript',
@ -284,17 +295,6 @@ var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
font: 'font' font: 'font'
}; };
// Gets the file name from a given URL.
function getFilenameFromUrl(url) {
var anchor = url.indexOf('#');
var query = url.indexOf('?');
var end = Math.min(
anchor > 0 ? anchor : url.length,
query > 0 ? query : url.length);
return url.substring(url.lastIndexOf('/', end) + 1, end);
}
PDFJS.getFilenameFromUrl = getFilenameFromUrl;
// Combines two URLs. The baseUrl shall be absolute URL. If the url is an // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
// absolute URL, it will be returned as is. // absolute URL, it will be returned as is.
function combineUrl(baseUrl, url) { function combineUrl(baseUrl, url) {
@ -342,27 +342,6 @@ function isValidUrl(url, allowRelative) {
return false; return false;
} }
} }
PDFJS.isValidUrl = isValidUrl;
/**
* Adds various attributes (href, title, target, rel) to hyperlinks.
* @param {HTMLLinkElement} link - The link element.
* @param {Object} params - An object with the properties:
* @param {string} params.url - An absolute URL.
*/
function addLinkAttributes(link, params) {
var url = params && params.url;
link.href = link.title = (url ? removeNullCharacters(url) : '');
if (url) {
if (isExternalLinkTargetSet()) {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
}
// Strip referrer from the URL.
link.rel = PDFJS.externalLinkRel;
}
}
PDFJS.addLinkAttributes = addLinkAttributes;
function shadow(obj, prop, value) { function shadow(obj, prop, value) {
Object.defineProperty(obj, prop, { value: value, Object.defineProperty(obj, prop, { value: value,
@ -371,7 +350,6 @@ function shadow(obj, prop, value) {
writable: false }); writable: false });
return value; return value;
} }
PDFJS.shadow = shadow;
function getLookupTableFactory(initializer) { function getLookupTableFactory(initializer) {
var lookup; var lookup;
@ -385,50 +363,7 @@ function getLookupTableFactory(initializer) {
}; };
} }
var LinkTarget = PDFJS.LinkTarget = { var PasswordResponses = {
NONE: 0, // Default value.
SELF: 1,
BLANK: 2,
PARENT: 3,
TOP: 4,
};
var LinkTargetStringMap = [
'',
'_self',
'_blank',
'_parent',
'_top'
];
function isExternalLinkTargetSet() {
//#if !MOZCENTRAL
if (PDFJS.openExternalLinksInNewWindow) {
deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
'"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
PDFJS.externalLinkTarget = LinkTarget.BLANK;
}
// Reset the deprecated parameter, to suppress further warnings.
PDFJS.openExternalLinksInNewWindow = false;
}
//#endif
switch (PDFJS.externalLinkTarget) {
case LinkTarget.NONE:
return false;
case LinkTarget.SELF:
case LinkTarget.BLANK:
case LinkTarget.PARENT:
case LinkTarget.TOP:
return true;
}
warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
// Reset the external link target, to suppress further warnings.
PDFJS.externalLinkTarget = LinkTarget.NONE;
return false;
}
PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
var PasswordResponses = PDFJS.PasswordResponses = {
NEED_PASSWORD: 1, NEED_PASSWORD: 1,
INCORRECT_PASSWORD: 2 INCORRECT_PASSWORD: 2
}; };
@ -445,7 +380,6 @@ var PasswordException = (function PasswordExceptionClosure() {
return PasswordException; return PasswordException;
})(); })();
PDFJS.PasswordException = PasswordException;
var UnknownErrorException = (function UnknownErrorExceptionClosure() { var UnknownErrorException = (function UnknownErrorExceptionClosure() {
function UnknownErrorException(msg, details) { function UnknownErrorException(msg, details) {
@ -459,7 +393,6 @@ var UnknownErrorException = (function UnknownErrorExceptionClosure() {
return UnknownErrorException; return UnknownErrorException;
})(); })();
PDFJS.UnknownErrorException = UnknownErrorException;
var InvalidPDFException = (function InvalidPDFExceptionClosure() { var InvalidPDFException = (function InvalidPDFExceptionClosure() {
function InvalidPDFException(msg) { function InvalidPDFException(msg) {
@ -472,7 +405,6 @@ var InvalidPDFException = (function InvalidPDFExceptionClosure() {
return InvalidPDFException; return InvalidPDFException;
})(); })();
PDFJS.InvalidPDFException = InvalidPDFException;
var MissingPDFException = (function MissingPDFExceptionClosure() { var MissingPDFException = (function MissingPDFExceptionClosure() {
function MissingPDFException(msg) { function MissingPDFException(msg) {
@ -485,7 +417,6 @@ var MissingPDFException = (function MissingPDFExceptionClosure() {
return MissingPDFException; return MissingPDFException;
})(); })();
PDFJS.MissingPDFException = MissingPDFException;
var UnexpectedResponseException = var UnexpectedResponseException =
(function UnexpectedResponseExceptionClosure() { (function UnexpectedResponseExceptionClosure() {
@ -500,7 +431,6 @@ var UnexpectedResponseException =
return UnexpectedResponseException; return UnexpectedResponseException;
})(); })();
PDFJS.UnexpectedResponseException = UnexpectedResponseException;
var NotImplementedException = (function NotImplementedExceptionClosure() { var NotImplementedException = (function NotImplementedExceptionClosure() {
function NotImplementedException(msg) { function NotImplementedException(msg) {
@ -549,7 +479,6 @@ function removeNullCharacters(str) {
} }
return str.replace(NullCharactersRegExp, ''); return str.replace(NullCharactersRegExp, '');
} }
PDFJS.removeNullCharacters = removeNullCharacters;
function bytesToString(bytes) { function bytesToString(bytes) {
assert(bytes !== null && typeof bytes === 'object' && assert(bytes !== null && typeof bytes === 'object' &&
@ -663,30 +592,7 @@ function isLittleEndian() {
return (buffer16[0] === 1); return (buffer16[0] === 1);
} }
Object.defineProperty(PDFJS, 'isLittleEndian', {
configurable: true,
get: function PDFJS_isLittleEndian() {
return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
}
});
//#if !(FIREFOX || MOZCENTRAL || CHROME) //#if !(FIREFOX || MOZCENTRAL || CHROME)
//// Lazy test if the userAgent support CanvasTypedArrays
function hasCanvasTypedArrays() {
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
var ctx = canvas.getContext('2d');
var imageData = ctx.createImageData(1, 1);
return (typeof imageData.data.buffer !== 'undefined');
}
Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
configurable: true,
get: function PDFJS_hasCanvasTypedArrays() {
return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
}
});
var Uint32ArrayView = (function Uint32ArrayViewClosure() { var Uint32ArrayView = (function Uint32ArrayViewClosure() {
function Uint32ArrayView(buffer, length) { function Uint32ArrayView(buffer, length) {
@ -728,13 +634,11 @@ var Uint32ArrayView = (function Uint32ArrayViewClosure() {
})(); })();
exports.Uint32ArrayView = Uint32ArrayView; exports.Uint32ArrayView = Uint32ArrayView;
//#else
//PDFJS.hasCanvasTypedArrays = true;
//#endif //#endif
var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
var Util = PDFJS.Util = (function UtilClosure() { var Util = (function UtilClosure() {
function Util() {} function Util() {}
var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
@ -987,7 +891,7 @@ var Util = PDFJS.Util = (function UtilClosure() {
* @class * @class
* @alias PDFJS.PageViewport * @alias PDFJS.PageViewport
*/ */
var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() { var PageViewport = (function PageViewportClosure() {
/** /**
* @constructor * @constructor
* @private * @private
@ -1211,8 +1115,6 @@ function createPromiseCapability() {
return capability; return capability;
} }
PDFJS.createPromiseCapability = createPromiseCapability;
/** /**
* Polyfill for Promises: * Polyfill for Promises:
* The following promise implementation tries to generally implement the * The following promise implementation tries to generally implement the
@ -1593,7 +1495,7 @@ var StatTimer = (function StatTimerClosure() {
return StatTimer; return StatTimer;
})(); })();
PDFJS.createBlob = function createBlob(data, contentType) { var createBlob = function createBlob(data, contentType) {
if (typeof Blob !== 'undefined') { if (typeof Blob !== 'undefined') {
return new Blob([data], { type: contentType }); return new Blob([data], { type: contentType });
} }
@ -1603,15 +1505,15 @@ PDFJS.createBlob = function createBlob(data, contentType) {
return bb.getBlob(contentType); return bb.getBlob(contentType);
}; };
PDFJS.createObjectURL = (function createObjectURLClosure() { var createObjectURL = (function createObjectURLClosure() {
// Blob/createObjectURL is not available, falling back to data schema. // Blob/createObjectURL is not available, falling back to data schema.
var digits = var digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
return function createObjectURL(data, contentType) { return function createObjectURL(data, contentType, forceDataSchema) {
if (!PDFJS.disableCreateObjectURL && if (!forceDataSchema &&
typeof URL !== 'undefined' && URL.createObjectURL) { typeof URL !== 'undefined' && URL.createObjectURL) {
var blob = PDFJS.createBlob(data, contentType); var blob = createBlob(data, contentType);
return URL.createObjectURL(blob); return URL.createObjectURL(blob);
} }
@ -2399,6 +2301,7 @@ function loadJpegStream(id, imageUrl, objs) {
exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX; exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
exports.IDENTITY_MATRIX = IDENTITY_MATRIX; exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
exports.OPS = OPS; exports.OPS = OPS;
exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES; exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
exports.AnnotationBorderStyleType = AnnotationBorderStyleType; exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
exports.AnnotationFlag = AnnotationFlag; exports.AnnotationFlag = AnnotationFlag;
@ -2406,12 +2309,11 @@ exports.AnnotationType = AnnotationType;
exports.FontType = FontType; exports.FontType = FontType;
exports.ImageKind = ImageKind; exports.ImageKind = ImageKind;
exports.InvalidPDFException = InvalidPDFException; exports.InvalidPDFException = InvalidPDFException;
exports.LinkTarget = LinkTarget;
exports.LinkTargetStringMap = LinkTargetStringMap;
exports.MessageHandler = MessageHandler; exports.MessageHandler = MessageHandler;
exports.MissingDataException = MissingDataException; exports.MissingDataException = MissingDataException;
exports.MissingPDFException = MissingPDFException; exports.MissingPDFException = MissingPDFException;
exports.NotImplementedException = NotImplementedException; exports.NotImplementedException = NotImplementedException;
exports.PageViewport = PageViewport;
exports.PasswordException = PasswordException; exports.PasswordException = PasswordException;
exports.PasswordResponses = PasswordResponses; exports.PasswordResponses = PasswordResponses;
exports.StatTimer = StatTimer; exports.StatTimer = StatTimer;
@ -2426,29 +2328,32 @@ exports.arraysToBytes = arraysToBytes;
exports.assert = assert; exports.assert = assert;
exports.bytesToString = bytesToString; exports.bytesToString = bytesToString;
exports.combineUrl = combineUrl; exports.combineUrl = combineUrl;
exports.createBlob = createBlob;
exports.createPromiseCapability = createPromiseCapability; exports.createPromiseCapability = createPromiseCapability;
exports.createObjectURL = createObjectURL;
exports.deprecated = deprecated; exports.deprecated = deprecated;
exports.error = error; exports.error = error;
exports.getFilenameFromUrl = getFilenameFromUrl;
exports.getLookupTableFactory = getLookupTableFactory; exports.getLookupTableFactory = getLookupTableFactory;
exports.getVerbosityLevel = getVerbosityLevel;
exports.globalScope = globalScope;
exports.info = info; exports.info = info;
exports.isArray = isArray; exports.isArray = isArray;
exports.isArrayBuffer = isArrayBuffer; exports.isArrayBuffer = isArrayBuffer;
exports.isBool = isBool; exports.isBool = isBool;
exports.isEmptyObj = isEmptyObj; exports.isEmptyObj = isEmptyObj;
exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
exports.isInt = isInt; exports.isInt = isInt;
exports.isNum = isNum; exports.isNum = isNum;
exports.isString = isString; exports.isString = isString;
exports.isSameOrigin = isSameOrigin; exports.isSameOrigin = isSameOrigin;
exports.isValidUrl = isValidUrl; exports.isValidUrl = isValidUrl;
exports.addLinkAttributes = addLinkAttributes; exports.isLittleEndian = isLittleEndian;
exports.loadJpegStream = loadJpegStream; exports.loadJpegStream = loadJpegStream;
exports.log2 = log2; exports.log2 = log2;
exports.readInt8 = readInt8; exports.readInt8 = readInt8;
exports.readUint16 = readUint16; exports.readUint16 = readUint16;
exports.readUint32 = readUint32; exports.readUint32 = readUint32;
exports.removeNullCharacters = removeNullCharacters; exports.removeNullCharacters = removeNullCharacters;
exports.setVerbosityLevel = setVerbosityLevel;
exports.shadow = shadow; exports.shadow = shadow;
exports.string32 = string32; exports.string32 = string32;
exports.stringToBytes = stringToBytes; exports.stringToBytes = stringToBytes;

View File

@ -0,0 +1,50 @@
/* globals expect, it, describe, PDFJS, isExternalLinkTargetSet, LinkTarget,
getFilenameFromUrl */
'use strict';
describe('dom_utils', function() {
describe('getFilenameFromUrl', function() {
it('should get the filename from an absolute URL', function() {
var url = 'http://server.org/filename.pdf';
var result = getFilenameFromUrl(url);
var expected = 'filename.pdf';
expect(result).toEqual(expected);
});
it('should get the filename from a relative URL', function() {
var url = '../../filename.pdf';
var result = getFilenameFromUrl(url);
var expected = 'filename.pdf';
expect(result).toEqual(expected);
});
});
describe('isExternalLinkTargetSet', function() {
// Save the current state, to avoid interfering with other tests.
var previousExternalLinkTarget = PDFJS.externalLinkTarget;
it('handles the predefined LinkTargets', function() {
for (var key in LinkTarget) {
var linkTarget = LinkTarget[key];
PDFJS.externalLinkTarget = linkTarget;
expect(isExternalLinkTargetSet()).toEqual(!!linkTarget);
}
});
it('handles incorrect LinkTargets', function() {
var targets = [true, '', false, -1, '_blank', null];
for (var i = 0, ii = targets.length; i < ii; i++) {
var linkTarget = targets[i];
PDFJS.externalLinkTarget = linkTarget;
expect(isExternalLinkTargetSet()).toEqual(false);
}
});
// Reset the state.
PDFJS.externalLinkTarget = previousExternalLinkTarget;
});
});

View File

@ -37,6 +37,7 @@
<script src="cmap_spec.js"></script> <script src="cmap_spec.js"></script>
<script src="annotation_layer_spec.js"></script> <script src="annotation_layer_spec.js"></script>
<script src="network_spec.js"></script> <script src="network_spec.js"></script>
<script src="dom_utils_spec.js"></script>
<script> <script>
'use strict'; 'use strict';
@ -45,20 +46,20 @@
function initializePDFJS(callback) { function initializePDFJS(callback) {
require.config({paths: {'pdfjs': '../../src'}}); require.config({paths: {'pdfjs': '../../src'}});
require(['pdfjs/shared/util', 'pdfjs/shared/global', 'pdfjs/core/primitives', require(['pdfjs/shared/util', 'pdfjs/display/global', 'pdfjs/core/primitives',
'pdfjs/core/annotation', 'pdfjs/core/crypto', 'pdfjs/core/stream', 'pdfjs/core/annotation', 'pdfjs/core/crypto', 'pdfjs/core/stream',
'pdfjs/core/fonts', 'pdfjs/core/ps_parser', 'pdfjs/core/function', 'pdfjs/core/fonts', 'pdfjs/core/ps_parser', 'pdfjs/core/function',
'pdfjs/core/parser', 'pdfjs/core/evaluator', 'pdfjs/core/cmap', 'pdfjs/core/parser', 'pdfjs/core/evaluator', 'pdfjs/core/cmap',
'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/display/api', 'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/display/api',
'pdfjs/display/metadata'], 'pdfjs/display/metadata', 'pdfjs/display/dom_utils'],
function (sharedUtil, sharedGlobal, corePrimitives, coreAnnotation, function (sharedUtil, displayGlobal, corePrimitives, coreAnnotation,
coreCrypto, coreStream, coreFonts, corePsParser, coreFunction, coreCrypto, coreStream, coreFonts, corePsParser, coreFunction,
coreParser, coreEvaluator, coreCMap, coreWorker, coreParser, coreEvaluator, coreCMap, coreWorker, coreNetwork,
coreNetwork, displayAPI, displayMetadata) { displayAPI, displayMetadata, displayDOMUtils) {
pdfjsLibs = { pdfjsLibs = {
sharedUtil: sharedUtil, sharedUtil: sharedUtil,
sharedGlobal: sharedGlobal, displayGlobal: displayGlobal,
corePrimitives: corePrimitives, corePrimitives: corePrimitives,
coreAnnotation: coreAnnotation, coreAnnotation: coreAnnotation,
coreCrypto: coreCrypto, coreCrypto: coreCrypto,
@ -72,7 +73,8 @@
coreWorker: coreWorker, coreWorker: coreWorker,
coreNetwork: coreNetwork, coreNetwork: coreNetwork,
displayAPI: displayAPI, displayAPI: displayAPI,
displayMetadata: displayMetadata displayMetadata: displayMetadata,
displayDOMUtils: displayDOMUtils
}; };
// Expose all loaded internal exported members to global scope. // Expose all loaded internal exported members to global scope.

View File

@ -1,26 +1,9 @@
/* globals expect, it, describe, combineUrl, Dict, isDict, Name, PDFJS, /* globals expect, it, describe, combineUrl, Dict, isDict, Name, PDFJS,
stringToPDFString, isExternalLinkTargetSet, LinkTarget, stringToPDFString, removeNullCharacters */
removeNullCharacters, getFilenameFromUrl */
'use strict'; 'use strict';
describe('util', function() { describe('util', function() {
describe('getFilenameFromUrl', function() {
it('should get the filename from an absolute URL', function() {
var url = 'http://server.org/filename.pdf';
var result = getFilenameFromUrl(url);
var expected = 'filename.pdf';
expect(result).toEqual(expected);
});
it('should get the filename from a relative URL', function() {
var url = '../../filename.pdf';
var result = getFilenameFromUrl(url);
var expected = 'filename.pdf';
expect(result).toEqual(expected);
});
});
describe('combineUrl', function() { describe('combineUrl', function() {
it('absolute url with protocol stays as is', function() { it('absolute url with protocol stays as is', function() {
var baseUrl = 'http://server/index.html'; var baseUrl = 'http://server/index.html';
@ -114,34 +97,6 @@ describe('util', function() {
}); });
}); });
describe('isExternalLinkTargetSet', function() {
// Save the current state, to avoid interfering with other tests.
var previousExternalLinkTarget = PDFJS.externalLinkTarget;
it('handles the predefined LinkTargets', function() {
for (var key in LinkTarget) {
var linkTarget = LinkTarget[key];
PDFJS.externalLinkTarget = linkTarget;
expect(isExternalLinkTargetSet()).toEqual(!!linkTarget);
}
});
it('handles incorrect LinkTargets', function() {
var targets = [true, '', false, -1, '_blank', null];
for (var i = 0, ii = targets.length; i < ii; i++) {
var linkTarget = targets[i];
PDFJS.externalLinkTarget = linkTarget;
expect(isExternalLinkTargetSet()).toEqual(false);
}
});
// Reset the state.
PDFJS.externalLinkTarget = previousExternalLinkTarget;
});
describe('removeNullCharacters', function() { describe('removeNullCharacters', function() {
it('should not modify string without null characters', function() { it('should not modify string without null characters', function() {
var str = 'string without null chars'; var str = 'string without null chars';