Enable the no-var rule in the src/core/type1_font.js file

These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:

```diff
diff --git a/src/core/type1_font.js b/src/core/type1_font.js
index 50a3e49e6..55a2005fb 100644
--- a/src/core/type1_font.js
+++ b/src/core/type1_font.js
@@ -38,10 +38,9 @@ const Type1Font = (function Type1FontClosure() {
     const scanLength = streamBytesLength - signatureLength;

     let i = startIndex,
-      j,
       found = false;
     while (i < scanLength) {
-      j = 0;
+      let j = 0;
       while (j < signatureLength && streamBytes[i + j] === signature[j]) {
         j++;
       }
@@ -248,14 +247,14 @@ const Type1Font = (function Type1FontClosure() {
         return charCodeToGlyphId;
       }

-      let glyphNames = [".notdef"],
-        glyphId;
+      const glyphNames = [".notdef"];
+      let builtInEncoding, glyphId;
       for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
         glyphNames.push(charstrings[glyphId].glyphName);
       }
       const encoding = properties.builtInEncoding;
       if (encoding) {
-        var builtInEncoding = Object.create(null);
+        builtInEncoding = Object.create(null);
         for (const charCode in encoding) {
           glyphId = glyphNames.indexOf(encoding[charCode]);
           if (glyphId >= 0
```
This commit is contained in:
Jonas Jenwald 2021-05-02 16:48:39 +02:00
parent ff85bcfc0e
commit 4bd69556ab

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-var */
import { import {
CFF, CFF,
@ -32,17 +31,16 @@ import { Type1Parser } from "./type1_parser.js";
import { warn } from "../shared/util.js"; import { warn } from "../shared/util.js";
// Type1Font is also a CIDFontType0. // Type1Font is also a CIDFontType0.
var Type1Font = (function Type1FontClosure() { const Type1Font = (function Type1FontClosure() {
function findBlock(streamBytes, signature, startIndex) { function findBlock(streamBytes, signature, startIndex) {
var streamBytesLength = streamBytes.length; const streamBytesLength = streamBytes.length;
var signatureLength = signature.length; const signatureLength = signature.length;
var scanLength = streamBytesLength - signatureLength; const scanLength = streamBytesLength - signatureLength;
var i = startIndex, let i = startIndex,
j,
found = false; found = false;
while (i < scanLength) { while (i < scanLength) {
j = 0; let j = 0;
while (j < signatureLength && streamBytes[i + j] === signature[j]) { while (j < signatureLength && streamBytes[i + j] === signature[j]) {
j++; j++;
} }
@ -64,10 +62,10 @@ var Type1Font = (function Type1FontClosure() {
} }
function getHeaderBlock(stream, suggestedLength) { function getHeaderBlock(stream, suggestedLength) {
var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63]; const EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
var streamStartPos = stream.pos; // Save the initial stream position. const streamStartPos = stream.pos; // Save the initial stream position.
var headerBytes, headerBytesLength, block; let headerBytes, headerBytesLength, block;
try { try {
headerBytes = stream.getBytes(suggestedLength); headerBytes = stream.getBytes(suggestedLength);
headerBytesLength = headerBytes.length; headerBytesLength = headerBytes.length;
@ -101,10 +99,10 @@ var Type1Font = (function Type1FontClosure() {
warn('Invalid "Length1" property in Type1 font -- trying to recover.'); warn('Invalid "Length1" property in Type1 font -- trying to recover.');
stream.pos = streamStartPos; // Reset the stream position. stream.pos = streamStartPos; // Reset the stream position.
var SCAN_BLOCK_LENGTH = 2048; const SCAN_BLOCK_LENGTH = 2048;
var actualLength; let actualLength;
while (true) { while (true) {
var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH); const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
block = findBlock(scanBytes, EEXEC_SIGNATURE, 0); block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
if (block.length === 0) { if (block.length === 0) {
@ -146,7 +144,7 @@ var Type1Font = (function Type1FontClosure() {
// NOTE: This means that the function can include the fixed-content portion // NOTE: This means that the function can include the fixed-content portion
// in the returned eexec block. In practice this does *not* seem to matter, // in the returned eexec block. In practice this does *not* seem to matter,
// since `Type1Parser_extractFontProgram` will skip over any non-commands. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
var eexecBytes = stream.getBytes(); const eexecBytes = stream.getBytes();
return { return {
stream: new Stream(eexecBytes), stream: new Stream(eexecBytes),
length: eexecBytes.length, length: eexecBytes.length,
@ -158,11 +156,11 @@ var Type1Font = (function Type1FontClosure() {
// Some bad generators embed pfb file as is, we have to strip 6-byte header. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
// Also, length1 and length2 might be off by 6 bytes as well. // Also, length1 and length2 might be off by 6 bytes as well.
// http://www.math.ubc.ca/~cass/piscript/type1.pdf // http://www.math.ubc.ca/~cass/piscript/type1.pdf
var PFB_HEADER_SIZE = 6; const PFB_HEADER_SIZE = 6;
var headerBlockLength = properties.length1; let headerBlockLength = properties.length1;
var eexecBlockLength = properties.length2; let eexecBlockLength = properties.length2;
var pfbHeader = file.peekBytes(PFB_HEADER_SIZE); let pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01; const pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
if (pfbHeaderPresent) { if (pfbHeaderPresent) {
file.skip(PFB_HEADER_SIZE); file.skip(PFB_HEADER_SIZE);
headerBlockLength = headerBlockLength =
@ -173,8 +171,8 @@ var Type1Font = (function Type1FontClosure() {
} }
// Get the data block containing glyphs and subrs information // Get the data block containing glyphs and subrs information
var headerBlock = getHeaderBlock(file, headerBlockLength); const headerBlock = getHeaderBlock(file, headerBlockLength);
var headerBlockParser = new Type1Parser( const headerBlockParser = new Type1Parser(
headerBlock.stream, headerBlock.stream,
false, false,
SEAC_ANALYSIS_ENABLED SEAC_ANALYSIS_ENABLED
@ -191,20 +189,20 @@ var Type1Font = (function Type1FontClosure() {
} }
// Decrypt the data blocks and retrieve it's content // Decrypt the data blocks and retrieve it's content
var eexecBlock = getEexecBlock(file, eexecBlockLength); const eexecBlock = getEexecBlock(file, eexecBlockLength);
var eexecBlockParser = new Type1Parser( const eexecBlockParser = new Type1Parser(
eexecBlock.stream, eexecBlock.stream,
true, true,
SEAC_ANALYSIS_ENABLED SEAC_ANALYSIS_ENABLED
); );
var data = eexecBlockParser.extractFontProgram(properties); const data = eexecBlockParser.extractFontProgram(properties);
for (const key in data.properties) { for (const key in data.properties) {
properties[key] = data.properties[key]; properties[key] = data.properties[key];
} }
var charstrings = data.charstrings; const charstrings = data.charstrings;
var type2Charstrings = this.getType2Charstrings(charstrings); const type2Charstrings = this.getType2Charstrings(charstrings);
var subrs = this.getType2Subrs(data.subrs); const subrs = this.getType2Subrs(data.subrs);
this.charstrings = charstrings; this.charstrings = charstrings;
this.data = this.wrap( this.data = this.wrap(
@ -223,16 +221,16 @@ var Type1Font = (function Type1FontClosure() {
}, },
getCharset: function Type1Font_getCharset() { getCharset: function Type1Font_getCharset() {
var charset = [".notdef"]; const charset = [".notdef"];
var charstrings = this.charstrings; const charstrings = this.charstrings;
for (var glyphId = 0; glyphId < charstrings.length; glyphId++) { for (let glyphId = 0; glyphId < charstrings.length; glyphId++) {
charset.push(charstrings[glyphId].glyphName); charset.push(charstrings[glyphId].glyphName);
} }
return charset; return charset;
}, },
getGlyphMapping: function Type1Font_getGlyphMapping(properties) { getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
var charstrings = this.charstrings; const charstrings = this.charstrings;
if (properties.composite) { if (properties.composite) {
const charCodeToGlyphId = Object.create(null); const charCodeToGlyphId = Object.create(null);
@ -249,15 +247,15 @@ var Type1Font = (function Type1FontClosure() {
return charCodeToGlyphId; return charCodeToGlyphId;
} }
var glyphNames = [".notdef"], const glyphNames = [".notdef"];
glyphId; let builtInEncoding, glyphId;
for (glyphId = 0; glyphId < charstrings.length; glyphId++) { for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
glyphNames.push(charstrings[glyphId].glyphName); glyphNames.push(charstrings[glyphId].glyphName);
} }
var encoding = properties.builtInEncoding; const encoding = properties.builtInEncoding;
if (encoding) { if (encoding) {
var builtInEncoding = Object.create(null); builtInEncoding = Object.create(null);
for (var charCode in encoding) { for (const charCode in encoding) {
glyphId = glyphNames.indexOf(encoding[charCode]); glyphId = glyphNames.indexOf(encoding[charCode]);
if (glyphId >= 0) { if (glyphId >= 0) {
builtInEncoding[charCode] = glyphId; builtInEncoding[charCode] = glyphId;
@ -276,15 +274,15 @@ var Type1Font = (function Type1FontClosure() {
// notdef is always defined. // notdef is always defined.
return true; return true;
} }
var glyph = this.charstrings[id - 1]; const glyph = this.charstrings[id - 1];
return glyph.charstring.length > 0; return glyph.charstring.length > 0;
}, },
getSeacs: function Type1Font_getSeacs(charstrings) { getSeacs: function Type1Font_getSeacs(charstrings) {
var i, ii; let i, ii;
var seacMap = []; const seacMap = [];
for (i = 0, ii = charstrings.length; i < ii; i++) { for (i = 0, ii = charstrings.length; i < ii; i++) {
var charstring = charstrings[i]; const charstring = charstrings[i];
if (charstring.seac) { if (charstring.seac) {
// Offset by 1 for .notdef // Offset by 1 for .notdef
seacMap[i + 1] = charstring.seac; seacMap[i + 1] = charstring.seac;
@ -296,16 +294,16 @@ var Type1Font = (function Type1FontClosure() {
getType2Charstrings: function Type1Font_getType2Charstrings( getType2Charstrings: function Type1Font_getType2Charstrings(
type1Charstrings type1Charstrings
) { ) {
var type2Charstrings = []; const type2Charstrings = [];
for (var i = 0, ii = type1Charstrings.length; i < ii; i++) { for (let i = 0, ii = type1Charstrings.length; i < ii; i++) {
type2Charstrings.push(type1Charstrings[i].charstring); type2Charstrings.push(type1Charstrings[i].charstring);
} }
return type2Charstrings; return type2Charstrings;
}, },
getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) { getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
var bias = 0; let bias = 0;
var count = type1Subrs.length; const count = type1Subrs.length;
if (count < 1133) { if (count < 1133) {
bias = 107; bias = 107;
} else if (count < 33769) { } else if (count < 33769) {
@ -315,8 +313,8 @@ var Type1Font = (function Type1FontClosure() {
} }
// Add a bunch of empty subrs to deal with the Type2 bias // Add a bunch of empty subrs to deal with the Type2 bias
var type2Subrs = []; const type2Subrs = [];
var i; let i;
for (i = 0; i < bias; i++) { for (i = 0; i < bias; i++) {
type2Subrs.push([0x0b]); type2Subrs.push([0x0b]);
} }
@ -335,12 +333,12 @@ var Type1Font = (function Type1FontClosure() {
subrs, subrs,
properties properties
) { ) {
var cff = new CFF(); const cff = new CFF();
cff.header = new CFFHeader(1, 0, 4, 4); cff.header = new CFFHeader(1, 0, 4, 4);
cff.names = [name]; cff.names = [name];
var topDict = new CFFTopDict(); const topDict = new CFFTopDict();
// CFF strings IDs 0...390 are predefined names, so refering // CFF strings IDs 0...390 are predefined names, so refering
// to entries in our own String INDEX starts at SID 391. // to entries in our own String INDEX starts at SID 391.
topDict.setByName("version", 391); topDict.setByName("version", 391);
@ -356,7 +354,7 @@ var Type1Font = (function Type1FontClosure() {
topDict.setByName("Private", null); // placeholder topDict.setByName("Private", null); // placeholder
cff.topDict = topDict; cff.topDict = topDict;
var strings = new CFFStrings(); const strings = new CFFStrings();
strings.add("Version 0.11"); // Version strings.add("Version 0.11"); // Version
strings.add("See original notice"); // Notice strings.add("See original notice"); // Notice
strings.add(name); // FullName strings.add(name); // FullName
@ -366,9 +364,9 @@ var Type1Font = (function Type1FontClosure() {
cff.globalSubrIndex = new CFFIndex(); cff.globalSubrIndex = new CFFIndex();
var count = glyphs.length; const count = glyphs.length;
var charsetArray = [".notdef"]; const charsetArray = [".notdef"];
var i, ii; let i, ii;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
const glyphName = charstrings[i].glyphName; const glyphName = charstrings[i].glyphName;
const index = CFFStandardStrings.indexOf(glyphName); const index = CFFStandardStrings.indexOf(glyphName);
@ -379,16 +377,16 @@ var Type1Font = (function Type1FontClosure() {
} }
cff.charset = new CFFCharset(false, 0, charsetArray); cff.charset = new CFFCharset(false, 0, charsetArray);
var charStringsIndex = new CFFIndex(); const charStringsIndex = new CFFIndex();
charStringsIndex.add([0x8b, 0x0e]); // .notdef charStringsIndex.add([0x8b, 0x0e]); // .notdef
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
charStringsIndex.add(glyphs[i]); charStringsIndex.add(glyphs[i]);
} }
cff.charStrings = charStringsIndex; cff.charStrings = charStringsIndex;
var privateDict = new CFFPrivateDict(); const privateDict = new CFFPrivateDict();
privateDict.setByName("Subrs", null); // placeholder privateDict.setByName("Subrs", null); // placeholder
var fields = [ const fields = [
"BlueValues", "BlueValues",
"OtherBlues", "OtherBlues",
"FamilyBlues", "FamilyBlues",
@ -405,15 +403,15 @@ var Type1Font = (function Type1FontClosure() {
"StdVW", "StdVW",
]; ];
for (i = 0, ii = fields.length; i < ii; i++) { for (i = 0, ii = fields.length; i < ii; i++) {
var field = fields[i]; const field = fields[i];
if (!(field in properties.privateData)) { if (!(field in properties.privateData)) {
continue; continue;
} }
var value = properties.privateData[field]; const value = properties.privateData[field];
if (Array.isArray(value)) { if (Array.isArray(value)) {
// All of the private dictionary array data in CFF must be stored as // All of the private dictionary array data in CFF must be stored as
// "delta-encoded" numbers. // "delta-encoded" numbers.
for (var j = value.length - 1; j > 0; j--) { for (let j = value.length - 1; j > 0; j--) {
value[j] -= value[j - 1]; // ... difference from previous value value[j] -= value[j - 1]; // ... difference from previous value
} }
} }
@ -421,13 +419,13 @@ var Type1Font = (function Type1FontClosure() {
} }
cff.topDict.privateDict = privateDict; cff.topDict.privateDict = privateDict;
var subrIndex = new CFFIndex(); const subrIndex = new CFFIndex();
for (i = 0, ii = subrs.length; i < ii; i++) { for (i = 0, ii = subrs.length; i < ii; i++) {
subrIndex.add(subrs[i]); subrIndex.add(subrs[i]);
} }
privateDict.subrsIndex = subrIndex; privateDict.subrsIndex = subrIndex;
var compiler = new CFFCompiler(cff); const compiler = new CFFCompiler(cff);
return compiler.compile(); return compiler.compile();
}, },
}; };