diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /gfx/harfbuzz/src/wasm/sample/rust/hello-wasm | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/harfbuzz/src/wasm/sample/rust/hello-wasm')
-rw-r--r-- | gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/Cargo.toml | 13 | ||||
-rw-r--r-- | gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/src/lib.rs | 24 |
2 files changed, 37 insertions, 0 deletions
diff --git a/gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/Cargo.toml b/gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/Cargo.toml new file mode 100644 index 0000000000..53357ea908 --- /dev/null +++ b/gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "hello-wasm" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +#externref = "0.1.0" +wasm-bindgen = "0.2.0" +tiny-rng = "0.2.0" +harfbuzz-wasm = { path="../../../rust/harfbuzz-wasm"} diff --git a/gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/src/lib.rs b/gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/src/lib.rs new file mode 100644 index 0000000000..ab8f153684 --- /dev/null +++ b/gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/src/lib.rs @@ -0,0 +1,24 @@ +use harfbuzz_wasm::{Font, GlyphBuffer}; +use tiny_rng::{Rand, Rng}; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn shape( + _shape_plan: u32, + font_ref: u32, + buf_ref: u32, + _features: u32, + _num_features: u32, +) -> i32 { + let mut rng = Rng::from_seed(123456); + let font = Font::from_ref(font_ref); + font.shape_with(buf_ref, "ot"); + let mut buffer = GlyphBuffer::from_ref(buf_ref); + for mut item in buffer.glyphs.iter_mut() { + // Randomize it! + item.x_offset = ((rng.rand_u32() as i32) >> 24) - 120; + item.y_offset = ((rng.rand_u32() as i32) >> 24) - 120; + } + // Buffer is written back to HB on drop + 1 +} |