1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08: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:
Jonas Jenwald 2022-10-03 12:33:49 +02:00
parent 4e58dabb32
commit 60f6272ed9
16 changed files with 70 additions and 101 deletions

View file

@ -2795,7 +2795,6 @@ class Font {
const cmapPlatformId = cmapTable.platformId;
const cmapEncodingId = cmapTable.encodingId;
const cmapMappings = cmapTable.mappings;
const cmapMappingsLength = cmapMappings.length;
let baseEncoding = [],
forcePostTable = false;
if (
@ -2860,18 +2859,18 @@ class Font {
}
}
for (let i = 0; i < cmapMappingsLength; ++i) {
if (cmapMappings[i].charCode !== unicodeOrCharCode) {
for (const mapping of cmapMappings) {
if (mapping.charCode !== unicodeOrCharCode) {
continue;
}
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
charCodeToGlyphId[charCode] = mapping.glyphId;
break;
}
}
} else if (cmapPlatformId === 0) {
// Default Unicode semantics, use the charcodes as is.
for (let i = 0; i < cmapMappingsLength; ++i) {
charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
for (const mapping of cmapMappings) {
charCodeToGlyphId[mapping.charCode] = mapping.glyphId;
}
// Always prefer the BaseEncoding/Differences arrays, when they exist
// (fixes issue13433.pdf).
@ -2888,8 +2887,8 @@ class Font {
// special range since some PDFs have char codes outside of this range
// (e.g. 0x2013) which when masked would overwrite other values in the
// cmap.
for (let i = 0; i < cmapMappingsLength; ++i) {
let charCode = cmapMappings[i].charCode;
for (const mapping of cmapMappings) {
let charCode = mapping.charCode;
if (
cmapPlatformId === 3 &&
charCode >= 0xf000 &&
@ -2897,7 +2896,7 @@ class Font {
) {
charCode &= 0xff;
}
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
charCodeToGlyphId[charCode] = mapping.glyphId;
}
}
@ -3093,8 +3092,7 @@ class Font {
// to begin with.
continue;
}
for (let i = 0, ii = charCodes.length; i < ii; i++) {
const charCode = charCodes[i];
for (const charCode of charCodes) {
// Find a fontCharCode that maps to the base and accent glyphs.
// If one doesn't exists, create it.
const charCodeToGlyphId = newMapping.charCodeToGlyphId;
@ -3212,8 +3210,7 @@ class Font {
// trying to estimate space character width
const possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
let width;
for (let i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
const glyphName = possibleSpaceReplacements[i];
for (const glyphName of possibleSpaceReplacements) {
// if possible, getting width by glyph name
if (glyphName in this.widths) {
width = this.widths[glyphName];