Skip to content

Commit d4da549

Browse files
committed
⬆️ upgrade bower pdfjs
1 parent bfcbedf commit d4da549

File tree

3 files changed

+253
-211
lines changed

3 files changed

+253
-211
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"homepage": "http://github.com/sayanee/angularjs-pdf",
88
"dependencies": {
99
"angular": "1.3.15",
10-
"pdfjs-dist": "1.1.337"
10+
"pdfjs-dist": "1.1.399"
1111
},
1212
"ignore": [
1313
"**/.*",

example/js/lib/pdf.js

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
2222
(typeof window !== 'undefined' ? window : this).PDFJS = {};
2323
}
2424

25-
PDFJS.version = '1.1.337';
26-
PDFJS.build = '61f9052';
25+
PDFJS.version = '1.1.399';
26+
PDFJS.build = '23cb01c';
2727

2828
(function pdfjsWrapper() {
2929
// Use strict in our context only - users might not want it
@@ -1508,6 +1508,10 @@ function MessageHandler(name, comObj) {
15081508
data: result
15091509
});
15101510
}, function (reason) {
1511+
if (reason instanceof Error) {
1512+
// Serialize error to avoid "DataCloneError"
1513+
reason = reason + '';
1514+
}
15111515
comObj.postMessage({
15121516
isReply: true,
15131517
callbackId: data.callbackId,
@@ -1751,6 +1755,14 @@ PDFJS.openExternalLinksInNewWindow = (
17511755
PDFJS.openExternalLinksInNewWindow === undefined ?
17521756
false : PDFJS.openExternalLinksInNewWindow);
17531757

1758+
/**
1759+
* Determines if we can eval strings as JS. Primarily used to improve
1760+
* performance for font rendering.
1761+
* @var {boolean}
1762+
*/
1763+
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
1764+
true : PDFJS.isEvalSupported);
1765+
17541766
/**
17551767
* Document initialization / loading parameters object.
17561768
*
@@ -1861,6 +1873,8 @@ PDFJS.getDocument = function getDocument(src,
18611873
} else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
18621874
!isNaN(pdfBytes.length)) {
18631875
params[key] = new Uint8Array(pdfBytes);
1876+
} else if (isArrayBuffer(pdfBytes)) {
1877+
params[key] = new Uint8Array(pdfBytes);
18641878
} else {
18651879
error('Invalid PDF binary data: either typed array, string or ' +
18661880
'array-like object is expected in the data property.');
@@ -5773,7 +5787,7 @@ var WebGLUtils = (function WebGLUtilsClosure() {
57735787
for (var j = 0, jj = ps.length; j < jj; j++) {
57745788
coords[pIndex] = coordsMap[ps[j]];
57755789
coords[pIndex + 1] = coordsMap[ps[j] + 1];
5776-
colors[cIndex] = colorsMap[cs[i]];
5790+
colors[cIndex] = colorsMap[cs[j]];
57775791
colors[cIndex + 1] = colorsMap[cs[j] + 1];
57785792
colors[cIndex + 2] = colorsMap[cs[j] + 2];
57795793
pIndex += 2;
@@ -6311,6 +6325,18 @@ var FontLoader = {
63116325
));
63126326
},
63136327

6328+
get isEvalSupported() {
6329+
var evalSupport = false;
6330+
if (PDFJS.isEvalSupported) {
6331+
try {
6332+
/* jshint evil: true */
6333+
new Function('');
6334+
evalSupport = true;
6335+
} catch (e) {}
6336+
}
6337+
return shadow(this, 'isEvalSupported', evalSupport);
6338+
},
6339+
63146340
loadTestFontId: 0,
63156341

63166342
loadingContext: {
@@ -6587,9 +6613,40 @@ var FontFaceObject = (function FontFaceObjectClosure() {
65876613

65886614
getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
65896615
if (!(character in this.compiledGlyphs)) {
6590-
var js = objs.get(this.loadedName + '_path_' + character);
6591-
/*jshint -W054 */
6592-
this.compiledGlyphs[character] = new Function('c', 'size', js);
6616+
var cmds = objs.get(this.loadedName + '_path_' + character);
6617+
var current, i, len;
6618+
6619+
// If we can, compile cmds into JS for MAXIMUM SPEED
6620+
if (FontLoader.isEvalSupported) {
6621+
var args, js = '';
6622+
for (i = 0, len = cmds.length; i < len; i++) {
6623+
current = cmds[i];
6624+
6625+
if (current.args !== undefined) {
6626+
args = current.args.join(',');
6627+
} else {
6628+
args = '';
6629+
}
6630+
6631+
js += 'c.' + current.cmd + '(' + args + ');\n';
6632+
}
6633+
/* jshint -W054 */
6634+
this.compiledGlyphs[character] = new Function('c', 'size', js);
6635+
} else {
6636+
// But fall back on using Function.prototype.apply() if we're
6637+
// blocked from using eval() for whatever reason (like CSP policies)
6638+
this.compiledGlyphs[character] = function(c, size) {
6639+
for (i = 0, len = cmds.length; i < len; i++) {
6640+
current = cmds[i];
6641+
6642+
if (current.cmd === 'scale') {
6643+
current.args = [size, -size];
6644+
}
6645+
6646+
c[current.cmd].apply(c, current.args);
6647+
}
6648+
};
6649+
}
65936650
}
65946651
return this.compiledGlyphs[character];
65956652
}

0 commit comments

Comments
 (0)