Remove the remaining closures in the src/core/cff_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 changes.
For e.g. the `gulp mozcentral` command the *built* `pdf.worker.js` file-size decreases `~2 kB` with this patch, and most of the improvement comes from having less overall indentation in the code.
This commit is contained in:
Jonas Jenwald 2022-08-13 18:19:26 +02:00
parent b040d64a3c
commit e5e756c0b4

View File

@ -107,7 +107,6 @@ const CFFStandardStrings = [
const NUM_STANDARD_CFF_STRINGS = 391; const NUM_STANDARD_CFF_STRINGS = 391;
const CFFParser = (function CFFParserClosure() {
const CharstringValidationData = [ const CharstringValidationData = [
null, null,
{ id: "hstem", min: 2, stackClearing: true, stem: true }, { id: "hstem", min: 2, stackClearing: true, stem: true },
@ -142,6 +141,7 @@ const CFFParser = (function CFFParserClosure() {
{ id: "vhcurveto", min: 4, resetStack: true }, { id: "vhcurveto", min: 4, resetStack: true },
{ id: "hvcurveto", min: 4, resetStack: true }, { id: "hvcurveto", min: 4, resetStack: true },
]; ];
const CharstringValidationData12 = [ const CharstringValidationData12 = [
null, null,
null, null,
@ -157,7 +157,7 @@ const CFFParser = (function CFFParserClosure() {
id: "add", id: "add",
min: 2, min: 2,
stackDelta: -1, stackDelta: -1,
stackFn: function stack_div(stack, index) { stackFn(stack, index) {
stack[index - 2] = stack[index - 2] + stack[index - 1]; stack[index - 2] = stack[index - 2] + stack[index - 1];
}, },
}, },
@ -165,7 +165,7 @@ const CFFParser = (function CFFParserClosure() {
id: "sub", id: "sub",
min: 2, min: 2,
stackDelta: -1, stackDelta: -1,
stackFn: function stack_div(stack, index) { stackFn(stack, index) {
stack[index - 2] = stack[index - 2] - stack[index - 1]; stack[index - 2] = stack[index - 2] - stack[index - 1];
}, },
}, },
@ -173,7 +173,7 @@ const CFFParser = (function CFFParserClosure() {
id: "div", id: "div",
min: 2, min: 2,
stackDelta: -1, stackDelta: -1,
stackFn: function stack_div(stack, index) { stackFn(stack, index) {
stack[index - 2] = stack[index - 2] / stack[index - 1]; stack[index - 2] = stack[index - 2] / stack[index - 1];
}, },
}, },
@ -182,7 +182,7 @@ const CFFParser = (function CFFParserClosure() {
id: "neg", id: "neg",
min: 1, min: 1,
stackDelta: 0, stackDelta: 0,
stackFn: function stack_div(stack, index) { stackFn(stack, index) {
stack[index - 1] = -stack[index - 1]; stack[index - 1] = -stack[index - 1];
}, },
}, },
@ -199,7 +199,7 @@ const CFFParser = (function CFFParserClosure() {
id: "mul", id: "mul",
min: 2, min: 2,
stackDelta: -1, stackDelta: -1,
stackFn: function stack_div(stack, index) { stackFn(stack, index) {
stack[index - 2] = stack[index - 2] * stack[index - 1]; stack[index - 2] = stack[index - 2] * stack[index - 1];
}, },
}, },
@ -218,7 +218,6 @@ const CFFParser = (function CFFParserClosure() {
{ id: "flex1", min: 11, resetStack: true }, { id: "flex1", min: 11, resetStack: true },
]; ];
// eslint-disable-next-line no-shadow
class CFFParser { class CFFParser {
constructor(file, properties, seacAnalysisEnabled) { constructor(file, properties, seacAnalysisEnabled) {
this.bytes = file.getBytes(); this.bytes = file.getBytes();
@ -752,11 +751,7 @@ const CFFParser = (function CFFParserClosure() {
} }
emptyPrivateDictionary(parentDict) { emptyPrivateDictionary(parentDict) {
const privateDict = this.createDict( const privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
CFFPrivateDict,
[],
parentDict.strings
);
parentDict.setByKey(18, [0, 0]); parentDict.setByKey(18, [0, 0]);
parentDict.privateDict = privateDict; parentDict.privateDict = privateDict;
} }
@ -983,8 +978,6 @@ const CFFParser = (function CFFParserClosure() {
return new CFFFDSelect(format, fdSelect); return new CFFFDSelect(format, fdSelect);
} }
} }
return CFFParser;
})();
// Compact Font Format // Compact Font Format
class CFF { class CFF {
@ -1189,8 +1182,7 @@ class CFFDict {
} }
} }
const CFFTopDict = (function CFFTopDictClosure() { const CFFTopDictLayout = [
const layout = [
[[12, 30], "ROS", ["sid", "sid", "num"], null], [[12, 30], "ROS", ["sid", "sid", "num"], null],
[[12, 20], "SyntheticBase", "num", null], [[12, 20], "SyntheticBase", "num", null],
[0, "version", "sid", null], [0, "version", "sid", null],
@ -1230,23 +1222,19 @@ const CFFTopDict = (function CFFTopDictClosure() {
[[12, 36], "FDArray", "offset", null], [[12, 36], "FDArray", "offset", null],
[[12, 38], "FontName", "sid", null], [[12, 38], "FontName", "sid", null],
]; ];
let tables = null;
// eslint-disable-next-line no-shadow
class CFFTopDict extends CFFDict { class CFFTopDict extends CFFDict {
constructor(strings) { static get tables() {
if (tables === null) { return shadow(this, "tables", this.createTables(CFFTopDictLayout));
tables = CFFDict.createTables(layout);
} }
super(tables, strings);
constructor(strings) {
super(CFFTopDict.tables, strings);
this.privateDict = null; this.privateDict = null;
} }
} }
return CFFTopDict;
})();
const CFFPrivateDict = (function CFFPrivateDictClosure() { const CFFPrivateDictLayout = [
const layout = [
[6, "BlueValues", "delta", null], [6, "BlueValues", "delta", null],
[7, "OtherBlues", "delta", null], [7, "OtherBlues", "delta", null],
[8, "FamilyBlues", "delta", null], [8, "FamilyBlues", "delta", null],
@ -1266,20 +1254,17 @@ const CFFPrivateDict = (function CFFPrivateDictClosure() {
[21, "nominalWidthX", "num", 0], [21, "nominalWidthX", "num", 0],
[19, "Subrs", "offset", null], [19, "Subrs", "offset", null],
]; ];
let tables = null;
// eslint-disable-next-line no-shadow
class CFFPrivateDict extends CFFDict { class CFFPrivateDict extends CFFDict {
constructor(strings) { static get tables() {
if (tables === null) { return shadow(this, "tables", this.createTables(CFFPrivateDictLayout));
tables = CFFDict.createTables(layout);
} }
super(tables, strings);
constructor(strings) {
super(CFFPrivateDict.tables, strings);
this.subrsIndex = null; this.subrsIndex = null;
} }
} }
return CFFPrivateDict;
})();
const CFFCharsetPredefinedTypes = { const CFFCharsetPredefinedTypes = {
ISO_ADOBE: 0, ISO_ADOBE: 0,