@weasel-js/text-shaping 1.14.2 → 1.15.1

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.
@@ -0,0 +1,2175 @@
1
+ // src/vendor/harfbuzzjs/index.js
2
+ var Module;
3
+ var exports$1;
4
+ var freeFuncPtr;
5
+ var utf8Decoder = new TextDecoder("utf8");
6
+ var utf8Encoder = new TextEncoder();
7
+ var registry = new FinalizationRegistry((cleanup) => {
8
+ cleanup();
9
+ });
10
+ function track(obj, destroy) {
11
+ const ptr = obj.ptr;
12
+ registry.register(obj, () => destroy(ptr));
13
+ }
14
+ function init(module) {
15
+ Module = module;
16
+ exports$1 = Module.wasmExports;
17
+ freeFuncPtr = Module.addFunction((ptr) => {
18
+ exports$1.free(ptr);
19
+ }, "vi");
20
+ }
21
+ function hb_tag(s) {
22
+ return (s.charCodeAt(0) & 255) << 24 | (s.charCodeAt(1) & 255) << 16 | (s.charCodeAt(2) & 255) << 8 | (s.charCodeAt(3) & 255) << 0;
23
+ }
24
+ function hb_untag(tag) {
25
+ return String.fromCharCode(tag >> 24 & 255, tag >> 16 & 255, tag >> 8 & 255, tag >> 0 & 255);
26
+ }
27
+ function utf8_ptr_to_string(ptr, length) {
28
+ let end;
29
+ if (length == void 0) end = Module.HEAPU8.indexOf(0, ptr);
30
+ else end = ptr + length;
31
+ return utf8Decoder.decode(Module.HEAPU8.subarray(ptr, end));
32
+ }
33
+ function utf16_ptr_to_string(ptr, length) {
34
+ const end = ptr / 2 + length;
35
+ return String.fromCharCode(...Module.HEAPU16.subarray(ptr / 2, end));
36
+ }
37
+ function string_to_ascii_ptr(text) {
38
+ const ptr = exports$1.malloc(text.length + 1);
39
+ for (let i = 0; i < text.length; ++i) {
40
+ const char = text.charCodeAt(i);
41
+ if (char > 127) throw new Error("Expected ASCII text");
42
+ Module.HEAPU8[ptr + i] = char;
43
+ }
44
+ Module.HEAPU8[ptr + text.length] = 0;
45
+ return {
46
+ ptr,
47
+ length: text.length,
48
+ free: function() {
49
+ exports$1.free(ptr);
50
+ }
51
+ };
52
+ }
53
+ function string_to_utf8_ptr(text) {
54
+ const ptr = exports$1.malloc(text.length);
55
+ utf8Encoder.encodeInto(text, Module.HEAPU8.subarray(ptr, ptr + text.length));
56
+ return {
57
+ ptr,
58
+ length: text.length,
59
+ free: function() {
60
+ exports$1.free(ptr);
61
+ }
62
+ };
63
+ }
64
+ function string_to_utf16_ptr(text) {
65
+ const ptr = exports$1.malloc(text.length * 2);
66
+ const words = Module.HEAPU16.subarray(ptr / 2, ptr / 2 + text.length);
67
+ for (let i = 0; i < words.length; ++i) words[i] = text.charCodeAt(i);
68
+ return {
69
+ ptr,
70
+ length: words.length,
71
+ free: function() {
72
+ exports$1.free(ptr);
73
+ }
74
+ };
75
+ }
76
+ function language_to_string(language) {
77
+ return utf8_ptr_to_string(exports$1.hb_language_to_string(language));
78
+ }
79
+ function language_from_string(str) {
80
+ const languageStr = string_to_ascii_ptr(str);
81
+ const languagePtr = exports$1.hb_language_from_string(languageStr.ptr, -1);
82
+ languageStr.free();
83
+ return languagePtr;
84
+ }
85
+ function typed_array_from_set(setPtr) {
86
+ const setCount = exports$1.hb_set_get_population(setPtr);
87
+ const arrayPtr = exports$1.malloc(setCount << 2);
88
+ const arrayOffset = arrayPtr >> 2;
89
+ exports$1.hb_set_next_many(setPtr, -1, arrayPtr, setCount);
90
+ return Module.HEAPU32.subarray(arrayOffset, arrayOffset + setCount);
91
+ }
92
+ var callbackData = [void 0];
93
+ var freeCallbackData = [];
94
+ function register_callback_data_pointer(data) {
95
+ if (data === void 0) return 0;
96
+ const dataPtr = freeCallbackData.pop() ?? callbackData.length;
97
+ callbackData[dataPtr] = data;
98
+ return dataPtr;
99
+ }
100
+ function get_callback_data(dataPtr) {
101
+ return callbackData[dataPtr];
102
+ }
103
+ function remove_callback_data_pointer(dataPtr) {
104
+ if (dataPtr === 0) return;
105
+ callbackData[dataPtr] = void 0;
106
+ freeCallbackData.push(dataPtr);
107
+ }
108
+ function color_from_int(color) {
109
+ return {
110
+ red: color >> 8 & 255,
111
+ green: color >> 16 & 255,
112
+ blue: color >> 24 & 255,
113
+ alpha: color & 255
114
+ };
115
+ }
116
+ function color_to_int(color) {
117
+ return (color.red << 8 | color.green << 16 | color.blue << 24 | color.alpha) >>> 0;
118
+ }
119
+ var ColorPaletteFlags = {
120
+ DEFAULT: 0,
121
+ USABLE_WITH_LIGHT_BACKGROUND: 1,
122
+ USABLE_WITH_DARK_BACKGROUND: 2
123
+ };
124
+ var PaintExtend = {
125
+ PAD: 0,
126
+ REPEAT: 1,
127
+ REFLECT: 2
128
+ };
129
+ var PaintCompositeMode = {
130
+ CLEAR: 0,
131
+ SRC: 1,
132
+ DEST: 2,
133
+ SRC_OVER: 3,
134
+ DEST_OVER: 4,
135
+ SRC_IN: 5,
136
+ DEST_IN: 6,
137
+ SRC_OUT: 7,
138
+ DEST_OUT: 8,
139
+ SRC_ATOP: 9,
140
+ DEST_ATOP: 10,
141
+ XOR: 11,
142
+ PLUS: 12,
143
+ SCREEN: 13,
144
+ OVERLAY: 14,
145
+ DARKEN: 15,
146
+ LIGHTEN: 16,
147
+ COLOR_DODGE: 17,
148
+ COLOR_BURN: 18,
149
+ HARD_LIGHT: 19,
150
+ SOFT_LIGHT: 20,
151
+ DIFFERENCE: 21,
152
+ EXCLUSION: 22,
153
+ MULTIPLY: 23,
154
+ HSL_HUE: 24,
155
+ HSL_SATURATION: 25,
156
+ HSL_COLOR: 26,
157
+ HSL_LUMINOSITY: 27
158
+ };
159
+ var AxisFlags = { HIDDEN: 1 };
160
+ var GlyphFlag = {
161
+ UNSAFE_TO_BREAK: 1,
162
+ UNSAFE_TO_CONCAT: 2,
163
+ SAFE_TO_INSERT_TATWEEL: 4,
164
+ DEFINED: 7
165
+ };
166
+ var Blob = class {
167
+ /**
168
+ * @param data Binary font data.
169
+ */
170
+ constructor(data) {
171
+ const array = data instanceof Uint8Array ? data : new Uint8Array(data);
172
+ const blobPtr = exports$1.malloc(array.byteLength);
173
+ Module.HEAPU8.set(array, blobPtr);
174
+ this.ptr = exports$1.hb_blob_create(blobPtr, array.byteLength, 2, blobPtr, freeFuncPtr);
175
+ track(this, exports$1.hb_blob_destroy);
176
+ }
177
+ };
178
+ var HB_OT_NAME_ID_INVALID = 65535;
179
+ var GlyphClass = {
180
+ UNCLASSIFIED: 0,
181
+ BASE_GLYPH: 1,
182
+ LIGATURE: 2,
183
+ MARK: 3,
184
+ COMPONENT: 4
185
+ };
186
+ var Face = class {
187
+ constructor(arg, index = 0) {
188
+ if (typeof arg === "number") this.ptr = exports$1.hb_face_reference(arg);
189
+ else this.ptr = exports$1.hb_face_create(arg.ptr, index);
190
+ this.upem = exports$1.hb_face_get_upem(this.ptr);
191
+ track(this, exports$1.hb_face_destroy);
192
+ }
193
+ /**
194
+ * Return the binary contents of an OpenType table.
195
+ * @param table Table name
196
+ * @returns A Uint8Array of the table data, or undefined if the table is not found.
197
+ */
198
+ referenceTable(table) {
199
+ const blob = exports$1.hb_face_reference_table(this.ptr, hb_tag(table));
200
+ const length = exports$1.hb_blob_get_length(blob);
201
+ if (!length) return;
202
+ const blobptr = exports$1.hb_blob_get_data(blob, 0);
203
+ return Module.HEAPU8.subarray(blobptr, blobptr + length);
204
+ }
205
+ /**
206
+ * Return variation axis infos.
207
+ * @returns A dictionary mapping axis tags to {@link AxisInfo} values.
208
+ */
209
+ getAxisInfos() {
210
+ const sp = Module.stackSave();
211
+ const axis = Module.stackAlloc(2048);
212
+ const c = Module.stackAlloc(4);
213
+ Module.HEAPU32[c / 4] = 64;
214
+ exports$1.hb_ot_var_get_axis_infos(this.ptr, 0, c, axis);
215
+ const result = {};
216
+ Array.from({ length: Module.HEAPU32[c / 4] }).forEach((_, i) => {
217
+ const info = {
218
+ axisIndex: Module.HEAPU32[axis / 4 + i * 8],
219
+ tag: hb_untag(Module.HEAPU32[axis / 4 + i * 8 + 1]),
220
+ nameId: Module.HEAPU32[axis / 4 + i * 8 + 2],
221
+ flags: Module.HEAPU32[axis / 4 + i * 8 + 3],
222
+ min: Module.HEAPF32[axis / 4 + i * 8 + 4],
223
+ default: Module.HEAPF32[axis / 4 + i * 8 + 5],
224
+ max: Module.HEAPF32[axis / 4 + i * 8 + 6]
225
+ };
226
+ result[info.tag] = info;
227
+ });
228
+ Module.stackRestore(sp);
229
+ return result;
230
+ }
231
+ /**
232
+ * Return unicodes the face supports.
233
+ * @returns A Uint32Array of supported Unicode code points.
234
+ */
235
+ collectUnicodes() {
236
+ const unicodeSetPtr = exports$1.hb_set_create();
237
+ exports$1.hb_face_collect_unicodes(this.ptr, unicodeSetPtr);
238
+ const result = typed_array_from_set(unicodeSetPtr);
239
+ exports$1.hb_set_destroy(unicodeSetPtr);
240
+ return result;
241
+ }
242
+ /**
243
+ * Return all scripts enumerated in the specified face's
244
+ * GSUB table or GPOS table.
245
+ * @param table The table to query, either "GSUB" or "GPOS".
246
+ * @returns An array of 4-character script tag strings.
247
+ */
248
+ getTableScriptTags(table) {
249
+ const sp = Module.stackSave();
250
+ const tableTag = hb_tag(table);
251
+ let startOffset = 0;
252
+ let scriptCount = 128;
253
+ const scriptCountPtr = Module.stackAlloc(4);
254
+ const scriptTagsPtr = Module.stackAlloc(512);
255
+ const tags = [];
256
+ while (scriptCount == 128) {
257
+ Module.HEAPU32[scriptCountPtr / 4] = scriptCount;
258
+ exports$1.hb_ot_layout_table_get_script_tags(this.ptr, tableTag, startOffset, scriptCountPtr, scriptTagsPtr);
259
+ scriptCount = Module.HEAPU32[scriptCountPtr / 4];
260
+ const scriptTags = Module.HEAPU32.subarray(scriptTagsPtr / 4, scriptTagsPtr / 4 + scriptCount);
261
+ tags.push(...Array.from(scriptTags).map(hb_untag));
262
+ startOffset += scriptCount;
263
+ }
264
+ Module.stackRestore(sp);
265
+ return tags;
266
+ }
267
+ /**
268
+ * Return all features enumerated in the specified face's
269
+ * GSUB table or GPOS table.
270
+ * @param table The table to query, either "GSUB" or "GPOS".
271
+ * @returns An array of 4-character feature tag strings.
272
+ */
273
+ getTableFeatureTags(table) {
274
+ const sp = Module.stackSave();
275
+ const tableTag = hb_tag(table);
276
+ let startOffset = 0;
277
+ let featureCount = 128;
278
+ const featureCountPtr = Module.stackAlloc(4);
279
+ const featureTagsPtr = Module.stackAlloc(512);
280
+ const tags = [];
281
+ while (featureCount == 128) {
282
+ Module.HEAPU32[featureCountPtr / 4] = featureCount;
283
+ exports$1.hb_ot_layout_table_get_feature_tags(this.ptr, tableTag, startOffset, featureCountPtr, featureTagsPtr);
284
+ featureCount = Module.HEAPU32[featureCountPtr / 4];
285
+ const featureTags = Module.HEAPU32.subarray(featureTagsPtr / 4, featureTagsPtr / 4 + featureCount);
286
+ tags.push(...Array.from(featureTags).map(hb_untag));
287
+ startOffset += featureCount;
288
+ }
289
+ Module.stackRestore(sp);
290
+ return tags;
291
+ }
292
+ /**
293
+ * Return language tags in the given face's GSUB or GPOS table, underneath
294
+ * the specified script index.
295
+ * @param table The table to query, either "GSUB" or "GPOS".
296
+ * @param scriptIndex The index of the script to query.
297
+ * @returns An array of 4-character language tag strings.
298
+ */
299
+ getScriptLanguageTags(table, scriptIndex) {
300
+ const sp = Module.stackSave();
301
+ const tableTag = hb_tag(table);
302
+ let startOffset = 0;
303
+ let languageCount = 128;
304
+ const languageCountPtr = Module.stackAlloc(4);
305
+ const languageTagsPtr = Module.stackAlloc(512);
306
+ const tags = [];
307
+ while (languageCount == 128) {
308
+ Module.HEAPU32[languageCountPtr / 4] = languageCount;
309
+ exports$1.hb_ot_layout_script_get_language_tags(this.ptr, tableTag, scriptIndex, startOffset, languageCountPtr, languageTagsPtr);
310
+ languageCount = Module.HEAPU32[languageCountPtr / 4];
311
+ const languageTags = Module.HEAPU32.subarray(languageTagsPtr / 4, languageTagsPtr / 4 + languageCount);
312
+ tags.push(...Array.from(languageTags).map(hb_untag));
313
+ startOffset += languageCount;
314
+ }
315
+ Module.stackRestore(sp);
316
+ return tags;
317
+ }
318
+ /**
319
+ * Return all features in the specified face's GSUB table or GPOS table,
320
+ * underneath the specified script and language.
321
+ * @param table The table to query, either "GSUB" or "GPOS".
322
+ * @param scriptIndex The index of the script to query.
323
+ * @param languageIndex The index of the language to query.
324
+ * @returns An array of 4-character feature tag strings.
325
+ */
326
+ getLanguageFeatureTags(table, scriptIndex, languageIndex) {
327
+ const sp = Module.stackSave();
328
+ const tableTag = hb_tag(table);
329
+ let startOffset = 0;
330
+ let featureCount = 128;
331
+ const featureCountPtr = Module.stackAlloc(4);
332
+ const featureTagsPtr = Module.stackAlloc(512);
333
+ const tags = [];
334
+ while (featureCount == 128) {
335
+ Module.HEAPU32[featureCountPtr / 4] = featureCount;
336
+ exports$1.hb_ot_layout_language_get_feature_tags(this.ptr, tableTag, scriptIndex, languageIndex, startOffset, featureCountPtr, featureTagsPtr);
337
+ featureCount = Module.HEAPU32[featureCountPtr / 4];
338
+ const featureTags = Module.HEAPU32.subarray(featureTagsPtr / 4, featureTagsPtr / 4 + featureCount);
339
+ tags.push(...Array.from(featureTags).map(hb_untag));
340
+ startOffset += featureCount;
341
+ }
342
+ Module.stackRestore(sp);
343
+ return tags;
344
+ }
345
+ /**
346
+ * Fetches a list of all lookups enumerated for the specified feature, in
347
+ * the specified face's GSUB table or GPOS table.
348
+ * @param table The table to query, either "GSUB" or "GPOS".
349
+ * @param featureIndex The index of the requested feature.
350
+ * @returns An array of lookup indexes.
351
+ */
352
+ getFeatureLookups(table, featureIndex) {
353
+ const sp = Module.stackSave();
354
+ const tableTag = hb_tag(table);
355
+ let startOffset = 0;
356
+ let lookupCount = 128;
357
+ const lookupCountPtr = Module.stackAlloc(4);
358
+ const lookupIndexesPtr = Module.stackAlloc(512);
359
+ const lookups = [];
360
+ while (lookupCount == 128) {
361
+ Module.HEAPU32[lookupCountPtr / 4] = lookupCount;
362
+ exports$1.hb_ot_layout_feature_get_lookups(this.ptr, tableTag, featureIndex, startOffset, lookupCountPtr, lookupIndexesPtr);
363
+ lookupCount = Module.HEAPU32[lookupCountPtr / 4];
364
+ const lookupIndexes = Module.HEAPU32.subarray(lookupIndexesPtr / 4, lookupIndexesPtr / 4 + lookupCount);
365
+ lookups.push(...Array.from(lookupIndexes));
366
+ startOffset += lookupCount;
367
+ }
368
+ Module.stackRestore(sp);
369
+ return lookups;
370
+ }
371
+ /**
372
+ * Get the GDEF class of the requested glyph.
373
+ * @param glyph The glyph to get the class of.
374
+ * @returns The {@link GlyphClass} of the glyph.
375
+ */
376
+ getGlyphClass(glyph) {
377
+ return exports$1.hb_ot_layout_get_glyph_class(this.ptr, glyph);
378
+ }
379
+ /**
380
+ * Return all names in the specified face's name table.
381
+ * @returns An array of {nameId, language} entries.
382
+ */
383
+ listNames() {
384
+ const sp = Module.stackSave();
385
+ const numEntriesPtr = Module.stackAlloc(4);
386
+ const entriesPtr = exports$1.hb_ot_name_list_names(this.ptr, numEntriesPtr);
387
+ const numEntries = Module.HEAPU32[numEntriesPtr / 4];
388
+ const entries = [];
389
+ for (let i = 0; i < numEntries; i++) entries.push({
390
+ nameId: Module.HEAPU32[entriesPtr / 4 + i * 3],
391
+ language: language_to_string(Module.HEAPU32[entriesPtr / 4 + i * 3 + 2])
392
+ });
393
+ Module.stackRestore(sp);
394
+ return entries;
395
+ }
396
+ /**
397
+ * Get the name of the specified face.
398
+ * @param nameId The ID of the name to get.
399
+ * @param language The language of the name to get.
400
+ * @returns The name string.
401
+ */
402
+ getName(nameId, language) {
403
+ const sp = Module.stackSave();
404
+ const languagePtr = language_from_string(language);
405
+ const nameLen = exports$1.hb_ot_name_get_utf16(this.ptr, nameId, languagePtr, 0, 0) + 1;
406
+ const textSizePtr = Module.stackAlloc(4);
407
+ const textPtr = exports$1.malloc(nameLen * 2);
408
+ Module.HEAPU32[textSizePtr / 4] = nameLen;
409
+ exports$1.hb_ot_name_get_utf16(this.ptr, nameId, languagePtr, textSizePtr, textPtr);
410
+ const name = utf16_ptr_to_string(textPtr, nameLen - 1);
411
+ exports$1.free(textPtr);
412
+ Module.stackRestore(sp);
413
+ return name;
414
+ }
415
+ /**
416
+ * Get the name IDs of the specified feature.
417
+ * @param table The table to query, either "GSUB" or "GPOS".
418
+ * @param featureIndex The index of the feature to query.
419
+ * @returns An object with name IDs, or undefined if not found.
420
+ */
421
+ getFeatureNameIds(table, featureIndex) {
422
+ const sp = Module.stackSave();
423
+ const tableTag = hb_tag(table);
424
+ const labelIdPtr = Module.stackAlloc(4);
425
+ const tooltipIdPtr = Module.stackAlloc(4);
426
+ const sampleIdPtr = Module.stackAlloc(4);
427
+ const numNamedParametersPtr = Module.stackAlloc(4);
428
+ const firstParameterIdPtr = Module.stackAlloc(4);
429
+ const found = exports$1.hb_ot_layout_feature_get_name_ids(this.ptr, tableTag, featureIndex, labelIdPtr, tooltipIdPtr, sampleIdPtr, numNamedParametersPtr, firstParameterIdPtr);
430
+ let names;
431
+ if (found) {
432
+ const uiLabelNameId = Module.HEAPU32[labelIdPtr / 4];
433
+ const uiTooltipTextNameId = Module.HEAPU32[tooltipIdPtr / 4];
434
+ const sampleTextNameId = Module.HEAPU32[sampleIdPtr / 4];
435
+ const numNamedParameters = Module.HEAPU32[numNamedParametersPtr / 4];
436
+ const firstParameterId = Module.HEAPU32[firstParameterIdPtr / 4];
437
+ names = { paramUiLabelNameIds: Array.from({ length: numNamedParameters }, (_, i) => firstParameterId + i) };
438
+ if (uiLabelNameId != HB_OT_NAME_ID_INVALID) names.uiLabelNameId = uiLabelNameId;
439
+ if (uiTooltipTextNameId != HB_OT_NAME_ID_INVALID) names.uiTooltipTextNameId = uiTooltipTextNameId;
440
+ if (sampleTextNameId != HB_OT_NAME_ID_INVALID) names.sampleTextNameId = sampleTextNameId;
441
+ }
442
+ Module.stackRestore(sp);
443
+ return names;
444
+ }
445
+ /**
446
+ * Tests whether a face includes a `CPAL` color-palette table.
447
+ * @returns `true` if data found, `false` otherwise.
448
+ */
449
+ hasColorPalettes() {
450
+ return !!exports$1.hb_ot_color_has_palettes(this.ptr);
451
+ }
452
+ /**
453
+ * Fetches the color palettes in the face's `CPAL` table.
454
+ * @returns An array of the face's {@link ColorPalette | color palettes}.
455
+ */
456
+ getColorPalettes() {
457
+ const count = exports$1.hb_ot_color_palette_get_count(this.ptr);
458
+ const palettes = [];
459
+ const sp = Module.stackSave();
460
+ const countPtr = Module.stackAlloc(4);
461
+ const colorsPtr = Module.stackAlloc(512);
462
+ for (let i = 0; i < count; i++) {
463
+ const colors = [];
464
+ let startOffset = 0;
465
+ let colorCount = 128;
466
+ while (colorCount === 128) {
467
+ Module.HEAPU32[countPtr / 4] = colorCount;
468
+ exports$1.hb_ot_color_palette_get_colors(this.ptr, i, startOffset, countPtr, colorsPtr);
469
+ colorCount = Module.HEAPU32[countPtr / 4];
470
+ for (let j = 0; j < colorCount; j++) {
471
+ const color = color_from_int(Module.HEAPU32[colorsPtr / 4 + j]);
472
+ const nameId2 = exports$1.hb_ot_color_palette_color_get_name_id(this.ptr, startOffset + j);
473
+ if (nameId2 != HB_OT_NAME_ID_INVALID) color.nameId = nameId2;
474
+ colors.push(color);
475
+ }
476
+ startOffset += colorCount;
477
+ }
478
+ const palette = {
479
+ colors,
480
+ flags: exports$1.hb_ot_color_palette_get_flags(this.ptr, i)
481
+ };
482
+ const nameId = exports$1.hb_ot_color_palette_get_name_id(this.ptr, i);
483
+ if (nameId != HB_OT_NAME_ID_INVALID) palette.nameId = nameId;
484
+ palettes.push(palette);
485
+ }
486
+ Module.stackRestore(sp);
487
+ return palettes;
488
+ }
489
+ /**
490
+ * Tests whether a face includes a `COLR` table with data according to COLRv0.
491
+ * @returns `true` if data found, `false` otherwise.
492
+ */
493
+ hasColorLayers() {
494
+ return !!exports$1.hb_ot_color_has_layers(this.ptr);
495
+ }
496
+ /**
497
+ * Fetches a list of all color layers for the specified glyph index in the
498
+ * specified face.
499
+ * @param glyph The glyph index to query.
500
+ * @returns An array of the glyph's {@link ColorLayer | color layers}.
501
+ */
502
+ getGlyphColorLayers(glyph) {
503
+ const layers = [];
504
+ const sp = Module.stackSave();
505
+ const countPtr = Module.stackAlloc(4);
506
+ const layersPtr = Module.stackAlloc(1024);
507
+ let startOffset = 0;
508
+ let layerCount = 128;
509
+ while (layerCount === 128) {
510
+ Module.HEAPU32[countPtr / 4] = layerCount;
511
+ exports$1.hb_ot_color_glyph_get_layers(this.ptr, glyph, startOffset, countPtr, layersPtr);
512
+ layerCount = Module.HEAPU32[countPtr / 4];
513
+ for (let i = 0; i < layerCount; i++) {
514
+ const o = layersPtr / 4 + i * 2;
515
+ const layer = { glyph: Module.HEAPU32[o] };
516
+ const colorIndex = Module.HEAPU32[o + 1];
517
+ if (colorIndex != 65535) layer.colorIndex = colorIndex;
518
+ layers.push(layer);
519
+ }
520
+ startOffset += layerCount;
521
+ }
522
+ Module.stackRestore(sp);
523
+ return layers;
524
+ }
525
+ /**
526
+ * Tests whether a face includes a `COLR` table with data according to COLRv1.
527
+ * @returns `true` if data found, `false` otherwise.
528
+ */
529
+ hasColorPaint() {
530
+ return !!exports$1.hb_ot_color_has_paint(this.ptr);
531
+ }
532
+ /**
533
+ * Tests whether a face includes COLRv1 paint data for a glyph.
534
+ * @param glyph The glyph index to query.
535
+ * @returns `true` if data found, `false` otherwise.
536
+ */
537
+ glyphHasColorPaint(glyph) {
538
+ return !!exports$1.hb_ot_color_glyph_has_paint(this.ptr, glyph);
539
+ }
540
+ /**
541
+ * Tests whether a face has PNG glyph images (either in `CBDT` or `sbix`
542
+ * tables).
543
+ * @returns `true` if data found, `false` otherwise.
544
+ */
545
+ hasColorPng() {
546
+ return !!exports$1.hb_ot_color_has_png(this.ptr);
547
+ }
548
+ };
549
+ var DrawFuncs = class {
550
+ constructor() {
551
+ this.funcPtrs = [];
552
+ this.userDataPtrs = [];
553
+ this.ptr = exports$1.hb_draw_funcs_create();
554
+ const ptr = this.ptr;
555
+ const funcPtrs = this.funcPtrs;
556
+ const userDataPtrs = this.userDataPtrs;
557
+ registry.register(this, () => {
558
+ exports$1.hb_draw_funcs_destroy(ptr);
559
+ for (const ptr2 of funcPtrs) Module.removeFunction(ptr2);
560
+ for (const ptr2 of userDataPtrs) remove_callback_data_pointer(ptr2);
561
+ });
562
+ }
563
+ /**
564
+ * Sets move-to callback to the draw functions object.
565
+ * @param func The move-to callback.
566
+ * @param userData Data to pass to `func`.
567
+ */
568
+ setMoveToFunc(func, userData) {
569
+ const userDataPtr = register_callback_data_pointer(userData);
570
+ this.userDataPtrs.push(userDataPtr);
571
+ const funcPtr = Module.addFunction((dfuncs, draw_data, draw_state, toX, toY, user_data) => {
572
+ func(toX, toY, get_callback_data(draw_data), get_callback_data(user_data));
573
+ }, "viiiffi");
574
+ this.funcPtrs.push(funcPtr);
575
+ exports$1.hb_draw_funcs_set_move_to_func(this.ptr, funcPtr, userDataPtr, 0);
576
+ }
577
+ /**
578
+ * Sets line-to callback to the draw functions object.
579
+ * @param func The line-to callback.
580
+ * @param userData Data to pass to `func`.
581
+ */
582
+ setLineToFunc(func, userData) {
583
+ const userDataPtr = register_callback_data_pointer(userData);
584
+ this.userDataPtrs.push(userDataPtr);
585
+ const funcPtr = Module.addFunction((dfuncs, draw_data, draw_state, toX, toY, user_data) => {
586
+ func(toX, toY, get_callback_data(draw_data), get_callback_data(user_data));
587
+ }, "viiiffi");
588
+ this.funcPtrs.push(funcPtr);
589
+ exports$1.hb_draw_funcs_set_line_to_func(this.ptr, funcPtr, userDataPtr, 0);
590
+ }
591
+ /**
592
+ * Sets quadratic-to callback to the draw functions object.
593
+ * @param func The quadratic-to callback.
594
+ * @param userData Data to pass to `func`.
595
+ */
596
+ setQuadraticToFunc(func, userData) {
597
+ const userDataPtr = register_callback_data_pointer(userData);
598
+ this.userDataPtrs.push(userDataPtr);
599
+ const funcPtr = Module.addFunction((dfuncs, draw_data, draw_state, cX, cY, toX, toY, user_data) => {
600
+ func(cX, cY, toX, toY, get_callback_data(draw_data), get_callback_data(user_data));
601
+ }, "viiiffffi");
602
+ this.funcPtrs.push(funcPtr);
603
+ exports$1.hb_draw_funcs_set_quadratic_to_func(this.ptr, funcPtr, userDataPtr, 0);
604
+ }
605
+ /**
606
+ * Sets cubic-to callback to the draw functions object.
607
+ * @param func The cubic-to callback.
608
+ * @param userData Data to pass to `func`.
609
+ */
610
+ setCubicToFunc(func, userData) {
611
+ const userDataPtr = register_callback_data_pointer(userData);
612
+ this.userDataPtrs.push(userDataPtr);
613
+ const funcPtr = Module.addFunction((dfuncs, draw_data, draw_state, c1X, c1Y, c2X, c2Y, toX, toY, user_data) => {
614
+ func(c1X, c1Y, c2X, c2Y, toX, toY, get_callback_data(draw_data), get_callback_data(user_data));
615
+ }, "viiiffffffi");
616
+ this.funcPtrs.push(funcPtr);
617
+ exports$1.hb_draw_funcs_set_cubic_to_func(this.ptr, funcPtr, userDataPtr, 0);
618
+ }
619
+ /**
620
+ * Sets close-path callback to the draw functions object.
621
+ * @param func The close-path callback.
622
+ * @param userData Data to pass to `func`.
623
+ */
624
+ setClosePathFunc(func, userData) {
625
+ const userDataPtr = register_callback_data_pointer(userData);
626
+ this.userDataPtrs.push(userDataPtr);
627
+ const funcPtr = Module.addFunction((dfuncs, draw_data, draw_state, user_data) => {
628
+ func(get_callback_data(draw_data), get_callback_data(user_data));
629
+ }, "viiii");
630
+ this.funcPtrs.push(funcPtr);
631
+ exports$1.hb_draw_funcs_set_close_path_func(this.ptr, funcPtr, userDataPtr, 0);
632
+ }
633
+ };
634
+ var MetricsTag = {
635
+ HORIZONTAL_ASCENDER: hb_tag("hasc"),
636
+ HORIZONTAL_DESCENDER: hb_tag("hdsc"),
637
+ HORIZONTAL_LINE_GAP: hb_tag("hlgp"),
638
+ HORIZONTAL_CLIPPING_ASCENT: hb_tag("hcla"),
639
+ HORIZONTAL_CLIPPING_DESCENT: hb_tag("hcld"),
640
+ VERTICAL_ASCENDER: hb_tag("vasc"),
641
+ VERTICAL_DESCENDER: hb_tag("vdsc"),
642
+ VERTICAL_LINE_GAP: hb_tag("vlgp"),
643
+ HORIZONTAL_CARET_RISE: hb_tag("hcrs"),
644
+ HORIZONTAL_CARET_RUN: hb_tag("hcrn"),
645
+ HORIZONTAL_CARET_OFFSET: hb_tag("hcof"),
646
+ VERTICAL_CARET_RISE: hb_tag("vcrs"),
647
+ VERTICAL_CARET_RUN: hb_tag("vcrn"),
648
+ VERTICAL_CARET_OFFSET: hb_tag("vcof"),
649
+ X_HEIGHT: hb_tag("xhgt"),
650
+ CAP_HEIGHT: hb_tag("cpht"),
651
+ SUBSCRIPT_EM_X_SIZE: hb_tag("sbxs"),
652
+ SUBSCRIPT_EM_Y_SIZE: hb_tag("sbys"),
653
+ SUBSCRIPT_EM_X_OFFSET: hb_tag("sbxo"),
654
+ SUBSCRIPT_EM_Y_OFFSET: hb_tag("sbyo"),
655
+ SUPERSCRIPT_EM_X_SIZE: hb_tag("spxs"),
656
+ SUPERSCRIPT_EM_Y_SIZE: hb_tag("spys"),
657
+ SUPERSCRIPT_EM_X_OFFSET: hb_tag("spxo"),
658
+ SUPERSCRIPT_EM_Y_OFFSET: hb_tag("spyo"),
659
+ STRIKEOUT_SIZE: hb_tag("strs"),
660
+ STRIKEOUT_OFFSET: hb_tag("stro"),
661
+ UNDERLINE_SIZE: hb_tag("unds"),
662
+ UNDERLINE_OFFSET: hb_tag("undo")
663
+ };
664
+ var pathDrawFuncs;
665
+ function getPathDrawFuncs() {
666
+ if (!pathDrawFuncs) {
667
+ pathDrawFuncs = new DrawFuncs();
668
+ pathDrawFuncs.setMoveToFunc((x, y, path) => {
669
+ path.push(`M${x},${y}`);
670
+ });
671
+ pathDrawFuncs.setLineToFunc((x, y, path) => {
672
+ path.push(`L${x},${y}`);
673
+ });
674
+ pathDrawFuncs.setCubicToFunc((c1x, c1y, c2x, c2y, x, y, path) => {
675
+ path.push(`C${c1x},${c1y} ${c2x},${c2y} ${x},${y}`);
676
+ });
677
+ pathDrawFuncs.setQuadraticToFunc((cx, cy, x, y, path) => {
678
+ path.push(`Q${cx},${cy} ${x},${y}`);
679
+ });
680
+ pathDrawFuncs.setClosePathFunc((path) => {
681
+ path.push("Z");
682
+ });
683
+ }
684
+ return pathDrawFuncs;
685
+ }
686
+ var jsonDrawFuncs;
687
+ function getJsonDrawFuncs() {
688
+ if (!jsonDrawFuncs) {
689
+ jsonDrawFuncs = new DrawFuncs();
690
+ jsonDrawFuncs.setMoveToFunc((x, y, commands) => {
691
+ commands.push({
692
+ type: "M",
693
+ values: [x, y]
694
+ });
695
+ });
696
+ jsonDrawFuncs.setLineToFunc((x, y, commands) => {
697
+ commands.push({
698
+ type: "L",
699
+ values: [x, y]
700
+ });
701
+ });
702
+ jsonDrawFuncs.setCubicToFunc((c1x, c1y, c2x, c2y, x, y, commands) => {
703
+ commands.push({
704
+ type: "C",
705
+ values: [
706
+ c1x,
707
+ c1y,
708
+ c2x,
709
+ c2y,
710
+ x,
711
+ y
712
+ ]
713
+ });
714
+ });
715
+ jsonDrawFuncs.setQuadraticToFunc((cx, cy, x, y, commands) => {
716
+ commands.push({
717
+ type: "Q",
718
+ values: [
719
+ cx,
720
+ cy,
721
+ x,
722
+ y
723
+ ]
724
+ });
725
+ });
726
+ jsonDrawFuncs.setClosePathFunc((commands) => {
727
+ commands.push({
728
+ type: "Z",
729
+ values: []
730
+ });
731
+ });
732
+ }
733
+ return jsonDrawFuncs;
734
+ }
735
+ var Font = class Font2 {
736
+ constructor(arg) {
737
+ if (typeof arg === "number") this.ptr = exports$1.hb_font_reference(arg);
738
+ else {
739
+ this.ptr = exports$1.hb_font_create(arg.ptr);
740
+ this._face = arg;
741
+ }
742
+ track(this, exports$1.hb_font_destroy);
743
+ }
744
+ /** The {@link Face} associated with this font. */
745
+ get face() {
746
+ if (!this._face) this._face = new Face(exports$1.hb_font_get_face(this.ptr));
747
+ return this._face;
748
+ }
749
+ /**
750
+ * Create a sub font that inherits this font's properties.
751
+ * @returns A new Font object representing the sub font.
752
+ */
753
+ subFont() {
754
+ return new Font2(exports$1.hb_font_create_sub_font(this.ptr));
755
+ }
756
+ /**
757
+ * Return font horizontal extents.
758
+ * @returns Object with ascender, descender, and lineGap properties.
759
+ */
760
+ hExtents() {
761
+ const sp = Module.stackSave();
762
+ const extentsPtr = Module.stackAlloc(48);
763
+ exports$1.hb_font_get_h_extents(this.ptr, extentsPtr);
764
+ const extents = {
765
+ ascender: Module.HEAP32[extentsPtr / 4],
766
+ descender: Module.HEAP32[extentsPtr / 4 + 1],
767
+ lineGap: Module.HEAP32[extentsPtr / 4 + 2]
768
+ };
769
+ Module.stackRestore(sp);
770
+ return extents;
771
+ }
772
+ /**
773
+ * Return font vertical extents.
774
+ * @returns Object with ascender, descender, and lineGap properties.
775
+ */
776
+ vExtents() {
777
+ const sp = Module.stackSave();
778
+ const extentsPtr = Module.stackAlloc(48);
779
+ exports$1.hb_font_get_v_extents(this.ptr, extentsPtr);
780
+ const extents = {
781
+ ascender: Module.HEAP32[extentsPtr / 4],
782
+ descender: Module.HEAP32[extentsPtr / 4 + 1],
783
+ lineGap: Module.HEAP32[extentsPtr / 4 + 2]
784
+ };
785
+ Module.stackRestore(sp);
786
+ return extents;
787
+ }
788
+ /**
789
+ * Return glyph name.
790
+ * @param glyphId ID of the requested glyph in the font.
791
+ * @returns The glyph name string.
792
+ */
793
+ glyphName(glyphId) {
794
+ const sp = Module.stackSave();
795
+ const strSize = 256;
796
+ const strPtr = Module.stackAlloc(strSize);
797
+ exports$1.hb_font_glyph_to_string(this.ptr, glyphId, strPtr, strSize);
798
+ const name = utf8_ptr_to_string(strPtr);
799
+ Module.stackRestore(sp);
800
+ return name;
801
+ }
802
+ /**
803
+ * Draws the outline that corresponds to a glyph in the specified font.
804
+ *
805
+ * The outline is returned by way of calls to the callbacks of the `drawFuncs`
806
+ * object, with `drawData` passed to them.
807
+ * @param glyphId The glyph ID.
808
+ * @param drawFuncs The {@link DrawFuncs} to draw to.
809
+ * @param drawData User data to pass to draw callbacks.
810
+ */
811
+ drawGlyph(glyphId, drawFuncs, drawData) {
812
+ const drawDataPtr = register_callback_data_pointer(drawData);
813
+ try {
814
+ exports$1.hb_font_draw_glyph(this.ptr, glyphId, drawFuncs.ptr, drawDataPtr);
815
+ } finally {
816
+ remove_callback_data_pointer(drawDataPtr);
817
+ }
818
+ }
819
+ /**
820
+ * Draws the outline that corresponds to a glyph in the specified font.
821
+ *
822
+ * This is a newer name for {@link Font.drawGlyph}, that returns `false` if the
823
+ * font has no outlines for the glyph.
824
+ *
825
+ * The outline is returned by way of calls to the callbacks of the `drawFuncs`
826
+ * object, with `drawData` passed to them.
827
+ * @param glyphId The glyph ID.
828
+ * @param drawFuncs The {@link DrawFuncs} to draw to.
829
+ * @param drawData User data to pass to draw callbacks.
830
+ * @returns `true` if the glyph was drawn, `false` otherwise.
831
+ */
832
+ drawGlyphOrFail(glyphId, drawFuncs, drawData) {
833
+ const drawDataPtr = register_callback_data_pointer(drawData);
834
+ try {
835
+ return !!exports$1.hb_font_draw_glyph_or_fail(this.ptr, glyphId, drawFuncs.ptr, drawDataPtr);
836
+ } finally {
837
+ remove_callback_data_pointer(drawDataPtr);
838
+ }
839
+ }
840
+ /**
841
+ * Paints the glyph. This function is similar to {@link Font.paintGlyphOrFail},
842
+ * but if painting a color glyph failed, it will fall back to painting an
843
+ * outline monochrome glyph.
844
+ *
845
+ * The painting instructions are returned by way of calls to the callbacks of
846
+ * the `paintFuncs` object, with `paintData` passed to them.
847
+ *
848
+ * If the font has color palettes, then `paletteIndex` selects the palette to
849
+ * use. If the font only has one palette, this will be 0.
850
+ * @param glyphId The glyph ID.
851
+ * @param paintFuncs The {@link PaintFuncs} to paint with.
852
+ * @param paintData User data to pass to paint callbacks.
853
+ * @param paletteIndex The index of the font's color palette to use.
854
+ * @param foreground The foreground color, unpremultiplied.
855
+ */
856
+ paintGlyph(glyphId, paintFuncs, paintData, paletteIndex = 0, foreground = {
857
+ red: 0,
858
+ green: 0,
859
+ blue: 0,
860
+ alpha: 255
861
+ }) {
862
+ const paintDataPtr = register_callback_data_pointer(paintData);
863
+ try {
864
+ exports$1.hb_font_paint_glyph(this.ptr, glyphId, paintFuncs.ptr, paintDataPtr, paletteIndex, color_to_int(foreground));
865
+ } finally {
866
+ remove_callback_data_pointer(paintDataPtr);
867
+ }
868
+ }
869
+ /**
870
+ * Paints a color glyph.
871
+ *
872
+ * Succeeds if the glyph has color paint layers (COLRv0), a color paint graph
873
+ * (COLRv1), or a bitmap image that the font's callbacks render successfully.
874
+ * Returns `false` if the font has no color data for the glyph; the client can
875
+ * then fall back to {@link Font.drawGlyphOrFail} for the monochrome outline.
876
+ *
877
+ * The painting instructions are returned by way of calls to the callbacks of
878
+ * the `paintFuncs` object, with `paintData` passed to them.
879
+ *
880
+ * If the font has color palettes, then `paletteIndex` selects the palette to
881
+ * use. If the font only has one palette, this will be 0.
882
+ * @param glyphId The glyph ID.
883
+ * @param paintFuncs The {@link PaintFuncs} to paint with.
884
+ * @param paintData User data to pass to paint callbacks.
885
+ * @param paletteIndex The index of the font's color palette to use.
886
+ * @param foreground The foreground color, unpremultiplied.
887
+ * @returns `true` if the glyph was painted, `false` otherwise.
888
+ */
889
+ paintGlyphOrFail(glyphId, paintFuncs, paintData, paletteIndex = 0, foreground = {
890
+ red: 0,
891
+ green: 0,
892
+ blue: 0,
893
+ alpha: 255
894
+ }) {
895
+ const paintDataPtr = register_callback_data_pointer(paintData);
896
+ try {
897
+ return !!exports$1.hb_font_paint_glyph_or_fail(this.ptr, glyphId, paintFuncs.ptr, paintDataPtr, paletteIndex, color_to_int(foreground));
898
+ } finally {
899
+ remove_callback_data_pointer(paintDataPtr);
900
+ }
901
+ }
902
+ /**
903
+ * Fetches the PNG image for a glyph.
904
+ *
905
+ * To get an optimally sized PNG blob, the PPEM values must be set on the font.
906
+ * If PPEM is unset, the blob returned will be the largest PNG available.
907
+ * @param glyphId A glyph index.
908
+ * @returns The PNG image for the glyph, or `undefined` if the glyph has no PNG
909
+ * image.
910
+ */
911
+ getGlyphColorPng(glyphId) {
912
+ const blob = exports$1.hb_ot_color_glyph_reference_png(this.ptr, glyphId);
913
+ const length = exports$1.hb_blob_get_length(blob);
914
+ let png;
915
+ if (length) {
916
+ const dataPtr = exports$1.hb_blob_get_data(blob, 0);
917
+ png = Module.HEAPU8.slice(dataPtr, dataPtr + length);
918
+ }
919
+ exports$1.hb_blob_destroy(blob);
920
+ return png;
921
+ }
922
+ /**
923
+ * Return a glyph as an SVG path string.
924
+ * @param glyphId ID of the requested glyph in the font.
925
+ * @returns SVG path data string.
926
+ */
927
+ glyphToPath(glyphId) {
928
+ const path = [];
929
+ this.drawGlyph(glyphId, getPathDrawFuncs(), path);
930
+ return path.join("");
931
+ }
932
+ /**
933
+ * Return glyph horizontal advance.
934
+ * @param glyphId ID of the requested glyph in the font.
935
+ * @returns The horizontal advance width.
936
+ */
937
+ glyphHAdvance(glyphId) {
938
+ return exports$1.hb_font_get_glyph_h_advance(this.ptr, glyphId);
939
+ }
940
+ /**
941
+ * Return glyph vertical advance.
942
+ * @param glyphId ID of the requested glyph in the font.
943
+ * @returns The vertical advance height.
944
+ */
945
+ glyphVAdvance(glyphId) {
946
+ return exports$1.hb_font_get_glyph_v_advance(this.ptr, glyphId);
947
+ }
948
+ /**
949
+ * Return glyph horizontal origin.
950
+ * @param glyphId ID of the requested glyph in the font.
951
+ * @returns [x, y] origin coordinates, or undefined if not available.
952
+ */
953
+ glyphHOrigin(glyphId) {
954
+ const sp = Module.stackSave();
955
+ const xPtr = Module.stackAlloc(4);
956
+ const yPtr = Module.stackAlloc(4);
957
+ let origin;
958
+ if (exports$1.hb_font_get_glyph_h_origin(this.ptr, glyphId, xPtr, yPtr)) origin = [Module.HEAP32[xPtr / 4], Module.HEAP32[yPtr / 4]];
959
+ Module.stackRestore(sp);
960
+ return origin;
961
+ }
962
+ /**
963
+ * Return glyph vertical origin.
964
+ * @param glyphId ID of the requested glyph in the font.
965
+ * @returns [x, y] origin coordinates, or undefined if not available.
966
+ */
967
+ glyphVOrigin(glyphId) {
968
+ const sp = Module.stackSave();
969
+ const xPtr = Module.stackAlloc(4);
970
+ const yPtr = Module.stackAlloc(4);
971
+ let origin;
972
+ if (exports$1.hb_font_get_glyph_v_origin(this.ptr, glyphId, xPtr, yPtr)) origin = [Module.HEAP32[xPtr / 4], Module.HEAP32[yPtr / 4]];
973
+ Module.stackRestore(sp);
974
+ return origin;
975
+ }
976
+ /**
977
+ * Return glyph extents.
978
+ * @param glyphId ID of the requested glyph in the font.
979
+ * @returns An object with xBearing, yBearing, width, and height, or undefined.
980
+ */
981
+ glyphExtents(glyphId) {
982
+ const sp = Module.stackSave();
983
+ const extentsPtr = Module.stackAlloc(16);
984
+ let extents;
985
+ if (exports$1.hb_font_get_glyph_extents(this.ptr, glyphId, extentsPtr)) extents = {
986
+ xBearing: Module.HEAP32[extentsPtr / 4],
987
+ yBearing: Module.HEAP32[extentsPtr / 4 + 1],
988
+ width: Module.HEAP32[extentsPtr / 4 + 2],
989
+ height: Module.HEAP32[extentsPtr / 4 + 3]
990
+ };
991
+ Module.stackRestore(sp);
992
+ return extents;
993
+ }
994
+ /**
995
+ * Fetches the glyph ID for a Unicode code point in the specified
996
+ * font, with an optional variation selector.
997
+ *
998
+ * If `variationSelector` is 0, it is equivalent to
999
+ * {@link Font.nominalGlyph}; otherwise it is equivalent to
1000
+ * {@link Font.variationGlyph}.
1001
+ *
1002
+ * @param unicode The Unicode code point to query.
1003
+ * @param variationSelector A variation-selector code point.
1004
+ * @returns The glyph ID, or undefined if not found.
1005
+ */
1006
+ glyph(unicode, variationSelector = 0) {
1007
+ const sp = Module.stackSave();
1008
+ const glyphIdPtr = Module.stackAlloc(4);
1009
+ let glyphId;
1010
+ if (exports$1.hb_font_get_glyph(this.ptr, unicode, variationSelector, glyphIdPtr)) glyphId = Module.HEAPU32[glyphIdPtr / 4];
1011
+ Module.stackRestore(sp);
1012
+ return glyphId;
1013
+ }
1014
+ /**
1015
+ * Fetches the nominal glyph ID for a Unicode code point in the
1016
+ * specified font.
1017
+ *
1018
+ * This version of the function should not be used to fetch glyph IDs
1019
+ * for code points modified by variation selectors. For variation-selector
1020
+ * support, use {@link Font.variationGlyph} or {@link Font.glyph}.
1021
+ *
1022
+ * @param unicode The Unicode code point to query.
1023
+ * @returns The glyph ID, or undefined if not found.
1024
+ */
1025
+ nominalGlyph(unicode) {
1026
+ const sp = Module.stackSave();
1027
+ const glyphIdPtr = Module.stackAlloc(4);
1028
+ let glyphId;
1029
+ if (exports$1.hb_font_get_nominal_glyph(this.ptr, unicode, glyphIdPtr)) glyphId = Module.HEAPU32[glyphIdPtr / 4];
1030
+ Module.stackRestore(sp);
1031
+ return glyphId;
1032
+ }
1033
+ /**
1034
+ * Fetches the glyph ID for a Unicode code point when followed by
1035
+ * by the specified variation-selector code point, in the specified
1036
+ * font.
1037
+ *
1038
+ * @param unicode The Unicode code point to query.
1039
+ * @param variationSelector The variation-selector code point to query.
1040
+ * @returns The glyph ID, or undefined if not found.
1041
+ */
1042
+ variationGlyph(unicode, variationSelector) {
1043
+ const sp = Module.stackSave();
1044
+ const glyphIdPtr = Module.stackAlloc(4);
1045
+ let glyphId;
1046
+ if (exports$1.hb_font_get_variation_glyph(this.ptr, unicode, variationSelector, glyphIdPtr)) glyphId = Module.HEAPU32[glyphIdPtr / 4];
1047
+ Module.stackRestore(sp);
1048
+ return glyphId;
1049
+ }
1050
+ /**
1051
+ * Return glyph ID from name.
1052
+ * @param name Name of the requested glyph in the font.
1053
+ * @returns The glyph ID, or undefined if not found.
1054
+ */
1055
+ glyphFromName(name) {
1056
+ const sp = Module.stackSave();
1057
+ const glyphIdPtr = Module.stackAlloc(4);
1058
+ const namePtr = string_to_utf8_ptr(name);
1059
+ let glyphId;
1060
+ if (exports$1.hb_font_get_glyph_from_name(this.ptr, namePtr.ptr, namePtr.length, glyphIdPtr)) glyphId = Module.HEAPU32[glyphIdPtr / 4];
1061
+ namePtr.free();
1062
+ Module.stackRestore(sp);
1063
+ return glyphId;
1064
+ }
1065
+ /**
1066
+ * Return a glyph as a JSON path string
1067
+ * based on format described on https://svgwg.org/specs/paths/#InterfaceSVGPathSegment
1068
+ * @param glyphId ID of the requested glyph in the font.
1069
+ * @returns An array of path segment objects with type and values.
1070
+ */
1071
+ glyphToJson(glyphId) {
1072
+ const commands = [];
1073
+ this.drawGlyph(glyphId, getJsonDrawFuncs(), commands);
1074
+ return commands;
1075
+ }
1076
+ /**
1077
+ * Set the font's scale factor, affecting the position values returned from
1078
+ * shaping.
1079
+ * @param xScale Units to scale in the X dimension.
1080
+ * @param yScale Units to scale in the Y dimension.
1081
+ */
1082
+ setScale(xScale, yScale) {
1083
+ exports$1.hb_font_set_scale(this.ptr, xScale, yScale);
1084
+ }
1085
+ /**
1086
+ * Applies a list of font-variation settings to a font.
1087
+ *
1088
+ * Note that this overrides all existing variations set on the font.
1089
+ * Axes not included in `variations` will be effectively set to their
1090
+ * default values.
1091
+ *
1092
+ * @param variations Array of variation settings to apply.
1093
+ */
1094
+ setVariations(variations) {
1095
+ const sp = Module.stackSave();
1096
+ const vars = Module.stackAlloc(8 * variations.length);
1097
+ variations.forEach((variation, i) => {
1098
+ variation.writeTo(vars + i * 8);
1099
+ });
1100
+ exports$1.hb_font_set_variations(this.ptr, vars, variations.length);
1101
+ Module.stackRestore(sp);
1102
+ }
1103
+ /** Set the font's font functions. */
1104
+ setFuncs(fontFuncs) {
1105
+ exports$1.hb_font_set_funcs(this.ptr, fontFuncs.ptr);
1106
+ }
1107
+ /**
1108
+ * Fetches the optical bound of a glyph positioned at the margin of text.
1109
+ * The direction identifies which edge of the glyph to query.
1110
+ * @param lookupIndex Index of the feature lookup to query.
1111
+ * @param direction Edge of the glyph to query.
1112
+ * @param glyph A glyph id.
1113
+ * @returns Adjustment value. Negative values mean the glyph will stick out of the margin.
1114
+ */
1115
+ getLookupOpticalBound(lookupIndex, direction, glyph) {
1116
+ return exports$1.hb_ot_layout_lookup_get_optical_bound(this.ptr, lookupIndex, direction, glyph);
1117
+ }
1118
+ /**
1119
+ * Fetches a list of the caret positions defined for a ligature glyph in the
1120
+ * GDEF table of the font.
1121
+ *
1122
+ * Note that a ligature that is formed from n characters will have n-1
1123
+ * caret positions. The first character is not represented in the array,
1124
+ * since its caret position is the glyph position.
1125
+ *
1126
+ * The positions returned by this function are 'unshaped', and will have to
1127
+ * be fixed up for kerning that may be applied to the ligature glyph.
1128
+ *
1129
+ * @param direction The text direction to use.
1130
+ * @param glyph The glyph to query.
1131
+ * @returns An array of caret positions.
1132
+ */
1133
+ getLigatureCarets(direction, glyph) {
1134
+ const sp = Module.stackSave();
1135
+ let startOffset = 0;
1136
+ let caretCount = 128;
1137
+ const caretCountPtr = Module.stackAlloc(4);
1138
+ const caretArrayPtr = Module.stackAlloc(512);
1139
+ const carets = [];
1140
+ while (caretCount == 128) {
1141
+ Module.HEAPU32[caretCountPtr / 4] = caretCount;
1142
+ exports$1.hb_ot_layout_get_ligature_carets(this.ptr, direction, glyph, startOffset, caretCountPtr, caretArrayPtr);
1143
+ caretCount = Module.HEAPU32[caretCountPtr / 4];
1144
+ const caretArray = Module.HEAP32.subarray(caretArrayPtr / 4, caretArrayPtr / 4 + caretCount);
1145
+ carets.push(...Array.from(caretArray));
1146
+ startOffset += caretCount;
1147
+ }
1148
+ Module.stackRestore(sp);
1149
+ return carets;
1150
+ }
1151
+ /**
1152
+ * Fetches metrics value corresponding to `metricsTag` from the font.
1153
+ *
1154
+ * @param metricsTag {@link MetricsTag} of metrics value you like to fetch.
1155
+ * @returns The metrics value, or undefined if not found in the font.
1156
+ */
1157
+ getMetricPosition(metricsTag) {
1158
+ const sp = Module.stackSave();
1159
+ const positionPtr = Module.stackAlloc(4);
1160
+ let position;
1161
+ if (exports$1.hb_ot_metrics_get_position(this.ptr, metricsTag, positionPtr)) position = Module.HEAP32[positionPtr / 4];
1162
+ Module.stackRestore(sp);
1163
+ return position;
1164
+ }
1165
+ /**
1166
+ * Fetches metrics value corresponding to `metricsTag` from the font, and
1167
+ * synthesizes a value if the value is missing in the font.
1168
+ *
1169
+ * @param metricsTag {@link MetricsTag} of metrics value you like to fetch.
1170
+ * @returns The metrics value.
1171
+ */
1172
+ getMetricPositionWithFallback(metricsTag) {
1173
+ const sp = Module.stackSave();
1174
+ const positionPtr = Module.stackAlloc(4);
1175
+ exports$1.hb_ot_metrics_get_position_with_fallback(this.ptr, metricsTag, positionPtr);
1176
+ const position = Module.HEAP32[positionPtr / 4];
1177
+ Module.stackRestore(sp);
1178
+ return position;
1179
+ }
1180
+ /**
1181
+ * Fetches metrics value corresponding to `metricsTag` from the font with the
1182
+ * current font variation settings applied.
1183
+ *
1184
+ * @param metricsTag {@link MetricsTag} of metrics value you like to fetch.
1185
+ * @returns The requested metric value.
1186
+ */
1187
+ getMetricVariation(metricsTag) {
1188
+ return exports$1.hb_ot_metrics_get_variation(this.ptr, metricsTag);
1189
+ }
1190
+ /**
1191
+ * Fetches horizontal metrics value corresponding to `metricsTag` from the
1192
+ * font with the current font variation settings applied.
1193
+ *
1194
+ * @param metricsTag {@link MetricsTag} of metrics value you like to fetch.
1195
+ * @returns The requested metric value.
1196
+ */
1197
+ getMetricXVariation(metricsTag) {
1198
+ return exports$1.hb_ot_metrics_get_x_variation(this.ptr, metricsTag);
1199
+ }
1200
+ /**
1201
+ * Fetches vertical metrics value corresponding to `metricsTag` from the font
1202
+ * with the current font variation settings applied.
1203
+ *
1204
+ * @param metricsTag {@link MetricsTag} of metrics value you like to fetch.
1205
+ * @returns The requested metric value.
1206
+ */
1207
+ getMetricYVariation(metricsTag) {
1208
+ return exports$1.hb_ot_metrics_get_y_variation(this.ptr, metricsTag);
1209
+ }
1210
+ };
1211
+ var FontFuncs = class {
1212
+ constructor() {
1213
+ this.ptr = exports$1.hb_font_funcs_create();
1214
+ track(this, exports$1.hb_font_funcs_destroy);
1215
+ }
1216
+ /**
1217
+ * Set the font's glyph extents function.
1218
+ * @param func The callback receives a Font and glyph ID. It should return
1219
+ * an object with xBearing, yBearing, width, and height, or undefined on failure.
1220
+ */
1221
+ setGlyphExtentsFunc(func) {
1222
+ const funcPtr = Module.addFunction((fontPtr, font_data, glyph, extentsPtr, user_data) => {
1223
+ const extents = func(new Font(fontPtr), glyph);
1224
+ if (extents) {
1225
+ Module.HEAP32[extentsPtr / 4] = extents.xBearing;
1226
+ Module.HEAP32[extentsPtr / 4 + 1] = extents.yBearing;
1227
+ Module.HEAP32[extentsPtr / 4 + 2] = extents.width;
1228
+ Module.HEAP32[extentsPtr / 4 + 3] = extents.height;
1229
+ return 1;
1230
+ }
1231
+ return 0;
1232
+ }, "ippipp");
1233
+ exports$1.hb_font_funcs_set_glyph_extents_func(this.ptr, funcPtr, 0, 0);
1234
+ }
1235
+ /**
1236
+ * Set the font's glyph from name function.
1237
+ * @param func The callback receives a Font and glyph name. It should return
1238
+ * the glyph ID, or undefined on failure.
1239
+ */
1240
+ setGlyphFromNameFunc(func) {
1241
+ const funcPtr = Module.addFunction((fontPtr, font_data, namePtr, len, glyphPtr, user_data) => {
1242
+ const glyph = func(new Font(fontPtr), utf8_ptr_to_string(namePtr, len));
1243
+ if (glyph) {
1244
+ Module.HEAPU32[glyphPtr / 4] = glyph;
1245
+ return 1;
1246
+ }
1247
+ return 0;
1248
+ }, "ipppipp");
1249
+ exports$1.hb_font_funcs_set_glyph_from_name_func(this.ptr, funcPtr, 0, 0);
1250
+ }
1251
+ /**
1252
+ * Set the font's glyph horizontal advance function.
1253
+ * @param func The callback receives a Font and glyph ID. It should return
1254
+ * the horizontal advance of the glyph.
1255
+ */
1256
+ setGlyphHAdvanceFunc(func) {
1257
+ const funcPtr = Module.addFunction((fontPtr, font_data, glyph, user_data) => {
1258
+ return func(new Font(fontPtr), glyph);
1259
+ }, "ippip");
1260
+ exports$1.hb_font_funcs_set_glyph_h_advance_func(this.ptr, funcPtr, 0, 0);
1261
+ }
1262
+ /**
1263
+ * Set the font's glyph vertical advance function.
1264
+ * @param func The callback receives a Font and glyph ID. It should return
1265
+ * the vertical advance of the glyph.
1266
+ */
1267
+ setGlyphVAdvanceFunc(func) {
1268
+ const funcPtr = Module.addFunction((fontPtr, font_data, glyph, user_data) => {
1269
+ return func(new Font(fontPtr), glyph);
1270
+ }, "ippip");
1271
+ exports$1.hb_font_funcs_set_glyph_v_advance_func(this.ptr, funcPtr, 0, 0);
1272
+ }
1273
+ /**
1274
+ * Set the font's glyph horizontal origin function.
1275
+ * @param func The callback receives a Font and glyph ID. It should return
1276
+ * the [x, y] horizontal origin of the glyph, or undefined on failure.
1277
+ */
1278
+ setGlyphHOriginFunc(func) {
1279
+ const funcPtr = Module.addFunction((fontPtr, font_data, glyph, xPtr, yPtr, user_data) => {
1280
+ const origin = func(new Font(fontPtr), glyph);
1281
+ if (origin) {
1282
+ Module.HEAP32[xPtr / 4] = origin[0];
1283
+ Module.HEAP32[yPtr / 4] = origin[1];
1284
+ return 1;
1285
+ }
1286
+ return 0;
1287
+ }, "ippippp");
1288
+ exports$1.hb_font_funcs_set_glyph_h_origin_func(this.ptr, funcPtr, 0, 0);
1289
+ }
1290
+ /**
1291
+ * Set the font's glyph vertical origin function.
1292
+ * @param func The callback receives a Font and glyph ID. It should return
1293
+ * the [x, y] vertical origin of the glyph, or undefined on failure.
1294
+ */
1295
+ setGlyphVOriginFunc(func) {
1296
+ const funcPtr = Module.addFunction((fontPtr, font_data, glyph, xPtr, yPtr, user_data) => {
1297
+ const origin = func(new Font(fontPtr), glyph);
1298
+ if (origin) {
1299
+ Module.HEAP32[xPtr / 4] = origin[0];
1300
+ Module.HEAP32[yPtr / 4] = origin[1];
1301
+ return 1;
1302
+ }
1303
+ return 0;
1304
+ }, "ippippp");
1305
+ exports$1.hb_font_funcs_set_glyph_v_origin_func(this.ptr, funcPtr, 0, 0);
1306
+ }
1307
+ /**
1308
+ * Set the font's glyph horizontal kerning function.
1309
+ * @param func The callback receives a Font, first glyph ID, and second glyph ID.
1310
+ * It should return the horizontal kerning of the glyphs.
1311
+ */
1312
+ setGlyphHKerningFunc(func) {
1313
+ const funcPtr = Module.addFunction((fontPtr, font_data, firstGlyph, secondGlyph, user_data) => {
1314
+ return func(new Font(fontPtr), firstGlyph, secondGlyph);
1315
+ }, "ippiip");
1316
+ exports$1.hb_font_funcs_set_glyph_h_kerning_func(this.ptr, funcPtr, 0, 0);
1317
+ }
1318
+ /**
1319
+ * Set the font's glyph name function.
1320
+ * @param func The callback receives a Font and glyph ID. It should return
1321
+ * the name of the glyph, or undefined on failure.
1322
+ */
1323
+ setGlyphNameFunc(func) {
1324
+ const utf8Encoder2 = new TextEncoder();
1325
+ const funcPtr = Module.addFunction((fontPtr, font_data, glyph, namePtr, size, user_data) => {
1326
+ const name = func(new Font(fontPtr), glyph);
1327
+ if (name) {
1328
+ utf8Encoder2.encodeInto(name, Module.HEAPU8.subarray(namePtr, namePtr + size));
1329
+ return 1;
1330
+ }
1331
+ return 0;
1332
+ }, "ippipip");
1333
+ exports$1.hb_font_funcs_set_glyph_name_func(this.ptr, funcPtr, 0, 0);
1334
+ }
1335
+ /**
1336
+ * Set the font's nominal glyph function.
1337
+ * @param func The callback receives a Font and unicode code point. It should
1338
+ * return the nominal glyph of the unicode, or undefined on failure.
1339
+ */
1340
+ setNominalGlyphFunc(func) {
1341
+ const funcPtr = Module.addFunction((fontPtr, font_data, unicode, glyphPtr, user_data) => {
1342
+ const glyph = func(new Font(fontPtr), unicode);
1343
+ if (glyph) {
1344
+ Module.HEAPU32[glyphPtr / 4] = glyph;
1345
+ return 1;
1346
+ }
1347
+ return 0;
1348
+ }, "ippipp");
1349
+ exports$1.hb_font_funcs_set_nominal_glyph_func(this.ptr, funcPtr, 0, 0);
1350
+ }
1351
+ /**
1352
+ * Set the font's variation glyph function.
1353
+ * @param func The callback receives a Font, unicode code point, and variation
1354
+ * selector. It should return the variation glyph, or undefined on failure.
1355
+ */
1356
+ setVariationGlyphFunc(func) {
1357
+ const funcPtr = Module.addFunction((fontPtr, font_data, unicode, variationSelector, glyphPtr, user_data) => {
1358
+ const glyph = func(new Font(fontPtr), unicode, variationSelector);
1359
+ if (glyph) {
1360
+ Module.HEAPU32[glyphPtr / 4] = glyph;
1361
+ return 1;
1362
+ }
1363
+ return 0;
1364
+ }, "ippiipp");
1365
+ exports$1.hb_font_funcs_set_variation_glyph_func(this.ptr, funcPtr, 0, 0);
1366
+ }
1367
+ /**
1368
+ * Set the font's horizontal extents function.
1369
+ * @param func The callback receives a Font. It should return an object with
1370
+ * ascender, descender, and lineGap, or undefined on failure.
1371
+ */
1372
+ setFontHExtentsFunc(func) {
1373
+ const funcPtr = Module.addFunction((fontPtr, font_data, extentsPtr, user_data) => {
1374
+ const extents = func(new Font(fontPtr));
1375
+ if (extents) {
1376
+ Module.HEAP32[extentsPtr / 4] = extents.ascender;
1377
+ Module.HEAP32[extentsPtr / 4 + 1] = extents.descender;
1378
+ Module.HEAP32[extentsPtr / 4 + 2] = extents.lineGap;
1379
+ return 1;
1380
+ }
1381
+ return 0;
1382
+ }, "ipppp");
1383
+ exports$1.hb_font_funcs_set_font_h_extents_func(this.ptr, funcPtr, 0, 0);
1384
+ }
1385
+ /**
1386
+ * Set the font's vertical extents function.
1387
+ * @param func The callback receives a Font. It should return an object with
1388
+ * ascender, descender, and lineGap, or undefined on failure.
1389
+ */
1390
+ setFontVExtentsFunc(func) {
1391
+ const funcPtr = Module.addFunction((fontPtr, font_data, extentsPtr, user_data) => {
1392
+ const extents = func(new Font(fontPtr));
1393
+ if (extents) {
1394
+ Module.HEAP32[extentsPtr / 4] = extents.ascender;
1395
+ Module.HEAP32[extentsPtr / 4 + 1] = extents.descender;
1396
+ Module.HEAP32[extentsPtr / 4 + 2] = extents.lineGap;
1397
+ return 1;
1398
+ }
1399
+ return 0;
1400
+ }, "ipppp");
1401
+ exports$1.hb_font_funcs_set_font_v_extents_func(this.ptr, funcPtr, 0, 0);
1402
+ }
1403
+ };
1404
+ function decode_color_line(colorLinePtr) {
1405
+ const extend = exports$1.hb_color_line_get_extend(colorLinePtr);
1406
+ const colorStops = [];
1407
+ const sp = Module.stackSave();
1408
+ const countPtr = Module.stackAlloc(4);
1409
+ const stopsPtr = Module.stackAlloc(1536);
1410
+ let startOffset = 0;
1411
+ let count = 128;
1412
+ while (count === 128) {
1413
+ Module.HEAPU32[countPtr / 4] = count;
1414
+ exports$1.hb_color_line_get_color_stops(colorLinePtr, startOffset, countPtr, stopsPtr);
1415
+ count = Module.HEAPU32[countPtr / 4];
1416
+ for (let i = 0; i < count; i++) {
1417
+ const o = (stopsPtr + i * 12) / 4;
1418
+ colorStops.push({
1419
+ offset: Module.HEAPF32[o],
1420
+ isForeground: Module.HEAPU32[o + 1] !== 0,
1421
+ color: color_from_int(Module.HEAPU32[o + 2])
1422
+ });
1423
+ }
1424
+ startOffset += count;
1425
+ }
1426
+ Module.stackRestore(sp);
1427
+ return {
1428
+ extend,
1429
+ colorStops
1430
+ };
1431
+ }
1432
+ var PaintFuncs = class {
1433
+ constructor() {
1434
+ this.funcPtrs = [];
1435
+ this.userDataPtrs = [];
1436
+ this.ptr = exports$1.hb_paint_funcs_create();
1437
+ const ptr = this.ptr;
1438
+ const funcPtrs = this.funcPtrs;
1439
+ const userDataPtrs = this.userDataPtrs;
1440
+ registry.register(this, () => {
1441
+ exports$1.hb_paint_funcs_destroy(ptr);
1442
+ for (const ptr2 of funcPtrs) Module.removeFunction(ptr2);
1443
+ for (const ptr2 of userDataPtrs) remove_callback_data_pointer(ptr2);
1444
+ });
1445
+ }
1446
+ /**
1447
+ * Sets the push-transform callback on the paint functions object.
1448
+ * @param func The push-transform callback.
1449
+ * @param userData Data to pass to `func`.
1450
+ */
1451
+ setPushTransformFunc(func, userData) {
1452
+ const userDataPtr = register_callback_data_pointer(userData);
1453
+ this.userDataPtrs.push(userDataPtr);
1454
+ const funcPtr = Module.addFunction((funcs, paintData, xx, yx, xy, yy, dx, dy, user) => func(xx, yx, xy, yy, dx, dy, get_callback_data(paintData), get_callback_data(user)), "viiffffffi");
1455
+ this.funcPtrs.push(funcPtr);
1456
+ exports$1.hb_paint_funcs_set_push_transform_func(this.ptr, funcPtr, userDataPtr, 0);
1457
+ }
1458
+ /**
1459
+ * Sets the pop-transform callback on the paint functions object.
1460
+ * @param func The pop-transform callback.
1461
+ * @param userData Data to pass to `func`.
1462
+ */
1463
+ setPopTransformFunc(func, userData) {
1464
+ const userDataPtr = register_callback_data_pointer(userData);
1465
+ this.userDataPtrs.push(userDataPtr);
1466
+ const funcPtr = Module.addFunction((funcs, paintData, user) => func(get_callback_data(paintData), get_callback_data(user)), "viii");
1467
+ this.funcPtrs.push(funcPtr);
1468
+ exports$1.hb_paint_funcs_set_pop_transform_func(this.ptr, funcPtr, userDataPtr, 0);
1469
+ }
1470
+ /**
1471
+ * Sets the color-glyph callback on the paint functions object.
1472
+ * @param func The color-glyph callback.
1473
+ * @param userData Data to pass to `func`.
1474
+ */
1475
+ setColorGlyphFunc(func, userData) {
1476
+ const userDataPtr = register_callback_data_pointer(userData);
1477
+ this.userDataPtrs.push(userDataPtr);
1478
+ const funcPtr = Module.addFunction((funcs, paintData, glyph, fontPtr, user) => func(glyph, new Font(fontPtr), get_callback_data(paintData), get_callback_data(user)) ? 1 : 0, "iiiiii");
1479
+ this.funcPtrs.push(funcPtr);
1480
+ exports$1.hb_paint_funcs_set_color_glyph_func(this.ptr, funcPtr, userDataPtr, 0);
1481
+ }
1482
+ /**
1483
+ * Sets the push-clip-glyph callback on the paint functions object.
1484
+ * @param func The push-clip-glyph callback.
1485
+ * @param userData Data to pass to `func`.
1486
+ */
1487
+ setPushClipGlyphFunc(func, userData) {
1488
+ const userDataPtr = register_callback_data_pointer(userData);
1489
+ this.userDataPtrs.push(userDataPtr);
1490
+ const funcPtr = Module.addFunction((funcs, paintData, glyph, fontPtr, user) => func(glyph, new Font(fontPtr), get_callback_data(paintData), get_callback_data(user)), "viiiii");
1491
+ this.funcPtrs.push(funcPtr);
1492
+ exports$1.hb_paint_funcs_set_push_clip_glyph_func(this.ptr, funcPtr, userDataPtr, 0);
1493
+ }
1494
+ /**
1495
+ * Sets the push-clip-rectangle callback on the paint functions object.
1496
+ * @param func The push-clip-rectangle callback.
1497
+ * @param userData Data to pass to `func`.
1498
+ */
1499
+ setPushClipRectangleFunc(func, userData) {
1500
+ const userDataPtr = register_callback_data_pointer(userData);
1501
+ this.userDataPtrs.push(userDataPtr);
1502
+ const funcPtr = Module.addFunction((funcs, paintData, xmin, ymin, xmax, ymax, user) => func(xmin, ymin, xmax, ymax, get_callback_data(paintData), get_callback_data(user)), "viiffffi");
1503
+ this.funcPtrs.push(funcPtr);
1504
+ exports$1.hb_paint_funcs_set_push_clip_rectangle_func(this.ptr, funcPtr, userDataPtr, 0);
1505
+ }
1506
+ /**
1507
+ * Sets the pop-clip callback on the paint functions object.
1508
+ * @param func The pop-clip callback.
1509
+ * @param userData Data to pass to `func`.
1510
+ */
1511
+ setPopClipFunc(func, userData) {
1512
+ const userDataPtr = register_callback_data_pointer(userData);
1513
+ this.userDataPtrs.push(userDataPtr);
1514
+ const funcPtr = Module.addFunction((funcs, paintData, user) => func(get_callback_data(paintData), get_callback_data(user)), "viii");
1515
+ this.funcPtrs.push(funcPtr);
1516
+ exports$1.hb_paint_funcs_set_pop_clip_func(this.ptr, funcPtr, userDataPtr, 0);
1517
+ }
1518
+ /**
1519
+ * Sets the paint-color callback on the paint functions object.
1520
+ * @param func The paint-color callback.
1521
+ * @param userData Data to pass to `func`.
1522
+ */
1523
+ setColorFunc(func, userData) {
1524
+ const userDataPtr = register_callback_data_pointer(userData);
1525
+ this.userDataPtrs.push(userDataPtr);
1526
+ const funcPtr = Module.addFunction((funcs, paintData, isForeground, color, user) => func(isForeground !== 0, color_from_int(color), get_callback_data(paintData), get_callback_data(user)), "viiiii");
1527
+ this.funcPtrs.push(funcPtr);
1528
+ exports$1.hb_paint_funcs_set_color_func(this.ptr, funcPtr, userDataPtr, 0);
1529
+ }
1530
+ /**
1531
+ * Sets the paint-image callback on the paint functions object.
1532
+ * @param func The paint-image callback.
1533
+ * @param userData Data to pass to `func`.
1534
+ */
1535
+ setImageFunc(func, userData) {
1536
+ const userDataPtr = register_callback_data_pointer(userData);
1537
+ this.userDataPtrs.push(userDataPtr);
1538
+ const funcPtr = Module.addFunction((funcs, paintData, blob, width, height, format, slant, extentsPtr, user) => {
1539
+ const length = exports$1.hb_blob_get_length(blob);
1540
+ const dataPtr = exports$1.hb_blob_get_data(blob, 0);
1541
+ const image = Module.HEAPU8.subarray(dataPtr, dataPtr + length);
1542
+ let extents;
1543
+ if (extentsPtr) extents = {
1544
+ xBearing: Module.HEAP32[extentsPtr / 4],
1545
+ yBearing: Module.HEAP32[extentsPtr / 4 + 1],
1546
+ width: Module.HEAP32[extentsPtr / 4 + 2],
1547
+ height: Module.HEAP32[extentsPtr / 4 + 3]
1548
+ };
1549
+ return func(image, width, height, hb_untag(format), extents, get_callback_data(paintData), get_callback_data(user)) ? 1 : 0;
1550
+ }, "iiiiiiifii");
1551
+ this.funcPtrs.push(funcPtr);
1552
+ exports$1.hb_paint_funcs_set_image_func(this.ptr, funcPtr, userDataPtr, 0);
1553
+ }
1554
+ /**
1555
+ * Sets the linear-gradient callback on the paint functions object.
1556
+ * @param func The linear-gradient callback.
1557
+ * @param userData Data to pass to `func`.
1558
+ */
1559
+ setLinearGradientFunc(func, userData) {
1560
+ const userDataPtr = register_callback_data_pointer(userData);
1561
+ this.userDataPtrs.push(userDataPtr);
1562
+ const funcPtr = Module.addFunction((funcs, paintData, colorLine, x0, y0, x1, y1, x2, y2, user) => func(decode_color_line(colorLine), x0, y0, x1, y1, x2, y2, get_callback_data(paintData), get_callback_data(user)), "viiiffffffi");
1563
+ this.funcPtrs.push(funcPtr);
1564
+ exports$1.hb_paint_funcs_set_linear_gradient_func(this.ptr, funcPtr, userDataPtr, 0);
1565
+ }
1566
+ /**
1567
+ * Sets the radial-gradient callback on the paint functions object.
1568
+ * @param func The radial-gradient callback.
1569
+ * @param userData Data to pass to `func`.
1570
+ */
1571
+ setRadialGradientFunc(func, userData) {
1572
+ const userDataPtr = register_callback_data_pointer(userData);
1573
+ this.userDataPtrs.push(userDataPtr);
1574
+ const funcPtr = Module.addFunction((funcs, paintData, colorLine, x0, y0, r0, x1, y1, r1, user) => func(decode_color_line(colorLine), x0, y0, r0, x1, y1, r1, get_callback_data(paintData), get_callback_data(user)), "viiiffffffi");
1575
+ this.funcPtrs.push(funcPtr);
1576
+ exports$1.hb_paint_funcs_set_radial_gradient_func(this.ptr, funcPtr, userDataPtr, 0);
1577
+ }
1578
+ /**
1579
+ * Sets the sweep-gradient callback on the paint functions object.
1580
+ * @param func The sweep-gradient callback.
1581
+ * @param userData Data to pass to `func`.
1582
+ */
1583
+ setSweepGradientFunc(func, userData) {
1584
+ const userDataPtr = register_callback_data_pointer(userData);
1585
+ this.userDataPtrs.push(userDataPtr);
1586
+ const funcPtr = Module.addFunction((funcs, paintData, colorLine, x0, y0, startAngle, endAngle, user) => func(decode_color_line(colorLine), x0, y0, startAngle, endAngle, get_callback_data(paintData), get_callback_data(user)), "viiiffffi");
1587
+ this.funcPtrs.push(funcPtr);
1588
+ exports$1.hb_paint_funcs_set_sweep_gradient_func(this.ptr, funcPtr, userDataPtr, 0);
1589
+ }
1590
+ /**
1591
+ * Sets the push-group callback on the paint functions object.
1592
+ * @param func The push-group callback.
1593
+ * @param userData Data to pass to `func`.
1594
+ */
1595
+ setPushGroupFunc(func, userData) {
1596
+ const userDataPtr = register_callback_data_pointer(userData);
1597
+ this.userDataPtrs.push(userDataPtr);
1598
+ const funcPtr = Module.addFunction((funcs, paintData, user) => func(get_callback_data(paintData), get_callback_data(user)), "viii");
1599
+ this.funcPtrs.push(funcPtr);
1600
+ exports$1.hb_paint_funcs_set_push_group_func(this.ptr, funcPtr, userDataPtr, 0);
1601
+ }
1602
+ /**
1603
+ * Sets the pop-group callback on the paint functions object.
1604
+ * @param func The pop-group callback.
1605
+ * @param userData Data to pass to `func`.
1606
+ */
1607
+ setPopGroupFunc(func, userData) {
1608
+ const userDataPtr = register_callback_data_pointer(userData);
1609
+ this.userDataPtrs.push(userDataPtr);
1610
+ const funcPtr = Module.addFunction((funcs, paintData, mode, user) => func(mode, get_callback_data(paintData), get_callback_data(user)), "viiii");
1611
+ this.funcPtrs.push(funcPtr);
1612
+ exports$1.hb_paint_funcs_set_pop_group_func(this.ptr, funcPtr, userDataPtr, 0);
1613
+ }
1614
+ /**
1615
+ * Sets the custom-palette-color callback on the paint functions object.
1616
+ * @param func The custom-palette-color callback.
1617
+ * @param userData Data to pass to `func`.
1618
+ */
1619
+ setCustomPaletteColorFunc(func, userData) {
1620
+ const userDataPtr = register_callback_data_pointer(userData);
1621
+ this.userDataPtrs.push(userDataPtr);
1622
+ const funcPtr = Module.addFunction((funcs, paintData, colorIndex, colorPtr, user) => {
1623
+ const color = func(colorIndex, get_callback_data(paintData), get_callback_data(user));
1624
+ if (color !== void 0) {
1625
+ Module.HEAPU32[colorPtr / 4] = color_to_int(color);
1626
+ return 1;
1627
+ }
1628
+ return 0;
1629
+ }, "iiiiii");
1630
+ this.funcPtrs.push(funcPtr);
1631
+ exports$1.hb_paint_funcs_set_custom_palette_color_func(this.ptr, funcPtr, userDataPtr, 0);
1632
+ }
1633
+ };
1634
+ var BufferContentType = {
1635
+ INVALID: 0,
1636
+ UNICODE: 1,
1637
+ GLYPHS: 2
1638
+ };
1639
+ var BufferSerializeFlag = {
1640
+ DEFAULT: 0,
1641
+ NO_CLUSTERS: 1,
1642
+ NO_POSITIONS: 2,
1643
+ NO_GLYPH_NAMES: 4,
1644
+ GLYPH_EXTENTS: 8,
1645
+ GLYPH_FLAGS: 16,
1646
+ NO_ADVANCES: 32,
1647
+ DEFINED: 63
1648
+ };
1649
+ var BufferFlag = {
1650
+ DEFAULT: 0,
1651
+ BOT: 1,
1652
+ EOT: 2,
1653
+ PRESERVE_DEFAULT_IGNORABLES: 4,
1654
+ REMOVE_DEFAULT_IGNORABLES: 8,
1655
+ DO_NOT_INSERT_DOTTED_CIRCLE: 16,
1656
+ VERIFY: 32,
1657
+ PRODUCE_UNSAFE_TO_CONCAT: 64,
1658
+ PRODUCE_SAFE_TO_INSERT_TATWEEL: 128,
1659
+ DEFINED: 255
1660
+ };
1661
+ var Direction = {
1662
+ INVALID: 0,
1663
+ LTR: 4,
1664
+ RTL: 5,
1665
+ TTB: 6,
1666
+ BTT: 7
1667
+ };
1668
+ var ClusterLevel = {
1669
+ MONOTONE_GRAPHEMES: 0,
1670
+ MONOTONE_CHARACTERS: 1,
1671
+ CHARACTERS: 2,
1672
+ GRAPHEMES: 3,
1673
+ DEFAULT: 0
1674
+ };
1675
+ var BufferSerializeFormat = {
1676
+ INVALID: 0,
1677
+ TEXT: hb_tag("TEXT"),
1678
+ JSON: hb_tag("JSON")
1679
+ };
1680
+ var Buffer = class Buffer2 {
1681
+ /**
1682
+ * @param existingPtr @internal Wrap an existing buffer pointer.
1683
+ */
1684
+ constructor(existingPtr) {
1685
+ if (existingPtr != void 0) this.ptr = exports$1.hb_buffer_reference(existingPtr);
1686
+ else this.ptr = exports$1.hb_buffer_create();
1687
+ track(this, exports$1.hb_buffer_destroy);
1688
+ }
1689
+ /**
1690
+ * Appends a character with the Unicode value of `codePoint` to the buffer,
1691
+ * and gives it the initial cluster value of `cluster`. Clusters can be any
1692
+ * thing the client wants, they are usually used to refer to the index of the
1693
+ * character in the input text stream and are output in the `cluster` field
1694
+ * of {@link GlyphInfo}.
1695
+ *
1696
+ * This function does not check the validity of `codePoint`, it is up to the
1697
+ * caller to ensure it is a valid Unicode code point.
1698
+ * @param codePoint A Unicode code point.
1699
+ * @param cluster The cluster value of `codePoint`.
1700
+ */
1701
+ add(codePoint, cluster) {
1702
+ exports$1.hb_buffer_add(this.ptr, codePoint, cluster);
1703
+ }
1704
+ /**
1705
+ * Add text to the buffer.
1706
+ * @param text Text to be added to the buffer.
1707
+ * @param itemOffset The offset of the first character to add to the buffer.
1708
+ * @param itemLength The number of characters to add to the buffer, or omit for the end of text.
1709
+ */
1710
+ addText(text, itemOffset = 0, itemLength) {
1711
+ const str = string_to_utf16_ptr(text);
1712
+ exports$1.hb_buffer_add_utf16(this.ptr, str.ptr, str.length, itemOffset, itemLength ?? str.length);
1713
+ str.free();
1714
+ }
1715
+ /**
1716
+ * Add code points to the buffer.
1717
+ * @param codePoints Array of code points to be added to the buffer.
1718
+ * @param itemOffset The offset of the first code point to add to the buffer.
1719
+ * @param itemLength The number of code points to add to the buffer, or omit for the end of the array.
1720
+ */
1721
+ addCodePoints(codePoints, itemOffset = 0, itemLength) {
1722
+ const codePointsPtr = exports$1.malloc(codePoints.length * 4);
1723
+ Module.HEAPU32.subarray(codePointsPtr / 4, codePointsPtr / 4 + codePoints.length).set(codePoints);
1724
+ exports$1.hb_buffer_add_codepoints(this.ptr, codePointsPtr, codePoints.length, itemOffset, itemLength ?? codePoints.length);
1725
+ exports$1.free(codePointsPtr);
1726
+ }
1727
+ /**
1728
+ * Set buffer script, language and direction.
1729
+ *
1730
+ * This needs to be done before shaping.
1731
+ */
1732
+ guessSegmentProperties() {
1733
+ exports$1.hb_buffer_guess_segment_properties(this.ptr);
1734
+ }
1735
+ /**
1736
+ * Set buffer direction explicitly.
1737
+ * @param dir A {@link Direction} value.
1738
+ */
1739
+ setDirection(dir) {
1740
+ exports$1.hb_buffer_set_direction(this.ptr, dir);
1741
+ }
1742
+ /**
1743
+ * Set buffer flags explicitly.
1744
+ * @param flags A combination of {@link BufferFlag} values (OR them together).
1745
+ */
1746
+ setFlags(flags) {
1747
+ exports$1.hb_buffer_set_flags(this.ptr, flags);
1748
+ }
1749
+ /**
1750
+ * Set buffer language explicitly.
1751
+ * @param language The buffer language
1752
+ */
1753
+ setLanguage(language) {
1754
+ const str = string_to_ascii_ptr(language);
1755
+ exports$1.hb_buffer_set_language(this.ptr, exports$1.hb_language_from_string(str.ptr, -1));
1756
+ str.free();
1757
+ }
1758
+ /**
1759
+ * Set buffer script explicitly.
1760
+ * @param script The buffer script
1761
+ */
1762
+ setScript(script) {
1763
+ const str = string_to_ascii_ptr(script);
1764
+ exports$1.hb_buffer_set_script(this.ptr, exports$1.hb_script_from_string(str.ptr, -1));
1765
+ str.free();
1766
+ }
1767
+ /**
1768
+ * Set the HarfBuzz clustering level.
1769
+ *
1770
+ * Affects the cluster values returned from shaping.
1771
+ * @param level A {@link ClusterLevel} value. See the HarfBuzz manual chapter on Clusters.
1772
+ */
1773
+ setClusterLevel(level) {
1774
+ exports$1.hb_buffer_set_cluster_level(this.ptr, level);
1775
+ }
1776
+ /** Reset the buffer to its initial status. */
1777
+ reset() {
1778
+ exports$1.hb_buffer_reset(this.ptr);
1779
+ }
1780
+ /**
1781
+ * Similar to reset(), but does not clear the Unicode functions and the
1782
+ * replacement code point.
1783
+ */
1784
+ clearContents() {
1785
+ exports$1.hb_buffer_clear_contents(this.ptr);
1786
+ }
1787
+ /**
1788
+ * Set message func.
1789
+ * @param func The function to set. It receives the buffer, font, and message
1790
+ * string as arguments. Returning false will skip this shaping step and move
1791
+ * to the next one.
1792
+ */
1793
+ setMessageFunc(func) {
1794
+ const traceFunc = (bufferPtr, fontPtr, messagePtr, user_data) => {
1795
+ const message = utf8_ptr_to_string(messagePtr);
1796
+ return func(new Buffer2(bufferPtr), new Font(fontPtr), message) ? 1 : 0;
1797
+ };
1798
+ const traceFuncPtr = Module.addFunction(traceFunc, "iiiii");
1799
+ exports$1.hb_buffer_set_message_func(this.ptr, traceFuncPtr, 0, 0);
1800
+ }
1801
+ /**
1802
+ * Get the the number of items in the buffer.
1803
+ * @returns The buffer length.
1804
+ */
1805
+ getLength() {
1806
+ return exports$1.hb_buffer_get_length(this.ptr);
1807
+ }
1808
+ /**
1809
+ * Get the glyph information from the buffer.
1810
+ * @returns An array of {@link GlyphInfo} objects.
1811
+ */
1812
+ getGlyphInfos() {
1813
+ const infosPtr = exports$1.hb_buffer_get_glyph_infos(this.ptr, 0);
1814
+ const infosArray = Module.HEAPU32.subarray(infosPtr / 4, infosPtr / 4 + this.getLength() * 5);
1815
+ const infos = [];
1816
+ for (let i = 0; i < infosArray.length; i += 5) infos.push({
1817
+ codepoint: infosArray[i],
1818
+ cluster: infosArray[i + 2],
1819
+ flags: exports$1.hb_glyph_info_get_glyph_flags(infosPtr + i * 4)
1820
+ });
1821
+ return infos;
1822
+ }
1823
+ /**
1824
+ * Get the glyph positions from the buffer.
1825
+ * @returns An array of {@link GlyphPosition} objects.
1826
+ */
1827
+ getGlyphPositions() {
1828
+ const positionsPtr32 = exports$1.hb_buffer_get_glyph_positions(this.ptr, 0) / 4;
1829
+ if (positionsPtr32 == 0) return [];
1830
+ const positionsArray = Module.HEAP32.subarray(positionsPtr32, positionsPtr32 + this.getLength() * 5);
1831
+ const positions = [];
1832
+ for (let i = 0; i < positionsArray.length; i += 5) positions.push({
1833
+ xAdvance: positionsArray[i],
1834
+ yAdvance: positionsArray[i + 1],
1835
+ xOffset: positionsArray[i + 2],
1836
+ yOffset: positionsArray[i + 3]
1837
+ });
1838
+ return positions;
1839
+ }
1840
+ /**
1841
+ * Get the glyph information and positions from the buffer.
1842
+ * @returns The glyph information and positions.
1843
+ *
1844
+ * The glyph information is returned as an array of objects with the
1845
+ * properties from getGlyphInfos and getGlyphPositions combined.
1846
+ */
1847
+ getGlyphInfosAndPositions() {
1848
+ const infosPtr = exports$1.hb_buffer_get_glyph_infos(this.ptr, 0);
1849
+ const infosArray = Module.HEAPU32.subarray(infosPtr / 4, infosPtr / 4 + this.getLength() * 5);
1850
+ const positionsPtr32 = exports$1.hb_buffer_get_glyph_positions(this.ptr, 0) / 4;
1851
+ const positionsArray = positionsPtr32 ? Module.HEAP32.subarray(positionsPtr32, positionsPtr32 + this.getLength() * 5) : void 0;
1852
+ const out = [];
1853
+ for (let i = 0; i < infosArray.length; i += 5) {
1854
+ const info = {
1855
+ codepoint: infosArray[i],
1856
+ cluster: infosArray[i + 2],
1857
+ flags: exports$1.hb_glyph_info_get_glyph_flags(infosPtr + i * 4)
1858
+ };
1859
+ for (const [name, idx] of [
1860
+ ["mask", 1],
1861
+ ["var1", 3],
1862
+ ["var2", 4]
1863
+ ]) Object.defineProperty(info, name, {
1864
+ value: infosArray[i + idx],
1865
+ enumerable: false
1866
+ });
1867
+ if (positionsArray) {
1868
+ info.xAdvance = positionsArray[i];
1869
+ info.yAdvance = positionsArray[i + 1];
1870
+ info.xOffset = positionsArray[i + 2];
1871
+ info.yOffset = positionsArray[i + 3];
1872
+ Object.defineProperty(info, "var", {
1873
+ value: positionsArray[i + 4],
1874
+ enumerable: false
1875
+ });
1876
+ }
1877
+ out.push(info);
1878
+ }
1879
+ return out;
1880
+ }
1881
+ /**
1882
+ * Update the glyph positions in the buffer.
1883
+ * WARNING: Do not use unless you know what you are doing.
1884
+ */
1885
+ updateGlyphPositions(positions) {
1886
+ const positionsPtr32 = exports$1.hb_buffer_get_glyph_positions(this.ptr, 0) / 4;
1887
+ if (positionsPtr32 == 0) return;
1888
+ const len = Math.min(positions.length, this.getLength());
1889
+ const positionsArray = Module.HEAP32.subarray(positionsPtr32, positionsPtr32 + len * 5);
1890
+ for (let i = 0; i < len; i++) {
1891
+ positionsArray[i * 5] = positions[i].xAdvance;
1892
+ positionsArray[i * 5 + 1] = positions[i].yAdvance;
1893
+ positionsArray[i * 5 + 2] = positions[i].xOffset;
1894
+ positionsArray[i * 5 + 3] = positions[i].yOffset;
1895
+ }
1896
+ }
1897
+ /**
1898
+ * Serialize the buffer contents to a string.
1899
+ * @param options Serialization options:
1900
+ * - `font`: the font to use for serialization;
1901
+ * - `start`: the starting index of the glyphs (default `0`);
1902
+ * - `end`: the ending index of the glyphs (default end of buffer);
1903
+ * - `format`: a {@link BufferSerializeFormat} value (default `TEXT`);
1904
+ * - `flags`: a combination of {@link BufferSerializeFlag} values (default `0`).
1905
+ * @returns The serialized buffer contents.
1906
+ */
1907
+ serialize(options = {}) {
1908
+ let { font, start = 0, end, format = BufferSerializeFormat.TEXT, flags = 0 } = options;
1909
+ const sp = Module.stackSave();
1910
+ const endPos = end ?? this.getLength();
1911
+ const bufLen = 32 * 1024;
1912
+ const bufPtr = exports$1.malloc(bufLen);
1913
+ const bufConsumedPtr = Module.stackAlloc(4);
1914
+ let result = "";
1915
+ while (start < endPos) {
1916
+ start += exports$1.hb_buffer_serialize(this.ptr, start, endPos, bufPtr, bufLen, bufConsumedPtr, font ? font.ptr : 0, format, flags);
1917
+ const bufConsumed = Module.HEAPU32[bufConsumedPtr / 4];
1918
+ if (bufConsumed == 0) break;
1919
+ result += utf8_ptr_to_string(bufPtr, bufConsumed);
1920
+ }
1921
+ exports$1.free(bufPtr);
1922
+ Module.stackRestore(sp);
1923
+ return result;
1924
+ }
1925
+ /**
1926
+ * Return the buffer content type.
1927
+ *
1928
+ * @returns The buffer content type as a {@link BufferContentType} value.
1929
+ */
1930
+ getContentType() {
1931
+ return exports$1.hb_buffer_get_content_type(this.ptr);
1932
+ }
1933
+ };
1934
+ var Feature = class Feature2 {
1935
+ static {
1936
+ this.GLOBAL_START = 0;
1937
+ }
1938
+ static {
1939
+ this.GLOBAL_END = 4294967295;
1940
+ }
1941
+ constructor(tag, value = 1, start = Feature2.GLOBAL_START, end = Feature2.GLOBAL_END) {
1942
+ this.tag = tag;
1943
+ this.value = value;
1944
+ this.start = start;
1945
+ this.end = end;
1946
+ }
1947
+ /**
1948
+ * Parses a string into a Feature.
1949
+ *
1950
+ * The format for specifying feature strings follows. All valid CSS
1951
+ * font-feature-settings values other than `normal` and the global values are
1952
+ * also accepted, though not documented below. CSS string escapes are not
1953
+ * supported.
1954
+ *
1955
+ * The range indices refer to the positions between Unicode characters. The
1956
+ * position before the first character is always 0.
1957
+ *
1958
+ * The format is Python-esque. Here is how it all works:
1959
+ *
1960
+ * | Syntax | Value | Start | End | Meaning |
1961
+ * | ------------- | ----- | ----- | --- | -------------------------------- |
1962
+ * | `kern` | 1 | 0 | ∞ | Turn feature on |
1963
+ * | `+kern` | 1 | 0 | ∞ | Turn feature on |
1964
+ * | `-kern` | 0 | 0 | ∞ | Turn feature off |
1965
+ * | `kern=0` | 0 | 0 | ∞ | Turn feature off |
1966
+ * | `kern=1` | 1 | 0 | ∞ | Turn feature on |
1967
+ * | `aalt=2` | 2 | 0 | ∞ | Choose 2nd alternate |
1968
+ * | `kern[]` | 1 | 0 | ∞ | Turn feature on |
1969
+ * | `kern[:]` | 1 | 0 | ∞ | Turn feature on |
1970
+ * | `kern[5:]` | 1 | 5 | ∞ | Turn feature on, partial |
1971
+ * | `kern[:5]` | 1 | 0 | 5 | Turn feature on, partial |
1972
+ * | `kern[3:5]` | 1 | 3 | 5 | Turn feature on, range |
1973
+ * | `kern[3]` | 1 | 3 | 3+1 | Turn feature on, single char |
1974
+ * | `aalt[3:5]=2` | 2 | 3 | 5 | Turn 2nd alternate on for range |
1975
+ *
1976
+ * @param str The string to parse.
1977
+ * @returns A Feature, or undefined if the string is not a valid feature.
1978
+ */
1979
+ static fromString(str) {
1980
+ const sp = Module.stackSave();
1981
+ const featurePtr = Module.stackAlloc(16);
1982
+ const strPtr = string_to_ascii_ptr(str);
1983
+ let feature;
1984
+ if (exports$1.hb_feature_from_string(strPtr.ptr, -1, featurePtr)) feature = new Feature2(hb_untag(Module.HEAPU32[featurePtr / 4]), Module.HEAPU32[featurePtr / 4 + 1], Module.HEAPU32[featurePtr / 4 + 2], Module.HEAPU32[featurePtr / 4 + 3]);
1985
+ strPtr.free();
1986
+ Module.stackRestore(sp);
1987
+ return feature;
1988
+ }
1989
+ /**
1990
+ * Converts the feature to a string in the format understood by
1991
+ * {@link Feature.fromString}.
1992
+ *
1993
+ * Note that the feature value will be omitted if it is `1`, but the string
1994
+ * won't include any whitespace.
1995
+ *
1996
+ * @returns The feature string.
1997
+ */
1998
+ toString() {
1999
+ const sp = Module.stackSave();
2000
+ const featurePtr = Module.stackAlloc(16);
2001
+ this.writeTo(featurePtr);
2002
+ const bufLen = 128;
2003
+ const bufPtr = Module.stackAlloc(bufLen);
2004
+ exports$1.hb_feature_to_string(featurePtr, bufPtr, bufLen);
2005
+ const result = utf8_ptr_to_string(bufPtr);
2006
+ Module.stackRestore(sp);
2007
+ return result;
2008
+ }
2009
+ /** @internal Write this feature into the given hb_feature_t pointer. */
2010
+ writeTo(ptr) {
2011
+ Module.HEAPU32[ptr / 4] = hb_tag(this.tag);
2012
+ Module.HEAPU32[ptr / 4 + 1] = this.value;
2013
+ Module.HEAPU32[ptr / 4 + 2] = this.start;
2014
+ Module.HEAPU32[ptr / 4 + 3] = this.end;
2015
+ }
2016
+ };
2017
+ var Variation = class Variation2 {
2018
+ constructor(tag, value = 0) {
2019
+ this.tag = tag;
2020
+ this.value = value;
2021
+ }
2022
+ /**
2023
+ * Parses a string into a Variation.
2024
+ *
2025
+ * The format for specifying variation settings follows. All valid CSS
2026
+ * font-variation-settings values other than `normal` and `inherited` are
2027
+ * also accepted, though, not documented below.
2028
+ *
2029
+ * The format is a tag, optionally followed by an equals sign, followed by a
2030
+ * number. For example `wght=500`, or `slnt=-7.5`.
2031
+ *
2032
+ * @param str The string to parse.
2033
+ * @returns A Variation, or undefined if the string is not a valid variation.
2034
+ */
2035
+ static fromString(str) {
2036
+ const sp = Module.stackSave();
2037
+ const variationPtr = Module.stackAlloc(8);
2038
+ const strPtr = string_to_ascii_ptr(str);
2039
+ let variation;
2040
+ if (exports$1.hb_variation_from_string(strPtr.ptr, -1, variationPtr)) variation = new Variation2(hb_untag(Module.HEAPU32[variationPtr / 4]), Module.HEAPF32[variationPtr / 4 + 1]);
2041
+ strPtr.free();
2042
+ Module.stackRestore(sp);
2043
+ return variation;
2044
+ }
2045
+ /**
2046
+ * Converts the variation to a string in the format understood by
2047
+ * {@link Variation.fromString}.
2048
+ *
2049
+ * Note that the string won't include any whitespace.
2050
+ *
2051
+ * @returns The variation string.
2052
+ */
2053
+ toString() {
2054
+ const sp = Module.stackSave();
2055
+ const variationPtr = Module.stackAlloc(8);
2056
+ this.writeTo(variationPtr);
2057
+ const bufLen = 128;
2058
+ const bufPtr = Module.stackAlloc(bufLen);
2059
+ exports$1.hb_variation_to_string(variationPtr, bufPtr, bufLen);
2060
+ const result = utf8_ptr_to_string(bufPtr);
2061
+ Module.stackRestore(sp);
2062
+ return result;
2063
+ }
2064
+ /** @internal Write this variation into the given hb_variation_t pointer. */
2065
+ writeTo(ptr) {
2066
+ Module.HEAPU32[ptr / 4] = hb_tag(this.tag);
2067
+ Module.HEAPF32[ptr / 4 + 1] = this.value;
2068
+ }
2069
+ };
2070
+ var TracePhase = {
2071
+ DONT_STOP: 0,
2072
+ GSUB: 1,
2073
+ GPOS: 2
2074
+ };
2075
+ function shape(font, buffer, features) {
2076
+ const featuresLen = features?.length ?? 0;
2077
+ const sp = Module.stackSave();
2078
+ let featuresPtr = 0;
2079
+ if (featuresLen) {
2080
+ featuresPtr = Module.stackAlloc(16 * featuresLen);
2081
+ features.forEach((feature, i) => {
2082
+ feature.writeTo(featuresPtr + i * 16);
2083
+ });
2084
+ }
2085
+ exports$1.hb_shape(font.ptr, buffer.ptr, featuresPtr, featuresLen);
2086
+ Module.stackRestore(sp);
2087
+ }
2088
+ function shapeWithTrace(font, buffer, features, stop_at, stop_phase) {
2089
+ const trace = [];
2090
+ let currentPhase = TracePhase.DONT_STOP;
2091
+ let stopping = false;
2092
+ buffer.setMessageFunc((buffer2, font2, message) => {
2093
+ if (message.startsWith("start table GSUB")) currentPhase = TracePhase.GSUB;
2094
+ else if (message.startsWith("start table GPOS")) currentPhase = TracePhase.GPOS;
2095
+ if (currentPhase != stop_phase) stopping = false;
2096
+ if (stop_phase != TracePhase.DONT_STOP && currentPhase == stop_phase && message.startsWith("end lookup " + stop_at)) stopping = true;
2097
+ if (stopping) return false;
2098
+ const traceBuf = buffer2.serialize({
2099
+ font: font2,
2100
+ format: BufferSerializeFormat.JSON,
2101
+ flags: BufferSerializeFlag.NO_GLYPH_NAMES
2102
+ });
2103
+ trace.push({
2104
+ m: message,
2105
+ t: JSON.parse(traceBuf),
2106
+ glyphs: buffer2.getContentType() == BufferContentType.GLYPHS
2107
+ });
2108
+ return true;
2109
+ });
2110
+ shape(font, buffer, features);
2111
+ return trace;
2112
+ }
2113
+ function version() {
2114
+ const sp = Module.stackSave();
2115
+ const versionPtr = Module.stackAlloc(12);
2116
+ exports$1.hb_version(versionPtr, versionPtr + 4, versionPtr + 8);
2117
+ const ver = {
2118
+ major: Module.HEAPU32[versionPtr / 4],
2119
+ minor: Module.HEAPU32[(versionPtr + 4) / 4],
2120
+ micro: Module.HEAPU32[(versionPtr + 8) / 4]
2121
+ };
2122
+ Module.stackRestore(sp);
2123
+ return ver;
2124
+ }
2125
+ function versionString() {
2126
+ return utf8_ptr_to_string(exports$1.hb_version_string());
2127
+ }
2128
+ function otTagToScript(tag) {
2129
+ const hbTag = hb_tag(tag);
2130
+ return hb_untag(exports$1.hb_ot_tag_to_script(hbTag));
2131
+ }
2132
+ function otTagToLanguage(tag) {
2133
+ const hbTag = hb_tag(tag);
2134
+ return language_to_string(exports$1.hb_ot_tag_to_language(hbTag));
2135
+ }
2136
+ var HB_OT_MAX_TAGS_PER_LANGUAGE = 3;
2137
+ var HB_OT_MAX_TAGS_PER_SCRIPT = 3;
2138
+ function otTagsFromScriptAndLanguage(script, language) {
2139
+ const sp = Module.stackSave();
2140
+ const scriptStr = string_to_ascii_ptr(script);
2141
+ const languageStr = string_to_ascii_ptr(language);
2142
+ const scriptCountPtr = Module.stackAlloc(4);
2143
+ Module.HEAPU32[scriptCountPtr / 4] = HB_OT_MAX_TAGS_PER_SCRIPT;
2144
+ const scriptTagsPtr = Module.stackAlloc(HB_OT_MAX_TAGS_PER_SCRIPT * 4);
2145
+ const languageCountPtr = Module.stackAlloc(4);
2146
+ Module.HEAPU32[languageCountPtr / 4] = HB_OT_MAX_TAGS_PER_LANGUAGE;
2147
+ const languageTagsPtr = Module.stackAlloc(HB_OT_MAX_TAGS_PER_LANGUAGE * 4);
2148
+ exports$1.hb_ot_tags_from_script_and_language(exports$1.hb_script_from_string(scriptStr.ptr, -1), exports$1.hb_language_from_string(languageStr.ptr, -1), scriptCountPtr, scriptTagsPtr, languageCountPtr, languageTagsPtr);
2149
+ scriptStr.free();
2150
+ languageStr.free();
2151
+ const scriptTags = Module.HEAPU32.subarray(scriptTagsPtr / 4, scriptTagsPtr / 4 + Module.HEAPU32[scriptCountPtr / 4]);
2152
+ const languageTags = Module.HEAPU32.subarray(languageTagsPtr / 4, languageTagsPtr / 4 + Module.HEAPU32[languageCountPtr / 4]);
2153
+ Module.stackRestore(sp);
2154
+ return {
2155
+ scriptTags: [...scriptTags].map(hb_untag),
2156
+ languageTags: [...languageTags].map(hb_untag)
2157
+ };
2158
+ }
2159
+ function otTagsToScriptAndLanguage(scriptTag, languageTag) {
2160
+ const sp = Module.stackSave();
2161
+ const scriptPtr = Module.stackAlloc(4);
2162
+ const languagePtr = Module.stackAlloc(4);
2163
+ exports$1.hb_ot_tags_to_script_and_language(hb_tag(scriptTag), hb_tag(languageTag), scriptPtr, languagePtr);
2164
+ const script = Module.HEAPU32[scriptPtr / 4];
2165
+ const language = Module.HEAPU32[languagePtr / 4];
2166
+ Module.stackRestore(sp);
2167
+ return {
2168
+ script: hb_untag(script),
2169
+ language: language_to_string(language)
2170
+ };
2171
+ }
2172
+
2173
+ export { AxisFlags, Blob, Buffer, BufferContentType, BufferFlag, BufferSerializeFlag, BufferSerializeFormat, ClusterLevel, ColorPaletteFlags, Direction, DrawFuncs, Face, Feature, Font, FontFuncs, GlyphClass, GlyphFlag, MetricsTag, PaintCompositeMode, PaintExtend, PaintFuncs, TracePhase, Variation, init, otTagToLanguage, otTagToScript, otTagsFromScriptAndLanguage, otTagsToScriptAndLanguage, shape, shapeWithTrace, version, versionString };
2174
+ //# sourceMappingURL=harfbuzzjs-GV2DMLBC.js.map
2175
+ //# sourceMappingURL=harfbuzzjs-GV2DMLBC.js.map