harfbuzzjs 0.10.3 → 1.0.0-beta.2
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/LICENSE +1 -4
- package/README.md +41 -48
- package/dist/harfbuzz-subset.wasm +0 -0
- package/dist/harfbuzz.d.ts +4 -0
- package/dist/harfbuzz.js +2 -0
- package/{hb.wasm → dist/harfbuzz.wasm} +0 -0
- package/dist/index.d.mts +749 -0
- package/dist/index.mjs +1406 -0
- package/package.json +50 -37
- package/Makefile +0 -70
- package/config-override-subset.h +0 -7
- package/config-override.h +0 -14
- package/em.runtime +0 -12
- package/examples/hb-subset.example.node.js +0 -66
- package/examples/hbjs.example.html +0 -16
- package/examples/hbjs.example.js +0 -37
- package/examples/hbjs.example.node.js +0 -8
- package/examples/nohbjs.html +0 -64
- package/hb-subset.symbols +0 -34
- package/hb-subset.wasm +0 -0
- package/hb.js +0 -2
- package/hb.symbols +0 -96
- package/hbjs.js +0 -1463
- package/index.js +0 -8
- package/logo.png +0 -0
- package/test/fonts/noto/NotoSans-Regular.otf +0 -0
- package/test/fonts/noto/NotoSans-Regular.ttf +0 -0
- package/test/fonts/noto/NotoSansArabic-Variable.ttf +0 -0
- package/test/fonts/noto/NotoSansDevanagari-Regular.otf +0 -0
- package/test/fonts/noto/OFL.txt +0 -93
- package/test/index.js +0 -1040
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
//#region src/helpers.d.ts
|
|
2
|
+
type ValueOf<T> = T[keyof T];
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
interface FontExtents {
|
|
6
|
+
ascender: number;
|
|
7
|
+
descender: number;
|
|
8
|
+
lineGap: number;
|
|
9
|
+
}
|
|
10
|
+
interface GlyphExtents {
|
|
11
|
+
xBearing: number;
|
|
12
|
+
yBearing: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}
|
|
16
|
+
interface GlyphInfo {
|
|
17
|
+
/** Either a Unicode code point (before shaping) or a glyph index (after shaping). */
|
|
18
|
+
codepoint: number;
|
|
19
|
+
/** The cluster index of the glyph. */
|
|
20
|
+
cluster: number;
|
|
21
|
+
/** Glyph flags, a combination of {@link GlyphFlag} values. */
|
|
22
|
+
flags: number;
|
|
23
|
+
}
|
|
24
|
+
interface GlyphPosition {
|
|
25
|
+
/** The x advance of the glyph. */
|
|
26
|
+
xAdvance: number;
|
|
27
|
+
/** The y advance of the glyph. */
|
|
28
|
+
yAdvance: number;
|
|
29
|
+
/** The x offset of the glyph. */
|
|
30
|
+
xOffset: number;
|
|
31
|
+
/** The y offset of the glyph. */
|
|
32
|
+
yOffset: number;
|
|
33
|
+
}
|
|
34
|
+
interface SvgPathCommand {
|
|
35
|
+
type: string;
|
|
36
|
+
values: number[];
|
|
37
|
+
}
|
|
38
|
+
interface AxisInfo {
|
|
39
|
+
min: number;
|
|
40
|
+
default: number;
|
|
41
|
+
max: number;
|
|
42
|
+
}
|
|
43
|
+
interface NameEntry {
|
|
44
|
+
nameId: number;
|
|
45
|
+
language: string;
|
|
46
|
+
}
|
|
47
|
+
interface FeatureNameIds {
|
|
48
|
+
uiLabelNameId?: number;
|
|
49
|
+
uiTooltipTextNameId?: number;
|
|
50
|
+
sampleTextNameId?: number;
|
|
51
|
+
paramUiLabelNameIds: number[];
|
|
52
|
+
}
|
|
53
|
+
interface TraceEntry {
|
|
54
|
+
m: string;
|
|
55
|
+
t: unknown[];
|
|
56
|
+
glyphs: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** EmscriptenModule extended with MODULARIZE runtime methods. */
|
|
59
|
+
interface HarfBuzzModule extends EmscriptenModule {
|
|
60
|
+
wasmExports: Record<string, (...args: any[]) => any>;
|
|
61
|
+
addFunction(func: (...args: any[]) => any, signature: string): number;
|
|
62
|
+
removeFunction(funcPtr: number): void;
|
|
63
|
+
stackSave(): number;
|
|
64
|
+
stackAlloc(size: number): number;
|
|
65
|
+
stackRestore(ptr: number): void;
|
|
66
|
+
}
|
|
67
|
+
declare const GlyphFlag: {
|
|
68
|
+
readonly UNSAFE_TO_BREAK: 1;
|
|
69
|
+
readonly UNSAFE_TO_CONCAT: 2;
|
|
70
|
+
readonly SAFE_TO_INSERT_TATWEEL: 4;
|
|
71
|
+
readonly DEFINED: 7;
|
|
72
|
+
};
|
|
73
|
+
type GlyphFlag = ValueOf<typeof GlyphFlag>;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/blob.d.ts
|
|
76
|
+
/**
|
|
77
|
+
* An object representing a {@link https://harfbuzz.github.io/harfbuzz-hb-blob.html | HarfBuzz blob}.
|
|
78
|
+
* A blob wraps a chunk of binary data, typically the contents of a font file.
|
|
79
|
+
*/
|
|
80
|
+
declare class Blob {
|
|
81
|
+
readonly ptr: number;
|
|
82
|
+
/**
|
|
83
|
+
* @param data Binary font data.
|
|
84
|
+
*/
|
|
85
|
+
constructor(data: ArrayBuffer);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/face.d.ts
|
|
89
|
+
declare const GlyphClass: {
|
|
90
|
+
readonly UNCLASSIFIED: 0;
|
|
91
|
+
readonly BASE_GLYPH: 1;
|
|
92
|
+
readonly LIGATURE: 2;
|
|
93
|
+
readonly MARK: 3;
|
|
94
|
+
readonly COMPONENT: 4;
|
|
95
|
+
};
|
|
96
|
+
type GlyphClass = ValueOf<typeof GlyphClass>;
|
|
97
|
+
/**
|
|
98
|
+
* An object representing a {@link https://harfbuzz.github.io/harfbuzz-hb-face.html | HarfBuzz face}.
|
|
99
|
+
* A face represents a single face in a binary font file and is the
|
|
100
|
+
* foundation for creating Font objects used in text shaping.
|
|
101
|
+
*/
|
|
102
|
+
declare class Face {
|
|
103
|
+
readonly ptr: number;
|
|
104
|
+
readonly upem: number;
|
|
105
|
+
/**
|
|
106
|
+
* @param blob A Blob containing font data.
|
|
107
|
+
* @param index The index of the font in the blob. (0 for most files,
|
|
108
|
+
* or a 0-indexed font number if the `blob` came from a font collection file.)
|
|
109
|
+
*/
|
|
110
|
+
constructor(blob: Blob, index?: number);
|
|
111
|
+
/**
|
|
112
|
+
* Return the binary contents of an OpenType table.
|
|
113
|
+
* @param table Table name
|
|
114
|
+
* @returns A Uint8Array of the table data, or undefined if the table is not found.
|
|
115
|
+
*/
|
|
116
|
+
referenceTable(table: string): Uint8Array | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Return variation axis infos.
|
|
119
|
+
* @returns A dictionary mapping axis tags to {min, default, max} values.
|
|
120
|
+
*/
|
|
121
|
+
getAxisInfos(): Record<string, AxisInfo>;
|
|
122
|
+
/**
|
|
123
|
+
* Return unicodes the face supports.
|
|
124
|
+
* @returns A Uint32Array of supported Unicode code points.
|
|
125
|
+
*/
|
|
126
|
+
collectUnicodes(): Uint32Array;
|
|
127
|
+
/**
|
|
128
|
+
* Return all scripts enumerated in the specified face's
|
|
129
|
+
* GSUB table or GPOS table.
|
|
130
|
+
* @param table The table to query, either "GSUB" or "GPOS".
|
|
131
|
+
* @returns An array of 4-character script tag strings.
|
|
132
|
+
*/
|
|
133
|
+
getTableScriptTags(table: string): string[];
|
|
134
|
+
/**
|
|
135
|
+
* Return all features enumerated in the specified face's
|
|
136
|
+
* GSUB table or GPOS table.
|
|
137
|
+
* @param table The table to query, either "GSUB" or "GPOS".
|
|
138
|
+
* @returns An array of 4-character feature tag strings.
|
|
139
|
+
*/
|
|
140
|
+
getTableFeatureTags(table: string): string[];
|
|
141
|
+
/**
|
|
142
|
+
* Return language tags in the given face's GSUB or GPOS table, underneath
|
|
143
|
+
* the specified script index.
|
|
144
|
+
* @param table The table to query, either "GSUB" or "GPOS".
|
|
145
|
+
* @param scriptIndex The index of the script to query.
|
|
146
|
+
* @returns An array of 4-character language tag strings.
|
|
147
|
+
*/
|
|
148
|
+
getScriptLanguageTags(table: string, scriptIndex: number): string[];
|
|
149
|
+
/**
|
|
150
|
+
* Return all features in the specified face's GSUB table or GPOS table,
|
|
151
|
+
* underneath the specified script and language.
|
|
152
|
+
* @param table The table to query, either "GSUB" or "GPOS".
|
|
153
|
+
* @param scriptIndex The index of the script to query.
|
|
154
|
+
* @param languageIndex The index of the language to query.
|
|
155
|
+
* @returns An array of 4-character feature tag strings.
|
|
156
|
+
*/
|
|
157
|
+
getLanguageFeatureTags(table: string, scriptIndex: number, languageIndex: number): string[];
|
|
158
|
+
/**
|
|
159
|
+
* Get the GDEF class of the requested glyph.
|
|
160
|
+
* @param glyph The glyph to get the class of.
|
|
161
|
+
* @returns The {@link GlyphClass} of the glyph.
|
|
162
|
+
*/
|
|
163
|
+
getGlyphClass(glyph: number): GlyphClass;
|
|
164
|
+
/**
|
|
165
|
+
* Return all names in the specified face's name table.
|
|
166
|
+
* @returns An array of {nameId, language} entries.
|
|
167
|
+
*/
|
|
168
|
+
listNames(): NameEntry[];
|
|
169
|
+
/**
|
|
170
|
+
* Get the name of the specified face.
|
|
171
|
+
* @param nameId The ID of the name to get.
|
|
172
|
+
* @param language The language of the name to get.
|
|
173
|
+
* @returns The name string.
|
|
174
|
+
*/
|
|
175
|
+
getName(nameId: number, language: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Get the name IDs of the specified feature.
|
|
178
|
+
* @param table The table to query, either "GSUB" or "GPOS".
|
|
179
|
+
* @param featureIndex The index of the feature to query.
|
|
180
|
+
* @returns An object with name IDs, or undefined if not found.
|
|
181
|
+
*/
|
|
182
|
+
getFeatureNameIds(table: string, featureIndex: number): FeatureNameIds | undefined;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/font-funcs.d.ts
|
|
186
|
+
/**
|
|
187
|
+
* An object representing {@link https://harfbuzz.github.io/harfbuzz-hb-font.html | HarfBuzz font functions}.
|
|
188
|
+
* Font functions define the methods used by a Font for lower-level queries
|
|
189
|
+
* like glyph advances and extents. HarfBuzz provides built-in default
|
|
190
|
+
* implementations which can be selectively overridden.
|
|
191
|
+
*/
|
|
192
|
+
declare class FontFuncs {
|
|
193
|
+
readonly ptr: number;
|
|
194
|
+
constructor();
|
|
195
|
+
/**
|
|
196
|
+
* Set the font's glyph extents function.
|
|
197
|
+
* @param func The callback receives a Font and glyph ID. It should return
|
|
198
|
+
* an object with xBearing, yBearing, width, and height, or undefined on failure.
|
|
199
|
+
*/
|
|
200
|
+
setGlyphExtentsFunc(func: (font: Font, glyph: number) => GlyphExtents | undefined): void;
|
|
201
|
+
/**
|
|
202
|
+
* Set the font's glyph from name function.
|
|
203
|
+
* @param func The callback receives a Font and glyph name. It should return
|
|
204
|
+
* the glyph ID, or undefined on failure.
|
|
205
|
+
*/
|
|
206
|
+
setGlyphFromNameFunc(func: (font: Font, name: string) => number | undefined): void;
|
|
207
|
+
/**
|
|
208
|
+
* Set the font's glyph horizontal advance function.
|
|
209
|
+
* @param func The callback receives a Font and glyph ID. It should return
|
|
210
|
+
* the horizontal advance of the glyph.
|
|
211
|
+
*/
|
|
212
|
+
setGlyphHAdvanceFunc(func: (font: Font, glyph: number) => number): void;
|
|
213
|
+
/**
|
|
214
|
+
* Set the font's glyph vertical advance function.
|
|
215
|
+
* @param func The callback receives a Font and glyph ID. It should return
|
|
216
|
+
* the vertical advance of the glyph.
|
|
217
|
+
*/
|
|
218
|
+
setGlyphVAdvanceFunc(func: (font: Font, glyph: number) => number): void;
|
|
219
|
+
/**
|
|
220
|
+
* Set the font's glyph horizontal origin function.
|
|
221
|
+
* @param func The callback receives a Font and glyph ID. It should return
|
|
222
|
+
* the [x, y] horizontal origin of the glyph, or undefined on failure.
|
|
223
|
+
*/
|
|
224
|
+
setGlyphHOriginFunc(func: (font: Font, glyph: number) => [number, number] | undefined): void;
|
|
225
|
+
/**
|
|
226
|
+
* Set the font's glyph vertical origin function.
|
|
227
|
+
* @param func The callback receives a Font and glyph ID. It should return
|
|
228
|
+
* the [x, y] vertical origin of the glyph, or undefined on failure.
|
|
229
|
+
*/
|
|
230
|
+
setGlyphVOriginFunc(func: (font: Font, glyph: number) => [number, number] | undefined): void;
|
|
231
|
+
/**
|
|
232
|
+
* Set the font's glyph horizontal kerning function.
|
|
233
|
+
* @param func The callback receives a Font, first glyph ID, and second glyph ID.
|
|
234
|
+
* It should return the horizontal kerning of the glyphs.
|
|
235
|
+
*/
|
|
236
|
+
setGlyphHKerningFunc(func: (font: Font, firstGlyph: number, secondGlyph: number) => number): void;
|
|
237
|
+
/**
|
|
238
|
+
* Set the font's glyph name function.
|
|
239
|
+
* @param func The callback receives a Font and glyph ID. It should return
|
|
240
|
+
* the name of the glyph, or undefined on failure.
|
|
241
|
+
*/
|
|
242
|
+
setGlyphNameFunc(func: (font: Font, glyph: number) => string | undefined): void;
|
|
243
|
+
/**
|
|
244
|
+
* Set the font's nominal glyph function.
|
|
245
|
+
* @param func The callback receives a Font and unicode code point. It should
|
|
246
|
+
* return the nominal glyph of the unicode, or undefined on failure.
|
|
247
|
+
*/
|
|
248
|
+
setNominalGlyphFunc(func: (font: Font, unicode: number) => number | undefined): void;
|
|
249
|
+
/**
|
|
250
|
+
* Set the font's variation glyph function.
|
|
251
|
+
* @param func The callback receives a Font, unicode code point, and variation
|
|
252
|
+
* selector. It should return the variation glyph, or undefined on failure.
|
|
253
|
+
*/
|
|
254
|
+
setVariationGlyphFunc(func: (font: Font, unicode: number, variationSelector: number) => number | undefined): void;
|
|
255
|
+
/**
|
|
256
|
+
* Set the font's horizontal extents function.
|
|
257
|
+
* @param func The callback receives a Font. It should return an object with
|
|
258
|
+
* ascender, descender, and lineGap, or undefined on failure.
|
|
259
|
+
*/
|
|
260
|
+
setFontHExtentsFunc(func: (font: Font) => FontExtents | undefined): void;
|
|
261
|
+
/**
|
|
262
|
+
* Set the font's vertical extents function.
|
|
263
|
+
* @param func The callback receives a Font. It should return an object with
|
|
264
|
+
* ascender, descender, and lineGap, or undefined on failure.
|
|
265
|
+
*/
|
|
266
|
+
setFontVExtentsFunc(func: (font: Font) => FontExtents | undefined): void;
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/variation.d.ts
|
|
270
|
+
/**
|
|
271
|
+
* A {@link https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-variation-t | HarfBuzz variation}.
|
|
272
|
+
*
|
|
273
|
+
* Data type for holding variation data. Registered OpenType variation-axis
|
|
274
|
+
* tags are listed in
|
|
275
|
+
* {@link https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg | OpenType Axis Tag Registry}.
|
|
276
|
+
*/
|
|
277
|
+
declare class Variation {
|
|
278
|
+
/** The tag of the variation-axis name. */
|
|
279
|
+
tag: string;
|
|
280
|
+
/** The value of the variation axis. */
|
|
281
|
+
value: number;
|
|
282
|
+
constructor(tag: string, value?: number);
|
|
283
|
+
/**
|
|
284
|
+
* Parses a string into a Variation.
|
|
285
|
+
*
|
|
286
|
+
* The format for specifying variation settings follows. All valid CSS
|
|
287
|
+
* font-variation-settings values other than `normal` and `inherited` are
|
|
288
|
+
* also accepted, though, not documented below.
|
|
289
|
+
*
|
|
290
|
+
* The format is a tag, optionally followed by an equals sign, followed by a
|
|
291
|
+
* number. For example `wght=500`, or `slnt=-7.5`.
|
|
292
|
+
*
|
|
293
|
+
* @param str The string to parse.
|
|
294
|
+
* @returns A Variation, or undefined if the string is not a valid variation.
|
|
295
|
+
*/
|
|
296
|
+
static fromString(str: string): Variation | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* Converts the variation to a string in the format understood by
|
|
299
|
+
* {@link Variation.fromString}.
|
|
300
|
+
*
|
|
301
|
+
* Note that the string won't include any whitespace.
|
|
302
|
+
*
|
|
303
|
+
* @returns The variation string.
|
|
304
|
+
*/
|
|
305
|
+
toString(): string;
|
|
306
|
+
/** @internal Write this variation into the given hb_variation_t pointer. */
|
|
307
|
+
writeTo(ptr: number): void;
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/font.d.ts
|
|
311
|
+
/**
|
|
312
|
+
* An object representing a {@link https://harfbuzz.github.io/harfbuzz-hb-font.html | HarfBuzz font}.
|
|
313
|
+
* A font represents a face at a specific size and with certain other
|
|
314
|
+
* parameters (pixels-per-em, variation settings) specified. Fonts are the
|
|
315
|
+
* primary input to the shaping process.
|
|
316
|
+
*/
|
|
317
|
+
declare class Font {
|
|
318
|
+
readonly ptr: number;
|
|
319
|
+
private drawPtrs;
|
|
320
|
+
/**
|
|
321
|
+
* @param face A Face to create the font from.
|
|
322
|
+
*/
|
|
323
|
+
constructor(face: Face);
|
|
324
|
+
/** @internal Wrap an existing font pointer. */
|
|
325
|
+
constructor(existingPtr: number);
|
|
326
|
+
/**
|
|
327
|
+
* Create a sub font that inherits this font's properties.
|
|
328
|
+
* @returns A new Font object representing the sub font.
|
|
329
|
+
*/
|
|
330
|
+
subFont(): Font;
|
|
331
|
+
/**
|
|
332
|
+
* Return font horizontal extents.
|
|
333
|
+
* @returns Object with ascender, descender, and lineGap properties.
|
|
334
|
+
*/
|
|
335
|
+
hExtents(): FontExtents;
|
|
336
|
+
/**
|
|
337
|
+
* Return font vertical extents.
|
|
338
|
+
* @returns Object with ascender, descender, and lineGap properties.
|
|
339
|
+
*/
|
|
340
|
+
vExtents(): FontExtents;
|
|
341
|
+
/**
|
|
342
|
+
* Return glyph name.
|
|
343
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
344
|
+
* @returns The glyph name string.
|
|
345
|
+
*/
|
|
346
|
+
glyphName(glyphId: number): string;
|
|
347
|
+
/**
|
|
348
|
+
* Return a glyph as an SVG path string.
|
|
349
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
350
|
+
* @returns SVG path data string.
|
|
351
|
+
*/
|
|
352
|
+
glyphToPath(glyphId: number): string;
|
|
353
|
+
/**
|
|
354
|
+
* Return glyph horizontal advance.
|
|
355
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
356
|
+
* @returns The horizontal advance width.
|
|
357
|
+
*/
|
|
358
|
+
glyphHAdvance(glyphId: number): number;
|
|
359
|
+
/**
|
|
360
|
+
* Return glyph vertical advance.
|
|
361
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
362
|
+
* @returns The vertical advance height.
|
|
363
|
+
*/
|
|
364
|
+
glyphVAdvance(glyphId: number): number;
|
|
365
|
+
/**
|
|
366
|
+
* Return glyph horizontal origin.
|
|
367
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
368
|
+
* @returns [x, y] origin coordinates, or undefined if not available.
|
|
369
|
+
*/
|
|
370
|
+
glyphHOrigin(glyphId: number): [number, number] | undefined;
|
|
371
|
+
/**
|
|
372
|
+
* Return glyph vertical origin.
|
|
373
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
374
|
+
* @returns [x, y] origin coordinates, or undefined if not available.
|
|
375
|
+
*/
|
|
376
|
+
glyphVOrigin(glyphId: number): [number, number] | undefined;
|
|
377
|
+
/**
|
|
378
|
+
* Return glyph extents.
|
|
379
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
380
|
+
* @returns An object with xBearing, yBearing, width, and height, or undefined.
|
|
381
|
+
*/
|
|
382
|
+
glyphExtents(glyphId: number): GlyphExtents | undefined;
|
|
383
|
+
/**
|
|
384
|
+
* Return glyph ID from name.
|
|
385
|
+
* @param name Name of the requested glyph in the font.
|
|
386
|
+
* @returns The glyph ID, or undefined if not found.
|
|
387
|
+
*/
|
|
388
|
+
glyphFromName(name: string): number | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* Return a glyph as a JSON path string
|
|
391
|
+
* based on format described on https://svgwg.org/specs/paths/#InterfaceSVGPathSegment
|
|
392
|
+
* @param glyphId ID of the requested glyph in the font.
|
|
393
|
+
* @returns An array of path segment objects with type and values.
|
|
394
|
+
*/
|
|
395
|
+
glyphToJson(glyphId: number): SvgPathCommand[];
|
|
396
|
+
/**
|
|
397
|
+
* Set the font's scale factor, affecting the position values returned from
|
|
398
|
+
* shaping.
|
|
399
|
+
* @param xScale Units to scale in the X dimension.
|
|
400
|
+
* @param yScale Units to scale in the Y dimension.
|
|
401
|
+
*/
|
|
402
|
+
setScale(xScale: number, yScale: number): void;
|
|
403
|
+
/**
|
|
404
|
+
* Applies a list of font-variation settings to a font.
|
|
405
|
+
*
|
|
406
|
+
* Note that this overrides all existing variations set on the font.
|
|
407
|
+
* Axes not included in `variations` will be effectively set to their
|
|
408
|
+
* default values.
|
|
409
|
+
*
|
|
410
|
+
* @param variations Array of variation settings to apply.
|
|
411
|
+
*/
|
|
412
|
+
setVariations(variations: Variation[]): void;
|
|
413
|
+
/** Set the font's font functions. */
|
|
414
|
+
setFuncs(fontFuncs: FontFuncs): void;
|
|
415
|
+
}
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/buffer.d.ts
|
|
418
|
+
declare const BufferContentType: {
|
|
419
|
+
readonly INVALID: 0;
|
|
420
|
+
readonly UNICODE: 1;
|
|
421
|
+
readonly GLYPHS: 2;
|
|
422
|
+
};
|
|
423
|
+
type BufferContentType = ValueOf<typeof BufferContentType>;
|
|
424
|
+
declare const BufferSerializeFlag: {
|
|
425
|
+
readonly DEFAULT: 0;
|
|
426
|
+
readonly NO_CLUSTERS: 1;
|
|
427
|
+
readonly NO_POSITIONS: 2;
|
|
428
|
+
readonly NO_GLYPH_NAMES: 4;
|
|
429
|
+
readonly GLYPH_EXTENTS: 8;
|
|
430
|
+
readonly GLYPH_FLAGS: 16;
|
|
431
|
+
readonly NO_ADVANCES: 32;
|
|
432
|
+
readonly DEFINED: 63;
|
|
433
|
+
};
|
|
434
|
+
type BufferSerializeFlag = ValueOf<typeof BufferSerializeFlag>;
|
|
435
|
+
declare const BufferFlag: {
|
|
436
|
+
readonly DEFAULT: 0;
|
|
437
|
+
readonly BOT: 1;
|
|
438
|
+
readonly EOT: 2;
|
|
439
|
+
readonly PRESERVE_DEFAULT_IGNORABLES: 4;
|
|
440
|
+
readonly REMOVE_DEFAULT_IGNORABLES: 8;
|
|
441
|
+
readonly DO_NOT_INSERT_DOTTED_CIRCLE: 16;
|
|
442
|
+
readonly VERIFY: 32;
|
|
443
|
+
readonly PRODUCE_UNSAFE_TO_CONCAT: 64;
|
|
444
|
+
readonly PRODUCE_SAFE_TO_INSERT_TATWEEL: 128;
|
|
445
|
+
readonly DEFINED: 255;
|
|
446
|
+
};
|
|
447
|
+
type BufferFlag = ValueOf<typeof BufferFlag>;
|
|
448
|
+
declare const Direction: {
|
|
449
|
+
readonly INVALID: 0;
|
|
450
|
+
readonly LTR: 4;
|
|
451
|
+
readonly RTL: 5;
|
|
452
|
+
readonly TTB: 6;
|
|
453
|
+
readonly BTT: 7;
|
|
454
|
+
};
|
|
455
|
+
type Direction = ValueOf<typeof Direction>;
|
|
456
|
+
declare const ClusterLevel: {
|
|
457
|
+
readonly MONOTONE_GRAPHEMES: 0;
|
|
458
|
+
readonly MONOTONE_CHARACTERS: 1;
|
|
459
|
+
readonly CHARACTERS: 2;
|
|
460
|
+
readonly GRAPHEMES: 3;
|
|
461
|
+
readonly DEFAULT: 0;
|
|
462
|
+
};
|
|
463
|
+
type ClusterLevel = ValueOf<typeof ClusterLevel>;
|
|
464
|
+
declare const BufferSerializeFormat: {
|
|
465
|
+
readonly INVALID: 0;
|
|
466
|
+
readonly TEXT: number;
|
|
467
|
+
readonly JSON: number;
|
|
468
|
+
};
|
|
469
|
+
type BufferSerializeFormat = ValueOf<typeof BufferSerializeFormat>;
|
|
470
|
+
/**
|
|
471
|
+
* An object representing a {@link https://harfbuzz.github.io/harfbuzz-hb-buffer.html | HarfBuzz buffer}.
|
|
472
|
+
* A buffer holds the input text and its properties before shaping, and the
|
|
473
|
+
* output glyphs and their information after shaping.
|
|
474
|
+
*/
|
|
475
|
+
declare class Buffer {
|
|
476
|
+
readonly ptr: number;
|
|
477
|
+
/**
|
|
478
|
+
* @param existingPtr @internal Wrap an existing buffer pointer.
|
|
479
|
+
*/
|
|
480
|
+
constructor(existingPtr?: number);
|
|
481
|
+
/**
|
|
482
|
+
* Appends a character with the Unicode value of `codePoint` to the buffer,
|
|
483
|
+
* and gives it the initial cluster value of `cluster`. Clusters can be any
|
|
484
|
+
* thing the client wants, they are usually used to refer to the index of the
|
|
485
|
+
* character in the input text stream and are output in the `cluster` field
|
|
486
|
+
* of {@link GlyphInfo}.
|
|
487
|
+
*
|
|
488
|
+
* This function does not check the validity of `codePoint`, it is up to the
|
|
489
|
+
* caller to ensure it is a valid Unicode code point.
|
|
490
|
+
* @param codePoint A Unicode code point.
|
|
491
|
+
* @param cluster The cluster value of `codePoint`.
|
|
492
|
+
*/
|
|
493
|
+
add(codePoint: number, cluster: number): void;
|
|
494
|
+
/**
|
|
495
|
+
* Add text to the buffer.
|
|
496
|
+
* @param text Text to be added to the buffer.
|
|
497
|
+
* @param itemOffset The offset of the first character to add to the buffer.
|
|
498
|
+
* @param itemLength The number of characters to add to the buffer, or omit for the end of text.
|
|
499
|
+
*/
|
|
500
|
+
addText(text: string, itemOffset?: number, itemLength?: number): void;
|
|
501
|
+
/**
|
|
502
|
+
* Add code points to the buffer.
|
|
503
|
+
* @param codePoints Array of code points to be added to the buffer.
|
|
504
|
+
* @param itemOffset The offset of the first code point to add to the buffer.
|
|
505
|
+
* @param itemLength The number of code points to add to the buffer, or omit for the end of the array.
|
|
506
|
+
*/
|
|
507
|
+
addCodePoints(codePoints: number[], itemOffset?: number, itemLength?: number): void;
|
|
508
|
+
/**
|
|
509
|
+
* Set buffer script, language and direction.
|
|
510
|
+
*
|
|
511
|
+
* This needs to be done before shaping.
|
|
512
|
+
*/
|
|
513
|
+
guessSegmentProperties(): void;
|
|
514
|
+
/**
|
|
515
|
+
* Set buffer direction explicitly.
|
|
516
|
+
* @param dir A {@link Direction} value.
|
|
517
|
+
*/
|
|
518
|
+
setDirection(dir: Direction): void;
|
|
519
|
+
/**
|
|
520
|
+
* Set buffer flags explicitly.
|
|
521
|
+
* @param flags A combination of {@link BufferFlag} values (OR them together).
|
|
522
|
+
*/
|
|
523
|
+
setFlags(flags: number): void;
|
|
524
|
+
/**
|
|
525
|
+
* Set buffer language explicitly.
|
|
526
|
+
* @param language The buffer language
|
|
527
|
+
*/
|
|
528
|
+
setLanguage(language: string): void;
|
|
529
|
+
/**
|
|
530
|
+
* Set buffer script explicitly.
|
|
531
|
+
* @param script The buffer script
|
|
532
|
+
*/
|
|
533
|
+
setScript(script: string): void;
|
|
534
|
+
/**
|
|
535
|
+
* Set the HarfBuzz clustering level.
|
|
536
|
+
*
|
|
537
|
+
* Affects the cluster values returned from shaping.
|
|
538
|
+
* @param level A {@link ClusterLevel} value. See the HarfBuzz manual chapter on Clusters.
|
|
539
|
+
*/
|
|
540
|
+
setClusterLevel(level: ClusterLevel): void;
|
|
541
|
+
/** Reset the buffer to its initial status. */
|
|
542
|
+
reset(): void;
|
|
543
|
+
/**
|
|
544
|
+
* Similar to reset(), but does not clear the Unicode functions and the
|
|
545
|
+
* replacement code point.
|
|
546
|
+
*/
|
|
547
|
+
clearContents(): void;
|
|
548
|
+
/**
|
|
549
|
+
* Set message func.
|
|
550
|
+
* @param func The function to set. It receives the buffer, font, and message
|
|
551
|
+
* string as arguments. Returning false will skip this shaping step and move
|
|
552
|
+
* to the next one.
|
|
553
|
+
*/
|
|
554
|
+
setMessageFunc(func: (buffer: Buffer, font: Font, message: string) => boolean): void;
|
|
555
|
+
/**
|
|
556
|
+
* Get the the number of items in the buffer.
|
|
557
|
+
* @returns The buffer length.
|
|
558
|
+
*/
|
|
559
|
+
getLength(): number;
|
|
560
|
+
/**
|
|
561
|
+
* Get the glyph information from the buffer.
|
|
562
|
+
* @returns An array of {@link GlyphInfo} objects.
|
|
563
|
+
*/
|
|
564
|
+
getGlyphInfos(): GlyphInfo[];
|
|
565
|
+
/**
|
|
566
|
+
* Get the glyph positions from the buffer.
|
|
567
|
+
* @returns An array of {@link GlyphPosition} objects.
|
|
568
|
+
*/
|
|
569
|
+
getGlyphPositions(): GlyphPosition[];
|
|
570
|
+
/**
|
|
571
|
+
* Get the glyph information and positions from the buffer.
|
|
572
|
+
* @returns The glyph information and positions.
|
|
573
|
+
*
|
|
574
|
+
* The glyph information is returned as an array of objects with the
|
|
575
|
+
* properties from getGlyphInfos and getGlyphPositions combined.
|
|
576
|
+
*/
|
|
577
|
+
getGlyphInfosAndPositions(): (GlyphInfo & Partial<GlyphPosition>)[];
|
|
578
|
+
/**
|
|
579
|
+
* Update the glyph positions in the buffer.
|
|
580
|
+
* WARNING: Do not use unless you know what you are doing.
|
|
581
|
+
*/
|
|
582
|
+
updateGlyphPositions(positions: GlyphPosition[]): void;
|
|
583
|
+
/**
|
|
584
|
+
* Serialize the buffer contents to a string.
|
|
585
|
+
* @param options Serialization options:
|
|
586
|
+
* - `font`: the font to use for serialization;
|
|
587
|
+
* - `start`: the starting index of the glyphs (default `0`);
|
|
588
|
+
* - `end`: the ending index of the glyphs (default end of buffer);
|
|
589
|
+
* - `format`: a {@link BufferSerializeFormat} value (default `TEXT`);
|
|
590
|
+
* - `flags`: a combination of {@link BufferSerializeFlag} values (default `0`).
|
|
591
|
+
* @returns The serialized buffer contents.
|
|
592
|
+
*/
|
|
593
|
+
serialize(options?: {
|
|
594
|
+
font?: Font;
|
|
595
|
+
start?: number;
|
|
596
|
+
end?: number;
|
|
597
|
+
format?: BufferSerializeFormat;
|
|
598
|
+
flags?: number;
|
|
599
|
+
}): string;
|
|
600
|
+
/**
|
|
601
|
+
* Return the buffer content type.
|
|
602
|
+
*
|
|
603
|
+
* @returns The buffer content type as a {@link BufferContentType} value.
|
|
604
|
+
*/
|
|
605
|
+
getContentType(): BufferContentType;
|
|
606
|
+
}
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/feature.d.ts
|
|
609
|
+
/**
|
|
610
|
+
* A {@link https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-feature-t | HarfBuzz feature}.
|
|
611
|
+
*
|
|
612
|
+
* The structure that holds information about requested feature application.
|
|
613
|
+
* The feature will be applied with the given value to all glyphs which are in
|
|
614
|
+
* clusters between {@link Feature.start} (inclusive) and {@link Feature.end}
|
|
615
|
+
* (exclusive). Setting `start` to `0` and `end` to `0xffffffff` specifies that
|
|
616
|
+
* the feature always applies to the entire buffer.
|
|
617
|
+
*/
|
|
618
|
+
declare class Feature {
|
|
619
|
+
/**
|
|
620
|
+
* Special setting for {@link Feature.start} to apply the feature from the
|
|
621
|
+
* start of the buffer.
|
|
622
|
+
*/
|
|
623
|
+
static readonly GLOBAL_START = 0;
|
|
624
|
+
/**
|
|
625
|
+
* Special setting for {@link Feature.end} to apply the feature from to the
|
|
626
|
+
* end of the buffer.
|
|
627
|
+
*/
|
|
628
|
+
static readonly GLOBAL_END = 4294967295;
|
|
629
|
+
/** The tag of the feature. */
|
|
630
|
+
tag: string;
|
|
631
|
+
/**
|
|
632
|
+
* The value of the feature. `0` disables the feature, non-zero (usually `1`)
|
|
633
|
+
* enables the feature. For features implemented as lookup type 3 (like
|
|
634
|
+
* `salt`) the value is a one-based index into the alternates.
|
|
635
|
+
*/
|
|
636
|
+
value: number;
|
|
637
|
+
/** The cluster to start applying this feature setting (inclusive). */
|
|
638
|
+
start: number;
|
|
639
|
+
/** The cluster to end applying this feature setting (exclusive). */
|
|
640
|
+
end: number;
|
|
641
|
+
constructor(tag: string, value?: number, start?: number, end?: number);
|
|
642
|
+
/**
|
|
643
|
+
* Parses a string into a Feature.
|
|
644
|
+
*
|
|
645
|
+
* The format for specifying feature strings follows. All valid CSS
|
|
646
|
+
* font-feature-settings values other than `normal` and the global values are
|
|
647
|
+
* also accepted, though not documented below. CSS string escapes are not
|
|
648
|
+
* supported.
|
|
649
|
+
*
|
|
650
|
+
* The range indices refer to the positions between Unicode characters. The
|
|
651
|
+
* position before the first character is always 0.
|
|
652
|
+
*
|
|
653
|
+
* The format is Python-esque. Here is how it all works:
|
|
654
|
+
*
|
|
655
|
+
* | Syntax | Value | Start | End | Meaning |
|
|
656
|
+
* | ------------- | ----- | ----- | --- | -------------------------------- |
|
|
657
|
+
* | `kern` | 1 | 0 | ∞ | Turn feature on |
|
|
658
|
+
* | `+kern` | 1 | 0 | ∞ | Turn feature on |
|
|
659
|
+
* | `-kern` | 0 | 0 | ∞ | Turn feature off |
|
|
660
|
+
* | `kern=0` | 0 | 0 | ∞ | Turn feature off |
|
|
661
|
+
* | `kern=1` | 1 | 0 | ∞ | Turn feature on |
|
|
662
|
+
* | `aalt=2` | 2 | 0 | ∞ | Choose 2nd alternate |
|
|
663
|
+
* | `kern[]` | 1 | 0 | ∞ | Turn feature on |
|
|
664
|
+
* | `kern[:]` | 1 | 0 | ∞ | Turn feature on |
|
|
665
|
+
* | `kern[5:]` | 1 | 5 | ∞ | Turn feature on, partial |
|
|
666
|
+
* | `kern[:5]` | 1 | 0 | 5 | Turn feature on, partial |
|
|
667
|
+
* | `kern[3:5]` | 1 | 3 | 5 | Turn feature on, range |
|
|
668
|
+
* | `kern[3]` | 1 | 3 | 3+1 | Turn feature on, single char |
|
|
669
|
+
* | `aalt[3:5]=2` | 2 | 3 | 5 | Turn 2nd alternate on for range |
|
|
670
|
+
*
|
|
671
|
+
* @param str The string to parse.
|
|
672
|
+
* @returns A Feature, or undefined if the string is not a valid feature.
|
|
673
|
+
*/
|
|
674
|
+
static fromString(str: string): Feature | undefined;
|
|
675
|
+
/**
|
|
676
|
+
* Converts the feature to a string in the format understood by
|
|
677
|
+
* {@link Feature.fromString}.
|
|
678
|
+
*
|
|
679
|
+
* Note that the feature value will be omitted if it is `1`, but the string
|
|
680
|
+
* won't include any whitespace.
|
|
681
|
+
*
|
|
682
|
+
* @returns The feature string.
|
|
683
|
+
*/
|
|
684
|
+
toString(): string;
|
|
685
|
+
/** @internal Write this feature into the given hb_feature_t pointer. */
|
|
686
|
+
writeTo(ptr: number): void;
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/shape.d.ts
|
|
690
|
+
declare const TracePhase: {
|
|
691
|
+
readonly DONT_STOP: 0;
|
|
692
|
+
readonly GSUB: 1;
|
|
693
|
+
readonly GPOS: 2;
|
|
694
|
+
};
|
|
695
|
+
type TracePhase = ValueOf<typeof TracePhase>;
|
|
696
|
+
/**
|
|
697
|
+
* Shape a buffer with a given font.
|
|
698
|
+
*
|
|
699
|
+
* Converts the Unicode text in the buffer into positioned glyphs.
|
|
700
|
+
* The buffer is modified in place.
|
|
701
|
+
*
|
|
702
|
+
* @param font The Font to shape with.
|
|
703
|
+
* @param buffer The Buffer containing text to shape, suitably prepared
|
|
704
|
+
* (text added, segment properties set).
|
|
705
|
+
* @param features An array of {@link Feature} values to apply.
|
|
706
|
+
*/
|
|
707
|
+
declare function shape(font: Font, buffer: Buffer, features?: Feature[]): void;
|
|
708
|
+
/**
|
|
709
|
+
* Shape a buffer with a given font, returning a JSON trace of the shaping process.
|
|
710
|
+
*
|
|
711
|
+
* This function supports "partial shaping", where the shaping process is
|
|
712
|
+
* terminated after a given lookup ID is reached.
|
|
713
|
+
*
|
|
714
|
+
* @param font The Font to shape with.
|
|
715
|
+
* @param buffer The Buffer containing text to shape, suitably prepared.
|
|
716
|
+
* @param features An array of {@link Feature} values to apply.
|
|
717
|
+
* @param stop_at A lookup ID at which to terminate shaping.
|
|
718
|
+
* @param stop_phase The {@link TracePhase} at which to stop shaping.
|
|
719
|
+
* @returns An array of trace entries, each with a message, serialized glyphs, and phase info.
|
|
720
|
+
*/
|
|
721
|
+
declare function shapeWithTrace(font: Font, buffer: Buffer, features: Feature[], stop_at: number, stop_phase: TracePhase): TraceEntry[];
|
|
722
|
+
/**
|
|
723
|
+
* Return the HarfBuzz version.
|
|
724
|
+
* @returns An object with major, minor, and micro version numbers.
|
|
725
|
+
*/
|
|
726
|
+
declare function version(): {
|
|
727
|
+
major: number;
|
|
728
|
+
minor: number;
|
|
729
|
+
micro: number;
|
|
730
|
+
};
|
|
731
|
+
/**
|
|
732
|
+
* Return the HarfBuzz version as a string.
|
|
733
|
+
* @returns A version string in the form "major.minor.micro".
|
|
734
|
+
*/
|
|
735
|
+
declare function versionString(): string;
|
|
736
|
+
/**
|
|
737
|
+
* Convert an OpenType script tag to HarfBuzz script.
|
|
738
|
+
* @param tag The tag to convert.
|
|
739
|
+
* @returns The script.
|
|
740
|
+
*/
|
|
741
|
+
declare function otTagToScript(tag: string): string;
|
|
742
|
+
/**
|
|
743
|
+
* Convert an OpenType language tag to HarfBuzz language.
|
|
744
|
+
* @param tag The tag to convert.
|
|
745
|
+
* @returns The language.
|
|
746
|
+
*/
|
|
747
|
+
declare function otTagToLanguage(tag: string): string;
|
|
748
|
+
//#endregion
|
|
749
|
+
export { AxisInfo, Blob, Buffer, BufferContentType, BufferFlag, BufferSerializeFlag, BufferSerializeFormat, ClusterLevel, Direction, Face, Feature, FeatureNameIds, Font, FontExtents, FontFuncs, GlyphClass, GlyphExtents, GlyphFlag, GlyphInfo, GlyphPosition, HarfBuzzModule, NameEntry, SvgPathCommand, TraceEntry, TracePhase, Variation, otTagToLanguage, otTagToScript, shape, shapeWithTrace, version, versionString };
|