Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

99
node_modules/fontkit/src/cff/CFFCharsets.js generated vendored Normal file
View File

@@ -0,0 +1,99 @@
export let ISOAdobeCharset = [
'.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
'ugrave', 'yacute', 'ydieresis', 'zcaron'
];
export let ExpertCharset = [
'.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
'Ydieresissmall'
];
export let ExpertSubsetCharset = [
'.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
'periodinferior', 'commainferior'
];

167
node_modules/fontkit/src/cff/CFFDict.js generated vendored Normal file
View File

@@ -0,0 +1,167 @@
import isEqual from 'fast-deep-equal';
import * as r from 'restructure';
import CFFOperand from './CFFOperand';
import { PropertyDescriptor } from 'restructure';
export default class CFFDict {
constructor(ops = []) {
this.ops = ops;
this.fields = {};
for (let field of ops) {
let key = Array.isArray(field[0]) ? field[0][0] << 8 | field[0][1] : field[0];
this.fields[key] = field;
}
}
decodeOperands(type, stream, ret, operands) {
if (Array.isArray(type)) {
return operands.map((op, i) => this.decodeOperands(type[i], stream, ret, [op]));
} else if (type.decode != null) {
return type.decode(stream, ret, operands);
} else {
switch (type) {
case 'number':
case 'offset':
case 'sid':
return operands[0];
case 'boolean':
return !!operands[0];
default:
return operands;
}
}
}
encodeOperands(type, stream, ctx, operands) {
if (Array.isArray(type)) {
return operands.map((op, i) => this.encodeOperands(type[i], stream, ctx, op)[0]);
} else if (type.encode != null) {
return type.encode(stream, operands, ctx);
} else if (typeof operands === 'number') {
return [operands];
} else if (typeof operands === 'boolean') {
return [+operands];
} else if (Array.isArray(operands)) {
return operands;
} else {
return [operands];
}
}
decode(stream, parent) {
let end = stream.pos + parent.length;
let ret = {};
let operands = [];
// define hidden properties
Object.defineProperties(ret, {
parent: { value: parent },
_startOffset: { value: stream.pos }
});
// fill in defaults
for (let key in this.fields) {
let field = this.fields[key];
ret[field[1]] = field[3];
}
while (stream.pos < end) {
let b = stream.readUInt8();
if (b < 28) {
if (b === 12) {
b = (b << 8) | stream.readUInt8();
}
let field = this.fields[b];
if (!field) {
throw new Error(`Unknown operator ${b}`);
}
let val = this.decodeOperands(field[2], stream, ret, operands);
if (val != null) {
if (val instanceof PropertyDescriptor) {
Object.defineProperty(ret, field[1], val);
} else {
ret[field[1]] = val;
}
}
operands = [];
} else {
operands.push(CFFOperand.decode(stream, b));
}
}
return ret;
}
size(dict, parent, includePointers = true) {
let ctx = {
parent,
val: dict,
pointerSize: 0,
startOffset: parent.startOffset || 0
};
let len = 0;
for (let k in this.fields) {
let field = this.fields[k];
let val = dict[field[1]];
if (val == null || isEqual(val, field[3])) {
continue;
}
let operands = this.encodeOperands(field[2], null, ctx, val);
for (let op of operands) {
len += CFFOperand.size(op);
}
let key = Array.isArray(field[0]) ? field[0] : [field[0]];
len += key.length;
}
if (includePointers) {
len += ctx.pointerSize;
}
return len;
}
encode(stream, dict, parent) {
let ctx = {
pointers: [],
startOffset: stream.pos,
parent,
val: dict,
pointerSize: 0
};
ctx.pointerOffset = stream.pos + this.size(dict, ctx, false);
for (let field of this.ops) {
let val = dict[field[1]];
if (val == null || isEqual(val, field[3])) {
continue;
}
let operands = this.encodeOperands(field[2], stream, ctx, val);
for (let op of operands) {
CFFOperand.encode(stream, op);
}
let key = Array.isArray(field[0]) ? field[0] : [field[0]];
for (let op of key) {
stream.writeUInt8(op);
}
}
let i = 0;
while (i < ctx.pointers.length) {
let ptr = ctx.pointers[i++];
ptr.type.encode(stream, ptr.val, ptr.parent);
}
return;
}
}

48
node_modules/fontkit/src/cff/CFFEncodings.js generated vendored Normal file
View File

@@ -0,0 +1,48 @@
export let StandardEncoding = [
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright',
'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two',
'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater',
'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'exclamdown', 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency', 'quotesingle',
'quotedblleft', 'guillemotleft', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger',
'daggerdbl', 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase', 'quotedblright',
'guillemotright', 'ellipsis', 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex', 'tilde',
'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla', '', 'hungarumlaut', 'ogonek', 'caron',
'emdash', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '', '',
'', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae', '', '', '', 'dotlessi', '', '',
'lslash', 'oslash', 'oe', 'germandbls'
];
export let ExpertEncoding = [
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle', 'dollarsuperior',
'ampersandsmall', 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader', 'onedotenleader',
'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior', 'questionsmall', '', 'asuperior',
'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior', '', 'ff', 'fi', 'fl', 'ffi', 'ffl',
'parenleftinferior', '', 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall',
'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall',
'Msmall', 'Nsmall', 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'exclamdownsmall', 'centoldstyle', 'Lslashsmall', '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
'Brevesmall', 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '', 'figuredash', 'hypheninferior',
'', '', 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds', '',
'', 'zerosuperior', 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall',
'Ocircumflexsmall', 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall'
];

159
node_modules/fontkit/src/cff/CFFFont.js generated vendored Normal file
View File

@@ -0,0 +1,159 @@
import * as r from 'restructure';
import CFFIndex from './CFFIndex';
import CFFTop from './CFFTop';
import CFFPrivateDict from './CFFPrivateDict';
import standardStrings from './CFFStandardStrings';
class CFFFont {
constructor(stream) {
this.stream = stream;
this.decode();
}
static decode(stream) {
return new CFFFont(stream);
}
decode() {
let start = this.stream.pos;
let top = CFFTop.decode(this.stream);
for (let key in top) {
let val = top[key];
this[key] = val;
}
if (this.version < 2) {
if (this.topDictIndex.length !== 1) {
throw new Error("Only a single font is allowed in CFF");
}
this.topDict = this.topDictIndex[0];
}
this.isCIDFont = this.topDict.ROS != null;
return this;
}
string(sid) {
if (this.version >= 2) {
return null;
}
if (sid < standardStrings.length) {
return standardStrings[sid];
}
return this.stringIndex[sid - standardStrings.length];
}
get postscriptName() {
if (this.version < 2) {
return this.nameIndex[0];
}
return null;
}
get fullName() {
return this.string(this.topDict.FullName);
}
get familyName() {
return this.string(this.topDict.FamilyName);
}
getCharString(glyph) {
this.stream.pos = this.topDict.CharStrings[glyph].offset;
return this.stream.readBuffer(this.topDict.CharStrings[glyph].length);
}
getGlyphName(gid) {
// CFF2 glyph names are in the post table.
if (this.version >= 2) {
return null;
}
// CID-keyed fonts don't have glyph names
if (this.isCIDFont) {
return null;
}
let { charset } = this.topDict;
if (Array.isArray(charset)) {
return charset[gid];
}
if (gid === 0) {
return '.notdef';
}
gid -= 1;
switch (charset.version) {
case 0:
return this.string(charset.glyphs[gid]);
case 1:
case 2:
for (let i = 0; i < charset.ranges.length; i++) {
let range = charset.ranges[i];
if (range.offset <= gid && gid <= range.offset + range.nLeft) {
return this.string(range.first + (gid - range.offset));
}
}
break;
}
return null;
}
fdForGlyph(gid) {
if (!this.topDict.FDSelect) {
return null;
}
switch (this.topDict.FDSelect.version) {
case 0:
return this.topDict.FDSelect.fds[gid];
case 3:
case 4:
let { ranges } = this.topDict.FDSelect;
let low = 0;
let high = ranges.length - 1;
while (low <= high) {
let mid = (low + high) >> 1;
if (gid < ranges[mid].first) {
high = mid - 1;
} else if (mid < high && gid >= ranges[mid + 1].first) {
low = mid + 1;
} else {
return ranges[mid].fd;
}
}
default:
throw new Error(`Unknown FDSelect version: ${this.topDict.FDSelect.version}`);
}
}
privateDictForGlyph(gid) {
if (this.topDict.FDSelect) {
let fd = this.fdForGlyph(gid);
if (this.topDict.FDArray[fd]) {
return this.topDict.FDArray[fd].Private;
}
return null;
}
if (this.version < 2) {
return this.topDict.Private;
}
return this.topDict.FDArray[0].Private;
}
}
export default CFFFont;

150
node_modules/fontkit/src/cff/CFFIndex.js generated vendored Normal file
View File

@@ -0,0 +1,150 @@
import * as r from 'restructure';
export default class CFFIndex {
constructor(type) {
this.type = type;
}
getCFFVersion(ctx) {
while (ctx && !ctx.hdrSize) {
ctx = ctx.parent;
}
return ctx ? ctx.version : -1;
}
decode(stream, parent) {
let version = this.getCFFVersion(parent);
let count = version >= 2
? stream.readUInt32BE()
: stream.readUInt16BE();
if (count === 0) {
return [];
}
let offSize = stream.readUInt8();
let offsetType;
if (offSize === 1) {
offsetType = r.uint8;
} else if (offSize === 2) {
offsetType = r.uint16;
} else if (offSize === 3) {
offsetType = r.uint24;
} else if (offSize === 4) {
offsetType = r.uint32;
} else {
throw new Error(`Bad offset size in CFFIndex: ${offSize} ${stream.pos}`);
}
let ret = [];
let startPos = stream.pos + ((count + 1) * offSize) - 1;
let start = offsetType.decode(stream);
for (let i = 0; i < count; i++) {
let end = offsetType.decode(stream);
if (this.type != null) {
let pos = stream.pos;
stream.pos = startPos + start;
parent.length = end - start;
ret.push(this.type.decode(stream, parent));
stream.pos = pos;
} else {
ret.push({
offset: startPos + start,
length: end - start
});
}
start = end;
}
stream.pos = startPos + start;
return ret;
}
size(arr, parent) {
let size = 2;
if (arr.length === 0) {
return size;
}
let type = this.type || new r.Buffer;
// find maximum offset to detminine offset type
let offset = 1;
for (let i = 0; i < arr.length; i++) {
let item = arr[i];
offset += type.size(item, parent);
}
let offsetType;
if (offset <= 0xff) {
offsetType = r.uint8;
} else if (offset <= 0xffff) {
offsetType = r.uint16;
} else if (offset <= 0xffffff) {
offsetType = r.uint24;
} else if (offset <= 0xffffffff) {
offsetType = r.uint32;
} else {
throw new Error("Bad offset in CFFIndex");
}
size += 1 + offsetType.size() * (arr.length + 1);
size += offset - 1;
return size;
}
encode(stream, arr, parent) {
stream.writeUInt16BE(arr.length);
if (arr.length === 0) {
return;
}
let type = this.type || new r.Buffer;
// find maximum offset to detminine offset type
let sizes = [];
let offset = 1;
for (let item of arr) {
let s = type.size(item, parent);
sizes.push(s);
offset += s;
}
let offsetType;
if (offset <= 0xff) {
offsetType = r.uint8;
} else if (offset <= 0xffff) {
offsetType = r.uint16;
} else if (offset <= 0xffffff) {
offsetType = r.uint24;
} else if (offset <= 0xffffffff) {
offsetType = r.uint32;
} else {
throw new Error("Bad offset in CFFIndex");
}
// write offset size
stream.writeUInt8(offsetType.size());
// write elements
offset = 1;
offsetType.encode(stream, offset);
for (let size of sizes) {
offset += size;
offsetType.encode(stream, offset);
}
for (let item of arr) {
type.encode(stream, item, parent);
}
return;
}
}

134
node_modules/fontkit/src/cff/CFFOperand.js generated vendored Normal file
View File

@@ -0,0 +1,134 @@
const FLOAT_EOF = 0xf;
const FLOAT_LOOKUP = [
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '.', 'E', 'E-', null, '-'
];
const FLOAT_ENCODE_LOOKUP = {
'.': 10,
'E': 11,
'E-': 12,
'-': 14
};
export default class CFFOperand {
static decode(stream, value) {
if (32 <= value && value <= 246) {
return value - 139;
}
if (247 <= value && value <= 250) {
return (value - 247) * 256 + stream.readUInt8() + 108;
}
if (251 <= value && value <= 254) {
return -(value - 251) * 256 - stream.readUInt8() - 108;
}
if (value === 28) {
return stream.readInt16BE();
}
if (value === 29) {
return stream.readInt32BE();
}
if (value === 30) {
let str = '';
while (true) {
let b = stream.readUInt8();
let n1 = b >> 4;
if (n1 === FLOAT_EOF) { break; }
str += FLOAT_LOOKUP[n1];
let n2 = b & 15;
if (n2 === FLOAT_EOF) { break; }
str += FLOAT_LOOKUP[n2];
}
return parseFloat(str);
}
return null;
}
static size(value) {
// if the value needs to be forced to the largest size (32 bit)
// e.g. for unknown pointers, set to 32768
if (value.forceLarge) {
value = 32768;
}
if ((value | 0) !== value) { // floating point
let str = '' + value;
return 1 + Math.ceil((str.length + 1) / 2);
} else if (-107 <= value && value <= 107) {
return 1;
} else if (108 <= value && value <= 1131 || -1131 <= value && value <= -108) {
return 2;
} else if (-32768 <= value && value <= 32767) {
return 3;
} else {
return 5;
}
}
static encode(stream, value) {
// if the value needs to be forced to the largest size (32 bit)
// e.g. for unknown pointers, save the old value and set to 32768
let val = Number(value);
if (value.forceLarge) {
stream.writeUInt8(29);
return stream.writeInt32BE(val);
} else if ((val | 0) !== val) { // floating point
stream.writeUInt8(30);
let str = '' + val;
for (let i = 0; i < str.length; i += 2) {
let c1 = str[i];
let n1 = FLOAT_ENCODE_LOOKUP[c1] || +c1;
if (i === str.length - 1) {
var n2 = FLOAT_EOF;
} else {
let c2 = str[i + 1];
var n2 = FLOAT_ENCODE_LOOKUP[c2] || +c2;
}
stream.writeUInt8((n1 << 4) | (n2 & 15));
}
if (n2 !== FLOAT_EOF) {
return stream.writeUInt8((FLOAT_EOF << 4));
}
} else if (-107 <= val && val <= 107) {
return stream.writeUInt8(val + 139);
} else if (108 <= val && val <= 1131) {
val -= 108;
stream.writeUInt8((val >> 8) + 247);
return stream.writeUInt8(val & 0xff);
} else if (-1131 <= val && val <= -108) {
val = -val - 108;
stream.writeUInt8((val >> 8) + 251);
return stream.writeUInt8(val & 0xff);
} else if (-32768 <= val && val <= 32767) {
stream.writeUInt8(28);
return stream.writeInt16BE(val);
} else {
stream.writeUInt8(29);
return stream.writeInt32BE(val);
}
}
}

50
node_modules/fontkit/src/cff/CFFPointer.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import * as r from 'restructure';
export default class CFFPointer extends r.Pointer {
constructor(type, options = {}) {
if (options.type == null) {
options.type = 'global';
}
super(null, type, options);
}
decode(stream, parent, operands) {
this.offsetType = {
decode: () => operands[0]
};
return super.decode(stream, parent, operands);
}
encode(stream, value, ctx) {
if (!stream) {
// compute the size (so ctx.pointerSize is correct)
this.offsetType = {
size: () => 0
};
this.size(value, ctx);
return [new Ptr(0)];
}
let ptr = null;
this.offsetType = {
encode: (stream, val) => ptr = val
};
super.encode(stream, value, ctx);
return [new Ptr(ptr)];
}
}
class Ptr {
constructor(val) {
this.val = val;
this.forceLarge = true;
}
valueOf() {
return this.val;
}
}

39
node_modules/fontkit/src/cff/CFFPrivateDict.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import CFFDict from './CFFDict';
import CFFIndex from './CFFIndex';
import CFFPointer from './CFFPointer';
class CFFBlendOp {
static decode(stream, parent, operands) {
let numBlends = operands.pop();
// TODO: actually blend. For now just consume the deltas
// since we don't use any of the values anyway.
while (operands.length > numBlends) {
operands.pop();
}
}
}
export default new CFFDict([
// key name type default
[6, 'BlueValues', 'delta', null],
[7, 'OtherBlues', 'delta', null],
[8, 'FamilyBlues', 'delta', null],
[9, 'FamilyOtherBlues', 'delta', null],
[[12, 9], 'BlueScale', 'number', 0.039625],
[[12, 10], 'BlueShift', 'number', 7],
[[12, 11], 'BlueFuzz', 'number', 1],
[10, 'StdHW', 'number', null],
[11, 'StdVW', 'number', null],
[[12, 12], 'StemSnapH', 'delta', null],
[[12, 13], 'StemSnapV', 'delta', null],
[[12, 14], 'ForceBold', 'boolean', false],
[[12, 17], 'LanguageGroup', 'number', 0],
[[12, 18], 'ExpansionFactor', 'number', 0.06],
[[12, 19], 'initialRandomSeed', 'number', 0],
[20, 'defaultWidthX', 'number', 0],
[21, 'nominalWidthX', 'number', 0],
[22, 'vsindex', 'number', 0],
[23, 'blend', CFFBlendOp, null],
[19, 'Subrs', new CFFPointer(new CFFIndex, {type: 'local'}), null]
]);

71
node_modules/fontkit/src/cff/CFFStandardStrings.js generated vendored Normal file
View File

@@ -0,0 +1,71 @@
// Automatically generated from Appendix A of the CFF specification; do
// not edit. Length should be 391.
export default [
".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar",
"percent", "ampersand", "quoteright", "parenleft", "parenright",
"asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one",
"two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
"semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
"bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c",
"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright",
"asciitilde", "exclamdown", "cent", "sterling", "fraction", "yen",
"florin", "section", "currency", "quotesingle", "quotedblleft",
"guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash",
"dagger", "daggerdbl", "periodcentered", "paragraph", "bullet",
"quotesinglbase", "quotedblbase", "quotedblright", "guillemotright",
"ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex",
"tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla",
"hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine", "Lslash",
"Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash", "oslash", "oe",
"germandbls", "onesuperior", "logicalnot", "mu", "trademark", "Eth",
"onehalf", "plusminus", "Thorn", "onequarter", "divide", "brokenbar",
"degree", "thorn", "threequarters", "twosuperior", "registered", "minus",
"eth", "multiply", "threesuperior", "copyright", "Aacute", "Acircumflex",
"Adieresis", "Agrave", "Aring", "Atilde", "Ccedilla", "Eacute",
"Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis",
"Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve",
"Otilde", "Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave",
"Yacute", "Ydieresis", "Zcaron", "aacute", "acircumflex", "adieresis",
"agrave", "aring", "atilde", "ccedilla", "eacute", "ecircumflex",
"edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave",
"ntilde", "oacute", "ocircumflex", "odieresis", "ograve", "otilde",
"scaron", "uacute", "ucircumflex", "udieresis", "ugrave", "yacute",
"ydieresis", "zcaron", "exclamsmall", "Hungarumlautsmall",
"dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall",
"parenleftsuperior", "parenrightsuperior", "twodotenleader",
"onedotenleader", "zerooldstyle", "oneoldstyle", "twooldstyle",
"threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle",
"sevenoldstyle", "eightoldstyle", "nineoldstyle", "commasuperior",
"threequartersemdash", "periodsuperior", "questionsmall", "asuperior",
"bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior",
"lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior",
"ssuperior", "tsuperior", "ff", "ffi", "ffl", "parenleftinferior",
"parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall",
"Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall",
"Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall",
"Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall",
"Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary",
"onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle",
"Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall",
"Caronsmall", "Dotaccentsmall", "Macronsmall", "figuredash",
"hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall",
"questiondownsmall", "oneeighth", "threeeighths", "fiveeighths",
"seveneighths", "onethird", "twothirds", "zerosuperior", "foursuperior",
"fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior",
"ninesuperior", "zeroinferior", "oneinferior", "twoinferior",
"threeinferior", "fourinferior", "fiveinferior", "sixinferior",
"seveninferior", "eightinferior", "nineinferior", "centinferior",
"dollarinferior", "periodinferior", "commainferior", "Agravesmall",
"Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall",
"Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall",
"Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall",
"Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall",
"Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall",
"Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall",
"Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall",
"Ydieresissmall", "001.000", "001.001", "001.002", "001.003", "Black",
"Bold", "Book", "Light", "Medium", "Regular", "Roman", "Semibold"
];

237
node_modules/fontkit/src/cff/CFFTop.js generated vendored Normal file
View File

@@ -0,0 +1,237 @@
import * as r from 'restructure';
import { resolveLength } from 'restructure';
import CFFDict from './CFFDict';
import CFFIndex from './CFFIndex';
import CFFPointer from './CFFPointer';
import CFFPrivateDict from './CFFPrivateDict';
import StandardStrings from './CFFStandardStrings';
import { StandardEncoding, ExpertEncoding } from './CFFEncodings';
import { ISOAdobeCharset, ExpertCharset, ExpertSubsetCharset } from './CFFCharsets';
import { ItemVariationStore } from '../tables/variations';
// Checks if an operand is an index of a predefined value,
// otherwise delegates to the provided type.
class PredefinedOp {
constructor(predefinedOps, type) {
this.predefinedOps = predefinedOps;
this.type = type;
}
decode(stream, parent, operands) {
if (this.predefinedOps[operands[0]]) {
return this.predefinedOps[operands[0]];
}
return this.type.decode(stream, parent, operands);
}
size(value, ctx) {
return this.type.size(value, ctx);
}
encode(stream, value, ctx) {
let index = this.predefinedOps.indexOf(value);
if (index !== -1) {
return index;
}
return this.type.encode(stream, value, ctx);
}
}
class CFFEncodingVersion extends r.Number {
constructor() {
super('UInt8');
}
decode(stream) {
return r.uint8.decode(stream) & 0x7f;
}
}
let Range1 = new r.Struct({
first: r.uint16,
nLeft: r.uint8
});
let Range2 = new r.Struct({
first: r.uint16,
nLeft: r.uint16
});
let CFFCustomEncoding = new r.VersionedStruct(new CFFEncodingVersion(), {
0: {
nCodes: r.uint8,
codes: new r.Array(r.uint8, 'nCodes')
},
1: {
nRanges: r.uint8,
ranges: new r.Array(Range1, 'nRanges')
}
// TODO: supplement?
});
let CFFEncoding = new PredefinedOp([ StandardEncoding, ExpertEncoding ], new CFFPointer(CFFCustomEncoding, { lazy: true }));
// Decodes an array of ranges until the total
// length is equal to the provided length.
class RangeArray extends r.Array {
decode(stream, parent) {
let length = resolveLength(this.length, stream, parent);
let count = 0;
let res = [];
while (count < length) {
let range = this.type.decode(stream, parent);
range.offset = count;
count += range.nLeft + 1;
res.push(range);
}
return res;
}
}
let CFFCustomCharset = new r.VersionedStruct(r.uint8, {
0: {
glyphs: new r.Array(r.uint16, t => t.parent.CharStrings.length - 1)
},
1: {
ranges: new RangeArray(Range1, t => t.parent.CharStrings.length - 1)
},
2: {
ranges: new RangeArray(Range2, t => t.parent.CharStrings.length - 1)
}
});
let CFFCharset = new PredefinedOp([ ISOAdobeCharset, ExpertCharset, ExpertSubsetCharset ], new CFFPointer(CFFCustomCharset, {lazy: true}));
let FDRange3 = new r.Struct({
first: r.uint16,
fd: r.uint8
});
let FDRange4 = new r.Struct({
first: r.uint32,
fd: r.uint16
});
let FDSelect = new r.VersionedStruct(r.uint8, {
0: {
fds: new r.Array(r.uint8, t => t.parent.CharStrings.length)
},
3: {
nRanges: r.uint16,
ranges: new r.Array(FDRange3, 'nRanges'),
sentinel: r.uint16
},
4: {
nRanges: r.uint32,
ranges: new r.Array(FDRange4, 'nRanges'),
sentinel: r.uint32
}
});
let ptr = new CFFPointer(CFFPrivateDict);
class CFFPrivateOp {
decode(stream, parent, operands) {
parent.length = operands[0];
return ptr.decode(stream, parent, [operands[1]]);
}
size(dict, ctx) {
return [CFFPrivateDict.size(dict, ctx, false), ptr.size(dict, ctx)[0]];
}
encode(stream, dict, ctx) {
return [CFFPrivateDict.size(dict, ctx, false), ptr.encode(stream, dict, ctx)[0]];
}
}
let FontDict = new CFFDict([
// key name type(s) default
[18, 'Private', new CFFPrivateOp, null],
[[12, 38], 'FontName', 'sid', null],
[[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],
[[12, 5], 'PaintType', 'number', 0],
]);
let CFFTopDict = new CFFDict([
// key name type(s) default
[[12, 30], 'ROS', ['sid', 'sid', 'number'], null],
[0, 'version', 'sid', null],
[1, 'Notice', 'sid', null],
[[12, 0], 'Copyright', 'sid', null],
[2, 'FullName', 'sid', null],
[3, 'FamilyName', 'sid', null],
[4, 'Weight', 'sid', null],
[[12, 1], 'isFixedPitch', 'boolean', false],
[[12, 2], 'ItalicAngle', 'number', 0],
[[12, 3], 'UnderlinePosition', 'number', -100],
[[12, 4], 'UnderlineThickness', 'number', 50],
[[12, 5], 'PaintType', 'number', 0],
[[12, 6], 'CharstringType', 'number', 2],
[[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],
[13, 'UniqueID', 'number', null],
[5, 'FontBBox', 'array', [0, 0, 0, 0]],
[[12, 8], 'StrokeWidth', 'number', 0],
[14, 'XUID', 'array', null],
[15, 'charset', CFFCharset, ISOAdobeCharset],
[16, 'Encoding', CFFEncoding, StandardEncoding],
[17, 'CharStrings', new CFFPointer(new CFFIndex), null],
[18, 'Private', new CFFPrivateOp, null],
[[12, 20], 'SyntheticBase', 'number', null],
[[12, 21], 'PostScript', 'sid', null],
[[12, 22], 'BaseFontName', 'sid', null],
[[12, 23], 'BaseFontBlend', 'delta', null],
// CID font specific
[[12, 31], 'CIDFontVersion', 'number', 0],
[[12, 32], 'CIDFontRevision', 'number', 0],
[[12, 33], 'CIDFontType', 'number', 0],
[[12, 34], 'CIDCount', 'number', 8720],
[[12, 35], 'UIDBase', 'number', null],
[[12, 37], 'FDSelect', new CFFPointer(FDSelect), null],
[[12, 36], 'FDArray', new CFFPointer(new CFFIndex(FontDict)), null],
[[12, 38], 'FontName', 'sid', null]
]);
let VariationStore = new r.Struct({
length: r.uint16,
itemVariationStore: ItemVariationStore
})
let CFF2TopDict = new CFFDict([
[[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],
[17, 'CharStrings', new CFFPointer(new CFFIndex), null],
[[12, 37], 'FDSelect', new CFFPointer(FDSelect), null],
[[12, 36], 'FDArray', new CFFPointer(new CFFIndex(FontDict)), null],
[24, 'vstore', new CFFPointer(VariationStore), null],
[25, 'maxstack', 'number', 193]
]);
let CFFTop = new r.VersionedStruct(r.fixed16, {
1: {
hdrSize: r.uint8,
offSize: r.uint8,
nameIndex: new CFFIndex(new r.String('length')),
topDictIndex: new CFFIndex(CFFTopDict),
stringIndex: new CFFIndex(new r.String('length')),
globalSubrIndex: new CFFIndex
},
2: {
hdrSize: r.uint8,
length: r.uint16,
topDict: CFF2TopDict,
globalSubrIndex: new CFFIndex
}
});
export default CFFTop;