text-shape 0.1.3 → 0.1.5
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/README.md +40 -20
- package/dist/font.d.ts +36 -2
- package/dist/font.d.ts.map +1 -1
- package/dist/font.js +65 -0
- package/dist/font.js.map +1 -1
- package/dist/typography.d.ts +4 -1
- package/dist/typography.d.ts.map +1 -1
- package/dist/typography.js.map +1 -1
- package/package.json +1 -1
- package/src/font.ts +84 -3
- package/src/typography.ts +4 -1
- package/wasm/text_shape.d.ts +117 -1
- package/wasm/text_shape.js +181 -0
- package/wasm/text_shape_bg.wasm +0 -0
- package/wasm/text_shape_bg.wasm.d.ts +12 -0
- package/wasm/text_shape_wasm_base64.js +1 -1
package/wasm/text_shape.d.ts
CHANGED
|
@@ -50,6 +50,51 @@ export function resolve_style(font_id: number, style: FontStyle | null | undefin
|
|
|
50
50
|
* current variations.
|
|
51
51
|
*/
|
|
52
52
|
export function get_outline(font_id: number, glyph_id: number, flip_y?: boolean | null): PathCommand[];
|
|
53
|
+
/**
|
|
54
|
+
* Names and basic facts from the `name`, `head` and `OS/2` tables.
|
|
55
|
+
*/
|
|
56
|
+
export function get_font_info(font_id: number): FontInfo;
|
|
57
|
+
/**
|
|
58
|
+
* A name from the `name` table by ID, in US English if available, otherwise
|
|
59
|
+
* English, otherwise the first one.
|
|
60
|
+
*/
|
|
61
|
+
export function get_name(font_id: number, name_id: number): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Every decodable string in the `name` table, by ID.
|
|
64
|
+
*/
|
|
65
|
+
export function get_names(font_id: number): NameEntry[];
|
|
66
|
+
/**
|
|
67
|
+
* The glyph the character map gives a code point, or undefined.
|
|
68
|
+
*/
|
|
69
|
+
export function get_glyph_id(font_id: number, code_point: number): number | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Every code point the character map covers, in order.
|
|
72
|
+
*/
|
|
73
|
+
export function get_characters(font_id: number): Uint32Array;
|
|
74
|
+
/**
|
|
75
|
+
* The glyph's name from the `post` or `CFF` table, or undefined.
|
|
76
|
+
*/
|
|
77
|
+
export function get_glyph_name(font_id: number, glyph_id: number): string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* The glyph with this name, or undefined.
|
|
80
|
+
*/
|
|
81
|
+
export function get_glyph_by_name(font_id: number, name: string): number | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* OpenType feature tags in `GSUB` and `GPOS`, sorted.
|
|
84
|
+
*/
|
|
85
|
+
export function get_features(font_id: number): string[];
|
|
86
|
+
/**
|
|
87
|
+
* OpenType script tags in `GSUB` and `GPOS`, sorted.
|
|
88
|
+
*/
|
|
89
|
+
export function get_scripts(font_id: number): string[];
|
|
90
|
+
/**
|
|
91
|
+
* The named instances of a variable font (empty for static fonts).
|
|
92
|
+
*/
|
|
93
|
+
export function get_named_instances(font_id: number): NamedInstance[];
|
|
94
|
+
/**
|
|
95
|
+
* The font's tables, in directory order.
|
|
96
|
+
*/
|
|
97
|
+
export function get_tables(font_id: number): FontTable[];
|
|
53
98
|
/**
|
|
54
99
|
* Lays out `text`: hard breaks, wrapping (with `max_width`), bidi reordering,
|
|
55
100
|
* alignment and bounds. Uses the font's current variations.
|
|
@@ -89,6 +134,62 @@ export interface FontMetrics {
|
|
|
89
134
|
global_bbox: GlyphBBox;
|
|
90
135
|
}
|
|
91
136
|
|
|
137
|
+
/** Names and basic facts from the `name`, `head` and `OS/2` tables. */
|
|
138
|
+
export interface FontInfo {
|
|
139
|
+
/** Typographic family name if the font has one, otherwise the family name. */
|
|
140
|
+
family_name: string | null;
|
|
141
|
+
/** Typographic subfamily name if the font has one, otherwise the subfamily name, e.g. "Bold Italic". */
|
|
142
|
+
subfamily_name: string | null;
|
|
143
|
+
full_name: string | null;
|
|
144
|
+
postscript_name: string | null;
|
|
145
|
+
/** The version string, e.g. "Version 3.011". */
|
|
146
|
+
version: string | null;
|
|
147
|
+
/** `head.fontRevision`, e.g. 3.011. */
|
|
148
|
+
font_revision: number;
|
|
149
|
+
/** Four-character vendor ID from `OS/2`, e.g. "GOOG", trailing spaces trimmed. */
|
|
150
|
+
vendor_id: string | null;
|
|
151
|
+
/** `OS/2` weight class: 100 (thin) to 900 (black), 400 regular, 700 bold. */
|
|
152
|
+
weight_class: number | null;
|
|
153
|
+
/** `OS/2` width class: 1 (ultra-condensed) to 9 (ultra-expanded), 5 normal. */
|
|
154
|
+
width_class: number | null;
|
|
155
|
+
/** `OS/2.fsType` embedding permission bits; 0 = installable. */
|
|
156
|
+
embedding: number | null;
|
|
157
|
+
/** Creation date from `head`, in seconds since the Unix epoch (`new Date(created * 1000)`). */
|
|
158
|
+
created: number | null;
|
|
159
|
+
modified: number | null;
|
|
160
|
+
num_glyphs: number;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** One localized string from the `name` table. */
|
|
164
|
+
export interface NameEntry {
|
|
165
|
+
/**
|
|
166
|
+
* Name ID: 0 copyright, 1 family, 2 subfamily, 4 full name, 5 version, 6 PostScript
|
|
167
|
+
* name, 9 designer, 13 license, 16/17 typographic family and subfamily, 256 and up
|
|
168
|
+
* for font-specific names (axes, instances, ...).
|
|
169
|
+
*/
|
|
170
|
+
id: number;
|
|
171
|
+
/** BCP 47 language tag, e.g. "en-US", or null if unknown. */
|
|
172
|
+
language: string | null;
|
|
173
|
+
value: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A predefined location of a variable font, e.g. "Bold Condensed". */
|
|
177
|
+
export interface NamedInstance {
|
|
178
|
+
/** Subfamily name, e.g. "Bold Condensed". */
|
|
179
|
+
name: string | null;
|
|
180
|
+
postscript_name: string | null;
|
|
181
|
+
/** The value of every axis; pass to `set_variations`. */
|
|
182
|
+
variations: Record<string, number>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** An entry in the font's table directory. */
|
|
186
|
+
export interface FontTable {
|
|
187
|
+
/** Four-character tag, e.g. "glyf", "CFF " (with its trailing space). */
|
|
188
|
+
tag: string;
|
|
189
|
+
/** Size in bytes. */
|
|
190
|
+
length: number;
|
|
191
|
+
}
|
|
192
|
+
|
|
92
193
|
export interface VariationAxis {
|
|
93
194
|
tag: string;
|
|
94
195
|
min: number;
|
|
@@ -189,7 +290,10 @@ export interface LayoutOptions {
|
|
|
189
290
|
size?: number;
|
|
190
291
|
/** Distance between baselines. Defaults to 1.25 × size. */
|
|
191
292
|
leading?: number | null;
|
|
192
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* Added after every cluster. When non-zero, optional ligatures (liga, clig, dlig,
|
|
295
|
+
* hlig) are off, as in CSS, unless `features` turns them on.
|
|
296
|
+
*/
|
|
193
297
|
letter_spacing?: number;
|
|
194
298
|
/** Added after every space. */
|
|
195
299
|
word_spacing?: number;
|
|
@@ -282,8 +386,19 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
282
386
|
export interface InitOutput {
|
|
283
387
|
readonly memory: WebAssembly.Memory;
|
|
284
388
|
readonly bidi_line: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
389
|
+
readonly get_characters: (a: number) => [number, number, number, number];
|
|
390
|
+
readonly get_features: (a: number) => [number, number, number, number];
|
|
391
|
+
readonly get_font_info: (a: number) => [number, number, number];
|
|
392
|
+
readonly get_glyph_by_name: (a: number, b: number, c: number) => [number, number, number];
|
|
393
|
+
readonly get_glyph_id: (a: number, b: number) => [number, number, number];
|
|
394
|
+
readonly get_glyph_name: (a: number, b: number) => [number, number, number, number];
|
|
285
395
|
readonly get_metrics: (a: number) => [number, number, number];
|
|
396
|
+
readonly get_name: (a: number, b: number) => [number, number, number, number];
|
|
397
|
+
readonly get_named_instances: (a: number) => [number, number, number];
|
|
398
|
+
readonly get_names: (a: number) => [number, number, number];
|
|
286
399
|
readonly get_outline: (a: number, b: number, c: number) => [number, number, number];
|
|
400
|
+
readonly get_scripts: (a: number) => [number, number, number, number];
|
|
401
|
+
readonly get_tables: (a: number) => [number, number, number];
|
|
287
402
|
readonly get_variation_axes: (a: number) => [number, number, number];
|
|
288
403
|
readonly graphemes: (a: number, b: number) => [number, number];
|
|
289
404
|
readonly layout: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
@@ -301,6 +416,7 @@ export interface InitOutput {
|
|
|
301
416
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
302
417
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
303
418
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
419
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
304
420
|
readonly __wbindgen_start: () => void;
|
|
305
421
|
}
|
|
306
422
|
|
package/wasm/text_shape.js
CHANGED
|
@@ -357,6 +357,182 @@ export function get_outline(font_id, glyph_id, flip_y) {
|
|
|
357
357
|
return takeFromExternrefTable0(ret[0]);
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Names and basic facts from the `name`, `head` and `OS/2` tables.
|
|
362
|
+
* @param {number} font_id
|
|
363
|
+
* @returns {FontInfo}
|
|
364
|
+
*/
|
|
365
|
+
export function get_font_info(font_id) {
|
|
366
|
+
const ret = wasm.get_font_info(font_id);
|
|
367
|
+
if (ret[2]) {
|
|
368
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
369
|
+
}
|
|
370
|
+
return takeFromExternrefTable0(ret[0]);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* A name from the `name` table by ID, in US English if available, otherwise
|
|
375
|
+
* English, otherwise the first one.
|
|
376
|
+
* @param {number} font_id
|
|
377
|
+
* @param {number} name_id
|
|
378
|
+
* @returns {string | undefined}
|
|
379
|
+
*/
|
|
380
|
+
export function get_name(font_id, name_id) {
|
|
381
|
+
const ret = wasm.get_name(font_id, name_id);
|
|
382
|
+
if (ret[3]) {
|
|
383
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
384
|
+
}
|
|
385
|
+
let v1;
|
|
386
|
+
if (ret[0] !== 0) {
|
|
387
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
388
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
389
|
+
}
|
|
390
|
+
return v1;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Every decodable string in the `name` table, by ID.
|
|
395
|
+
* @param {number} font_id
|
|
396
|
+
* @returns {NameEntry[]}
|
|
397
|
+
*/
|
|
398
|
+
export function get_names(font_id) {
|
|
399
|
+
const ret = wasm.get_names(font_id);
|
|
400
|
+
if (ret[2]) {
|
|
401
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
402
|
+
}
|
|
403
|
+
return takeFromExternrefTable0(ret[0]);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* The glyph the character map gives a code point, or undefined.
|
|
408
|
+
* @param {number} font_id
|
|
409
|
+
* @param {number} code_point
|
|
410
|
+
* @returns {number | undefined}
|
|
411
|
+
*/
|
|
412
|
+
export function get_glyph_id(font_id, code_point) {
|
|
413
|
+
const ret = wasm.get_glyph_id(font_id, code_point);
|
|
414
|
+
if (ret[2]) {
|
|
415
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
416
|
+
}
|
|
417
|
+
return ret[0] === 0xFFFFFF ? undefined : ret[0];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Every code point the character map covers, in order.
|
|
422
|
+
* @param {number} font_id
|
|
423
|
+
* @returns {Uint32Array}
|
|
424
|
+
*/
|
|
425
|
+
export function get_characters(font_id) {
|
|
426
|
+
const ret = wasm.get_characters(font_id);
|
|
427
|
+
if (ret[3]) {
|
|
428
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
429
|
+
}
|
|
430
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
431
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
432
|
+
return v1;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* The glyph's name from the `post` or `CFF` table, or undefined.
|
|
437
|
+
* @param {number} font_id
|
|
438
|
+
* @param {number} glyph_id
|
|
439
|
+
* @returns {string | undefined}
|
|
440
|
+
*/
|
|
441
|
+
export function get_glyph_name(font_id, glyph_id) {
|
|
442
|
+
const ret = wasm.get_glyph_name(font_id, glyph_id);
|
|
443
|
+
if (ret[3]) {
|
|
444
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
445
|
+
}
|
|
446
|
+
let v1;
|
|
447
|
+
if (ret[0] !== 0) {
|
|
448
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
449
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
450
|
+
}
|
|
451
|
+
return v1;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* The glyph with this name, or undefined.
|
|
456
|
+
* @param {number} font_id
|
|
457
|
+
* @param {string} name
|
|
458
|
+
* @returns {number | undefined}
|
|
459
|
+
*/
|
|
460
|
+
export function get_glyph_by_name(font_id, name) {
|
|
461
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
462
|
+
const len0 = WASM_VECTOR_LEN;
|
|
463
|
+
const ret = wasm.get_glyph_by_name(font_id, ptr0, len0);
|
|
464
|
+
if (ret[2]) {
|
|
465
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
466
|
+
}
|
|
467
|
+
return ret[0] === 0xFFFFFF ? undefined : ret[0];
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
471
|
+
ptr = ptr >>> 0;
|
|
472
|
+
const mem = getDataViewMemory0();
|
|
473
|
+
const result = [];
|
|
474
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
475
|
+
result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
|
|
476
|
+
}
|
|
477
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
478
|
+
return result;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* OpenType feature tags in `GSUB` and `GPOS`, sorted.
|
|
482
|
+
* @param {number} font_id
|
|
483
|
+
* @returns {string[]}
|
|
484
|
+
*/
|
|
485
|
+
export function get_features(font_id) {
|
|
486
|
+
const ret = wasm.get_features(font_id);
|
|
487
|
+
if (ret[3]) {
|
|
488
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
489
|
+
}
|
|
490
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
491
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
492
|
+
return v1;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* OpenType script tags in `GSUB` and `GPOS`, sorted.
|
|
497
|
+
* @param {number} font_id
|
|
498
|
+
* @returns {string[]}
|
|
499
|
+
*/
|
|
500
|
+
export function get_scripts(font_id) {
|
|
501
|
+
const ret = wasm.get_scripts(font_id);
|
|
502
|
+
if (ret[3]) {
|
|
503
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
504
|
+
}
|
|
505
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
506
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
507
|
+
return v1;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* The named instances of a variable font (empty for static fonts).
|
|
512
|
+
* @param {number} font_id
|
|
513
|
+
* @returns {NamedInstance[]}
|
|
514
|
+
*/
|
|
515
|
+
export function get_named_instances(font_id) {
|
|
516
|
+
const ret = wasm.get_named_instances(font_id);
|
|
517
|
+
if (ret[2]) {
|
|
518
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
519
|
+
}
|
|
520
|
+
return takeFromExternrefTable0(ret[0]);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The font's tables, in directory order.
|
|
525
|
+
* @param {number} font_id
|
|
526
|
+
* @returns {FontTable[]}
|
|
527
|
+
*/
|
|
528
|
+
export function get_tables(font_id) {
|
|
529
|
+
const ret = wasm.get_tables(font_id);
|
|
530
|
+
if (ret[2]) {
|
|
531
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
532
|
+
}
|
|
533
|
+
return takeFromExternrefTable0(ret[0]);
|
|
534
|
+
}
|
|
535
|
+
|
|
360
536
|
/**
|
|
361
537
|
* Lays out `text`: hard breaks, wrapping (with `max_width`), bidi reordering,
|
|
362
538
|
* alignment and bounds. Uses the font's current variations.
|
|
@@ -633,6 +809,11 @@ function __wbg_get_imports() {
|
|
|
633
809
|
const ret = BigInt.asUintN(64, arg0);
|
|
634
810
|
return ret;
|
|
635
811
|
};
|
|
812
|
+
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
813
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
814
|
+
const ret = arg0;
|
|
815
|
+
return ret;
|
|
816
|
+
};
|
|
636
817
|
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
637
818
|
// Cast intrinsic for `F64 -> Externref`.
|
|
638
819
|
const ret = arg0;
|
package/wasm/text_shape_bg.wasm
CHANGED
|
Binary file
|
|
@@ -2,8 +2,19 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const bidi_line: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
5
|
+
export const get_characters: (a: number) => [number, number, number, number];
|
|
6
|
+
export const get_features: (a: number) => [number, number, number, number];
|
|
7
|
+
export const get_font_info: (a: number) => [number, number, number];
|
|
8
|
+
export const get_glyph_by_name: (a: number, b: number, c: number) => [number, number, number];
|
|
9
|
+
export const get_glyph_id: (a: number, b: number) => [number, number, number];
|
|
10
|
+
export const get_glyph_name: (a: number, b: number) => [number, number, number, number];
|
|
5
11
|
export const get_metrics: (a: number) => [number, number, number];
|
|
12
|
+
export const get_name: (a: number, b: number) => [number, number, number, number];
|
|
13
|
+
export const get_named_instances: (a: number) => [number, number, number];
|
|
14
|
+
export const get_names: (a: number) => [number, number, number];
|
|
6
15
|
export const get_outline: (a: number, b: number, c: number) => [number, number, number];
|
|
16
|
+
export const get_scripts: (a: number) => [number, number, number, number];
|
|
17
|
+
export const get_tables: (a: number) => [number, number, number];
|
|
7
18
|
export const get_variation_axes: (a: number) => [number, number, number];
|
|
8
19
|
export const graphemes: (a: number, b: number) => [number, number];
|
|
9
20
|
export const layout: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
@@ -21,4 +32,5 @@ export const __externref_table_alloc: () => number;
|
|
|
21
32
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
22
33
|
export const __externref_table_dealloc: (a: number) => void;
|
|
23
34
|
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
35
|
+
export const __externref_drop_slice: (a: number, b: number) => void;
|
|
24
36
|
export const __wbindgen_start: () => void;
|