Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes global PDFJS usage from the src/core/. #7053

Merged
merged 4 commits into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/core/bidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@

(function (root, factory) {
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') {
factory(exports, require('../shared/global.js'));
factory(exports);
} 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.
var baseTypes = [
'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is gone, will the export line at the end of the file still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 120 below defines bidi function

Expand Down Expand Up @@ -430,8 +427,5 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
return createBidiText(chars.join(''), isLTR);
}

return bidi;
})();

exports.bidi = bidi;
}));
2 changes: 0 additions & 2 deletions src/core/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS */

'use strict';

Expand All @@ -35,7 +34,6 @@ var assert = sharedUtil.assert;
var error = sharedUtil.error;
var isInt = sharedUtil.isInt;
var isString = sharedUtil.isString;
var warn = sharedUtil.warn;
var isName = corePrimitives.isName;
var isCmd = corePrimitives.isCmd;
var isStream = corePrimitives.isStream;
Expand Down
7 changes: 5 additions & 2 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var Page = (function PageClosure() {
this.idCounters = {
obj: 0
};
this.evaluatorOptions = pdfManager.evaluatorOptions;
this.resourcesPromise = null;
}

Expand Down Expand Up @@ -224,7 +225,8 @@ var Page = (function PageClosure() {
handler, this.pageIndex,
'p' + this.pageIndex + '_',
this.idCounters,
this.fontCache);
this.fontCache,
this.evaluatorOptions);

var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
var pageListPromise = dataPromises.then(function(data) {
Expand Down Expand Up @@ -289,7 +291,8 @@ var Page = (function PageClosure() {
handler, self.pageIndex,
'p' + self.pageIndex + '_',
self.idCounters,
self.fontCache);
self.fontCache,
self.evaluatorOptions);

return partialEvaluator.getTextContent(contentStream,
task,
Expand Down
38 changes: 23 additions & 15 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS */

'use strict';

Expand Down Expand Up @@ -108,15 +107,23 @@ var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;

var PartialEvaluator = (function PartialEvaluatorClosure() {
var DefaultPartialEvaluatorOptions = {
forceDataSchema: false,
maxImageSize: -1,
disableFontFace: false,
cMapOptions: { url: null, packed: false }
};

function PartialEvaluator(pdfManager, xref, handler, pageIndex,
uniquePrefix, idCounters, fontCache) {
uniquePrefix, idCounters, fontCache, options) {
this.pdfManager = pdfManager;
this.xref = xref;
this.handler = handler;
this.pageIndex = pageIndex;
this.uniquePrefix = uniquePrefix;
this.idCounters = idCounters;
this.fontCache = fontCache;
this.options = options || DefaultPartialEvaluatorOptions;
}

// Trying to minimize Date.now() usage and check every 100 time
Expand Down Expand Up @@ -275,7 +282,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
warn('Image dimensions are missing, or not numbers.');
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.');
return;
}
Expand Down Expand Up @@ -339,11 +347,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// These JPEGs don't need any more processing so we can just send it.
operatorList.addOp(OPS.paintJpegXObject, args);
this.handler.send('obj',
[objId, this.pageIndex, 'JpegStream', image.getIR()]);
[objId, this.pageIndex, 'JpegStream',
image.getIR(this.options.forceDataSchema)]);
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) {
var imgData = imageObj.createImageData(/* forceRGBA = */ false);
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
Expand Down Expand Up @@ -451,7 +461,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var glyphs = font.charsToGlyphs(chars);
var isAddToPathSet = !!(state.textRenderingMode &
TextRenderingMode.ADD_TO_PATH_FLAG);
if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
var buildPath = function (fontChar) {
if (!font.renderer.hasBuiltPath(fontChar)) {
var path = font.renderer.getPathJs(fontChar);
Expand Down Expand Up @@ -1174,7 +1184,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {

function runBidiTransform(textChunk) {
var str = textChunk.str.join('');
var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
var bidiResult = bidi(str, -1, textChunk.vertical);
return {
str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
bidiResult.str),
Expand Down Expand Up @@ -1757,8 +1767,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
// d) Obtain the CMap with the name constructed in step (c) (available
// from the ASN Web site; see the Bibliography).
return CMapFactory.create(ucs2CMapName,
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
null).then(
function (ucs2CMap) {
var cMap = properties.cMap;
toUnicode = [];
Expand All @@ -1785,17 +1795,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
var cmapObj = toUnicode;
if (isName(cmapObj)) {
return CMapFactory.create(cmapObj,
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
function (cmap) {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xFFFF);
}
return new ToUnicodeMap(cmap.getMap());
});
} else if (isStream(cmapObj)) {
return CMapFactory.create(cmapObj,
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
function (cmap) {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xFFFF);
Expand Down Expand Up @@ -2086,6 +2094,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var descriptor = preEvaluatedFont.descriptor;
var type = preEvaluatedFont.type;
var maxCharIndex = (composite ? 0xFFFF : 0xFF);
var cMapOptions = this.options.cMapOptions;
var properties;

if (!descriptor) {
Expand Down Expand Up @@ -2213,8 +2222,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (isName(cidEncoding)) {
properties.cidEncoding = cidEncoding.name;
}
cMapPromise = CMapFactory.create(cidEncoding,
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).then(
cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
function (cMap) {
properties.cMap = cMap;
properties.vertical = properties.cMap.vertical;
Expand Down
12 changes: 4 additions & 8 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS */

'use strict';

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs/core/fonts', ['exports', 'pdfjs/shared/util',
'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/standard_fonts', 'pdfjs/core/unicode'], factory);
} else if (typeof exports !== 'undefined') {
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('./font_renderer.js'), require('./encodings.js'),
require('./standard_fonts'), require('./unicode.js'));
} else {
factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode);
}
}(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
coreCMap, coreGlyphList, coreCharsets, coreFontRenderer,
coreGlyphList, coreCharsets, coreFontRenderer,
coreEncodings, coreStandardFonts, coreUnicode) {

var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
Expand All @@ -55,11 +54,8 @@ var shadow = sharedUtil.shadow;
var stringToBytes = sharedUtil.stringToBytes;
var string32 = sharedUtil.string32;
var warn = sharedUtil.warn;
var Name = corePrimitives.Name;
var Stream = coreStream.Stream;
var Lexer = coreParser.Lexer;
var CMapFactory = coreCMap.CMapFactory;
var IdentityCMap = coreCMap.IdentityCMap;
var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
Expand Down
17 changes: 11 additions & 6 deletions src/core/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ var PDFImage = (function PDFImageClosure() {
* Decode the image in the main thread if it supported. Resovles the promise
* 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)) {
// For natively supported jpegs send them to the main thread for decoding.
var dict = image.dict;
var colorSpace = dict.get('ColorSpace', 'CS');
colorSpace = ColorSpace.parse(colorSpace, xref, res);
var numComps = colorSpace.numComps;
var decodePromise = handler.sendWithPromise('JpegDecode',
[image.getIR(), numComps]);
[image.getIR(forceDataSchema),
numComps]);
return decodePromise.then(function (message) {
var data = message.data;
return new Stream(data, 0, data.length, image.dict);
Expand Down Expand Up @@ -184,22 +185,26 @@ var PDFImage = (function PDFImageClosure() {
* with a PDFImage when the image is ready to be used.
*/
PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
res, image, inline) {
var imagePromise = handleImageData(handler, xref, res, image);
res, image, inline,
forceDataSchema) {
var imagePromise = handleImageData(handler, xref, res, image,
forceDataSchema);
var smaskPromise;
var maskPromise;

var smask = image.dict.get('SMask');
var mask = image.dict.get('Mask');

if (smask) {
smaskPromise = handleImageData(handler, xref, res, smask);
smaskPromise = handleImageData(handler, xref, res, smask,
forceDataSchema);
maskPromise = Promise.resolve(null);
} else {
smaskPromise = Promise.resolve(null);
if (mask) {
if (isStream(mask)) {
maskPromise = handleImageData(handler, xref, res, mask);
maskPromise = handleImageData(handler, xref, res, mask,
forceDataSchema);
} else if (isArray(mask)) {
maskPromise = Promise.resolve(mask);
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/core/pdf_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ var BasePdfManager = (function BasePdfManagerClosure() {
})();

var LocalPdfManager = (function LocalPdfManagerClosure() {
function LocalPdfManager(docId, data, password) {
function LocalPdfManager(docId, data, password, evaluatorOptions) {
this._docId = docId;
this.evaluatorOptions = evaluatorOptions;
var stream = new Stream(data);
this.pdfDocument = new PDFDocument(this, stream, password);
this._loadedStreamCapability = createPromiseCapability();
Expand Down Expand Up @@ -157,9 +158,10 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
})();

var NetworkPdfManager = (function NetworkPdfManagerClosure() {
function NetworkPdfManager(docId, pdfNetworkStream, args) {
function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
this._docId = docId;
this.msgHandler = args.msgHandler;
this.evaluatorOptions = evaluatorOptions;

var params = {
msgHandler: args.msgHandler,
Expand Down
6 changes: 3 additions & 3 deletions src/core/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS */

'use strict';

Expand All @@ -36,6 +35,7 @@ var Util = sharedUtil.Util;
var error = sharedUtil.error;
var info = sharedUtil.info;
var isArray = sharedUtil.isArray;
var createObjectURL = sharedUtil.createObjectURL;
var shadow = sharedUtil.shadow;
var warn = sharedUtil.warn;
var Dict = corePrimitives.Dict;
Expand Down Expand Up @@ -963,8 +963,8 @@ var JpegStream = (function JpegStreamClosure() {
return this.buffer;
};

JpegStream.prototype.getIR = function JpegStream_getIR() {
return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
};
/**
* Checks if the image can be decoded and displayed by the browser without any
Expand Down
Loading