Skip to content

Commit

Permalink
Merge pull request #13436 from Snuffleupagus/getPathGenerator-buf
Browse files Browse the repository at this point in the history
Re-factor FontFaceObject.getPathGenerator to use Arrays instead of strings
  • Loading branch information
timvandermeij authored May 25, 2021
2 parents 774f4da + 9ad7746 commit 6e92b56
Showing 1 changed file with 15 additions and 20 deletions.
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

0 comments on commit 6e92b56

Please sign in to comment.