Fix the remaining no-var failures, which couldn't be handled automatically, in the src/core/fonts.js file

This commit is contained in:
Jonas Jenwald 2021-05-02 17:40:08 +02:00
parent b9cd080c01
commit cadc20d8b9

View File

@ -297,8 +297,8 @@ const Font = (function FontClosure() {
); );
} }
let data;
try { try {
var data;
switch (type) { switch (type) {
case "MMType1": case "MMType1":
info("MMType1 font (" + name + "), falling back to Type1."); info("MMType1 font (" + name + "), falling back to Type1.");
@ -307,7 +307,7 @@ const Font = (function FontClosure() {
case "CIDFontType0": case "CIDFontType0":
this.mimetype = "font/opentype"; this.mimetype = "font/opentype";
var cff = const cff =
subtype === "Type1C" || subtype === "CIDFontType0C" subtype === "Type1C" || subtype === "CIDFontType0C"
? new CFFFont(file, properties) ? new CFFFont(file, properties)
: new Type1Font(name, file, properties); : new Type1Font(name, file, properties);
@ -474,8 +474,8 @@ const Font = (function FontClosure() {
} }
function buildToFontChar(encoding, glyphsUnicodeMap, differences) { function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
let toFontChar = [], const toFontChar = [];
unicode; let unicode;
for (let i = 0, ii = encoding.length; i < ii; i++) { for (let i = 0, ii = encoding.length; i < ii; i++) {
unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap); unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
if (unicode !== -1) { if (unicode !== -1) {
@ -1299,7 +1299,7 @@ const Font = (function FontClosure() {
// - symbolic fonts the preference is a 3,0 table then a 1,0 table // - symbolic fonts the preference is a 3,0 table then a 1,0 table
// The following takes advantage of the fact that the tables are sorted // The following takes advantage of the fact that the tables are sorted
// to work. // to work.
for (var i = 0; i < numTables; i++) { for (let i = 0; i < numTables; i++) {
const platformId = file.getUint16(); const platformId = file.getUint16();
const encodingId = file.getUint16(); const encodingId = file.getUint16();
const offset = file.getInt32() >>> 0; const offset = file.getInt32() >>> 0;
@ -1392,8 +1392,8 @@ const Font = (function FontClosure() {
// might be changed // might be changed
const segCount = file.getUint16() >> 1; const segCount = file.getUint16() >> 1;
file.skip(6); // skipping range fields file.skip(6); // skipping range fields
let segIndex, const segments = [];
segments = []; let segIndex;
for (segIndex = 0; segIndex < segCount; segIndex++) { for (segIndex = 0; segIndex < segCount; segIndex++) {
segments.push({ end: file.getUint16() }); segments.push({ end: file.getUint16() });
} }
@ -1406,7 +1406,8 @@ const Font = (function FontClosure() {
segments[segIndex].delta = file.getUint16(); segments[segIndex].delta = file.getUint16();
} }
let offsetsCount = 0; let offsetsCount = 0,
offsetIndex;
for (segIndex = 0; segIndex < segCount; segIndex++) { for (segIndex = 0; segIndex < segCount; segIndex++) {
segment = segments[segIndex]; segment = segments[segIndex];
const rangeOffset = file.getUint16(); const rangeOffset = file.getUint16();
@ -1415,7 +1416,7 @@ const Font = (function FontClosure() {
continue; continue;
} }
var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex); offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
segment.offsetIndex = offsetIndex; segment.offsetIndex = offsetIndex;
offsetsCount = Math.max( offsetsCount = Math.max(
offsetsCount, offsetsCount,
@ -1480,7 +1481,7 @@ const Font = (function FontClosure() {
mappings.sort(function (a, b) { mappings.sort(function (a, b) {
return a.charCode - b.charCode; return a.charCode - b.charCode;
}); });
for (i = 1; i < mappings.length; i++) { for (let i = 1; i < mappings.length; i++) {
if (mappings[i - 1].charCode === mappings[i].charCode) { if (mappings[i - 1].charCode === mappings[i].charCode) {
mappings.splice(i, 1); mappings.splice(i, 1);
i--; i--;
@ -1887,12 +1888,12 @@ const Font = (function FontClosure() {
glyphNames = MacStandardGlyphOrdering; glyphNames = MacStandardGlyphOrdering;
break; break;
case 0x00020000: case 0x00020000:
var numGlyphs = font.getUint16(); const numGlyphs = font.getUint16();
if (numGlyphs !== maxpNumGlyphs) { if (numGlyphs !== maxpNumGlyphs) {
valid = false; valid = false;
break; break;
} }
var glyphNameIndexes = []; const glyphNameIndexes = [];
for (i = 0; i < numGlyphs; ++i) { for (i = 0; i < numGlyphs; ++i) {
const index = font.getUint16(); const index = font.getUint16();
if (index >= 32768) { if (index >= 32768) {
@ -1904,8 +1905,8 @@ const Font = (function FontClosure() {
if (!valid) { if (!valid) {
break; break;
} }
var customNames = []; const customNames = [],
var strBuf = []; strBuf = [];
while (font.pos < end) { while (font.pos < end) {
const stringLength = font.getByte(); const stringLength = font.getByte();
strBuf.length = stringLength; strBuf.length = stringLength;
@ -2522,7 +2523,7 @@ const Font = (function FontClosure() {
) { ) {
const glyphsUnicodeMap = getGlyphsUnicode(); const glyphsUnicodeMap = getGlyphsUnicode();
for (let charCode = 0; charCode < 256; charCode++) { for (let charCode = 0; charCode < 256; charCode++) {
var glyphName, standardGlyphName; let glyphName;
if (this.differences && charCode in this.differences) { if (this.differences && charCode in this.differences) {
glyphName = this.differences[charCode]; glyphName = this.differences[charCode];
} else if ( } else if (
@ -2537,9 +2538,12 @@ const Font = (function FontClosure() {
continue; continue;
} }
// Ensure that non-standard glyph names are resolved to valid ones. // Ensure that non-standard glyph names are resolved to valid ones.
standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap); const standardGlyphName = recoverGlyphName(
glyphName,
glyphsUnicodeMap
);
var unicodeOrCharCode; let unicodeOrCharCode;
if (cmapPlatformId === 3 && cmapEncodingId === 1) { if (cmapPlatformId === 3 && cmapEncodingId === 1) {
unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName]; unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
} else if (cmapPlatformId === 1 && cmapEncodingId === 0) { } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
@ -2595,7 +2599,7 @@ const Font = (function FontClosure() {
if (charCodeToGlyphId[i] !== undefined) { if (charCodeToGlyphId[i] !== undefined) {
continue; continue;
} }
glyphName = this.differences[i] || baseEncoding[i]; const glyphName = this.differences[i] || baseEncoding[i];
if (!glyphName) { if (!glyphName) {
continue; continue;
} }