Repository
Current version released
4 years ago
Dependencies
deno.land/x
Versions
Font
This is a simple deno module providing wasm bindings to the fontdue
for font rasterization and layout with support for TrueType (.ttf/.ttc
) and OpenType (.otf
).
Example
Rasterization
import { Font } from "https://deno.land/x/font/mod.ts";
// Read the font data.
const data = await Deno.readFile("../Roboto-Regular.ttf");
// Parse it into the font type.
const font = new Font(font);
// Rasterize and get the layout metrics for the letter 'g' at 17px.
let { metrics, bitmap } = font.rasterize("g", 17.0);
Prerequisites
prerequisite | installation |
---|---|
deno | deno_install |
rust | rustup |
rustfmt | rustup component add rustfmt |
rust-clippy | rustup component add clippy |
wasm-pack | cargo install wasm-pack |
Development
build
$ deno run --unstable --allow-read --allow-write --allow-run scripts/build.ts
building rust ("wasm-pack build --target web --release")
read wasm (size: 150856 bytes)
compressed wasm using lz4 (reduction: 58651 bytes, size: 92205 bytes)
encoded wasm using base64 (increase: 30735 bytes, size: 122940 bytes)
read js (size: 5895 bytes)
inlined js and wasm (size: 129016 bytes)
minified js (size reduction: 3100 bytes, size: 125916 bytes)
writing output to file (wasm.js)
final size is: 125916 bytes
clean
$ deno run --unstable --allow-read --allow-write --allow-run scripts/clean.ts
cleaning cargo build ("cargo clean")
removing pkg
fmt
$ deno run --unstable --allow-run scripts/fmt.ts
formatting typescript ("deno --unstable fmt scripts/ test_deps.ts test.ts mod.ts")
Checked 9 files
formatting rust ("cargo fmt")
lint
$ deno run --unstable --allow-run scripts/lint.ts
linting typescript ("deno --unstable lint scripts test_deps.ts test.ts mod.ts")
Checked 9 files
linting rust ("cargo clippy -q")
Testing
Requires the wasm.js
file to be built first.
$ deno test
running 1 tests
test add ... ok (2ms)
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (2ms)
Other
Contribution
Pull request, issues and feedback are very welcome. Code style is formatted with deno fmt
and commit messages are done following Conventional Commits spec.
Licence
Copyright 2021, Denosaurs. All rights reserved. MIT license.