Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factor FontFaceObject.getPathGenerator to use Arrays instead of strings #13436

Merged
merged 2 commits into from
May 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
this.insertRule(rule);

const names = [];
for (i = 0, ii = fonts.length; i < ii; i++) {
names.push(fonts[i].loadedName);
for (const font of fonts) {
names.push(font.loadedName);
}
names.push(loadTestFontId);

Expand All @@ -326,10 +326,10 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
div.style.position = "absolute";
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");
span.textContent = "Hi";
span.style.fontFamily = names[i];
span.style.fontFamily = name;
div.appendChild(span);
}
this._document.body.appendChild(div);
Expand Down Expand Up @@ -422,7 +422,7 @@ class FontFaceObject {
return this.compiledGlyphs[character];
}

let cmds, current;
let cmds;
try {
cmds = objs.get(this.loadedName + "_path_" + character);
} catch (ex) {
Expand All @@ -441,27 +441,22 @@ class FontFaceObject {

// 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";
const jsBuf = [];
for (const current of cmds) {
const args = current.args !== undefined ? current.args.join(",") : "";
jsBuf.push("c.", current.cmd, "(", args, ");\n");
}
// 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
// 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];

for (const current of cmds) {
if (current.cmd === "scale") {
current.args = [size, -size];
}
Expand Down