Skip to content

Commit

Permalink
feat: migrate to wasm components
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond committed Apr 12, 2024
1 parent 694db8e commit 3a1b776
Show file tree
Hide file tree
Showing 15 changed files with 2,187 additions and 450 deletions.
19 changes: 6 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ license = "MIT OR Apache-2.0"
[lib]
crate-type = ["cdylib", "rlib"]

[package.metadata.component]
package = "alibaba:fontkit"

[dependencies]
wit-bindgen-rt = "0.24.0"
ab_glyph_rasterizer = { version = "0.1.5", optional = true }
arc-swap = "1.6.0"
brotli-decompressor = { version = "2.3.2", optional = true }
byteorder = { version = "1.4.3", optional = true }
dashmap = { version = "5.3.4", optional = true }
dashmap = "5.3.4"
flate2 = { version = "1.0.22", optional = true }
log = "0.4.17"
ordered-float = "3.9.1"
Expand All @@ -41,16 +45,8 @@ unicode-script = { version = "0.5.4", optional = true }
# wit-bindgen-rust = { git = "https://github.com/bytecodealliance/wit-bindgen", tag = "v0.2.0", optional = true }
woff2 = { git = "https://github.com/zimond/woff2-rs", rev = "0e25872", optional = true, version = "0.3.0" }

[target.'cfg(not(all(target_os = "unknown", target_arch = "wasm32")))'.dependencies]
walkdir = "2.3.1"

[target.'cfg(all(target_os = "unknown", target_arch = "wasm32"))'.dependencies]
wasm-bindgen = "0.2.79"
js-sys = "0.3.56"
console_error_panic_hook = "0.1.7"

[features]
default = ["woff", "woff2", "metrics", "ras", "dashmap"]
default = ["woff", "woff2", "metrics", "ras"]
woff = ["byteorder", "flate2"]
metrics = [
"unicode-bidi",
Expand All @@ -66,6 +62,3 @@ ras = [
]
optimize_stroke_broken = []
# wit = ["wit-bindgen-rust", "dashmap"]

[build-dependencies]
cfg_aliases = "0.1.1"
12 changes: 0 additions & 12 deletions build.rs

This file was deleted.

13 changes: 8 additions & 5 deletions examples/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { homedir } from 'os';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

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

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

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

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

fontkit.free();
// eslint-disable-next-line no-console
console.log(font.hasGlyph('c'));
// eslint-disable-next-line no-console
console.log(fontkit.fontsInfo());
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { fontkitInterface } from './pkg/fontkit.js';

export const Font = fontkitInterface.Font;
export const FontKit = fontkitInterface.FontKit;
export const TextMetrics = fontkitInterface.TextMetrics;
export const numberWidthToStr = fontkitInterface.numberWidthToStr;
export const strWidthToNumber = fontkitInterface.strWidthToNumber;
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "fontkit-rs",
"version": "0.0.7-beta.1",
"version": "0.0.9-beta.3",
"description": "Toolkit used to load, match, measure, and render texts",
"main": "pkg/bundler/index.js",
"main": "index.js",
"directories": {
"example": "examples",
"test": "tests"
},
"files": [
"pkg/**/*",
"node.js",
"index.js",
"Readme.md"
],
"author": "Zimon Dai <[email protected]>",
Expand Down Expand Up @@ -66,6 +66,7 @@
},
"type": "module",
"dependencies": {
"@bytecodealliance/preview2-shim": "^0.16.1",
"walkdir": "^0.4.1"
}
}
Loading

0 comments on commit 3a1b776

Please sign in to comment.