text-shape 0.1.0 → 0.1.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.
- package/package.json +5 -4
- package/wasm/text_shape.d.ts +17 -17
- package/wasm/text_shape.js +44 -44
- package/wasm/text_shape_bg.wasm +0 -0
- package/wasm/text_shape_wasm_base64.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "text-shape",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Text layout and measurement (shaping, metrics, wrapping, bidi) on a Rust/WebAssembly core",
|
|
5
5
|
"author": "yyyk",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"types": "./wasm/text_shape.d.ts",
|
|
35
35
|
"default": "./wasm/text_shape.js"
|
|
36
36
|
},
|
|
37
|
-
"./text_shape_bg.wasm": "./wasm/text_shape_bg.wasm"
|
|
37
|
+
"./text_shape_bg.wasm": "./wasm/text_shape_bg.wasm",
|
|
38
|
+
"./package.json": "./package.json"
|
|
38
39
|
},
|
|
39
40
|
"files": [
|
|
40
41
|
"dist",
|
|
@@ -59,8 +60,8 @@
|
|
|
59
60
|
"prepublishOnly": "npm test && npm run test:rust",
|
|
60
61
|
"test:rust": "cargo test --manifest-path ../Cargo.toml --workspace",
|
|
61
62
|
"prepack": "cp ../LICENSE ../THIRD_PARTY_NOTICES .",
|
|
62
|
-
"format": "prettier --write --ignore-path ../.prettierignore \"**/*.{ts,mjs,json,md}\" ../README.md ../CHANGELOG.md ../fonts/README.md ../crates/text-shape/README.md",
|
|
63
|
-
"format:check": "prettier --check --ignore-path ../.prettierignore \"**/*.{ts,mjs,json,md}\" ../README.md ../CHANGELOG.md ../fonts/README.md ../crates/text-shape/README.md"
|
|
63
|
+
"format": "prettier --write --ignore-path ../.prettierignore \"**/*.{ts,mjs,json,md}\" ../README.md ../crates/text-shape/CHANGELOG.md ../fonts/README.md ../crates/text-shape/README.md",
|
|
64
|
+
"format:check": "prettier --check --ignore-path ../.prettierignore \"**/*.{ts,mjs,json,md}\" ../README.md ../crates/text-shape/CHANGELOG.md ../fonts/README.md ../crates/text-shape/README.md"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"prettier": "^3.10.1",
|
package/wasm/text_shape.d.ts
CHANGED
|
@@ -14,41 +14,41 @@ export function graphemes(text: string): Uint32Array;
|
|
|
14
14
|
* resolved with full context.
|
|
15
15
|
*/
|
|
16
16
|
export function bidi_line(text: string, base: "ltr" | "rtl" | "auto" | null | undefined, line_start?: number | null, line_end?: number | null): BidiLine;
|
|
17
|
-
/**
|
|
18
|
-
* Glyph outline in font units (y up). Reflects current variations.
|
|
19
|
-
*/
|
|
20
|
-
export function get_outline(font_id: number, glyph_id: number): PathCmd[];
|
|
21
17
|
/**
|
|
22
18
|
* Loads a font (TTF/OTF, or a face from a TTC via `face_index`) and returns its id.
|
|
23
19
|
*/
|
|
24
20
|
export function load_font(data: Uint8Array, face_index?: number | null): number;
|
|
21
|
+
/**
|
|
22
|
+
* Frees a loaded font. Returns false if the id was unknown.
|
|
23
|
+
*/
|
|
24
|
+
export function unload_font(font_id: number): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Vertical metrics and basic info, in font units. Reflects current variations.
|
|
27
|
+
*/
|
|
28
|
+
export function get_metrics(font_id: number): FontMetrics;
|
|
29
|
+
/**
|
|
30
|
+
* Variation axes of a variable font (empty for static fonts).
|
|
31
|
+
*/
|
|
32
|
+
export function get_variation_axes(font_id: number): VariationAxis[];
|
|
25
33
|
/**
|
|
26
34
|
* Sets axis values, e.g. `{ wght: 700, slnt: -10 }`, clamped to each axis range.
|
|
27
35
|
* Unlisted axes keep their current value. Affects later `shape`, `layout`,
|
|
28
36
|
* `get_outline` and `get_metrics` calls.
|
|
29
37
|
*/
|
|
30
38
|
export function set_variations(font_id: number, values: Record<string, number>): void;
|
|
31
|
-
/**
|
|
32
|
-
* Maps a requested weight/style onto the font: real axes when it has them,
|
|
33
|
-
* otherwise faux bold/italic parameters.
|
|
34
|
-
*/
|
|
35
|
-
export function resolve_style(font_id: number, style: FontStyle | null | undefined): ResolvedStyle;
|
|
36
39
|
/**
|
|
37
40
|
* Resets every axis to its default value.
|
|
38
41
|
*/
|
|
39
42
|
export function reset_variations(font_id: number): void;
|
|
40
43
|
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
export function unload_font(font_id: number): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Variation axes of a variable font (empty for static fonts).
|
|
44
|
+
* Maps a requested weight/style onto the font: real axes when it has them,
|
|
45
|
+
* otherwise faux bold/italic parameters.
|
|
46
46
|
*/
|
|
47
|
-
export function
|
|
47
|
+
export function resolve_style(font_id: number, style: FontStyle | null | undefined): ResolvedStyle;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Glyph outline in font units (y up). Reflects current variations.
|
|
50
50
|
*/
|
|
51
|
-
export function
|
|
51
|
+
export function get_outline(font_id: number, glyph_id: number): PathCmd[];
|
|
52
52
|
/**
|
|
53
53
|
* Lays out `text`: hard breaks, wrapping (with `max_width`), bidi reordering,
|
|
54
54
|
* alignment and bounds. Uses the font's current variations.
|
package/wasm/text_shape.js
CHANGED
|
@@ -251,20 +251,6 @@ export function bidi_line(text, base, line_start, line_end) {
|
|
|
251
251
|
return takeFromExternrefTable0(ret[0]);
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
/**
|
|
255
|
-
* Glyph outline in font units (y up). Reflects current variations.
|
|
256
|
-
* @param {number} font_id
|
|
257
|
-
* @param {number} glyph_id
|
|
258
|
-
* @returns {PathCmd[]}
|
|
259
|
-
*/
|
|
260
|
-
export function get_outline(font_id, glyph_id) {
|
|
261
|
-
const ret = wasm.get_outline(font_id, glyph_id);
|
|
262
|
-
if (ret[2]) {
|
|
263
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
264
|
-
}
|
|
265
|
-
return takeFromExternrefTable0(ret[0]);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
254
|
/**
|
|
269
255
|
* Loads a font (TTF/OTF, or a face from a TTC via `face_index`) and returns its id.
|
|
270
256
|
* @param {Uint8Array} data
|
|
@@ -280,28 +266,35 @@ export function load_font(data, face_index) {
|
|
|
280
266
|
}
|
|
281
267
|
|
|
282
268
|
/**
|
|
283
|
-
*
|
|
284
|
-
* Unlisted axes keep their current value. Affects later `shape`, `layout`,
|
|
285
|
-
* `get_outline` and `get_metrics` calls.
|
|
269
|
+
* Frees a loaded font. Returns false if the id was unknown.
|
|
286
270
|
* @param {number} font_id
|
|
287
|
-
* @
|
|
271
|
+
* @returns {boolean}
|
|
288
272
|
*/
|
|
289
|
-
export function
|
|
290
|
-
const ret = wasm.
|
|
291
|
-
|
|
292
|
-
|
|
273
|
+
export function unload_font(font_id) {
|
|
274
|
+
const ret = wasm.unload_font(font_id);
|
|
275
|
+
return ret !== 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Vertical metrics and basic info, in font units. Reflects current variations.
|
|
280
|
+
* @param {number} font_id
|
|
281
|
+
* @returns {FontMetrics}
|
|
282
|
+
*/
|
|
283
|
+
export function get_metrics(font_id) {
|
|
284
|
+
const ret = wasm.get_metrics(font_id);
|
|
285
|
+
if (ret[2]) {
|
|
286
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
293
287
|
}
|
|
288
|
+
return takeFromExternrefTable0(ret[0]);
|
|
294
289
|
}
|
|
295
290
|
|
|
296
291
|
/**
|
|
297
|
-
*
|
|
298
|
-
* otherwise faux bold/italic parameters.
|
|
292
|
+
* Variation axes of a variable font (empty for static fonts).
|
|
299
293
|
* @param {number} font_id
|
|
300
|
-
* @
|
|
301
|
-
* @returns {ResolvedStyle}
|
|
294
|
+
* @returns {VariationAxis[]}
|
|
302
295
|
*/
|
|
303
|
-
export function
|
|
304
|
-
const ret = wasm.
|
|
296
|
+
export function get_variation_axes(font_id) {
|
|
297
|
+
const ret = wasm.get_variation_axes(font_id);
|
|
305
298
|
if (ret[2]) {
|
|
306
299
|
throw takeFromExternrefTable0(ret[1]);
|
|
307
300
|
}
|
|
@@ -309,33 +302,39 @@ export function resolve_style(font_id, style) {
|
|
|
309
302
|
}
|
|
310
303
|
|
|
311
304
|
/**
|
|
312
|
-
*
|
|
305
|
+
* Sets axis values, e.g. `{ wght: 700, slnt: -10 }`, clamped to each axis range.
|
|
306
|
+
* Unlisted axes keep their current value. Affects later `shape`, `layout`,
|
|
307
|
+
* `get_outline` and `get_metrics` calls.
|
|
313
308
|
* @param {number} font_id
|
|
309
|
+
* @param {Record<string, number>} values
|
|
314
310
|
*/
|
|
315
|
-
export function
|
|
316
|
-
const ret = wasm.
|
|
311
|
+
export function set_variations(font_id, values) {
|
|
312
|
+
const ret = wasm.set_variations(font_id, values);
|
|
317
313
|
if (ret[1]) {
|
|
318
314
|
throw takeFromExternrefTable0(ret[0]);
|
|
319
315
|
}
|
|
320
316
|
}
|
|
321
317
|
|
|
322
318
|
/**
|
|
323
|
-
*
|
|
319
|
+
* Resets every axis to its default value.
|
|
324
320
|
* @param {number} font_id
|
|
325
|
-
* @returns {boolean}
|
|
326
321
|
*/
|
|
327
|
-
export function
|
|
328
|
-
const ret = wasm.
|
|
329
|
-
|
|
322
|
+
export function reset_variations(font_id) {
|
|
323
|
+
const ret = wasm.reset_variations(font_id);
|
|
324
|
+
if (ret[1]) {
|
|
325
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
326
|
+
}
|
|
330
327
|
}
|
|
331
328
|
|
|
332
329
|
/**
|
|
333
|
-
*
|
|
330
|
+
* Maps a requested weight/style onto the font: real axes when it has them,
|
|
331
|
+
* otherwise faux bold/italic parameters.
|
|
334
332
|
* @param {number} font_id
|
|
335
|
-
* @
|
|
333
|
+
* @param {FontStyle | null | undefined} style
|
|
334
|
+
* @returns {ResolvedStyle}
|
|
336
335
|
*/
|
|
337
|
-
export function
|
|
338
|
-
const ret = wasm.
|
|
336
|
+
export function resolve_style(font_id, style) {
|
|
337
|
+
const ret = wasm.resolve_style(font_id, isLikeNone(style) ? 0 : addToExternrefTable0(style));
|
|
339
338
|
if (ret[2]) {
|
|
340
339
|
throw takeFromExternrefTable0(ret[1]);
|
|
341
340
|
}
|
|
@@ -343,12 +342,13 @@ export function get_variation_axes(font_id) {
|
|
|
343
342
|
}
|
|
344
343
|
|
|
345
344
|
/**
|
|
346
|
-
*
|
|
345
|
+
* Glyph outline in font units (y up). Reflects current variations.
|
|
347
346
|
* @param {number} font_id
|
|
348
|
-
* @
|
|
347
|
+
* @param {number} glyph_id
|
|
348
|
+
* @returns {PathCmd[]}
|
|
349
349
|
*/
|
|
350
|
-
export function
|
|
351
|
-
const ret = wasm.
|
|
350
|
+
export function get_outline(font_id, glyph_id) {
|
|
351
|
+
const ret = wasm.get_outline(font_id, glyph_id);
|
|
352
352
|
if (ret[2]) {
|
|
353
353
|
throw takeFromExternrefTable0(ret[1]);
|
|
354
354
|
}
|
package/wasm/text_shape_bg.wasm
CHANGED
|
Binary file
|