forked from kekee000/fonteditor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
430 lines (372 loc) · 10.5 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
/**
* @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;
type FontOutput = FontInput;
type UInt8 = number;
interface FontReadOptions {
/**
* font type for read
*/
type: FontType;
/**
* subset font file to specified unicode code points;
*/
subset?: TTF.CodePoint[];
/**
* keep hinting or not, default false
*/
hinting?: 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;
/**
* svg output meta data
*/
metadata?: string;
/**
* deflate function for woff
*
* @see pako.deflate https://github.com/nodeca/pako
*/
deflate?: (rawData: UInt8[]) => UInt8[];
}
type FindCondition = {
unicode?: TTF.CodePoint[];
name?: string;
filter?: (glyph: TTF.Glyph) => boolean;
};
type MergeOptions = ({
/**
* scale glyphs to fit fonts. default true
*/
scale: boolean;
}) | ({
/**
* auto adjuct glyphs to the first font em box. default true
*/
adjustGlyf: boolean;
});
class Font {
/**
* create empty font object
*/
static create(): Font;
/**
* create font object with font data
*
* @param buffer font data, support format: ArrayBuffer, Buffer, string
* @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
* @param options font read options
*/
read(buffer: FontInput, options: FontReadOptions): Font;
/**
* write font data
* @param options write options
*/
write(options: FontWriteOptions): FontOutput;
write(options: {type: 'svg'} & FontWriteOptions): string;
write(options: {toBuffer: true} & FontWriteOptions): Buffer;
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?: {result: true | {repeatList: number[]}}): 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
*/
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: typeof Font;
woff2: Woff2;
TTF: any;
TTFReader: any;
TTFWriter: any;
Reader: any;
Writer: any;
OTFReader: any;
otf2ttfobject: (otfBuffer: any, options: any) => any;
ttf2eot: (ttfBuffer: ArrayBuffer, options?: any) => ArrayBuffer;
eot2ttf: (eotBuffer: ArrayBuffer, options?: any) => ArrayBuffer;
ttf2woff: (ttfBuffer: ArrayBuffer, options?: {
metadata: any;
deflate?: (rawData: UInt8[]) => UInt8[];
}) => ArrayBuffer;
woff2ttf: (woffBuffer: ArrayBuffer, options?: {
inflate?: (deflatedData: UInt8[]) => UInt8[];
}) => ArrayBuffer;
ttf2svg: (ttfBuffer: ArrayBuffer | TTF.TTFObject, options?: {
metadata: string;
}) => string;
svg2ttfobject: (svg: string, options?: any) => TTF.TTFObject;
ttf2base64: (arrayBuffer: ArrayBuffer) => string;
ttf2icon: (ttfBuffer: ArrayBuffer | TTF.TTFObject, options?: {
metadata: any;
}) => any;
ttftowoff2: (ttfBuffer: ArrayBuffer, options?: any) => Uint8Array;
woff2tottf: (woff2Buffer: ArrayBuffer, options?: any) => Uint8Array;
}
/**
* core exports
*/
const core: Core;
}
export const Font: typeof FontEditor.Font;
export const woff2: FontEditor.Woff2;
export default FontEditor.core;