-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathindex.d.ts
610 lines (547 loc) · 15.1 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/**
* @file index.d.ts
* @author mengke01([email protected])
*/
export namespace TTF {
type CodePoint = number;
type Point = {
x: number;
y: number;
onCurve: boolean;
};
type Contour = Point[];
type Glyph = {
contours: Contour[];
xMin: number;
yMin: number;
xMax: number;
yMax: number;
advanceWidth: number;
leftSideBearing: number;
name: string;
unicode: CodePoint[];
};
type Head = {
[k: string]: number;
version: number;
fontRevision: number;
checkSumAdjustment: number;
magickNumber: number;
flags: number;
unitsPerE: number;
created: number;
modified: number;
xMin: number;
yMin: number;
xMax: number;
yMax: number;
macStyle: number;
lowestRecPPEM: number;
fontDirectionHint: number;
indexToLocFormat: number;
glyphDataFormat: number;
};
type Hhea = {
version: number;
ascent: number;
descent: number;
lineGap: number;
advanceWidthMax: number;
minLeftSideBearing: number;
minRightSideBearing: number;
xMaxExtent: number;
caretSlopeRise: number;
caretSlopeRun: number;
caretOffset: number;
reserved0: number;
reserved1: number;
reserved2: number;
reserved3: number;
metricDataFormat: number;
numOfLongHorMetrics: number;
};
type Post = {
italicAngle: number;
postoints: number;
underlinePosition: number;
underlineThickness: number;
isFixedPitch: number;
minMemType42: number;
maxMemType42: number;
minMemType1: number;
maxMemType1: number;
format: number;
};
type Maxp = {
version: number;
numGlyphs: number;
maxPoints: number;
maxContours: number;
maxCompositePoints: number;
maxCompositeContours: number;
maxZones: number;
maxTwilightPoints: number;
maxStorage: number;
maxFunctionDefs: number;
maxStackElements: number;
maxSizeOfInstructions: number;
maxComponentElements: number;
maxComponentDepth: number;
};
type OS2 = {
version: number;
xAvgCharWidth: number;
usWeightClass: number;
usWidthClass: number;
fsType: number;
ySubscriptXSize: number;
ySubscriptYSize: number;
ySubscriptXOffset: number;
ySubscriptYOffset: number;
ySuperscriptXSize: number;
ySuperscriptYSize: number;
ySuperscriptXOffset: number;
ySuperscriptYOffset: number;
yStrikeoutSize: number;
yStrikeoutPosition: number;
sFamilyClass: number;
bFamilyType: number;
bSerifStyle: number;
bWeight: number;
bProportion: number;
bContrast: number;
bStrokeVariation: number;
bArmStyle: number;
bLetterform: number;
bMidline: number;
bXHeight: number;
ulUnicodeRange1: number;
ulUnicodeRange2: number;
ulUnicodeRange3: number;
ulUnicodeRange4: number;
achVendID: string;
fsSelection: number;
usFirstCharIndex: number;
usLastCharIndex: number;
sTypoAscender: number;
sTypoDescender: number;
sTypoLineGap: number;
usWinAscent: number;
usWinDescent: number;
ulCodePageRange1: number;
ulCodePageRange2: number;
sxHeight: number;
sCapHeight: number;
usDefaultChar: number;
usBreakChar: number;
usMaxContext: number;
};
type Name = {
[k: string]: string;
fontFamily: string;
fontSubFamily: string;
uniqueSubFamily: string;
version: string;
};
type TTFObject = {
version: number;
numTables: number;
searchRange: number;
entrySelector: number;
rangeShift: number;
head: Head;
glyf: Glyph[];
cmap: Record<string, number>;
name: Name;
hhea: Hhea;
post: Post;
maxp: Maxp;
'OS/2': OS2;
};
}
export namespace FontEditor {
type FontType = 'ttf' | 'otf' | 'eot' | 'woff' | 'woff2' | 'svg';
type FontInput = ArrayBuffer | Buffer | string | Document;
type FontOutput = ArrayBuffer | Buffer | string;
type UInt8 = number;
interface FontReadOptions {
/**
* font type for read
*/
type: FontType;
/**
* subset font file to specified unicode code points;
*/
subset?: TTF.CodePoint[];
/**
* keep hinting table or not, default false
*/
hinting?: boolean;
/**
* keep kerning table or not, default false
* kerning table adjusting the space between individual letters or characters
*/
kerning?: boolean;
/**
* tranfrom compound glyph to simple,
* @default true
*/
compound2simple?: boolean;
/**
* inflate function for woff
*
* @see pako.inflate https://github.com/nodeca/pako
*/
inflate?: (deflatedData: UInt8[]) => UInt8[];
/**
* combine svg paths to one glyph in one svg file.
* @default true
*/
combinePath?: boolean;
}
interface FontWriteOptions {
/**
* font type for write
*/
type: FontType;
/**
* use Buffer when in Node enviroment, in browser will use ArrayBuffer.
* default true
*/
toBuffer?: boolean;
/**
* keep hinting or not, default false
*/
hinting?: boolean;
/**
* write glyf data when simple glyph has no contours, default false
*/
writeZeroContoursGlyfData?: boolean;
/**
* svg output meta data
*/
metadata?: string;
/**
* deflate function for woff
*
* @see pako.deflate https://github.com/nodeca/pako
*/
deflate?: (rawData: UInt8[]) => UInt8[];
/**
* for user to overwrite head.xMin, head.xMax, head.yMin, head.yMax, hhea etc.
*/
support?: {
/**
* overwrite head
*/
head?: {
xMin?: number;
yMin?: number;
xMax?: number;
yMax?: number;
},
/**
* overwrite hhea
*/
hhea?: {
advanceWidthMax?: number;
xMaxExtent?: number;
minLeftSideBearing?: number;
minRightSideBearing?: number;
}
};
}
type FindCondition = {
/**
* find glyfs with unicode array
*/
unicode?: TTF.CodePoint[];
/**
* find by glyf name
*/
name?: string;
/**
* use filter function to find glyfs
* @param glyph glyf object
* @returns
*/
filter?: (glyph: TTF.Glyph) => boolean;
};
type MergeOptions = ({
/**
* scale glyphs to fit fonts. default true
*/
scale: number;
}) | ({
/**
* auto adjuct glyphs to the first font em box. default true
*/
adjustGlyf: boolean;
});
type OptimizeResult = {
/**
* result
*
* - true optimize success
* - {repeat} repeat glyf codepoints
*/
result: true | {
/**
* repeat glyf codepoints
*/
repeat: number[];
};
};
class Font {
/**
* create empty font object
*/
static create(): Font;
/**
* create font object with font data
*
* @param buffer font data, support format
* - for ttf, otf, woff, woff2, support ArrayBuffer, Buffer
* - for svg, support string or Document(parsed svg)
* @param options font read options
*/
static create(buffer: FontInput, options: FontReadOptions): Font;
/**
* convert buffer data to base64 string
*
* @param buffer buffer data
*/
static toBase64(buffer: FontInput): string;
/**
* read empty ttf object
*/
readEmpty(): Font;
/**
* read font data
*
* @param buffer font data, support format: ArrayBuffer, Buffer, string, Document(parsed svg)
* @param options font read options
*/
read(buffer: FontInput, options: FontReadOptions): Font;
/**
* write font to svg string
* @param options font write options
*/
write(options: {type: 'svg'} & FontWriteOptions): string;
/**
* write font to Buffer
* @param options font write options
*/
write(options: {toBuffer: true} & FontWriteOptions): Buffer;
/**
* write font data
* @param options write options
*/
write(options: FontWriteOptions): FontOutput;
/**
* write font to base64 uri
* @param options font write options
* @param buffer use another font buffer to base64
*/
toBase64(options: FontWriteOptions, buffer?: FontInput): string;
/**
* use ttf object data
* @param data ttf object
*/
set(data: TTF.TTFObject): Font;
/**
* get ttf object
*/
get(): TTF.TTFObject;
/**
* optimize glyphs
* @param outRef optimize results, will get result field after optimize
*/
optimize(outRef?: OptimizeResult): Font;
/**
* tranfrom compound glyph to simple, default true
*/
compound2simple(): Font;
/**
* sort glyphs with unicode order
*/
sort(): Font;
/**
* find glyphs with conditions
*
* @param condition find conditions
*/
find(condition: FindCondition): TTF.Glyph[];
/**
* merge two font object
*
* @param font another font object
* @param options merge options
*/
merge(font: Font, options: MergeOptions): Font;
}
interface Woff2 {
/**
* is woff2 wasm loaded
*/
isInited: () => boolean;
/**
* init woff2 wasm module
*
* @param wasmUrl wasm file url or wasm file buffer, in nodejs enviroment wasmUrl can be omited.
*/
init(wasmUrl?: string | ArrayBuffer): Promise<Woff2>;
/**
* convert ttf buffer to woff buffer
*
* @param ttfBuffer ttf data buffer
*/
encode(ttfBuffer: ArrayBuffer | Buffer | UInt8[]): Uint8Array;
/**
* convert woff2 buffer to ttf buffer
*
* @param woff2Buffer woff2 data buffer
*/
decode(woff2Buffer: ArrayBuffer | Buffer | UInt8[]): Uint8Array;
}
interface Core {
/**
* Font class
*/
Font: typeof Font;
/**
* woff2 module
*/
woff2: Woff2;
/**
* TTF class
*/
TTF: any;
/**
* TTFReader class
*/
TTFReader: any;
/**
* TTFWriter class
*/
TTFWriter: any;
/**
* Reader Table base class
*/
Reader: any;
/**
* Writer Table base class
*/
Writer: any;
/**
* OTFReader class
*/
OTFReader: any;
/**
* convert otf font buffer to ttf object
* @param arrayBuffer font data
* @param options
* @returns
*/
otf2ttfobject: (arrayBuffer: ArrayBuffer, options: any) => TTF.TTFObject;
/**
* convert ttf font buffer to eot font
* @param arrayBuffer font data
* @param options
* @returns
*/
ttf2eot: (arrayBuffer: ArrayBuffer, options?: any) => ArrayBuffer;
/**
* convert eot font buffer to ttf
* @param arrayBuffer font data
* @param options
* @returns
*/
eot2ttf: (arrayBuffer: ArrayBuffer, options?: any) => ArrayBuffer;
/**
* convert ttf font buffer to woff
* @param arrayBuffer font data
* @param options
* @returns
*/
ttf2woff: (arrayBuffer: ArrayBuffer, options?: {
metadata: any;
deflate?: (rawData: UInt8[]) => UInt8[];
}) => ArrayBuffer;
/**
* convert woff font buffer to ttf
* @param arrayBuffer font data
* @param options
* @returns
*/
woff2ttf: (buffer: ArrayBuffer, options?: {
inflate?: (deflatedData: UInt8[]) => UInt8[];
}) => ArrayBuffer;
/**
* convert ttf font buffer to svg font
* @param arrayBuffer font data
* @param options
* @returns
*/
ttf2svg: (arrayBuffer: ArrayBuffer | TTF.TTFObject, options?: {
metadata: string;
}) => string;
/**
* convert svg font to ttf object
* @param svg svg text
* @param options
* @param options.combinePath if true, combine path to one glyph, default is false
* @returns
*/
svg2ttfobject: (svg: string | Document, options?: {combinePath: boolean}) => TTF.TTFObject;
/**
* convert ttf font buffer to base64 uri
* @param arrayBuffer ttf data
* @returns
*/
ttf2base64: (arrayBuffer: ArrayBuffer) => string;
/**
* convert ttf font to icon array
* @param arrayBuffer ttf data
* @param options
* @returns
*/
ttf2icon: (arrayBuffer: ArrayBuffer | TTF.TTFObject, options?: {
metadata: any;
iconPrefix?: string;
}) => any;
/**
* convert ttf font buffer to woff2 font
* @param arrayBuffer ttf data
* @param options
* @returns
*/
ttftowoff2: (arrayBuffer: ArrayBuffer, options?: any) => Uint8Array;
/**
* convert woff2 font buffer to ttf font
* @param arrayBuffer ttf data
* @param options
* @returns
*/
woff2tottf: (arrayBuffer: ArrayBuffer, options?: any) => Uint8Array;
/**
* convert Buffer to ArrayBuffer
* @param buffer
* @returns
*/
toArrayBuffer: (buffer: Buffer | UInt8[]) => ArrayBuffer;
/**
* convert ArrayBuffer to Buffer
* @param buffer
* @returns
*/
toBuffer: (buffer: ArrayBuffer | UInt8[]) => Buffer;
}
/**
* core exports
*/
const core: Core;
}
export const Font: typeof FontEditor.Font;
export const woff2: FontEditor.Woff2;
export default FontEditor.core;