Merge pull request #13436 from Snuffleupagus/getPathGenerator-buf
Re-factor FontFaceObject.getPathGenerator to use Arrays instead of strings
This commit is contained in:
commit
6e92b56efa
@ -315,8 +315,8 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|||||||
this.insertRule(rule);
|
this.insertRule(rule);
|
||||||
|
|
||||||
const names = [];
|
const names = [];
|
||||||
for (i = 0, ii = fonts.length; i < ii; i++) {
|
for (const font of fonts) {
|
||||||
names.push(fonts[i].loadedName);
|
names.push(font.loadedName);
|
||||||
}
|
}
|
||||||
names.push(loadTestFontId);
|
names.push(loadTestFontId);
|
||||||
|
|
||||||
@ -326,10 +326,10 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|||||||
div.style.position = "absolute";
|
div.style.position = "absolute";
|
||||||
div.style.top = div.style.left = "0px";
|
div.style.top = div.style.left = "0px";
|
||||||
|
|
||||||
for (i = 0, ii = names.length; i < ii; ++i) {
|
for (const name of names) {
|
||||||
const span = this._document.createElement("span");
|
const span = this._document.createElement("span");
|
||||||
span.textContent = "Hi";
|
span.textContent = "Hi";
|
||||||
span.style.fontFamily = names[i];
|
span.style.fontFamily = name;
|
||||||
div.appendChild(span);
|
div.appendChild(span);
|
||||||
}
|
}
|
||||||
this._document.body.appendChild(div);
|
this._document.body.appendChild(div);
|
||||||
@ -422,7 +422,7 @@ class FontFaceObject {
|
|||||||
return this.compiledGlyphs[character];
|
return this.compiledGlyphs[character];
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmds, current;
|
let cmds;
|
||||||
try {
|
try {
|
||||||
cmds = objs.get(this.loadedName + "_path_" + character);
|
cmds = objs.get(this.loadedName + "_path_" + character);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -441,27 +441,22 @@ class FontFaceObject {
|
|||||||
|
|
||||||
// If we can, compile cmds into JS for MAXIMUM SPEED...
|
// If we can, compile cmds into JS for MAXIMUM SPEED...
|
||||||
if (this.isEvalSupported && IsEvalSupportedCached.value) {
|
if (this.isEvalSupported && IsEvalSupportedCached.value) {
|
||||||
let args,
|
const jsBuf = [];
|
||||||
js = "";
|
for (const current of cmds) {
|
||||||
for (let i = 0, ii = cmds.length; i < ii; i++) {
|
const args = current.args !== undefined ? current.args.join(",") : "";
|
||||||
current = cmds[i];
|
jsBuf.push("c.", current.cmd, "(", args, ");\n");
|
||||||
|
|
||||||
if (current.args !== undefined) {
|
|
||||||
args = current.args.join(",");
|
|
||||||
} else {
|
|
||||||
args = "";
|
|
||||||
}
|
|
||||||
js += "c." + current.cmd + "(" + args + ");\n";
|
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-new-func
|
// eslint-disable-next-line no-new-func
|
||||||
return (this.compiledGlyphs[character] = new Function("c", "size", js));
|
return (this.compiledGlyphs[character] = new Function(
|
||||||
|
"c",
|
||||||
|
"size",
|
||||||
|
jsBuf.join("")
|
||||||
|
));
|
||||||
}
|
}
|
||||||
// ... but fall back on using Function.prototype.apply() if we're
|
// ... but fall back on using Function.prototype.apply() if we're
|
||||||
// blocked from using eval() for whatever reason (like CSP policies).
|
// blocked from using eval() for whatever reason (like CSP policies).
|
||||||
return (this.compiledGlyphs[character] = function (c, size) {
|
return (this.compiledGlyphs[character] = function (c, size) {
|
||||||
for (let i = 0, ii = cmds.length; i < ii; i++) {
|
for (const current of cmds) {
|
||||||
current = cmds[i];
|
|
||||||
|
|
||||||
if (current.cmd === "scale") {
|
if (current.cmd === "scale") {
|
||||||
current.args = [size, -size];
|
current.args = [size, -size];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user