Convert the code in src/core/cff_parser.js to use ES6 classes

This removes multiple instances of `// eslint-disable-next-line no-shadow`, which our old pseudo-classes necessitated.

*Please note:* I'm purposely not doing any `var` to `let`/`const` conversion here, since it's generally better to (if possible) do that automatically on e.g. a directory basis instead.
This commit is contained in:
Jonas Jenwald 2020-06-16 12:33:21 +02:00
parent 6bb64da1c3
commit 880a0a0f59

View File

@ -17,6 +17,7 @@ import {
bytesToString, bytesToString,
FormatError, FormatError,
info, info,
shadow,
stringToBytes, stringToBytes,
Util, Util,
warn, warn,
@ -218,13 +219,14 @@ var CFFParser = (function CFFParserClosure() {
]; ];
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
function CFFParser(file, properties, seacAnalysisEnabled) { class CFFParser {
constructor(file, properties, seacAnalysisEnabled) {
this.bytes = file.getBytes(); this.bytes = file.getBytes();
this.properties = properties; this.properties = properties;
this.seacAnalysisEnabled = !!seacAnalysisEnabled; this.seacAnalysisEnabled = !!seacAnalysisEnabled;
} }
CFFParser.prototype = {
parse: function CFFParser_parse() { parse() {
var properties = this.properties; var properties = this.properties;
var cff = new CFF(); var cff = new CFF();
this.cff = cff; this.cff = cff;
@ -322,8 +324,9 @@ var CFFParser = (function CFFParserClosure() {
cff.widths = charStringsAndSeacs.widths; cff.widths = charStringsAndSeacs.widths;
return cff; return cff;
}, }
parseHeader: function CFFParser_parseHeader() {
parseHeader() {
var bytes = this.bytes; var bytes = this.bytes;
var bytesLength = bytes.length; var bytesLength = bytes.length;
var offset = 0; var offset = 0;
@ -347,8 +350,9 @@ var CFFParser = (function CFFParserClosure() {
var offSize = bytes[3]; var offSize = bytes[3];
var header = new CFFHeader(major, minor, hdrSize, offSize); var header = new CFFHeader(major, minor, hdrSize, offSize);
return { obj: header, endPos: hdrSize }; return { obj: header, endPos: hdrSize };
}, }
parseDict: function CFFParser_parseDict(dict) {
parseDict(dict) {
var pos = 0; var pos = 0;
function parseOperand() { function parseOperand() {
@ -420,8 +424,9 @@ var CFFParser = (function CFFParserClosure() {
} }
} }
return entries; return entries;
}, }
parseIndex: function CFFParser_parseIndex(pos) {
parseIndex(pos) {
var cffIndex = new CFFIndex(); var cffIndex = new CFFIndex();
var bytes = this.bytes; var bytes = this.bytes;
var count = (bytes[pos++] << 8) | bytes[pos++]; var count = (bytes[pos++] << 8) | bytes[pos++];
@ -450,24 +455,27 @@ var CFFParser = (function CFFParserClosure() {
cffIndex.add(bytes.subarray(offsetStart, offsetEnd)); cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
} }
return { obj: cffIndex, endPos: end }; return { obj: cffIndex, endPos: end };
}, }
parseNameIndex: function CFFParser_parseNameIndex(index) {
parseNameIndex(index) {
var names = []; var names = [];
for (var i = 0, ii = index.count; i < ii; ++i) { for (var i = 0, ii = index.count; i < ii; ++i) {
var name = index.get(i); var name = index.get(i);
names.push(bytesToString(name)); names.push(bytesToString(name));
} }
return names; return names;
}, }
parseStringIndex: function CFFParser_parseStringIndex(index) {
parseStringIndex(index) {
var strings = new CFFStrings(); var strings = new CFFStrings();
for (var i = 0, ii = index.count; i < ii; ++i) { for (var i = 0, ii = index.count; i < ii; ++i) {
var data = index.get(i); var data = index.get(i);
strings.add(bytesToString(data)); strings.add(bytesToString(data));
} }
return strings; return strings;
}, }
createDict: function CFFParser_createDict(Type, dict, strings) {
createDict(Type, dict, strings) {
var cffDict = new Type(strings); var cffDict = new Type(strings);
for (var i = 0, ii = dict.length; i < ii; ++i) { for (var i = 0, ii = dict.length; i < ii; ++i) {
var pair = dict[i]; var pair = dict[i];
@ -476,13 +484,9 @@ var CFFParser = (function CFFParserClosure() {
cffDict.setByKey(key, value); cffDict.setByKey(key, value);
} }
return cffDict; return cffDict;
}, }
parseCharString: function CFFParser_parseCharString(
state, parseCharString(state, data, localSubrIndex, globalSubrIndex) {
data,
localSubrIndex,
globalSubrIndex
) {
if (!data || state.callDepth > MAX_SUBR_NESTING) { if (!data || state.callDepth > MAX_SUBR_NESTING) {
return false; return false;
} }
@ -659,7 +663,8 @@ var CFFParser = (function CFFParserClosure() {
} }
state.stackSize = stackSize; state.stackSize = stackSize;
return true; return true;
}, }
parseCharStrings({ parseCharStrings({
charStrings, charStrings,
localSubrIndex, localSubrIndex,
@ -728,15 +733,15 @@ var CFFParser = (function CFFParserClosure() {
} }
} }
return { charStrings, seacs, widths }; return { charStrings, seacs, widths };
}, }
emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(
parentDict emptyPrivateDictionary(parentDict) {
) {
var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings); var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
parentDict.setByKey(18, [0, 0]); parentDict.setByKey(18, [0, 0]);
parentDict.privateDict = privateDict; parentDict.privateDict = privateDict;
}, }
parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
parsePrivateDict(parentDict) {
// no private dict, do nothing // no private dict, do nothing
if (!parentDict.hasName("Private")) { if (!parentDict.hasName("Private")) {
this.emptyPrivateDictionary(parentDict); this.emptyPrivateDictionary(parentDict);
@ -779,8 +784,9 @@ var CFFParser = (function CFFParserClosure() {
} }
var subrsIndex = this.parseIndex(relativeOffset); var subrsIndex = this.parseIndex(relativeOffset);
privateDict.subrsIndex = subrsIndex.obj; privateDict.subrsIndex = subrsIndex.obj;
}, }
parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
parseCharsets(pos, length, strings, cid) {
if (pos === 0) { if (pos === 0) {
return new CFFCharset( return new CFFCharset(
true, true,
@ -843,13 +849,9 @@ var CFFParser = (function CFFParserClosure() {
var raw = bytes.subarray(start, end); var raw = bytes.subarray(start, end);
return new CFFCharset(false, format, charset, raw); return new CFFCharset(false, format, charset, raw);
}, }
parseEncoding: function CFFParser_parseEncoding(
pos, parseEncoding(pos, properties, strings, charset) {
properties,
strings,
charset
) {
var encoding = Object.create(null); var encoding = Object.create(null);
var bytes = this.bytes; var bytes = this.bytes;
var predefined = false; var predefined = false;
@ -916,8 +918,9 @@ var CFFParser = (function CFFParserClosure() {
} }
format = format & 0x7f; format = format & 0x7f;
return new CFFEncoding(predefined, format, encoding, raw); return new CFFEncoding(predefined, format, encoding, raw);
}, }
parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
parseFDSelect(pos, length) {
var bytes = this.bytes; var bytes = this.bytes;
var format = bytes[pos++]; var format = bytes[pos++];
var fdSelect = []; var fdSelect = [];
@ -958,15 +961,14 @@ var CFFParser = (function CFFParserClosure() {
} }
return new CFFFDSelect(format, fdSelect); return new CFFFDSelect(format, fdSelect);
}, }
}; }
return CFFParser; return CFFParser;
})(); })();
// Compact Font Format // Compact Font Format
var CFF = (function CFFClosure() { class CFF {
// eslint-disable-next-line no-shadow constructor() {
function CFF() {
this.header = null; this.header = null;
this.names = []; this.names = [];
this.topDict = null; this.topDict = null;
@ -983,8 +985,8 @@ var CFF = (function CFFClosure() {
this.isCIDFont = false; this.isCIDFont = false;
} }
CFF.prototype = {
duplicateFirstGlyph: function CFF_duplicateFirstGlyph() { duplicateFirstGlyph() {
// Browsers will not display a glyph at position 0. Typically glyph 0 is // Browsers will not display a glyph at position 0. Typically glyph 0 is
// notdef, but a number of fonts put a valid glyph there so it must be // notdef, but a number of fonts put a valid glyph there so it must be
// duplicated and appended. // duplicated and appended.
@ -997,37 +999,32 @@ var CFF = (function CFFClosure() {
if (this.isCIDFont) { if (this.isCIDFont) {
this.fdSelect.fdSelect.push(this.fdSelect.fdSelect[0]); this.fdSelect.fdSelect.push(this.fdSelect.fdSelect[0]);
} }
}, }
hasGlyphId: function CFF_hasGlyphID(id) {
hasGlyphId(id) {
if (id < 0 || id >= this.charStrings.count) { if (id < 0 || id >= this.charStrings.count) {
return false; return false;
} }
var glyph = this.charStrings.get(id); var glyph = this.charStrings.get(id);
return glyph.length > 0; return glyph.length > 0;
}, }
}; }
return CFF; class CFFHeader {
})(); constructor(major, minor, hdrSize, offSize) {
var CFFHeader = (function CFFHeaderClosure() {
// eslint-disable-next-line no-shadow
function CFFHeader(major, minor, hdrSize, offSize) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.hdrSize = hdrSize; this.hdrSize = hdrSize;
this.offSize = offSize; this.offSize = offSize;
} }
return CFFHeader; }
})();
var CFFStrings = (function CFFStringsClosure() { class CFFStrings {
// eslint-disable-next-line no-shadow constructor() {
function CFFStrings() {
this.strings = []; this.strings = [];
} }
CFFStrings.prototype = {
get: function CFFStrings_get(index) { get(index) {
if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) { if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) {
return CFFStandardStrings[index]; return CFFStandardStrings[index];
} }
@ -1035,8 +1032,9 @@ var CFFStrings = (function CFFStringsClosure() {
return this.strings[index - NUM_STANDARD_CFF_STRINGS]; return this.strings[index - NUM_STANDARD_CFF_STRINGS];
} }
return CFFStandardStrings[0]; return CFFStandardStrings[0];
}, }
getSID: function CFFStrings_getSID(str) {
getSID(str) {
let index = CFFStandardStrings.indexOf(str); let index = CFFStandardStrings.indexOf(str);
if (index !== -1) { if (index !== -1) {
return index; return index;
@ -1046,45 +1044,44 @@ var CFFStrings = (function CFFStringsClosure() {
return index + NUM_STANDARD_CFF_STRINGS; return index + NUM_STANDARD_CFF_STRINGS;
} }
return -1; return -1;
}, }
add: function CFFStrings_add(value) {
add(value) {
this.strings.push(value); this.strings.push(value);
}, }
get count() { get count() {
return this.strings.length; return this.strings.length;
}, }
}; }
return CFFStrings;
})();
var CFFIndex = (function CFFIndexClosure() { class CFFIndex {
// eslint-disable-next-line no-shadow constructor() {
function CFFIndex() {
this.objects = []; this.objects = [];
this.length = 0; this.length = 0;
} }
CFFIndex.prototype = {
add: function CFFIndex_add(data) { add(data) {
this.length += data.length; this.length += data.length;
this.objects.push(data); this.objects.push(data);
}, }
set: function CFFIndex_set(index, data) {
set(index, data) {
this.length += data.length - this.objects[index].length; this.length += data.length - this.objects[index].length;
this.objects[index] = data; this.objects[index] = data;
}, }
get: function CFFIndex_get(index) {
get(index) {
return this.objects[index]; return this.objects[index];
}, }
get count() { get count() {
return this.objects.length; return this.objects.length;
}, }
}; }
return CFFIndex;
})();
var CFFDict = (function CFFDictClosure() { class CFFDict {
// eslint-disable-next-line no-shadow constructor(tables, strings) {
function CFFDict(tables, strings) {
this.keyToNameMap = tables.keyToNameMap; this.keyToNameMap = tables.keyToNameMap;
this.nameToKeyMap = tables.nameToKeyMap; this.nameToKeyMap = tables.nameToKeyMap;
this.defaults = tables.defaults; this.defaults = tables.defaults;
@ -1094,9 +1091,9 @@ var CFFDict = (function CFFDictClosure() {
this.strings = strings; this.strings = strings;
this.values = Object.create(null); this.values = Object.create(null);
} }
CFFDict.prototype = {
// value should always be an array // value should always be an array
setByKey: function CFFDict_setByKey(key, value) { setByKey(key, value) {
if (!(key in this.keyToNameMap)) { if (!(key in this.keyToNameMap)) {
return false; return false;
} }
@ -1119,17 +1116,20 @@ var CFFDict = (function CFFDictClosure() {
} }
this.values[key] = value; this.values[key] = value;
return true; return true;
}, }
setByName: function CFFDict_setByName(name, value) {
setByName(name, value) {
if (!(name in this.nameToKeyMap)) { if (!(name in this.nameToKeyMap)) {
throw new FormatError(`Invalid dictionary name "${name}"`); throw new FormatError(`Invalid dictionary name "${name}"`);
} }
this.values[this.nameToKeyMap[name]] = value; this.values[this.nameToKeyMap[name]] = value;
}, }
hasName: function CFFDict_hasName(name) {
hasName(name) {
return this.nameToKeyMap[name] in this.values; return this.nameToKeyMap[name] in this.values;
}, }
getByName: function CFFDict_getByName(name) {
getByName(name) {
if (!(name in this.nameToKeyMap)) { if (!(name in this.nameToKeyMap)) {
throw new FormatError(`Invalid dictionary name ${name}"`); throw new FormatError(`Invalid dictionary name ${name}"`);
} }
@ -1138,12 +1138,13 @@ var CFFDict = (function CFFDictClosure() {
return this.defaults[key]; return this.defaults[key];
} }
return this.values[key]; return this.values[key];
}, }
removeByName: function CFFDict_removeByName(name) {
removeByName(name) {
delete this.values[this.nameToKeyMap[name]]; delete this.values[this.nameToKeyMap[name]];
}, }
};
CFFDict.createTables = function CFFDict_createTables(layout) { static createTables(layout) {
var tables = { var tables = {
keyToNameMap: {}, keyToNameMap: {},
nameToKeyMap: {}, nameToKeyMap: {},
@ -1165,9 +1166,8 @@ var CFFDict = (function CFFDictClosure() {
tables.order.push(key); tables.order.push(key);
} }
return tables; return tables;
}; }
return CFFDict; }
})();
var CFFTopDict = (function CFFTopDictClosure() { var CFFTopDict = (function CFFTopDictClosure() {
var layout = [ var layout = [
@ -1213,14 +1213,15 @@ var CFFTopDict = (function CFFTopDictClosure() {
var tables = null; var tables = null;
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
function CFFTopDict(strings) { class CFFTopDict extends CFFDict {
constructor(strings) {
if (tables === null) { if (tables === null) {
tables = CFFDict.createTables(layout); tables = CFFDict.createTables(layout);
} }
CFFDict.call(this, tables, strings); super(tables, strings);
this.privateDict = null; this.privateDict = null;
} }
CFFTopDict.prototype = Object.create(CFFDict.prototype); }
return CFFTopDict; return CFFTopDict;
})(); })();
@ -1248,14 +1249,15 @@ var CFFPrivateDict = (function CFFPrivateDictClosure() {
var tables = null; var tables = null;
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
function CFFPrivateDict(strings) { class CFFPrivateDict extends CFFDict {
constructor(strings) {
if (tables === null) { if (tables === null) {
tables = CFFDict.createTables(layout); tables = CFFDict.createTables(layout);
} }
CFFDict.call(this, tables, strings); super(tables, strings);
this.subrsIndex = null; this.subrsIndex = null;
} }
CFFPrivateDict.prototype = Object.create(CFFDict.prototype); }
return CFFPrivateDict; return CFFPrivateDict;
})(); })();
@ -1264,72 +1266,63 @@ var CFFCharsetPredefinedTypes = {
EXPERT: 1, EXPERT: 1,
EXPERT_SUBSET: 2, EXPERT_SUBSET: 2,
}; };
var CFFCharset = (function CFFCharsetClosure() { class CFFCharset {
// eslint-disable-next-line no-shadow constructor(predefined, format, charset, raw) {
function CFFCharset(predefined, format, charset, raw) {
this.predefined = predefined; this.predefined = predefined;
this.format = format; this.format = format;
this.charset = charset; this.charset = charset;
this.raw = raw; this.raw = raw;
} }
return CFFCharset; }
})();
var CFFEncoding = (function CFFEncodingClosure() { class CFFEncoding {
// eslint-disable-next-line no-shadow constructor(predefined, format, encoding, raw) {
function CFFEncoding(predefined, format, encoding, raw) {
this.predefined = predefined; this.predefined = predefined;
this.format = format; this.format = format;
this.encoding = encoding; this.encoding = encoding;
this.raw = raw; this.raw = raw;
} }
return CFFEncoding; }
})();
var CFFFDSelect = (function CFFFDSelectClosure() { class CFFFDSelect {
// eslint-disable-next-line no-shadow constructor(format, fdSelect) {
function CFFFDSelect(format, fdSelect) {
this.format = format; this.format = format;
this.fdSelect = fdSelect; this.fdSelect = fdSelect;
} }
CFFFDSelect.prototype = {
getFDIndex: function CFFFDSelect_get(glyphIndex) { getFDIndex(glyphIndex) {
if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) { if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
return -1; return -1;
} }
return this.fdSelect[glyphIndex]; return this.fdSelect[glyphIndex];
}, }
}; }
return CFFFDSelect;
})();
// Helper class to keep track of where an offset is within the data and helps // Helper class to keep track of where an offset is within the data and helps
// filling in that offset once it's known. // filling in that offset once it's known.
var CFFOffsetTracker = (function CFFOffsetTrackerClosure() { class CFFOffsetTracker {
// eslint-disable-next-line no-shadow constructor() {
function CFFOffsetTracker() {
this.offsets = Object.create(null); this.offsets = Object.create(null);
} }
CFFOffsetTracker.prototype = {
isTracking: function CFFOffsetTracker_isTracking(key) { isTracking(key) {
return key in this.offsets; return key in this.offsets;
}, }
track: function CFFOffsetTracker_track(key, location) {
track(key, location) {
if (key in this.offsets) { if (key in this.offsets) {
throw new FormatError(`Already tracking location of ${key}`); throw new FormatError(`Already tracking location of ${key}`);
} }
this.offsets[key] = location; this.offsets[key] = location;
}, }
offset: function CFFOffsetTracker_offset(value) {
offset(value) {
for (var key in this.offsets) { for (var key in this.offsets) {
this.offsets[key] += value; this.offsets[key] += value;
} }
}, }
setEntryLocation: function CFFOffsetTracker_setEntryLocation(
key, setEntryLocation(key, values, output) {
values,
output
) {
if (!(key in this.offsets)) { if (!(key in this.offsets)) {
throw new FormatError(`Not tracking location of ${key}`); throw new FormatError(`Not tracking location of ${key}`);
} }
@ -1359,21 +1352,16 @@ var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
data[offset3] = (value >> 8) & 0xff; data[offset3] = (value >> 8) & 0xff;
data[offset4] = value & 0xff; data[offset4] = value & 0xff;
} }
}, }
}; }
return CFFOffsetTracker;
})();
// Takes a CFF and converts it to the binary representation. // Takes a CFF and converts it to the binary representation.
var CFFCompiler = (function CFFCompilerClosure() { class CFFCompiler {
let EncodeFloatRegExp = null; // Lazily initialized by `encodeFloat`. constructor(cff) {
// eslint-disable-next-line no-shadow
function CFFCompiler(cff) {
this.cff = cff; this.cff = cff;
} }
CFFCompiler.prototype = {
compile: function CFFCompiler_compile() { compile() {
var cff = this.cff; var cff = this.cff;
var output = { var output = {
data: [], data: [],
@ -1483,21 +1471,28 @@ var CFFCompiler = (function CFFCompilerClosure() {
output.add([0]); output.add([0]);
return output.data; return output.data;
}, }
encodeNumber: function CFFCompiler_encodeNumber(value) {
encodeNumber(value) {
if (Number.isInteger(value)) { if (Number.isInteger(value)) {
return this.encodeInteger(value); return this.encodeInteger(value);
} }
return this.encodeFloat(value); return this.encodeFloat(value);
}, }
encodeFloat: function CFFCompiler_encodeFloat(num) {
static get EncodeFloatRegExp() {
return shadow(
this,
"EncodeFloatRegExp",
/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/
);
}
encodeFloat(num) {
var value = num.toString(); var value = num.toString();
if (!EncodeFloatRegExp) {
EncodeFloatRegExp = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/;
}
// Rounding inaccurate doubles. // Rounding inaccurate doubles.
var m = EncodeFloatRegExp.exec(value); var m = CFFCompiler.EncodeFloatRegExp.exec(value);
if (m) { if (m) {
var epsilon = parseFloat("1e" + ((m[2] ? +m[2] : 0) + m[1].length)); var epsilon = parseFloat("1e" + ((m[2] ? +m[2] : 0) + m[1].length));
value = (Math.round(num * epsilon) / epsilon).toString(); value = (Math.round(num * epsilon) / epsilon).toString();
@ -1523,8 +1518,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
out.push(parseInt(nibbles.substring(i, i + 2), 16)); out.push(parseInt(nibbles.substring(i, i + 2), 16));
} }
return out; return out;
}, }
encodeInteger: function CFFCompiler_encodeInteger(value) {
encodeInteger(value) {
var code; var code;
if (value >= -107 && value <= 107) { if (value >= -107 && value <= 107) {
code = [value + 139]; code = [value + 139];
@ -1546,11 +1542,13 @@ var CFFCompiler = (function CFFCompilerClosure() {
]; ];
} }
return code; return code;
}, }
compileHeader: function CFFCompiler_compileHeader(header) {
compileHeader(header) {
return [header.major, header.minor, header.hdrSize, header.offSize]; return [header.major, header.minor, header.hdrSize, header.offSize];
}, }
compileNameIndex: function CFFCompiler_compileNameIndex(names) {
compileNameIndex(names) {
var nameIndex = new CFFIndex(); var nameIndex = new CFFIndex();
for (var i = 0, ii = names.length; i < ii; ++i) { for (var i = 0, ii = names.length; i < ii; ++i) {
var name = names[i]; var name = names[i];
@ -1587,12 +1585,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
nameIndex.add(stringToBytes(sanitizedName)); nameIndex.add(stringToBytes(sanitizedName));
} }
return this.compileIndex(nameIndex); return this.compileIndex(nameIndex);
}, }
compileTopDicts: function CFFCompiler_compileTopDicts(
dicts, compileTopDicts(dicts, length, removeCidKeys) {
length,
removeCidKeys
) {
var fontDictTrackers = []; var fontDictTrackers = [];
var fdArrayIndex = new CFFIndex(); var fdArrayIndex = new CFFIndex();
for (var i = 0, ii = dicts.length; i < ii; ++i) { for (var i = 0, ii = dicts.length; i < ii; ++i) {
@ -1615,12 +1610,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
trackers: fontDictTrackers, trackers: fontDictTrackers,
output: fdArrayIndex, output: fdArrayIndex,
}; };
}, }
compilePrivateDicts: function CFFCompiler_compilePrivateDicts(
dicts, compilePrivateDicts(dicts, trackers, output) {
trackers,
output
) {
for (var i = 0, ii = dicts.length; i < ii; ++i) { for (var i = 0, ii = dicts.length; i < ii; ++i) {
var fontDict = dicts[i]; var fontDict = dicts[i];
var privateDict = fontDict.privateDict; var privateDict = fontDict.privateDict;
@ -1656,8 +1648,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
output.add(subrs); output.add(subrs);
} }
} }
}, }
compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
compileDict(dict, offsetTracker) {
var out = []; var out = [];
// The dictionary keys must be in a certain order. // The dictionary keys must be in a certain order.
var order = dict.order; var order = dict.order;
@ -1714,19 +1707,22 @@ var CFFCompiler = (function CFFCompilerClosure() {
out = out.concat(dict.opcodes[key]); out = out.concat(dict.opcodes[key]);
} }
return out; return out;
}, }
compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
compileStringIndex(strings) {
var stringIndex = new CFFIndex(); var stringIndex = new CFFIndex();
for (var i = 0, ii = strings.length; i < ii; ++i) { for (var i = 0, ii = strings.length; i < ii; ++i) {
stringIndex.add(stringToBytes(strings[i])); stringIndex.add(stringToBytes(strings[i]));
} }
return this.compileIndex(stringIndex); return this.compileIndex(stringIndex);
}, }
compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
compileGlobalSubrIndex() {
var globalSubrIndex = this.cff.globalSubrIndex; var globalSubrIndex = this.cff.globalSubrIndex;
this.out.writeByteArray(this.compileIndex(globalSubrIndex)); this.out.writeByteArray(this.compileIndex(globalSubrIndex));
}, }
compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
compileCharStrings(charStrings) {
var charStringsIndex = new CFFIndex(); var charStringsIndex = new CFFIndex();
for (var i = 0; i < charStrings.count; i++) { for (var i = 0; i < charStrings.count; i++) {
var glyph = charStrings.get(i); var glyph = charStrings.get(i);
@ -1739,13 +1735,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
charStringsIndex.add(glyph); charStringsIndex.add(glyph);
} }
return this.compileIndex(charStringsIndex); return this.compileIndex(charStringsIndex);
}, }
compileCharset: function CFFCompiler_compileCharset(
charset, compileCharset(charset, numGlyphs, strings, isCIDFont) {
numGlyphs,
strings,
isCIDFont
) {
// Freetype requires the number of charset strings be correct and MacOS // Freetype requires the number of charset strings be correct and MacOS
// requires a valid mapping for printing. // requires a valid mapping for printing.
let out; let out;
@ -1785,11 +1777,13 @@ var CFFCompiler = (function CFFCompilerClosure() {
} }
} }
return this.compileTypedArray(out); return this.compileTypedArray(out);
}, }
compileEncoding: function CFFCompiler_compileEncoding(encoding) {
compileEncoding(encoding) {
return this.compileTypedArray(encoding.raw); return this.compileTypedArray(encoding.raw);
}, }
compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
compileFDSelect(fdSelect) {
const format = fdSelect.format; const format = fdSelect.format;
let out, i; let out, i;
switch (format) { switch (format) {
@ -1828,16 +1822,17 @@ var CFFCompiler = (function CFFCompilerClosure() {
break; break;
} }
return this.compileTypedArray(out); return this.compileTypedArray(out);
}, }
compileTypedArray: function CFFCompiler_compileTypedArray(data) {
compileTypedArray(data) {
var out = []; var out = [];
for (var i = 0, ii = data.length; i < ii; ++i) { for (var i = 0, ii = data.length; i < ii; ++i) {
out[i] = data[i]; out[i] = data[i];
} }
return out; return out;
}, }
compileIndex: function CFFCompiler_compileIndex(index, trackers) {
trackers = trackers || []; compileIndex(index, trackers = []) {
var objects = index.objects; var objects = index.objects;
// First 2 bytes contains the number of objects contained into this index // First 2 bytes contains the number of objects contained into this index
var count = objects.length; var count = objects.length;
@ -1907,10 +1902,8 @@ var CFFCompiler = (function CFFCompilerClosure() {
} }
} }
return data; return data;
}, }
}; }
return CFFCompiler;
})();
export { export {
CFFStandardStrings, CFFStandardStrings,