@cantoo/fontkit 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-module.d.ts +239 -0
- package/dist/browser-module.mjs +4423 -1117
- package/dist/browser-module.mjs.map +1 -1
- package/dist/browser.cjs +4424 -1117
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +239 -0
- package/dist/fontkit.umd.d.ts +239 -0
- package/dist/fontkit.umd.js +22076 -0
- package/dist/fontkit.umd.js.map +7 -0
- package/dist/index.d.ts +239 -0
- package/dist/main.cjs +4424 -1117
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.ts +239 -0
- package/dist/module.d.ts +239 -0
- package/dist/module.mjs +4423 -1117
- package/dist/module.mjs.map +1 -1
- package/package.json +22 -5
- package/src/CmapProcessor.js +59 -20
- package/src/DFont.js +114 -14
- package/src/TTFFont.js +259 -57
- package/src/TrueTypeCollection.js +54 -10
- package/src/WOFF2Font.js +128 -16
- package/src/WOFFFont.js +45 -8
- package/src/aat/AATFeatureMap.js +62 -18
- package/src/aat/AATLayoutEngine.js +33 -1
- package/src/aat/AATLookupTable.js +22 -4
- package/src/aat/AATMorxProcessor.js +189 -52
- package/src/aat/AATStateMachine.js +32 -0
- package/src/base.js +19 -0
- package/src/cff/CFFCharsets.js +3 -0
- package/src/cff/CFFDict.js +79 -9
- package/src/cff/CFFEncodings.js +2 -0
- package/src/cff/CFFFont.js +119 -23
- package/src/cff/CFFIndex.js +62 -5
- package/src/cff/CFFOperand.js +52 -17
- package/src/cff/CFFPointer.js +41 -2
- package/src/cff/CFFPrivateDict.js +14 -4
- package/src/cff/CFFStandardStrings.js +1 -0
- package/src/cff/CFFTop.js +103 -10
- package/src/decorators.js +32 -13
- package/src/encodings.js +22 -5
- package/src/fs.js +10 -0
- package/src/glyph/BBox.js +14 -0
- package/src/glyph/CFFGlyph.js +290 -148
- package/src/glyph/COLRGlyph.js +38 -3
- package/src/glyph/Glyph.js +68 -9
- package/src/glyph/GlyphVariationProcessor.js +135 -34
- package/src/glyph/Path.js +107 -20
- package/src/glyph/SBIXGlyph.js +57 -8
- package/src/glyph/StandardNames.js +1 -0
- package/src/glyph/TTFGlyph.js +176 -29
- package/src/glyph/TTFGlyphEncoder.js +32 -0
- package/src/glyph/WOFF2Glyph.js +23 -4
- package/src/layout/GlyphPosition.js +6 -0
- package/src/layout/GlyphRun.js +25 -7
- package/src/layout/KernProcessor.js +62 -3
- package/src/layout/LayoutEngine.js +86 -12
- package/src/layout/Script.js +27 -1
- package/src/layout/UnicodeLayoutEngine.js +29 -4
- package/src/opentype/GPOSProcessor.js +156 -45
- package/src/opentype/GSUBProcessor.js +92 -33
- package/src/opentype/GlyphInfo.js +52 -4
- package/src/opentype/GlyphIterator.js +51 -2
- package/src/opentype/OTLayoutEngine.js +66 -8
- package/src/opentype/OTProcessor.js +283 -70
- package/src/opentype/ShapingPlan.js +51 -3
- package/src/opentype/shapers/ArabicShaper.js +19 -0
- package/src/opentype/shapers/DefaultShaper.js +51 -7
- package/src/opentype/shapers/HangulShaper.js +85 -7
- package/src/opentype/shapers/HebrewShaper.js +45 -11
- package/src/opentype/shapers/IndicShaper.js +141 -26
- package/src/opentype/shapers/ThaiShaper.js +35 -4
- package/src/opentype/shapers/UniversalShaper.js +83 -17
- package/src/opentype/shapers/index.js +15 -2
- package/src/packages/unicode-properties/data-trie.js +1 -0
- package/src/packages/unicode-properties/data.js +12 -0
- package/src/packages/unicode-properties/dist/index.cjs +22 -9
- package/src/packages/unicode-properties/dist/index.cjs.map +2 -2
- package/src/packages/unicode-properties/dist/index.mjs +21 -9
- package/src/packages/unicode-properties/dist/index.mjs.map +2 -2
- package/src/packages/unicode-properties/index.js +65 -0
- package/src/packages/unicode-properties/package.json +1 -1
- package/src/packages/unicode-trie/builder.js +128 -7
- package/src/packages/unicode-trie/dist/builder.cjs +129 -16
- package/src/packages/unicode-trie/dist/builder.cjs.map +2 -2
- package/src/packages/unicode-trie/dist/builder.mjs +128 -16
- package/src/packages/unicode-trie/dist/builder.mjs.map +2 -2
- package/src/packages/unicode-trie/dist/index.cjs +22 -9
- package/src/packages/unicode-trie/dist/index.cjs.map +2 -2
- package/src/packages/unicode-trie/dist/index.mjs +21 -9
- package/src/packages/unicode-trie/dist/index.mjs.map +2 -2
- package/src/packages/unicode-trie/index.js +62 -10
- package/src/packages/unicode-trie/package.json +1 -1
- package/src/packages/unicode-trie/swap.js +13 -0
- package/src/subset/CFFSubset.js +112 -22
- package/src/subset/Subset.js +21 -1
- package/src/subset/TTFSubset.js +79 -36
- package/src/tables/BASE.js +1 -0
- package/src/tables/COLR.js +1 -0
- package/src/tables/CPAL.js +1 -0
- package/src/tables/DSIG.js +1 -0
- package/src/tables/EBDT.js +10 -3
- package/src/tables/EBLC.js +67 -7
- package/src/tables/GDEF.js +1 -0
- package/src/tables/GPOS.js +79 -16
- package/src/tables/GSUB.js +14 -3
- package/src/tables/HVAR.js +51 -5
- package/src/tables/JSTF.js +3 -2
- package/src/tables/LTSH.js +1 -0
- package/src/tables/OS2.js +1 -0
- package/src/tables/PCLT.js +1 -0
- package/src/tables/STAT.js +46 -6
- package/src/tables/VDMX.js +1 -0
- package/src/tables/VORG.js +1 -0
- package/src/tables/WOFF2Directory.js +56 -8
- package/src/tables/WOFFDirectory.js +14 -2
- package/src/tables/aat.js +160 -35
- package/src/tables/avar.js +1 -0
- package/src/tables/bsln.js +3 -2
- package/src/tables/cmap.js +26 -6
- package/src/tables/cvt.js +1 -0
- package/src/tables/directory.js +44 -16
- package/src/tables/feat.js +24 -2
- package/src/tables/fpgm.js +1 -0
- package/src/tables/fvar.js +32 -4
- package/src/tables/gasp.js +1 -0
- package/src/tables/glyf.js +1 -0
- package/src/tables/gvar.js +29 -2
- package/src/tables/hdmx.js +12 -1
- package/src/tables/head.js +1 -0
- package/src/tables/hhea.js +1 -0
- package/src/tables/hmtx.js +18 -2
- package/src/tables/index.js +1 -0
- package/src/tables/just.js +15 -4
- package/src/tables/kern.js +43 -6
- package/src/tables/loca.js +21 -8
- package/src/tables/maxp.js +1 -0
- package/src/tables/morx.js +14 -7
- package/src/tables/name.js +104 -23
- package/src/tables/opbd.js +2 -1
- package/src/tables/opentype.js +39 -4
- package/src/tables/post.js +8 -1
- package/src/tables/prep.js +1 -0
- package/src/tables/sbix.js +12 -1
- package/src/tables/variations.js +23 -3
- package/src/tables/vhea.js +1 -0
- package/src/tables/vmtx.js +18 -2
- package/src/utils.js +15 -0
- package/types/assets.d.ts +13 -0
- package/types/deps.d.ts +83 -0
- package/types/fontkit.d.ts +1324 -0
- package/types/index.d.ts +239 -0
- package/types/restructure.d.ts +354 -0
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public TypeScript API for `@cantoo/fontkit`.
|
|
3
|
+
* Built for consumers; internal checkJs types live in `./fontkit.d.ts`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type ScriptTag = string;
|
|
7
|
+
export type LanguageTag = string;
|
|
8
|
+
export type TextDirection = 'ltr' | 'rtl';
|
|
9
|
+
export type FeatureValue = boolean | number;
|
|
10
|
+
export type FeatureMap = Record<string, FeatureValue>;
|
|
11
|
+
export type FeatureInput = string[] | FeatureMap;
|
|
12
|
+
|
|
13
|
+
/** Bounding box in font units. */
|
|
14
|
+
export interface BBox {
|
|
15
|
+
minX: number;
|
|
16
|
+
minY: number;
|
|
17
|
+
maxX: number;
|
|
18
|
+
maxY: number;
|
|
19
|
+
readonly width: number;
|
|
20
|
+
readonly height: number;
|
|
21
|
+
addPoint(x: number, y: number): void;
|
|
22
|
+
copy(): BBox;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Vector path command. */
|
|
26
|
+
export interface PathCommand {
|
|
27
|
+
command: 'moveTo' | 'lineTo' | 'quadraticCurveTo' | 'bezierCurveTo' | 'closePath';
|
|
28
|
+
args: number[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Minimal canvas-like context used by Path.toFunction / Glyph.render. */
|
|
32
|
+
export interface PathRenderingContext {
|
|
33
|
+
save(): void;
|
|
34
|
+
restore(): void;
|
|
35
|
+
scale(x: number, y: number): void;
|
|
36
|
+
fill(): void;
|
|
37
|
+
moveTo?(x: number, y: number): void;
|
|
38
|
+
lineTo?(x: number, y: number): void;
|
|
39
|
+
quadraticCurveTo?(cpx: number, cpy: number, x: number, y: number): void;
|
|
40
|
+
bezierCurveTo?(
|
|
41
|
+
cp1x: number,
|
|
42
|
+
cp1y: number,
|
|
43
|
+
cp2x: number,
|
|
44
|
+
cp2y: number,
|
|
45
|
+
x: number,
|
|
46
|
+
y: number
|
|
47
|
+
): void;
|
|
48
|
+
closePath?(): void;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Outline path returned by glyphs. */
|
|
53
|
+
export interface Path {
|
|
54
|
+
commands: PathCommand[];
|
|
55
|
+
readonly cbox: BBox;
|
|
56
|
+
readonly bbox: BBox;
|
|
57
|
+
toFunction(): (ctx: PathRenderingContext) => void;
|
|
58
|
+
toSVG(): string;
|
|
59
|
+
mapPoints(fn: (x: number, y: number) => [number, number]): Path;
|
|
60
|
+
transform(m0: number, m1: number, m2: number, m3: number, m4: number, m5: number): Path;
|
|
61
|
+
translate(x: number, y: number): Path;
|
|
62
|
+
rotate(angle: number): Path;
|
|
63
|
+
scale(scaleX: number, scaleY?: number): Path;
|
|
64
|
+
moveTo(x: number, y: number): Path;
|
|
65
|
+
lineTo(x: number, y: number): Path;
|
|
66
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): Path;
|
|
67
|
+
bezierCurveTo(
|
|
68
|
+
cp1x: number,
|
|
69
|
+
cp1y: number,
|
|
70
|
+
cp2x: number,
|
|
71
|
+
cp2y: number,
|
|
72
|
+
x: number,
|
|
73
|
+
y: number
|
|
74
|
+
): Path;
|
|
75
|
+
closePath(): Path;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Per-glyph advance / bearing metrics. */
|
|
79
|
+
export interface GlyphMetrics {
|
|
80
|
+
width: number;
|
|
81
|
+
height: number;
|
|
82
|
+
advanceWidth: number;
|
|
83
|
+
advanceHeight: number;
|
|
84
|
+
leftBearing: number;
|
|
85
|
+
topBearing: number;
|
|
86
|
+
rightBearing: number;
|
|
87
|
+
bottomBearing: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A glyph in a font. */
|
|
91
|
+
export interface Glyph {
|
|
92
|
+
id: number;
|
|
93
|
+
codePoints: number[];
|
|
94
|
+
isMark: boolean;
|
|
95
|
+
isLigature: boolean;
|
|
96
|
+
readonly cbox: BBox;
|
|
97
|
+
readonly bbox: BBox;
|
|
98
|
+
readonly path: Path;
|
|
99
|
+
readonly width: number;
|
|
100
|
+
readonly height: number;
|
|
101
|
+
readonly advanceWidth: number;
|
|
102
|
+
readonly advanceHeight: number;
|
|
103
|
+
readonly leftBearing: number;
|
|
104
|
+
readonly topBearing: number;
|
|
105
|
+
readonly rightBearing: number;
|
|
106
|
+
readonly bottomBearing: number;
|
|
107
|
+
readonly name: string | null;
|
|
108
|
+
getScaledPath(size: number): Path;
|
|
109
|
+
render(ctx: PathRenderingContext, size: number): void;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Positioning for one glyph in a GlyphRun. */
|
|
113
|
+
export interface GlyphPosition {
|
|
114
|
+
xAdvance: number;
|
|
115
|
+
yAdvance: number;
|
|
116
|
+
xOffset: number;
|
|
117
|
+
yOffset: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Result of Font.layout(). */
|
|
121
|
+
export interface GlyphRun {
|
|
122
|
+
glyphs: Glyph[];
|
|
123
|
+
positions: GlyphPosition[] | null;
|
|
124
|
+
script: ScriptTag | string[] | null | undefined;
|
|
125
|
+
language: LanguageTag | null;
|
|
126
|
+
direction: TextDirection;
|
|
127
|
+
features: FeatureMap;
|
|
128
|
+
readonly advanceWidth: number;
|
|
129
|
+
readonly advanceHeight: number;
|
|
130
|
+
readonly bbox: BBox;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Variation axis description. */
|
|
134
|
+
export interface VariationAxisInfo {
|
|
135
|
+
name: string | null;
|
|
136
|
+
min: number;
|
|
137
|
+
default: number;
|
|
138
|
+
max: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Font subset writer. */
|
|
142
|
+
export interface Subset {
|
|
143
|
+
includeGlyph(glyph: Glyph | number): number;
|
|
144
|
+
encodeStream(): unknown;
|
|
145
|
+
encode(cb?: (err: Error | null, data?: Uint8Array) => void): Promise<Uint8Array> | void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* An opened font (or a font selected from a collection).
|
|
150
|
+
* Matches the public surface of TTFFont / WOFF / WOFF2 / etc.
|
|
151
|
+
*/
|
|
152
|
+
export interface Font {
|
|
153
|
+
type: string;
|
|
154
|
+
readonly postscriptName: string | null;
|
|
155
|
+
readonly fullName: string | null;
|
|
156
|
+
readonly familyName: string | null;
|
|
157
|
+
readonly subfamilyName: string | null;
|
|
158
|
+
readonly copyright: string | null;
|
|
159
|
+
readonly version: string | null;
|
|
160
|
+
readonly unitsPerEm: number;
|
|
161
|
+
readonly ascent: number;
|
|
162
|
+
readonly descent: number;
|
|
163
|
+
readonly lineGap: number;
|
|
164
|
+
readonly underlinePosition: number;
|
|
165
|
+
readonly underlineThickness: number;
|
|
166
|
+
readonly italicAngle: number;
|
|
167
|
+
readonly capHeight: number;
|
|
168
|
+
readonly xHeight: number;
|
|
169
|
+
readonly bbox: BBox;
|
|
170
|
+
readonly numGlyphs: number;
|
|
171
|
+
readonly characterSet: number[];
|
|
172
|
+
readonly availableFeatures: string[];
|
|
173
|
+
readonly variationAxes: Record<string, VariationAxisInfo>;
|
|
174
|
+
readonly namedVariations: Record<string, Record<string, number>>;
|
|
175
|
+
|
|
176
|
+
setDefaultLanguage(lang?: string | null): void;
|
|
177
|
+
getName(key: string, lang?: string): string | null;
|
|
178
|
+
hasGlyphForCodePoint(codePoint: number): boolean;
|
|
179
|
+
glyphForCodePoint(codePoint: number): Glyph | null;
|
|
180
|
+
glyphsForString(string: string): Glyph[];
|
|
181
|
+
layout(
|
|
182
|
+
string: string,
|
|
183
|
+
userFeatures?: FeatureInput | null,
|
|
184
|
+
script?: ScriptTag | string[] | null,
|
|
185
|
+
language?: LanguageTag | null,
|
|
186
|
+
direction?: TextDirection | null
|
|
187
|
+
): GlyphRun;
|
|
188
|
+
stringsForGlyph(gid: number): string[];
|
|
189
|
+
getAvailableFeatures(
|
|
190
|
+
script?: ScriptTag | string[] | null,
|
|
191
|
+
language?: LanguageTag | null
|
|
192
|
+
): string[];
|
|
193
|
+
getGlyph(glyph: number, characters?: number[]): Glyph | null;
|
|
194
|
+
createSubset(): Subset;
|
|
195
|
+
getVariation(variation: string | Record<string, number> | number[]): Font;
|
|
196
|
+
getFont?(
|
|
197
|
+
postscriptName: string | Uint8Array | Record<string, number>
|
|
198
|
+
): Font | null | undefined;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Constructible font format registered with registerFormat(). */
|
|
202
|
+
export interface FontFormat {
|
|
203
|
+
new (stream: unknown, variationCoords?: number[] | null): Font;
|
|
204
|
+
probe(buffer: ArrayBufferView): boolean;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export declare let logErrors: boolean;
|
|
208
|
+
export declare let defaultLanguage: string;
|
|
209
|
+
|
|
210
|
+
export declare function registerFormat(format: FontFormat): void;
|
|
211
|
+
export declare function create(
|
|
212
|
+
buffer: ArrayBufferView,
|
|
213
|
+
postscriptName?: string | Uint8Array
|
|
214
|
+
): Font | null | undefined;
|
|
215
|
+
export declare function setDefaultLanguage(lang?: string): void;
|
|
216
|
+
|
|
217
|
+
/** Node-only: open a font file asynchronously. */
|
|
218
|
+
export declare function open(
|
|
219
|
+
filename: string | import('fs').PathLike,
|
|
220
|
+
postscriptName?: string | Uint8Array
|
|
221
|
+
): Promise<Font | null | undefined>;
|
|
222
|
+
|
|
223
|
+
/** Node-only: open a font file synchronously. */
|
|
224
|
+
export declare function openSync(
|
|
225
|
+
filename: string | import('fs').PathLike,
|
|
226
|
+
postscriptName?: string | Uint8Array
|
|
227
|
+
): Font | null | undefined;
|
|
228
|
+
|
|
229
|
+
declare const fontkit: {
|
|
230
|
+
logErrors: boolean;
|
|
231
|
+
defaultLanguage: string;
|
|
232
|
+
registerFormat: typeof registerFormat;
|
|
233
|
+
create: typeof create;
|
|
234
|
+
setDefaultLanguage: typeof setDefaultLanguage;
|
|
235
|
+
open: typeof open;
|
|
236
|
+
openSync: typeof openSync;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export default fontkit;
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient typings for the `restructure` binary codec library.
|
|
3
|
+
* Uses `unknown` (never `any`) for opaque parent/context values.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
declare module 'restructure' {
|
|
7
|
+
/** Font/binary payloads; includes Node Buffer (Uint8Array subclass). */
|
|
8
|
+
export type BinaryBuffer = ArrayBufferView;
|
|
9
|
+
|
|
10
|
+
export type LengthSpec =
|
|
11
|
+
| number
|
|
12
|
+
| string
|
|
13
|
+
| NumberT
|
|
14
|
+
| ((this: StructValue, parent: StructValue) => number);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A restructure field may be a full codec, a partial codec, or a computed value function.
|
|
18
|
+
*/
|
|
19
|
+
export type FieldSpec =
|
|
20
|
+
| BaseType
|
|
21
|
+
| ((this: StructValue, parent: StructValue) => unknown);
|
|
22
|
+
|
|
23
|
+
export type StructFields = Record<string, FieldSpec>;
|
|
24
|
+
|
|
25
|
+
/** Decoded struct instance with restructure metadata. */
|
|
26
|
+
export interface StructValue {
|
|
27
|
+
parent?: StructValue;
|
|
28
|
+
_startOffset?: number;
|
|
29
|
+
_currentOffset?: number;
|
|
30
|
+
_length?: number;
|
|
31
|
+
version?: number | string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PointerOptions {
|
|
36
|
+
type?: 'local' | 'immediate' | 'parent' | 'global';
|
|
37
|
+
allowNull?: boolean;
|
|
38
|
+
nullValue?: number;
|
|
39
|
+
lazy?: boolean;
|
|
40
|
+
relativeTo?: (ctx: StructValue) => number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class DecodeStream {
|
|
44
|
+
buffer: BinaryBuffer;
|
|
45
|
+
view: DataView;
|
|
46
|
+
pos: number;
|
|
47
|
+
length: number;
|
|
48
|
+
|
|
49
|
+
constructor(buffer: BinaryBuffer | Uint8Array);
|
|
50
|
+
|
|
51
|
+
readString(length: number, encoding?: string): string | BinaryBuffer;
|
|
52
|
+
readBuffer(length: number): BinaryBuffer;
|
|
53
|
+
|
|
54
|
+
readUInt8(): number;
|
|
55
|
+
readUInt16BE(): number;
|
|
56
|
+
readUInt16LE(): number;
|
|
57
|
+
readUInt24BE(): number;
|
|
58
|
+
readUInt24LE(): number;
|
|
59
|
+
readUInt32BE(): number;
|
|
60
|
+
readUInt32LE(): number;
|
|
61
|
+
readInt8(): number;
|
|
62
|
+
readInt16BE(): number;
|
|
63
|
+
readInt16LE(): number;
|
|
64
|
+
readInt24BE(): number;
|
|
65
|
+
readInt24LE(): number;
|
|
66
|
+
readInt32BE(): number;
|
|
67
|
+
readInt32LE(): number;
|
|
68
|
+
readFloatBE(): number;
|
|
69
|
+
readFloatLE(): number;
|
|
70
|
+
readDoubleBE(): number;
|
|
71
|
+
readDoubleLE(): number;
|
|
72
|
+
|
|
73
|
+
static TYPES: Record<string, number>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class EncodeStream {
|
|
77
|
+
buffer: BinaryBuffer;
|
|
78
|
+
view: DataView;
|
|
79
|
+
pos: number;
|
|
80
|
+
length: number;
|
|
81
|
+
|
|
82
|
+
constructor(buffer?: BinaryBuffer | number);
|
|
83
|
+
|
|
84
|
+
writeBuffer(buffer: BinaryBuffer): void;
|
|
85
|
+
writeString(string: string, encoding?: string): void;
|
|
86
|
+
|
|
87
|
+
writeUInt8(value: number): void;
|
|
88
|
+
writeUInt16BE(value: number): void;
|
|
89
|
+
writeUInt16LE(value: number): void;
|
|
90
|
+
writeUInt24BE(value: number): void;
|
|
91
|
+
writeUInt24LE(value: number): void;
|
|
92
|
+
writeUInt32BE(value: number): void;
|
|
93
|
+
writeUInt32LE(value: number): void;
|
|
94
|
+
writeInt8(value: number): void;
|
|
95
|
+
writeInt16BE(value: number): void;
|
|
96
|
+
writeInt16LE(value: number): void;
|
|
97
|
+
writeInt24BE(value: number): void;
|
|
98
|
+
writeInt24LE(value: number): void;
|
|
99
|
+
writeInt32BE(value: number): void;
|
|
100
|
+
writeInt32LE(value: number): void;
|
|
101
|
+
writeFloatBE(value: number): void;
|
|
102
|
+
writeFloatLE(value: number): void;
|
|
103
|
+
writeDoubleBE(value: number): void;
|
|
104
|
+
writeDoubleLE(value: number): void;
|
|
105
|
+
|
|
106
|
+
/** Fill `length` bytes with `val` starting at the current position. */
|
|
107
|
+
fill(val: number, length: number): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Structural type for restructure codecs.
|
|
112
|
+
* Custom table helpers often only implement a subset of methods.
|
|
113
|
+
* CFF codecs may pass operands as an extra decode/encode argument, and
|
|
114
|
+
* size-computation passes a null stream to encode().
|
|
115
|
+
*/
|
|
116
|
+
export interface BaseType {
|
|
117
|
+
decode?(
|
|
118
|
+
stream: DecodeStream,
|
|
119
|
+
parent?: StructValue | null,
|
|
120
|
+
lengthOrOperands?: number | unknown[]
|
|
121
|
+
): unknown;
|
|
122
|
+
encode?(
|
|
123
|
+
stream: EncodeStream | null,
|
|
124
|
+
value?: unknown,
|
|
125
|
+
parent?: StructValue | null
|
|
126
|
+
): unknown;
|
|
127
|
+
size?(value?: unknown, parent?: StructValue | null, includePointers?: boolean): number | unknown;
|
|
128
|
+
fromBuffer?(buffer: BinaryBuffer): unknown;
|
|
129
|
+
toBuffer?(value: unknown): BinaryBuffer;
|
|
130
|
+
process?: (this: StructValue, stream: DecodeStream) => void;
|
|
131
|
+
preEncode?: (this: StructValue, stream?: EncodeStream) => void;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class NumberT implements BaseType {
|
|
135
|
+
type: string;
|
|
136
|
+
endian: string;
|
|
137
|
+
fn: string;
|
|
138
|
+
constructor(type: string, endian?: string);
|
|
139
|
+
decode(stream: DecodeStream, parent?: StructValue | null, length?: number): number;
|
|
140
|
+
encode(stream: EncodeStream, value?: number, parent?: StructValue | null): void;
|
|
141
|
+
size(value?: unknown, parent?: StructValue | null): number;
|
|
142
|
+
fromBuffer(buffer: BinaryBuffer): number;
|
|
143
|
+
toBuffer(value: number): BinaryBuffer;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class Fixed extends NumberT {
|
|
147
|
+
constructor(size: number, endian: string, fracBits?: number);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export class Struct implements BaseType {
|
|
151
|
+
fields: StructFields;
|
|
152
|
+
process?: (this: StructValue, stream: DecodeStream) => void;
|
|
153
|
+
preEncode?: (this: StructValue, stream?: EncodeStream) => void;
|
|
154
|
+
constructor(fields?: StructFields);
|
|
155
|
+
decode(stream: DecodeStream, parent?: StructValue | null, length?: number): StructValue;
|
|
156
|
+
encode(stream: EncodeStream, value?: StructValue, parent?: StructValue | null): void;
|
|
157
|
+
size(value?: StructValue | null, parent?: StructValue | null, includePointers?: boolean): number;
|
|
158
|
+
fromBuffer(buffer: BinaryBuffer): StructValue;
|
|
159
|
+
toBuffer(value: StructValue): BinaryBuffer;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export class VersionedStruct extends Struct {
|
|
163
|
+
type: BaseType | string;
|
|
164
|
+
versions: Record<string | number, StructFields | VersionedStruct>;
|
|
165
|
+
constructor(type: BaseType | string, versions?: Record<string | number, StructFields | VersionedStruct>);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export class ArrayT implements BaseType {
|
|
169
|
+
type: BaseType;
|
|
170
|
+
length: LengthSpec | null | undefined;
|
|
171
|
+
lengthType: 'count' | 'bytes';
|
|
172
|
+
constructor(type: BaseType, length?: LengthSpec | null, lengthType?: 'count' | 'bytes');
|
|
173
|
+
decode(stream: DecodeStream, parent?: StructValue | null): unknown[];
|
|
174
|
+
encode(stream: EncodeStream, value?: unknown[], parent?: StructValue | null): void;
|
|
175
|
+
size(value?: unknown[], parent?: StructValue | null): number;
|
|
176
|
+
fromBuffer(buffer: BinaryBuffer): unknown[];
|
|
177
|
+
toBuffer(value: unknown[]): BinaryBuffer;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Decoded lazy array instance (get/toArray live on the value, not the codec). */
|
|
181
|
+
export interface LazyArrayValue<T = unknown> {
|
|
182
|
+
length: number;
|
|
183
|
+
get(index: number): T | undefined;
|
|
184
|
+
toArray(): T[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export class LazyArray extends ArrayT {
|
|
188
|
+
decode(stream: DecodeStream, parent?: StructValue | null): LazyArrayValue;
|
|
189
|
+
encode(stream: EncodeStream, value?: unknown[] | LazyArrayValue, parent?: StructValue | null): void;
|
|
190
|
+
size(value?: unknown[] | LazyArrayValue, parent?: StructValue | null): number;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export class Pointer implements BaseType {
|
|
194
|
+
/** May be filled in lazily (e.g. CFFPointer sets a stub at decode/encode time). */
|
|
195
|
+
offsetType: BaseType | null;
|
|
196
|
+
type: BaseType | null;
|
|
197
|
+
options: PointerOptions;
|
|
198
|
+
constructor(
|
|
199
|
+
offsetType: BaseType | null,
|
|
200
|
+
type: BaseType | 'void' | null,
|
|
201
|
+
options?: PointerOptions
|
|
202
|
+
);
|
|
203
|
+
decode(
|
|
204
|
+
stream: DecodeStream,
|
|
205
|
+
parent?: StructValue | null,
|
|
206
|
+
lengthOrOperands?: number | unknown[]
|
|
207
|
+
): unknown;
|
|
208
|
+
encode(
|
|
209
|
+
stream: EncodeStream | null,
|
|
210
|
+
value?: unknown,
|
|
211
|
+
parent?: StructValue | null
|
|
212
|
+
): unknown;
|
|
213
|
+
size(value?: unknown, parent?: StructValue | null): number;
|
|
214
|
+
fromBuffer(buffer: BinaryBuffer): unknown;
|
|
215
|
+
toBuffer(value: unknown): BinaryBuffer;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Deferred pointer payload whose codec type is chosen at encode/size time
|
|
220
|
+
* (used by SFNT directory table entries).
|
|
221
|
+
*/
|
|
222
|
+
export class VoidPointer {
|
|
223
|
+
type: BaseType;
|
|
224
|
+
value: unknown;
|
|
225
|
+
constructor(type: BaseType, value: unknown);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export class StringT implements BaseType {
|
|
229
|
+
constructor(length?: LengthSpec | null, encoding?: string | ((this: StructValue, parent: StructValue) => string));
|
|
230
|
+
decode(stream: DecodeStream, parent?: StructValue | null): string;
|
|
231
|
+
encode(stream: EncodeStream, value?: string, parent?: StructValue | null): void;
|
|
232
|
+
size(value?: string, parent?: StructValue | null): number;
|
|
233
|
+
fromBuffer(buffer: BinaryBuffer): string;
|
|
234
|
+
toBuffer(value: string): BinaryBuffer;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export class BufferT implements BaseType {
|
|
238
|
+
constructor(length?: LengthSpec | null);
|
|
239
|
+
decode(stream: DecodeStream, parent?: StructValue | null): BinaryBuffer;
|
|
240
|
+
encode(stream: EncodeStream, value?: BinaryBuffer, parent?: StructValue | null): void;
|
|
241
|
+
size(value?: BinaryBuffer, parent?: StructValue | null): number;
|
|
242
|
+
fromBuffer(buffer: BinaryBuffer): BinaryBuffer;
|
|
243
|
+
toBuffer(value: BinaryBuffer): BinaryBuffer;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export class Optional implements BaseType {
|
|
247
|
+
type: BaseType;
|
|
248
|
+
condition: boolean | ((this: StructValue, parent: StructValue) => boolean);
|
|
249
|
+
constructor(type: BaseType, condition?: boolean | ((this: StructValue, parent: StructValue) => boolean));
|
|
250
|
+
decode(stream: DecodeStream, parent?: StructValue | null): unknown;
|
|
251
|
+
encode(stream: EncodeStream, value?: unknown, parent?: StructValue | null): void;
|
|
252
|
+
size(value?: unknown, parent?: StructValue | null): number;
|
|
253
|
+
fromBuffer(buffer: BinaryBuffer): unknown;
|
|
254
|
+
toBuffer(value: unknown): BinaryBuffer;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export class Reserved implements BaseType {
|
|
258
|
+
constructor(type?: BaseType, length?: LengthSpec);
|
|
259
|
+
decode(stream: DecodeStream, parent?: StructValue | null): undefined;
|
|
260
|
+
encode(stream: EncodeStream, value?: unknown, parent?: StructValue | null): void;
|
|
261
|
+
size(value?: unknown, parent?: StructValue | null): number;
|
|
262
|
+
fromBuffer(buffer: BinaryBuffer): undefined;
|
|
263
|
+
toBuffer(value: unknown): BinaryBuffer;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export class Enum implements BaseType {
|
|
267
|
+
constructor(type: BaseType, options?: string[] | Record<number, string>);
|
|
268
|
+
decode(stream: DecodeStream, parent?: StructValue | null): string | number;
|
|
269
|
+
encode(stream: EncodeStream, value?: string | number, parent?: StructValue | null): void;
|
|
270
|
+
size(value?: unknown, parent?: StructValue | null): number;
|
|
271
|
+
fromBuffer(buffer: BinaryBuffer): string | number;
|
|
272
|
+
toBuffer(value: string | number): BinaryBuffer;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export class Bitfield implements BaseType {
|
|
276
|
+
constructor(type: BaseType, flags?: Array<string | null>);
|
|
277
|
+
decode(stream: DecodeStream, parent?: StructValue | null): Record<string, boolean>;
|
|
278
|
+
encode(stream: EncodeStream, value?: Record<string, boolean>, parent?: StructValue | null): void;
|
|
279
|
+
size(value?: unknown, parent?: StructValue | null): number;
|
|
280
|
+
fromBuffer(buffer: BinaryBuffer): Record<string, boolean>;
|
|
281
|
+
toBuffer(value: Record<string, boolean>): BinaryBuffer;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export class BooleanT implements BaseType {
|
|
285
|
+
constructor(type?: BaseType);
|
|
286
|
+
decode(stream: DecodeStream, parent?: StructValue | null): boolean;
|
|
287
|
+
encode(stream: EncodeStream, value?: boolean, parent?: StructValue | null): void;
|
|
288
|
+
size(value?: unknown, parent?: StructValue | null): number;
|
|
289
|
+
fromBuffer(buffer: BinaryBuffer): boolean;
|
|
290
|
+
toBuffer(value: boolean): BinaryBuffer;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export class PropertyDescriptor {
|
|
294
|
+
enumerable: boolean;
|
|
295
|
+
configurable: boolean;
|
|
296
|
+
get?: () => unknown;
|
|
297
|
+
set?: (value: unknown) => void;
|
|
298
|
+
value?: unknown;
|
|
299
|
+
writable?: boolean;
|
|
300
|
+
constructor(opts?: {
|
|
301
|
+
enumerable?: boolean;
|
|
302
|
+
configurable?: boolean;
|
|
303
|
+
writable?: boolean;
|
|
304
|
+
value?: unknown;
|
|
305
|
+
get?: () => unknown;
|
|
306
|
+
set?: (value: unknown) => void;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function resolveLength(
|
|
311
|
+
length: LengthSpec,
|
|
312
|
+
stream?: DecodeStream | null,
|
|
313
|
+
parent?: StructValue | null
|
|
314
|
+
): number;
|
|
315
|
+
|
|
316
|
+
export { ArrayT as Array };
|
|
317
|
+
export { StringT as String };
|
|
318
|
+
export { BufferT as Buffer };
|
|
319
|
+
export { BooleanT as Boolean };
|
|
320
|
+
export { NumberT as Number };
|
|
321
|
+
|
|
322
|
+
export const uint8: NumberT;
|
|
323
|
+
export const uint16: NumberT;
|
|
324
|
+
export const uint16be: NumberT;
|
|
325
|
+
export const uint16le: NumberT;
|
|
326
|
+
export const uint24: NumberT;
|
|
327
|
+
export const uint24be: NumberT;
|
|
328
|
+
export const uint24le: NumberT;
|
|
329
|
+
export const uint32: NumberT;
|
|
330
|
+
export const uint32be: NumberT;
|
|
331
|
+
export const uint32le: NumberT;
|
|
332
|
+
export const int8: NumberT;
|
|
333
|
+
export const int16: NumberT;
|
|
334
|
+
export const int16be: NumberT;
|
|
335
|
+
export const int16le: NumberT;
|
|
336
|
+
export const int24: NumberT;
|
|
337
|
+
export const int24be: NumberT;
|
|
338
|
+
export const int24le: NumberT;
|
|
339
|
+
export const int32: NumberT;
|
|
340
|
+
export const int32be: NumberT;
|
|
341
|
+
export const int32le: NumberT;
|
|
342
|
+
export const float: NumberT;
|
|
343
|
+
export const floatbe: NumberT;
|
|
344
|
+
export const floatle: NumberT;
|
|
345
|
+
export const double: NumberT;
|
|
346
|
+
export const doublebe: NumberT;
|
|
347
|
+
export const doublele: NumberT;
|
|
348
|
+
export const fixed16: Fixed;
|
|
349
|
+
export const fixed16be: Fixed;
|
|
350
|
+
export const fixed16le: Fixed;
|
|
351
|
+
export const fixed32: Fixed;
|
|
352
|
+
export const fixed32be: Fixed;
|
|
353
|
+
export const fixed32le: Fixed;
|
|
354
|
+
}
|