Remove the remaining closure in the src/core/cmap.js
file
With modern JavaScript we (usually) no longer need to keep old closures, which slightly reduces the size of the code.
This commit is contained in:
parent
244002502b
commit
cabc98f310
@ -444,28 +444,27 @@ class IdentityCMap extends CMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CMapFactory = (function CMapFactoryClosure() {
|
function strToInt(str) {
|
||||||
function strToInt(str) {
|
|
||||||
let a = 0;
|
let a = 0;
|
||||||
for (let i = 0; i < str.length; i++) {
|
for (let i = 0; i < str.length; i++) {
|
||||||
a = (a << 8) | str.charCodeAt(i);
|
a = (a << 8) | str.charCodeAt(i);
|
||||||
}
|
}
|
||||||
return a >>> 0;
|
return a >>> 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectString(obj) {
|
function expectString(obj) {
|
||||||
if (typeof obj !== "string") {
|
if (typeof obj !== "string") {
|
||||||
throw new FormatError("Malformed CMap: expected string.");
|
throw new FormatError("Malformed CMap: expected string.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectInt(obj) {
|
function expectInt(obj) {
|
||||||
if (!Number.isInteger(obj)) {
|
if (!Number.isInteger(obj)) {
|
||||||
throw new FormatError("Malformed CMap: expected int.");
|
throw new FormatError("Malformed CMap: expected int.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseBfChar(cMap, lexer) {
|
function parseBfChar(cMap, lexer) {
|
||||||
while (true) {
|
while (true) {
|
||||||
let obj = lexer.getObj();
|
let obj = lexer.getObj();
|
||||||
if (obj === EOF) {
|
if (obj === EOF) {
|
||||||
@ -482,9 +481,9 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
const dst = obj;
|
const dst = obj;
|
||||||
cMap.mapOne(src, dst);
|
cMap.mapOne(src, dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseBfRange(cMap, lexer) {
|
function parseBfRange(cMap, lexer) {
|
||||||
while (true) {
|
while (true) {
|
||||||
let obj = lexer.getObj();
|
let obj = lexer.getObj();
|
||||||
if (obj === EOF) {
|
if (obj === EOF) {
|
||||||
@ -515,9 +514,9 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new FormatError("Invalid bf range.");
|
throw new FormatError("Invalid bf range.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCidChar(cMap, lexer) {
|
function parseCidChar(cMap, lexer) {
|
||||||
while (true) {
|
while (true) {
|
||||||
let obj = lexer.getObj();
|
let obj = lexer.getObj();
|
||||||
if (obj === EOF) {
|
if (obj === EOF) {
|
||||||
@ -533,9 +532,9 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
const dst = obj;
|
const dst = obj;
|
||||||
cMap.mapOne(src, dst);
|
cMap.mapOne(src, dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCidRange(cMap, lexer) {
|
function parseCidRange(cMap, lexer) {
|
||||||
while (true) {
|
while (true) {
|
||||||
let obj = lexer.getObj();
|
let obj = lexer.getObj();
|
||||||
if (obj === EOF) {
|
if (obj === EOF) {
|
||||||
@ -554,9 +553,9 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
const dstLow = obj;
|
const dstLow = obj;
|
||||||
cMap.mapCidRange(low, high, dstLow);
|
cMap.mapCidRange(low, high, dstLow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCodespaceRange(cMap, lexer) {
|
function parseCodespaceRange(cMap, lexer) {
|
||||||
while (true) {
|
while (true) {
|
||||||
let obj = lexer.getObj();
|
let obj = lexer.getObj();
|
||||||
if (obj === EOF) {
|
if (obj === EOF) {
|
||||||
@ -577,23 +576,23 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
cMap.addCodespaceRange(obj.length, low, high);
|
cMap.addCodespaceRange(obj.length, low, high);
|
||||||
}
|
}
|
||||||
throw new FormatError("Invalid codespace range.");
|
throw new FormatError("Invalid codespace range.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseWMode(cMap, lexer) {
|
function parseWMode(cMap, lexer) {
|
||||||
const obj = lexer.getObj();
|
const obj = lexer.getObj();
|
||||||
if (Number.isInteger(obj)) {
|
if (Number.isInteger(obj)) {
|
||||||
cMap.vertical = !!obj;
|
cMap.vertical = !!obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCMapName(cMap, lexer) {
|
function parseCMapName(cMap, lexer) {
|
||||||
const obj = lexer.getObj();
|
const obj = lexer.getObj();
|
||||||
if (obj instanceof Name) {
|
if (obj instanceof Name) {
|
||||||
cMap.name = obj.name;
|
cMap.name = obj.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) {
|
async function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) {
|
||||||
let previous, embeddedUseCMap;
|
let previous, embeddedUseCMap;
|
||||||
objLoop: while (true) {
|
objLoop: while (true) {
|
||||||
try {
|
try {
|
||||||
@ -651,9 +650,9 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
return extendCMap(cMap, fetchBuiltInCMap, useCMap);
|
return extendCMap(cMap, fetchBuiltInCMap, useCMap);
|
||||||
}
|
}
|
||||||
return cMap;
|
return cMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extendCMap(cMap, fetchBuiltInCMap, useCMap) {
|
async function extendCMap(cMap, fetchBuiltInCMap, useCMap) {
|
||||||
cMap.useCMap = await createBuiltInCMap(useCMap, fetchBuiltInCMap);
|
cMap.useCMap = await createBuiltInCMap(useCMap, fetchBuiltInCMap);
|
||||||
// If there aren't any code space ranges defined clone all the parent ones
|
// If there aren't any code space ranges defined clone all the parent ones
|
||||||
// into this cMap.
|
// into this cMap.
|
||||||
@ -673,9 +672,9 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return cMap;
|
return cMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createBuiltInCMap(name, fetchBuiltInCMap) {
|
async function createBuiltInCMap(name, fetchBuiltInCMap) {
|
||||||
if (name === "Identity-H") {
|
if (name === "Identity-H") {
|
||||||
return new IdentityCMap(false, 2);
|
return new IdentityCMap(false, 2);
|
||||||
} else if (name === "Identity-V") {
|
} else if (name === "Identity-V") {
|
||||||
@ -701,14 +700,10 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
|
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
|
||||||
}
|
}
|
||||||
throw new Error(`Invalid CMap "compressionType" value: ${compressionType}`);
|
throw new Error(`Invalid CMap "compressionType" value: ${compressionType}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
async create(params) {
|
|
||||||
const encoding = params.encoding;
|
|
||||||
const fetchBuiltInCMap = params.fetchBuiltInCMap;
|
|
||||||
const useCMap = params.useCMap;
|
|
||||||
|
|
||||||
|
class CMapFactory {
|
||||||
|
static async create({ encoding, fetchBuiltInCMap, useCMap }) {
|
||||||
if (encoding instanceof Name) {
|
if (encoding instanceof Name) {
|
||||||
return createBuiltInCMap(encoding.name, fetchBuiltInCMap);
|
return createBuiltInCMap(encoding.name, fetchBuiltInCMap);
|
||||||
} else if (encoding instanceof BaseStream) {
|
} else if (encoding instanceof BaseStream) {
|
||||||
@ -725,8 +720,7 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||||||
return parsedCMap;
|
return parsedCMap;
|
||||||
}
|
}
|
||||||
throw new Error("Encoding required.");
|
throw new Error("Encoding required.");
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
})();
|
|
||||||
|
|
||||||
export { CMap, CMapFactory, IdentityCMap };
|
export { CMap, CMapFactory, IdentityCMap };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user