Merge pull request #6141 from skalnik/fix-font-csp-issues
Provide a fallback for font rendering when not allowed to use `eval`
This commit is contained in:
commit
c56dc9a093
3 changed files with 83 additions and 34 deletions
|
@ -77,6 +77,18 @@ var FontLoader = {
|
|||
));
|
||||
},
|
||||
|
||||
get isEvalSupported() {
|
||||
var evalSupport = false;
|
||||
if (PDFJS.isEvalSupported) {
|
||||
try {
|
||||
/* jshint evil: true */
|
||||
new Function('');
|
||||
evalSupport = true;
|
||||
} catch (e) {}
|
||||
}
|
||||
return shadow(this, 'isEvalSupported', evalSupport);
|
||||
},
|
||||
|
||||
loadTestFontId: 0,
|
||||
|
||||
loadingContext: {
|
||||
|
@ -372,9 +384,40 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||
|
||||
getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
|
||||
if (!(character in this.compiledGlyphs)) {
|
||||
var js = objs.get(this.loadedName + '_path_' + character);
|
||||
/*jshint -W054 */
|
||||
this.compiledGlyphs[character] = new Function('c', 'size', js);
|
||||
var cmds = objs.get(this.loadedName + '_path_' + character);
|
||||
var current, i, len;
|
||||
|
||||
// If we can, compile cmds into JS for MAXIMUM SPEED
|
||||
if (FontLoader.isEvalSupported) {
|
||||
var args, js = '';
|
||||
for (i = 0, len = cmds.length; i < len; i++) {
|
||||
current = cmds[i];
|
||||
|
||||
if (current.args !== undefined) {
|
||||
args = current.args.join(',');
|
||||
} else {
|
||||
args = '';
|
||||
}
|
||||
|
||||
js += 'c.' + current.cmd + '(' + args + ');\n';
|
||||
}
|
||||
/* jshint -W054 */
|
||||
this.compiledGlyphs[character] = new Function('c', 'size', js);
|
||||
} else {
|
||||
// But fall back on using Function.prototype.apply() if we're
|
||||
// blocked from using eval() for whatever reason (like CSP policies)
|
||||
this.compiledGlyphs[character] = function(c, size) {
|
||||
for (i = 0, len = cmds.length; i < len; i++) {
|
||||
current = cmds[i];
|
||||
|
||||
if (current.cmd === 'scale') {
|
||||
current.args = [size, -size];
|
||||
}
|
||||
|
||||
c[current.cmd].apply(c, current.args);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
return this.compiledGlyphs[character];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue