Refactor the FontFaceObject.getPathGenerator
method
- Reduce the overall indentation level, by making use of early returns. - Replace `var` with `let`.
This commit is contained in:
parent
778981ec89
commit
fe288bb872
@ -385,45 +385,41 @@ var FontFaceObject = (function FontFaceObjectClosure() {
|
|||||||
return rule;
|
return rule;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPathGenerator:
|
getPathGenerator(objs, character) {
|
||||||
function FontFaceObject_getPathGenerator(objs, character) {
|
if (this.compiledGlyphs[character] !== undefined) {
|
||||||
if (!(character in this.compiledGlyphs)) {
|
return this.compiledGlyphs[character];
|
||||||
var cmds = objs.get(this.loadedName + '_path_' + character);
|
|
||||||
var current, i, len;
|
|
||||||
|
|
||||||
// If we can, compile cmds into JS for MAXIMUM SPEED
|
|
||||||
if (this.isEvalSupported && IsEvalSupportedCached.value) {
|
|
||||||
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';
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line no-new-func
|
|
||||||
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];
|
|
||||||
|
let cmds = objs.get(this.loadedName + '_path_' + character), current;
|
||||||
|
|
||||||
|
// If we can, compile cmds into JS for MAXIMUM SPEED...
|
||||||
|
if (this.isEvalSupported && IsEvalSupportedCached.value) {
|
||||||
|
let args, js = '';
|
||||||
|
for (let i = 0, ii = cmds.length; i < ii; i++) {
|
||||||
|
current = cmds[i];
|
||||||
|
|
||||||
|
if (current.args !== undefined) {
|
||||||
|
args = current.args.join(',');
|
||||||
|
} else {
|
||||||
|
args = '';
|
||||||
|
}
|
||||||
|
js += 'c.' + current.cmd + '(' + args + ');\n';
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line no-new-func
|
||||||
|
return this.compiledGlyphs[character] = new Function('c', 'size', js);
|
||||||
|
}
|
||||||
|
// ... but fall back on using Function.prototype.apply() if we're
|
||||||
|
// blocked from using eval() for whatever reason (like CSP policies).
|
||||||
|
return this.compiledGlyphs[character] = function(c, size) {
|
||||||
|
for (let i = 0, ii = cmds.length; i < ii; i++) {
|
||||||
|
current = cmds[i];
|
||||||
|
|
||||||
|
if (current.cmd === 'scale') {
|
||||||
|
current.args = [size, -size];
|
||||||
|
}
|
||||||
|
c[current.cmd].apply(c, current.args);
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user