mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Use more for...of
loops in the code-base
Most, if not all, of this code is old enough to predate the general availability of `for...of` iteration.
This commit is contained in:
parent
4e58dabb32
commit
60f6272ed9
16 changed files with 70 additions and 101 deletions
|
@ -476,10 +476,7 @@ class CFFParser {
|
|||
|
||||
createDict(Type, dict, strings) {
|
||||
const cffDict = new Type(strings);
|
||||
for (let i = 0, ii = dict.length; i < ii; ++i) {
|
||||
const pair = dict[i];
|
||||
const key = pair[0];
|
||||
const value = pair[1];
|
||||
for (const [key, value] of dict) {
|
||||
cffDict.setByKey(key, value);
|
||||
}
|
||||
return cffDict;
|
||||
|
@ -1110,15 +1107,14 @@ class CFFDict {
|
|||
if (!(key in this.keyToNameMap)) {
|
||||
return false;
|
||||
}
|
||||
const valueLength = value.length;
|
||||
// ignore empty values
|
||||
if (valueLength === 0) {
|
||||
if (value.length === 0) {
|
||||
return true;
|
||||
}
|
||||
// Ignore invalid values (fixes bug1068432.pdf and bug1308536.pdf).
|
||||
for (let i = 0; i < valueLength; i++) {
|
||||
if (isNaN(value[i])) {
|
||||
warn('Invalid CFFDict value: "' + value + '" for key "' + key + '".');
|
||||
for (const val of value) {
|
||||
if (isNaN(val)) {
|
||||
warn(`Invalid CFFDict value: "${value}" for key "${key}".`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1166,8 +1162,7 @@ class CFFDict {
|
|||
opcodes: {},
|
||||
order: [],
|
||||
};
|
||||
for (let i = 0, ii = layout.length; i < ii; ++i) {
|
||||
const entry = layout[i];
|
||||
for (const entry of layout) {
|
||||
const key = Array.isArray(entry[0])
|
||||
? (entry[0][0] << 8) + entry[0][1]
|
||||
: entry[0];
|
||||
|
@ -1401,8 +1396,7 @@ class CFFCompiler {
|
|||
if (cff.topDict.hasName("FontMatrix")) {
|
||||
const base = cff.topDict.getByName("FontMatrix");
|
||||
cff.topDict.removeByName("FontMatrix");
|
||||
for (let i = 0, ii = cff.fdArray.length; i < ii; i++) {
|
||||
const subDict = cff.fdArray[i];
|
||||
for (const subDict of cff.fdArray) {
|
||||
let matrix = base.slice(0);
|
||||
if (subDict.hasName("FontMatrix")) {
|
||||
matrix = Util.transform(matrix, subDict.getByName("FontMatrix"));
|
||||
|
@ -1564,8 +1558,7 @@ class CFFCompiler {
|
|||
|
||||
compileNameIndex(names) {
|
||||
const nameIndex = new CFFIndex();
|
||||
for (let i = 0, ii = names.length; i < ii; ++i) {
|
||||
const name = names[i];
|
||||
for (const name of names) {
|
||||
// OTS doesn't allow names to be over 127 characters.
|
||||
const length = Math.min(name.length, 127);
|
||||
let sanitizedName = new Array(length);
|
||||
|
@ -1604,8 +1597,7 @@ class CFFCompiler {
|
|||
compileTopDicts(dicts, length, removeCidKeys) {
|
||||
const fontDictTrackers = [];
|
||||
let fdArrayIndex = new CFFIndex();
|
||||
for (let i = 0, ii = dicts.length; i < ii; ++i) {
|
||||
const fontDict = dicts[i];
|
||||
for (const fontDict of dicts) {
|
||||
if (removeCidKeys) {
|
||||
fontDict.removeByName("CIDFontVersion");
|
||||
fontDict.removeByName("CIDFontRevision");
|
||||
|
@ -1723,8 +1715,8 @@ class CFFCompiler {
|
|||
|
||||
compileStringIndex(strings) {
|
||||
const stringIndex = new CFFIndex();
|
||||
for (let i = 0, ii = strings.length; i < ii; ++i) {
|
||||
stringIndex.add(stringToBytes(strings[i]));
|
||||
for (const string of strings) {
|
||||
stringIndex.add(stringToBytes(string));
|
||||
}
|
||||
return this.compileIndex(stringIndex);
|
||||
}
|
||||
|
@ -1908,9 +1900,7 @@ class CFFCompiler {
|
|||
if (trackers[i]) {
|
||||
trackers[i].offset(data.length);
|
||||
}
|
||||
for (let j = 0, jj = objects[i].length; j < jj; j++) {
|
||||
data.push(objects[i][j]);
|
||||
}
|
||||
data.push(...objects[i]);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue