Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'opbd', 'prop', 'trak', 'Zapf', 'Silf', 'Glat', 'Gloc', 'Feat', 'Sill'
];
let WOFF2DirectoryEntry = new r.Struct({
flags: r.uint8,
customTag: new r.Optional(new r.String(4), t => (t.flags & 0x3f) === 0x3f),
tag: t => t.customTag || knownTags[t.flags & 0x3f],// || (() => { throw new Error(`Bad tag: ${flags & 0x3f}`); })(); },
length: Base128,
transformVersion: t => (t.flags >>> 6) & 0x03,
transformed: t => (t.tag === 'glyf' || t.tag === 'loca') ? t.transformVersion === 0 : t.transformVersion !== 0,
transformLength: new r.Optional(Base128, t => t.transformed)
});
let WOFF2Directory = new r.Struct({
tag: new r.String(4), // should be 'wOF2'
flavor: r.uint32,
length: r.uint32,
numTables: r.uint16,
reserved: new r.Reserved(r.uint16),
totalSfntSize: r.uint32,
totalCompressedSize: r.uint32,
majorVersion: r.uint16,
minorVersion: r.uint16,
metaOffset: r.uint32,
metaLength: r.uint32,
metaOrigLength: r.uint32,
privOffset: r.uint32,
privLength: r.uint32,
tables: new r.Array(WOFF2DirectoryEntry, 'numTables')
});
WOFF2Directory.process = function() {
return new r.DecodeStream(this._buf.decode(stream, parent));
}
}
// This struct represents the entire glyf table
let GlyfTable = new r.Struct({
version: r.uint32,
numGlyphs: r.uint16,
indexFormat: r.uint16,
nContourStreamSize: r.uint32,
nPointsStreamSize: r.uint32,
flagStreamSize: r.uint32,
glyphStreamSize: r.uint32,
compositeStreamSize: r.uint32,
bboxStreamSize: r.uint32,
instructionStreamSize: r.uint32,
nContours: new Substream('nContourStreamSize'),
nPoints: new Substream('nPointsStreamSize'),
flags: new Substream('flagStreamSize'),
glyphs: new Substream('glyphStreamSize'),
composites: new Substream('compositeStreamSize'),
bboxes: new Substream('bboxStreamSize'),
instructions: new Substream('instructionStreamSize')
});
const WORD_CODE = 253;
const ONE_MORE_BYTE_CODE2 = 254;
const ONE_MORE_BYTE_CODE1 = 255;
const LOWEST_U_CODE = 253;
function read255UInt16(stream) {
let code = stream.readUInt8();
import r from 'restructure';
// font header
export default new r.Struct({
version: r.int32, // 0x00010000 (version 1.0)
revision: r.int32, // set by font manufacturer
checkSumAdjustment: r.uint32,
magicNumber: r.uint32, // set to 0x5F0F3CF5
flags: r.uint16,
unitsPerEm: r.uint16, // range from 64 to 16384
created: new r.Array(r.int32, 2),
modified: new r.Array(r.int32, 2),
xMin: r.int16, // for all glyph bounding boxes
yMin: r.int16, // for all glyph bounding boxes
xMax: r.int16, // for all glyph bounding boxes
yMax: r.int16, // for all glyph bounding boxes
macStyle: new r.Bitfield(r.uint16, [
'bold', 'italic', 'underline', 'outline',
'shadow', 'condensed', 'extended'
]),
lowestRecPPEM: r.uint16, // smallest readable size in pixels
fontDirectionHint: r.int16,
indexToLocFormat: r.int16, // 0 for short offsets, 1 for long
let KernTable = new r.VersionedStruct('version', {
0: { // Microsoft uses this format
subVersion: r.uint16, // Microsoft has an extra sub-table version number
length: r.uint16, // Length of the subtable, in bytes
format: r.uint8, // Format of subtable
coverage: new r.Bitfield(r.uint8, [
'horizontal', // 1 if table has horizontal data, 0 if vertical
'minimum', // If set to 1, the table has minimum values. If set to 0, the table has kerning values.
'crossStream', // If set to 1, kerning is perpendicular to the flow of the text
'override' // If set to 1 the value in this table replaces the accumulated value
]),
subtable: KernSubtable,
padding: new r.Reserved(r.uint8, t => t.length - t._currentOffset)
},
1: { // Apple uses this format
length: r.uint32,
coverage: new r.Bitfield(r.uint8, [
null, null, null, null, null,
'variation', // Set if table has variation kerning values
'crossStream', // Set if table has cross-stream kerning values
'vertical' // Set if table has vertical kerning values
]),
format: r.uint8,
tupleIndex: r.uint16,
subtable: KernSubtable,
padding: new r.Reserved(r.uint8, t => t.length - t._currentOffset)
}
});
export default new r.VersionedStruct(r.uint16, {
0: { // Microsoft Version
nTables: r.uint16,
8: { // mixed 16-bit and 32-bit coverage
reserved: new r.Reserved(r.uint16),
length: r.uint32,
language: r.uint16,
is32: new r.LazyArray(r.uint8, 8192),
nGroups: r.uint32,
groups: new r.LazyArray(CmapGroup, 'nGroups')
},
10: { // Trimmed Array
reserved: new r.Reserved(r.uint16),
length: r.uint32,
language: r.uint32,
firstCode: r.uint32,
entryCount: r.uint32,
glyphIndices: new r.LazyArray(r.uint16, 'numChars')
},
12: { // Segmented coverage
reserved: new r.Reserved(r.uint16),
length: r.uint32,
language: r.uint32,
nGroups: r.uint32,
groups: new r.LazyArray(CmapGroup, 'nGroups')
},
13: { // Many-to-one range mappings (same as 12 except for group.startGlyphID)
reserved: new r.Reserved(r.uint16),
length: r.uint32,
language: r.uint32,
nGroups: r.uint32,
constructor(length) {
this.length = length;
this._buf = new r.Buffer(length);
}
decode(stream, parent) {
return new r.DecodeStream(this._buf.decode(stream, parent));
}
}
// This struct represents the entire glyf table
let GlyfTable = new r.Struct({
version: r.uint32,
numGlyphs: r.uint16,
indexFormat: r.uint16,
nContourStreamSize: r.uint32,
nPointsStreamSize: r.uint32,
flagStreamSize: r.uint32,
glyphStreamSize: r.uint32,
compositeStreamSize: r.uint32,
bboxStreamSize: r.uint32,
instructionStreamSize: r.uint32,
nContours: new Substream('nContourStreamSize'),
nPoints: new Substream('nPointsStreamSize'),
flags: new Substream('flagStreamSize'),
glyphs: new Substream('glyphStreamSize'),
composites: new Substream('compositeStreamSize'),
bboxes: new Substream('bboxStreamSize'),
instructions: new Substream('instructionStreamSize')
});
const WORD_CODE = 253;
bigMetrics: BigMetrics
},
3: {
offsetArray: new r.Array(r.uint16, t => t.parent.lastGlyphIndex - t.parent.firstGlyphIndex + 1)
},
4: {
numGlyphs: r.uint32,
glyphArray: new r.Array(CodeOffsetPair, t => t.numGlyphs + 1)
},
5: {
imageSize: r.uint32,
bigMetrics: BigMetrics,
numGlyphs: r.uint32,
glyphCodeArray: new r.Array(r.uint16, 'numGlyphs')
}
});
let IndexSubtableArray = new r.Struct({
firstGlyphIndex: r.uint16,
lastGlyphIndex: r.uint16,
subtable: new r.Pointer(r.uint32, IndexSubtable)
});
let BitmapSizeTable = new r.Struct({
indexSubTableArray: new r.Pointer(r.uint32, new r.Array(IndexSubtableArray, 1), { type: 'parent' }),
indexTablesSize: r.uint32,
numberOfIndexSubTables: r.uint32,
colorRef: r.uint32,
hori: SBitLineMetrics,
deviceTable: new r.Pointer(r.uint16, Device)
}
});
let LigGlyph = new r.Array(new r.Pointer(r.uint16, CaretValue), r.uint16);
let LigCaretList = new r.Struct({
coverage: new r.Pointer(r.uint16, Coverage),
ligGlyphCount: r.uint16,
ligGlyphs: new r.Array(new r.Pointer(r.uint16, LigGlyph), 'ligGlyphCount')
});
let MarkGlyphSetsDef = new r.Struct({
markSetTableFormat: r.uint16,
markSetCount: r.uint16,
coverage: new r.Array(new r.Pointer(r.uint32, Coverage), 'markSetCount')
});
export default new r.VersionedStruct(r.uint32, {
header: {
glyphClassDef: new r.Pointer(r.uint16, ClassDef),
attachList: new r.Pointer(r.uint16, AttachList),
ligCaretList: new r.Pointer(r.uint16, LigCaretList),
markAttachClassDef: new r.Pointer(r.uint16, ClassDef)
},
0x00010000: {},
0x00010002: {
markGlyphSetsDef: new r.Pointer(r.uint16, MarkGlyphSetsDef)
},
0x00010003: {
markGlyphSetsDef: new r.Pointer(r.uint16, MarkGlyphSetsDef),
}
});
let Subtable = new r.Struct({
length: r.uint32,
coverage: r.uint24,
type: r.uint8,
subFeatureFlags: r.uint32,
table: SubtableData,
padding: new r.Reserved(r.uint8, t => t.length - t._currentOffset)
});
let FeatureEntry = new r.Struct({
featureType: r.uint16,
featureSetting: r.uint16,
enableFlags: r.uint32,
disableFlags: r.uint32
});
let MorxChain = new r.Struct({
defaultFlags: r.uint32,
chainLength: r.uint32,
nFeatureEntries: r.uint32,
nSubtables: r.uint32,
features: new r.Array(FeatureEntry, 'nFeatureEntries'),
subtables: new r.Array(Subtable, 'nSubtables')
});
export default new r.Struct({
version: r.uint16,
unused: new r.Reserved(r.uint16),
nChains: r.uint32,
export function StateTable(entryData = {}, lookupType = r.uint16) {
let entry = Object.assign({
newState: r.uint16,
flags: r.uint16
}, entryData);
let Entry = new r.Struct(entry);
let StateArray = new UnboundedArray(new r.Array(r.uint16, t => t.nClasses));
let StateHeader = new r.Struct({
nClasses: r.uint32,
classTable: new r.Pointer(r.uint32, new LookupTable(lookupType)),
stateArray: new r.Pointer(r.uint32, StateArray),
entryTable: new r.Pointer(r.uint32, new UnboundedArray(Entry))
});
return StateHeader;
}