1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Remove variable shadowing from the JavaScript files in the src/core/ folder

*This is part of a series of patches that will try to split PR 11566 into smaller chunks, to make reviewing more feasible.*

Once all the code has been fixed, we'll be able to eventually enable the ESLint no-shadow rule; see https://eslint.org/docs/rules/no-shadow
This commit is contained in:
Jonas Jenwald 2020-03-23 17:04:47 +01:00
parent b86df97725
commit 216cbca16c
11 changed files with 135 additions and 140 deletions

View file

@ -1269,7 +1269,6 @@ var Font = (function FontClosure() {
fallbackToSystemFont: function Font_fallbackToSystemFont() {
this.missingFile = true;
var charCode, unicode;
// The file data is not specified. Trying to fix the font name
// to be used with the canvas.font.
var name = this.name;
@ -1303,17 +1302,17 @@ var Font = (function FontClosure() {
// Standard fonts might be embedded as CID font without glyph mapping.
// Building one based on GlyphMapForStandardFonts.
const map = [];
for (charCode in GlyphMapForStandardFonts) {
for (const charCode in GlyphMapForStandardFonts) {
map[+charCode] = GlyphMapForStandardFonts[charCode];
}
if (/Arial-?Black/i.test(name)) {
var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
for (charCode in SupplementalGlyphMapForArialBlack) {
for (const charCode in SupplementalGlyphMapForArialBlack) {
map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
}
} else if (/Calibri/i.test(name)) {
const SupplementalGlyphMapForCalibri = getSupplementalGlyphMapForCalibri();
for (charCode in SupplementalGlyphMapForCalibri) {
for (const charCode in SupplementalGlyphMapForCalibri) {
map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
}
}
@ -1354,7 +1353,7 @@ var Font = (function FontClosure() {
if (!this.composite) {
var glyphName =
this.differences[charCode] || this.defaultEncoding[charCode];
unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
if (unicode !== -1) {
unicodeCharCode = unicode;
}
@ -1368,7 +1367,7 @@ var Font = (function FontClosure() {
if (/Verdana/i.test(name)) {
// Fixes issue11242_reduced.pdf
const GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
for (charCode in GlyphMapForStandardFonts) {
for (const charCode in GlyphMapForStandardFonts) {
map[+charCode] = GlyphMapForStandardFonts[charCode];
}
}
@ -1409,7 +1408,7 @@ var Font = (function FontClosure() {
tables["post"] = null;
for (let i = 0; i < numTables; i++) {
const table = readTableEntry(font);
const table = readTableEntry(file);
if (!VALID_TABLES.includes(table.tag)) {
continue; // skipping table if it's not a required or optional table
}
@ -1529,7 +1528,7 @@ var Font = (function FontClosure() {
* Read the appropriate subtable from the cmap according to 9.6.6.4 from
* PDF spec
*/
function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {
if (!cmap) {
warn("No cmap table available.");
return {
@ -1540,11 +1539,11 @@ var Font = (function FontClosure() {
};
}
var segment;
var start = (font.start ? font.start : 0) + cmap.offset;
font.pos = start;
var start = (file.start ? file.start : 0) + cmap.offset;
file.pos = start;
font.getUint16(); // version
var numTables = font.getUint16();
file.getUint16(); // version
var numTables = file.getUint16();
var potentialTable;
var canBreak = false;
@ -1555,9 +1554,9 @@ var Font = (function FontClosure() {
// The following takes advantage of the fact that the tables are sorted
// to work.
for (var i = 0; i < numTables; i++) {
var platformId = font.getUint16();
var encodingId = font.getUint16();
var offset = font.getInt32() >>> 0;
var platformId = file.getUint16();
var encodingId = file.getUint16();
var offset = file.getInt32() >>> 0;
var useTable = false;
// Sometimes there are multiple of the same type of table. Default
@ -1605,9 +1604,9 @@ var Font = (function FontClosure() {
}
if (potentialTable) {
font.pos = start + potentialTable.offset;
file.pos = start + potentialTable.offset;
}
if (!potentialTable || font.peekByte() === -1) {
if (!potentialTable || file.peekByte() === -1) {
warn("Could not find a preferred cmap table.");
return {
platformId: -1,
@ -1617,9 +1616,9 @@ var Font = (function FontClosure() {
};
}
var format = font.getUint16();
font.getUint16(); // length
font.getUint16(); // language
var format = file.getUint16();
file.getUint16(); // length
file.getUint16(); // language
var hasShortCmap = false;
var mappings = [];
@ -1628,7 +1627,7 @@ var Font = (function FontClosure() {
// TODO(mack): refactor this cmap subtable reading logic out
if (format === 0) {
for (j = 0; j < 256; j++) {
var index = font.getByte();
var index = file.getByte();
if (!index) {
continue;
}
@ -1641,26 +1640,26 @@ var Font = (function FontClosure() {
} else if (format === 4) {
// re-creating the table in format 4 since the encoding
// might be changed
var segCount = font.getUint16() >> 1;
font.getBytes(6); // skipping range fields
var segCount = file.getUint16() >> 1;
file.getBytes(6); // skipping range fields
var segIndex,
segments = [];
for (segIndex = 0; segIndex < segCount; segIndex++) {
segments.push({ end: font.getUint16() });
segments.push({ end: file.getUint16() });
}
font.getUint16();
file.getUint16();
for (segIndex = 0; segIndex < segCount; segIndex++) {
segments[segIndex].start = font.getUint16();
segments[segIndex].start = file.getUint16();
}
for (segIndex = 0; segIndex < segCount; segIndex++) {
segments[segIndex].delta = font.getUint16();
segments[segIndex].delta = file.getUint16();
}
var offsetsCount = 0;
for (segIndex = 0; segIndex < segCount; segIndex++) {
segment = segments[segIndex];
var rangeOffset = font.getUint16();
var rangeOffset = file.getUint16();
if (!rangeOffset) {
segment.offsetIndex = -1;
continue;
@ -1676,7 +1675,7 @@ var Font = (function FontClosure() {
var offsets = [];
for (j = 0; j < offsetsCount; j++) {
offsets.push(font.getUint16());
offsets.push(file.getUint16());
}
for (segIndex = 0; segIndex < segCount; segIndex++) {
@ -1705,11 +1704,11 @@ var Font = (function FontClosure() {
// table. (This looks weird, so I can have missed something), this
// works on Linux but seems to fails on Mac so let's rewrite the
// cmap table to a 3-1-4 style
var firstCode = font.getUint16();
var entryCount = font.getUint16();
var firstCode = file.getUint16();
var entryCount = file.getUint16();
for (j = 0; j < entryCount; j++) {
glyphId = font.getUint16();
glyphId = file.getUint16();
var charCode = firstCode + j;
mappings.push({
@ -1747,7 +1746,7 @@ var Font = (function FontClosure() {
}
function sanitizeMetrics(
font,
file,
header,
metrics,
numGlyphs,
@ -1760,21 +1759,21 @@ var Font = (function FontClosure() {
return;
}
font.pos = (font.start ? font.start : 0) + header.offset;
font.pos += 4; // version
font.pos += 2; // ascent
font.pos += 2; // descent
font.pos += 2; // linegap
font.pos += 2; // adv_width_max
font.pos += 2; // min_sb1
font.pos += 2; // min_sb2
font.pos += 2; // max_extent
font.pos += 2; // caret_slope_rise
font.pos += 2; // caret_slope_run
font.pos += 2; // caret_offset
font.pos += 8; // reserved
font.pos += 2; // format
var numOfMetrics = font.getUint16();
file.pos = (file.start ? file.start : 0) + header.offset;
file.pos += 4; // version
file.pos += 2; // ascent
file.pos += 2; // descent
file.pos += 2; // linegap
file.pos += 2; // adv_width_max
file.pos += 2; // min_sb1
file.pos += 2; // min_sb2
file.pos += 2; // max_extent
file.pos += 2; // caret_slope_rise
file.pos += 2; // caret_slope_run
file.pos += 2; // caret_offset
file.pos += 8; // reserved
file.pos += 2; // format
var numOfMetrics = file.getUint16();
if (numOfMetrics > numGlyphs) {
info(
@ -2107,7 +2106,7 @@ var Font = (function FontClosure() {
};
}
function readPostScriptTable(post, properties, maxpNumGlyphs) {
function readPostScriptTable(post, propertiesObj, maxpNumGlyphs) {
var start = (font.start ? font.start : 0) + post.offset;
font.pos = start;
@ -2168,12 +2167,12 @@ var Font = (function FontClosure() {
default:
warn("Unknown/unsupported post table version " + version);
valid = false;
if (properties.defaultEncoding) {
glyphNames = properties.defaultEncoding;
if (propertiesObj.defaultEncoding) {
glyphNames = propertiesObj.defaultEncoding;
}
break;
}
properties.glyphNames = glyphNames;
propertiesObj.glyphNames = glyphNames;
return valid;
}
@ -2706,8 +2705,7 @@ var Font = (function FontClosure() {
data: createPostTable(properties),
};
var charCodeToGlyphId = [],
charCode;
const charCodeToGlyphId = [];
// Helper function to try to skip mapping of empty glyphs.
function hasGlyph(glyphId) {
@ -2773,7 +2771,7 @@ var Font = (function FontClosure() {
baseEncoding = getEncoding(properties.baseEncodingName);
}
var glyphsUnicodeMap = getGlyphsUnicode();
for (charCode = 0; charCode < 256; charCode++) {
for (let charCode = 0; charCode < 256; charCode++) {
var glyphName, standardGlyphName;
if (this.differences && charCode in this.differences) {
glyphName = this.differences[charCode];
@ -2840,7 +2838,7 @@ var Font = (function FontClosure() {
// (e.g. 0x2013) which when masked would overwrite other values in the
// cmap.
for (let i = 0; i < cmapMappingsLength; ++i) {
charCode = cmapMappings[i].charCode;
let charCode = cmapMappings[i].charCode;
if (
cmapPlatformId === 3 &&
charCode >= 0xf000 &&
@ -3000,7 +2998,7 @@ var Font = (function FontClosure() {
// to begin with.
continue;
}
for (var i = 0, ii = charCodes.length; i < ii; i++) {
for (let i = 0, ii = charCodes.length; i < ii; i++) {
var charCode = charCodes[i];
// Find a fontCharCode that maps to the base and accent glyphs.
// If one doesn't exists, create it.
@ -3089,7 +3087,7 @@ var Font = (function FontClosure() {
var charstrings = font.charstrings;
var cffWidths = font.cff ? font.cff.widths : null;
var hmtx = "\x00\x00\x00\x00"; // Fake .notdef
for (var i = 1, ii = numGlyphs; i < ii; i++) {
for (let i = 1, ii = numGlyphs; i < ii; i++) {
var width = 0;
if (charstrings) {
var charstring = charstrings[i - 1];
@ -3564,8 +3562,8 @@ var Type1Font = (function Type1FontClosure() {
SEAC_ANALYSIS_ENABLED
);
var data = eexecBlockParser.extractFontProgram(properties);
for (var info in data.properties) {
properties[info] = data.properties[info];
for (const key in data.properties) {
properties[key] = data.properties[key];
}
var charstrings = data.charstrings;