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:
parent
e6fe127433
commit
6a2c2a646f
@ -22,7 +22,25 @@ import { warn } from "../shared/util.js";
|
||||
// in tracemonkey and various other pdfs with type1 fonts.
|
||||
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
|
||||
* describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
|
||||
* The value in a byte indicates a command, a number, or subsequent bytes
|
||||
@ -60,27 +78,7 @@ const HINTING_ENABLED = false;
|
||||
* to be encoded and this encoding technique helps to minimize the length of
|
||||
* 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() {
|
||||
this.width = 0;
|
||||
this.lsb = 0;
|
||||
@ -155,11 +153,7 @@ const Type1CharString = (function Type1CharStringClosure() {
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
error = this.convert(
|
||||
subrs[subrNumber],
|
||||
subrs,
|
||||
seacAnalysisEnabled
|
||||
);
|
||||
error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
|
||||
break;
|
||||
case 11: // return
|
||||
return error;
|
||||
@ -359,37 +353,25 @@ const Type1CharString = (function Type1CharStringClosure() {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
* of Plaintext Bytes. The function took a key as a parameter which can be
|
||||
* for decrypting the eexec block of for decoding charStrings.
|
||||
* of Plaintext Bytes. The function takes a key as a parameter which can be
|
||||
* for decrypting the eexec block or for decoding charStrings.
|
||||
*/
|
||||
const EEXEC_ENCRYPT_KEY = 55665;
|
||||
const CHAR_STRS_ENCRYPT_KEY = 4330;
|
||||
const EEXEC_ENCRYPT_KEY = 55665;
|
||||
const CHAR_STRS_ENCRYPT_KEY = 4330;
|
||||
|
||||
function isHexDigit(code) {
|
||||
function isHexDigit(code) {
|
||||
return (
|
||||
(code >= 48 && code <= 57) || // '0'-'9'
|
||||
(code >= 65 && code <= 70) || // 'A'-'F'
|
||||
(code >= 97 && code <= 102) // 'a'-'f'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function decrypt(data, key, discardNumber) {
|
||||
function decrypt(data, key, discardNumber) {
|
||||
if (discardNumber >= data.length) {
|
||||
return new Uint8Array(0);
|
||||
}
|
||||
@ -409,9 +391,9 @@ const Type1Parser = (function Type1ParserClosure() {
|
||||
r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
|
||||
}
|
||||
return decrypted;
|
||||
}
|
||||
}
|
||||
|
||||
function decryptAscii(data, key, discardNumber) {
|
||||
function decryptAscii(data, key, discardNumber) {
|
||||
const c1 = 52845,
|
||||
c2 = 22719;
|
||||
let r = key | 0;
|
||||
@ -436,9 +418,9 @@ const Type1Parser = (function Type1ParserClosure() {
|
||||
}
|
||||
}
|
||||
return decrypted.slice(discardNumber, j);
|
||||
}
|
||||
}
|
||||
|
||||
function isSpecial(c) {
|
||||
function isSpecial(c) {
|
||||
return (
|
||||
c === /* '/' = */ 0x2f ||
|
||||
c === /* '[' = */ 0x5b ||
|
||||
@ -448,10 +430,16 @@ const Type1Parser = (function Type1ParserClosure() {
|
||||
c === /* '(' = */ 0x28 ||
|
||||
c === /* ')' = */ 0x29
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
class Type1Parser {
|
||||
/**
|
||||
* 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 {
|
||||
constructor(stream, encrypted, seacAnalysisEnabled) {
|
||||
if (encrypted) {
|
||||
const data = stream.getBytes();
|
||||
@ -775,9 +763,6 @@ const Type1Parser = (function Type1ParserClosure() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Type1Parser;
|
||||
})();
|
||||
}
|
||||
|
||||
export { Type1Parser };
|
||||
|
Loading…
x
Reference in New Issue
Block a user