Remove the remaining closures in the src/core/type1_parser.js file

Given that the code is written with JavaScript module-syntax, none of this functionality will "leak" outside of this file with these change.
By removing this closure the file-size is decreased, even for the *built* `pdf.worker.js` file, since there's now less overall indentation in the code.
This commit is contained in:
Jonas Jenwald 2022-08-14 12:50:26 +02:00
parent e6fe127433
commit 6a2c2a646f

View File

@ -22,7 +22,25 @@ import { warn } from "../shared/util.js";
// in tracemonkey and various other pdfs with type1 fonts. // in tracemonkey and various other pdfs with type1 fonts.
const HINTING_ENABLED = false; const HINTING_ENABLED = false;
/* const COMMAND_MAP = {
hstem: [1],
vstem: [3],
vmoveto: [4],
rlineto: [5],
hlineto: [6],
vlineto: [7],
rrcurveto: [8],
callsubr: [10],
flex: [12, 35],
drop: [12, 18],
endchar: [14],
rmoveto: [21],
hmoveto: [22],
vhcurveto: [30],
hvcurveto: [31],
};
/**
* CharStrings are encoded following the the CharString Encoding sequence * CharStrings are encoded following the the CharString Encoding sequence
* describe in Chapter 6 of the "Adobe Type1 Font Format" specification. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
* The value in a byte indicates a command, a number, or subsequent bytes * The value in a byte indicates a command, a number, or subsequent bytes
@ -60,26 +78,6 @@ const HINTING_ENABLED = false;
* to be encoded and this encoding technique helps to minimize the length of * to be encoded and this encoding technique helps to minimize the length of
* the charStrings. * the charStrings.
*/ */
const Type1CharString = (function Type1CharStringClosure() {
const COMMAND_MAP = {
hstem: [1],
vstem: [3],
vmoveto: [4],
rlineto: [5],
hlineto: [6],
vlineto: [7],
rrcurveto: [8],
callsubr: [10],
flex: [12, 35],
drop: [12, 18],
endchar: [14],
rmoveto: [21],
hmoveto: [22],
vhcurveto: [30],
hvcurveto: [31],
};
// eslint-disable-next-line no-shadow
class Type1CharString { class Type1CharString {
constructor() { constructor() {
this.width = 0; this.width = 0;
@ -155,11 +153,7 @@ const Type1CharString = (function Type1CharStringClosure() {
error = true; error = true;
break; break;
} }
error = this.convert( error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
subrs[subrNumber],
subrs,
seacAnalysisEnabled
);
break; break;
case 11: // return case 11: // return
return error; return error;
@ -361,22 +355,10 @@ const Type1CharString = (function Type1CharStringClosure() {
} }
} }
return Type1CharString; /**
})();
/*
* Type1Parser encapsulate the needed code for parsing a Type1 font
* program. Some of its logic depends on the Type2 charstrings
* structure.
* Note: this doesn't really parse the font since that would require evaluation
* of PostScript, but it is possible in most cases to extract what we need
* without a full parse.
*/
const Type1Parser = (function Type1ParserClosure() {
/*
* Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
* of Plaintext Bytes. The function took a key as a parameter which can be * of Plaintext Bytes. The function takes a key as a parameter which can be
* for decrypting the eexec block of for decoding charStrings. * for decrypting the eexec block or for decoding charStrings.
*/ */
const EEXEC_ENCRYPT_KEY = 55665; const EEXEC_ENCRYPT_KEY = 55665;
const CHAR_STRS_ENCRYPT_KEY = 4330; const CHAR_STRS_ENCRYPT_KEY = 4330;
@ -450,7 +432,13 @@ const Type1Parser = (function Type1ParserClosure() {
); );
} }
// eslint-disable-next-line no-shadow /**
* Type1Parser encapsulate the needed code for parsing a Type1 font program.
* Some of its logic depends on the Type2 charstrings structure.
* NOTE: This doesn't really parse the font since that would require evaluation
* of PostScript, but it is possible in most cases to extract what we need
* without a full parse.
*/
class Type1Parser { class Type1Parser {
constructor(stream, encrypted, seacAnalysisEnabled) { constructor(stream, encrypted, seacAnalysisEnabled) {
if (encrypted) { if (encrypted) {
@ -777,7 +765,4 @@ const Type1Parser = (function Type1ParserClosure() {
} }
} }
return Type1Parser;
})();
export { Type1Parser }; export { Type1Parser };