Skip to content

Commit 057f353

Browse files
committed
feat: migrate to wasm components
1 parent 694db8e commit 057f353

File tree

16 files changed

+2240
-450
lines changed

16 files changed

+2240
-450
lines changed

Cargo.toml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ license = "MIT OR Apache-2.0"
1010
[lib]
1111
crate-type = ["cdylib", "rlib"]
1212

13+
[package.metadata.component]
14+
package = "alibaba:fontkit"
15+
1316
[dependencies]
17+
wit-bindgen-rt = "0.24.0"
1418
ab_glyph_rasterizer = { version = "0.1.5", optional = true }
1519
arc-swap = "1.6.0"
1620
brotli-decompressor = { version = "2.3.2", optional = true }
1721
byteorder = { version = "1.4.3", optional = true }
18-
dashmap = { version = "5.3.4", optional = true }
22+
dashmap = "5.3.4"
1923
flate2 = { version = "1.0.22", optional = true }
2024
log = "0.4.17"
2125
ordered-float = "3.9.1"
@@ -41,16 +45,8 @@ unicode-script = { version = "0.5.4", optional = true }
4145
# wit-bindgen-rust = { git = "https://github.com/bytecodealliance/wit-bindgen", tag = "v0.2.0", optional = true }
4246
woff2 = { git = "https://github.com/zimond/woff2-rs", rev = "0e25872", optional = true, version = "0.3.0" }
4347

44-
[target.'cfg(not(all(target_os = "unknown", target_arch = "wasm32")))'.dependencies]
45-
walkdir = "2.3.1"
46-
47-
[target.'cfg(all(target_os = "unknown", target_arch = "wasm32"))'.dependencies]
48-
wasm-bindgen = "0.2.79"
49-
js-sys = "0.3.56"
50-
console_error_panic_hook = "0.1.7"
51-
5248
[features]
53-
default = ["woff", "woff2", "metrics", "ras", "dashmap"]
49+
default = ["woff", "woff2", "metrics", "ras"]
5450
woff = ["byteorder", "flate2"]
5551
metrics = [
5652
"unicode-bidi",
@@ -66,6 +62,3 @@ ras = [
6662
]
6763
optimize_stroke_broken = []
6864
# wit = ["wit-bindgen-rust", "dashmap"]
69-
70-
[build-dependencies]
71-
cfg_aliases = "0.1.1"

build.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/node.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import { homedir } from 'os';
22
import { dirname } from 'path';
33
import { fileURLToPath } from 'url';
44

5-
import { FontKitIndex } from '../node.js';
5+
import { fontkitInterface as fi } from '../pkg/fontkit.js';
66

77
const __dirname = dirname(fileURLToPath(import.meta.url));
88

9-
const fontkit = new FontKitIndex();
10-
await fontkit.initiate();
9+
const fontkit = new fi.FontKit();
10+
fontkit.addSearchPath(__dirname + '/OpenSans-Italic.ttf');
1111
fontkit.addSearchPath(homedir() + '/Library/Fonts');
1212

13-
const font = fontkit.font('Open Sans');
13+
const font = fontkit.query({ family: 'Open Sans' });
1414

15-
fontkit.free();
15+
// eslint-disable-next-line no-console
16+
console.log(font.hasGlyph('c'));
17+
// eslint-disable-next-line no-console
18+
console.log(fontkit.fontsInfo());

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { FontKit, Font, FontInfo, FontKey } from './pkg/interfaces/alibaba-fontkit-fontkit-interface';

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { fontkitInterface } from './pkg/fontkit.js';
2+
3+
export const Font = fontkitInterface.Font;
4+
export const FontKit = fontkitInterface.FontKit;
5+
export const TextMetrics = fontkitInterface.TextMetrics;
6+
export const numberWidthToStr = fontkitInterface.numberWidthToStr;
7+
export const strWidthToNumber = fontkitInterface.strWidthToNumber;

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "fontkit-rs",
3-
"version": "0.0.7-beta.1",
3+
"version": "0.0.9-beta.3",
44
"description": "Toolkit used to load, match, measure, and render texts",
5-
"main": "pkg/bundler/index.js",
5+
"main": "index.js",
66
"directories": {
77
"example": "examples",
88
"test": "tests"
99
},
1010
"files": [
1111
"pkg/**/*",
12-
"node.js",
12+
"index.js",
1313
"Readme.md"
1414
],
1515
"author": "Zimon Dai <[email protected]>",
@@ -66,6 +66,7 @@
6666
},
6767
"type": "module",
6868
"dependencies": {
69+
"@bytecodealliance/preview2-shim": "^0.16.1",
6970
"walkdir": "^0.4.1"
7071
}
7172
}

0 commit comments

Comments
 (0)