1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #15174 from Snuffleupagus/more-for-of

Use more `for...of` loops in the code-base
This commit is contained in:
Jonas Jenwald 2022-07-19 19:04:47 +02:00 committed by GitHub
commit 98f70d87f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 35 additions and 50 deletions

View file

@ -1682,9 +1682,7 @@ class CFFCompiler {
compileDict(dict, offsetTracker) {
const out = [];
// The dictionary keys must be in a certain order.
const order = dict.order;
for (let i = 0; i < order.length; ++i) {
const key = order[i];
for (const key of dict.order) {
if (!(key in dict.values)) {
continue;
}

View file

@ -219,9 +219,8 @@ class Type1Font {
getCharset() {
const charset = [".notdef"];
const charstrings = this.charstrings;
for (let glyphId = 0; glyphId < charstrings.length; glyphId++) {
charset.push(charstrings[glyphId].glyphName);
for (const { glyphName } of this.charstrings) {
charset.push(glyphName);
}
return charset;
}

View file

@ -576,7 +576,7 @@ const Type1Parser = (function Type1ParserClosure() {
privateData,
},
};
let token, length, data, lenIV, encoded;
let token, length, data, lenIV;
while ((token = this.getToken()) !== null) {
if (token !== "/") {
continue;
@ -604,7 +604,7 @@ const Type1Parser = (function Type1ParserClosure() {
this.getToken(); // read in 'RD' or '-|'
data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
lenIV = program.properties.privateData.lenIV;
encoded = this.readCharStrings(data, lenIV);
const encoded = this.readCharStrings(data, lenIV);
this.nextChar();
token = this.getToken(); // read in 'ND' or '|-'
if (token === "noaccess") {
@ -629,7 +629,7 @@ const Type1Parser = (function Type1ParserClosure() {
this.getToken(); // read in 'RD' or '-|'
data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
lenIV = program.properties.privateData.lenIV;
encoded = this.readCharStrings(data, lenIV);
const encoded = this.readCharStrings(data, lenIV);
this.nextChar();
token = this.getToken(); // read in 'NP' or '|'
if (token === "noaccess") {
@ -675,9 +675,7 @@ const Type1Parser = (function Type1ParserClosure() {
}
}
for (let i = 0; i < charstrings.length; i++) {
const glyph = charstrings[i].glyph;
encoded = charstrings[i].encoded;
for (const { encoded, glyph } of charstrings) {
const charString = new Type1CharString();
const error = charString.convert(
encoded,

View file

@ -263,8 +263,8 @@ class WorkerMessageHandler {
// There may be a chance that `newPdfManager` is not initialized for
// the first few runs of `readchunk` block of code. Be sure to send
// all cached chunks, if any, to chunked_stream via pdf_manager.
for (let i = 0; i < cachedChunks.length; i++) {
newPdfManager.sendProgressiveData(cachedChunks[i]);
for (const chunk of cachedChunks) {
newPdfManager.sendProgressiveData(chunk);
}
cachedChunks = [];

View file

@ -2211,8 +2211,7 @@ class CanvasGraphics {
ctx.save();
ctx.beginPath();
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
for (const path of paths) {
ctx.setTransform.apply(ctx, path.transform);
ctx.translate(path.x, path.y);
path.addToPath(ctx, path.fontSize);