Merge pull request #8355 from Snuffleupagus/evaluator-rm-bind

Replace unnecessary `bind(this)` and `var self = this` statements with arrow functions in `src/core/evaluator.js`
This commit is contained in:
Tim van der Meij 2017-05-01 23:41:06 +02:00 committed by GitHub
commit e18a08ffeb
2 changed files with 49 additions and 56 deletions

View File

@ -396,7 +396,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
function PartialEvaluator_buildPaintImageXObject(resources, image, function PartialEvaluator_buildPaintImageXObject(resources, image,
inline, operatorList, inline, operatorList,
cacheKey, imageCache) { cacheKey, imageCache) {
var self = this;
var dict = image.dict; var dict = image.dict;
var w = dict.get('Width', 'W'); var w = dict.get('Width', 'W');
var h = dict.get('Height', 'H'); var h = dict.get('Height', 'H');
@ -481,20 +480,19 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (useNativeImageDecoder && if (useNativeImageDecoder &&
(image instanceof JpegStream || mask instanceof JpegStream || (image instanceof JpegStream || mask instanceof JpegStream ||
softMask instanceof JpegStream)) { softMask instanceof JpegStream)) {
nativeImageDecoder = new NativeImageDecoder(self.xref, resources, nativeImageDecoder = new NativeImageDecoder(this.xref, resources,
self.handler, self.options.forceDataSchema); this.handler, this.options.forceDataSchema);
} }
PDFImage.buildImage(self.handler, self.xref, resources, image, inline, PDFImage.buildImage(this.handler, this.xref, resources, image, inline,
nativeImageDecoder). nativeImageDecoder).then((imageObj) => {
then(function(imageObj) { var imgData = imageObj.createImageData(/* forceRGBA = */ false);
var imgData = imageObj.createImageData(/* forceRGBA = */ false); this.handler.send('obj', [objId, this.pageIndex, 'Image', imgData],
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData], [imgData.data.buffer]);
[imgData.data.buffer]); }).catch((reason) => {
}).then(undefined, function (reason) { warn('Unable to decode image: ' + reason);
warn('Unable to decode image: ' + reason); this.handler.send('obj', [objId, this.pageIndex, 'Image', null]);
self.handler.send('obj', [objId, self.pageIndex, 'Image', null]); });
});
operatorList.addOp(OPS.paintImageXObject, args); operatorList.addOp(OPS.paintImageXObject, args);
if (cacheKey) { if (cacheKey) {
@ -567,25 +565,23 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
fontName = fontArgs[0].name; fontName = fontArgs[0].name;
} }
var self = this; return this.loadFont(fontName, fontRef, resources).then((translated) => {
return this.loadFont(fontName, fontRef, resources).then(
function (translated) {
if (!translated.font.isType3Font) { if (!translated.font.isType3Font) {
return translated; return translated;
} }
return translated.loadType3Data(self, resources, operatorList, task). return translated.loadType3Data(this, resources, operatorList, task).
then(function () { then(function () {
return translated; return translated;
}, function (reason) { }).catch((reason) => {
// Error in the font data -- sending unsupported feature notification. // Error in the font data -- sending unsupported feature notification.
self.handler.send('UnsupportedFeature', this.handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.font}); {featureId: UNSUPPORTED_FEATURES.font});
return new TranslatedFont('g_font_error', return new TranslatedFont('g_font_error',
new ErrorFont('Type3 font load error: ' + reason), translated.font); new ErrorFont('Type3 font load error: ' + reason), translated.font);
}); });
}).then(function (translated) { }).then((translated) => {
state.font = translated.font; state.font = translated.font;
translated.send(self.handler); translated.send(this.handler);
return translated.loadedName; return translated.loadedName;
}); });
}, },
@ -596,7 +592,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var isAddToPathSet = !!(state.textRenderingMode & var isAddToPathSet = !!(state.textRenderingMode &
TextRenderingMode.ADD_TO_PATH_FLAG); TextRenderingMode.ADD_TO_PATH_FLAG);
if (font.data && (isAddToPathSet || this.options.disableFontFace)) { if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
var buildPath = function (fontChar) { var buildPath = (fontChar) => {
if (!font.renderer.hasBuiltPath(fontChar)) { if (!font.renderer.hasBuiltPath(fontChar)) {
var path = font.renderer.getPathJs(fontChar); var path = font.renderer.getPathJs(fontChar);
this.handler.send('commonobj', [ this.handler.send('commonobj', [
@ -605,7 +601,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
path path
]); ]);
} }
}.bind(this); };
for (var i = 0, ii = glyphs.length; i < ii; i++) { for (var i = 0, ii = glyphs.length; i < ii; i++) {
var glyph = glyphs[i]; var glyph = glyphs[i];
@ -629,11 +625,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// This array holds the converted/processed state data. // This array holds the converted/processed state data.
var gStateObj = []; var gStateObj = [];
var gStateKeys = gState.getKeys(); var gStateKeys = gState.getKeys();
var self = this;
var promise = Promise.resolve(); var promise = Promise.resolve();
for (var i = 0, ii = gStateKeys.length; i < ii; i++) { for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
var key = gStateKeys[i]; let key = gStateKeys[i];
var value = gState.get(key); let value = gState.get(key);
switch (key) { switch (key) {
case 'Type': case 'Type':
break; break;
@ -649,8 +644,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
gStateObj.push([key, value]); gStateObj.push([key, value]);
break; break;
case 'Font': case 'Font':
promise = promise.then(function () { promise = promise.then(() => {
return self.handleSetFont(resources, null, value[0], operatorList, return this.handleSetFont(resources, null, value[0], operatorList,
task, stateManager.state). task, stateManager.state).
then(function (loadedName) { then(function (loadedName) {
operatorList.addDependency(loadedName); operatorList.addDependency(loadedName);
@ -667,10 +662,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
break; break;
} }
if (isDict(value)) { if (isDict(value)) {
promise = promise.then(function (dict) { promise = promise.then(() => {
return self.handleSMask(dict, resources, operatorList, return this.handleSMask(value, resources, operatorList,
task, stateManager); task, stateManager);
}.bind(this, value)); });
gStateObj.push([key, true]); gStateObj.push([key, true]);
} else { } else {
warn('Unsupported SMask type'); warn('Unsupported SMask type');
@ -824,7 +819,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
translatedPromise = Promise.reject(e); translatedPromise = Promise.reject(e);
} }
var self = this;
translatedPromise.then(function (translatedFont) { translatedPromise.then(function (translatedFont) {
if (translatedFont.fontType !== undefined) { if (translatedFont.fontType !== undefined) {
var xrefFontStats = xref.stats.fontTypes; var xrefFontStats = xref.stats.fontTypes;
@ -833,10 +827,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
fontCapability.resolve(new TranslatedFont(font.loadedName, fontCapability.resolve(new TranslatedFont(font.loadedName,
translatedFont, font)); translatedFont, font));
}, function (reason) { }).catch((reason) => {
// TODO fontCapability.reject? // TODO fontCapability.reject?
// Error in the font data -- sending unsupported feature notification. // Error in the font data -- sending unsupported feature notification.
self.handler.send('UnsupportedFeature', this.handler.send('UnsupportedFeature',
{featureId: UNSUPPORTED_FEATURES.font}); {featureId: UNSUPPORTED_FEATURES.font});
try { try {
@ -1203,7 +1197,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// Closing those for them. // Closing those for them.
closePendingRestoreOPS(); closePendingRestoreOPS();
resolve(); resolve();
}).catch(function(reason) { }).catch((reason) => {
if (this.options.ignoreErrors) { if (this.options.ignoreErrors) {
// Error(s) in the OperatorList -- sending unsupported feature // Error(s) in the OperatorList -- sending unsupported feature
// notification and allow rendering to continue. // notification and allow rendering to continue.
@ -1215,7 +1209,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return; return;
} }
throw reason; throw reason;
}.bind(this)); });
}, },
getTextContent: getTextContent:
@ -1735,7 +1729,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} }
flushTextContentItem(); flushTextContentItem();
resolve(textContent); resolve(textContent);
}).catch(function(reason) { }).catch((reason) => {
if (this.options.ignoreErrors) { if (this.options.ignoreErrors) {
// Error(s) in the TextContent -- allow text-extraction to continue. // Error(s) in the TextContent -- allow text-extraction to continue.
warn('getTextContent - ignoring errors during task: ' + task.name); warn('getTextContent - ignoring errors during task: ' + task.name);
@ -1744,7 +1738,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return textContent; return textContent;
} }
throw reason; throw reason;
}.bind(this)); });
}, },
extractDataStructures: extractDataStructures:
@ -1848,10 +1842,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
properties.baseEncodingName = baseEncodingName; properties.baseEncodingName = baseEncodingName;
properties.hasEncoding = !!baseEncodingName || differences.length > 0; properties.hasEncoding = !!baseEncodingName || differences.length > 0;
properties.dict = dict; properties.dict = dict;
return toUnicodePromise.then(function(toUnicode) { return toUnicodePromise.then((toUnicode) => {
properties.toUnicode = toUnicode; properties.toUnicode = toUnicode;
return this.buildToUnicode(properties); return this.buildToUnicode(properties);
}.bind(this)).then(function (toUnicode) { }).then(function (toUnicode) {
properties.toUnicode = toUnicode; properties.toUnicode = toUnicode;
return properties; return properties;
}); });
@ -2360,12 +2354,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
firstChar: 0, firstChar: 0,
lastChar: maxCharIndex lastChar: maxCharIndex
}; };
return this.extractDataStructures(dict, dict, properties).then( return this.extractDataStructures(dict, dict, properties).
function (properties) { then((properties) => {
properties.widths = this.buildCharCodeToWidth(metrics.widths, properties.widths = this.buildCharCodeToWidth(metrics.widths,
properties); properties);
return new Font(baseFontName, null, properties); return new Font(baseFontName, null, properties);
}.bind(this)); });
} }
} }
@ -2462,17 +2456,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
cMapPromise = Promise.resolve(undefined); cMapPromise = Promise.resolve(undefined);
} }
return cMapPromise.then(function () { return cMapPromise.then(() => {
return this.extractDataStructures(dict, baseDict, properties); return this.extractDataStructures(dict, baseDict, properties);
}.bind(this)).then(function (properties) { }).then((properties) => {
this.extractWidths(dict, descriptor, properties); this.extractWidths(dict, descriptor, properties);
if (type === 'Type3') { if (type === 'Type3') {
properties.isType3Font = true; properties.isType3Font = true;
} }
return new Font(fontName.name, fontFile, properties); return new Font(fontName.name, fontFile, properties);
}.bind(this)); });
} }
}; };
@ -2521,7 +2514,8 @@ var TranslatedFont = (function TranslatedFontClosure() {
var charProcOperatorList = Object.create(null); var charProcOperatorList = Object.create(null);
for (var i = 0, n = charProcKeys.length; i < n; ++i) { for (var i = 0, n = charProcKeys.length; i < n; ++i) {
loadCharProcsPromise = loadCharProcsPromise.then(function (key) { let key = charProcKeys[i];
loadCharProcsPromise = loadCharProcsPromise.then(function () {
var glyphStream = charProcs.get(key); var glyphStream = charProcs.get(key);
var operatorList = new OperatorList(); var operatorList = new OperatorList();
return type3Evaluator.getOperatorList(glyphStream, task, return type3Evaluator.getOperatorList(glyphStream, task,
@ -2532,12 +2526,12 @@ var TranslatedFont = (function TranslatedFontClosure() {
// Add the dependencies to the parent operator list so they are // Add the dependencies to the parent operator list so they are
// resolved before sub operator list is executed synchronously. // resolved before sub operator list is executed synchronously.
parentOperatorList.addDependencies(operatorList.dependencies); parentOperatorList.addDependencies(operatorList.dependencies);
}, function (reason) { }).catch(function(reason) {
warn('Type3 font resource \"' + key + '\" is not available'); warn(`Type3 font resource "${key}" is not available.`);
var operatorList = new OperatorList(); var operatorList = new OperatorList();
charProcOperatorList[key] = operatorList.getIR(); charProcOperatorList[key] = operatorList.getIR();
}); });
}.bind(this, charProcKeys[i])); });
} }
this.type3Loaded = loadCharProcsPromise.then(function () { this.type3Loaded = loadCharProcsPromise.then(function () {
translatedFont.charProcOperatorList = charProcOperatorList; translatedFont.charProcOperatorList = charProcOperatorList;

View File

@ -1584,8 +1584,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing; var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
var operatorList = font.charProcOperatorList[glyph.operatorListId]; var operatorList = font.charProcOperatorList[glyph.operatorListId];
if (!operatorList) { if (!operatorList) {
warn('Type3 character \"' + glyph.operatorListId + warn(`Type3 character "${glyph.operatorListId}" is not available.`);
'\" is not available');
continue; continue;
} }
this.processingType3 = glyph; this.processingType3 = glyph;