From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- gfx/harfbuzz/src/wasm/sample/c/Makefile | 25 +++++++++ gfx/harfbuzz/src/wasm/sample/c/shape-fallback.cc | 60 +++++++++++++++++++++ gfx/harfbuzz/src/wasm/sample/c/shape-ot.cc | 18 +++++++ gfx/harfbuzz/src/wasm/sample/c/test.ttf | Bin 0 -> 22116 bytes .../src/wasm/sample/rust/hello-wasm/Cargo.toml | 13 +++++ .../src/wasm/sample/rust/hello-wasm/src/lib.rs | 24 +++++++++ 6 files changed, 140 insertions(+) create mode 100644 gfx/harfbuzz/src/wasm/sample/c/Makefile create mode 100644 gfx/harfbuzz/src/wasm/sample/c/shape-fallback.cc create mode 100644 gfx/harfbuzz/src/wasm/sample/c/shape-ot.cc create mode 100644 gfx/harfbuzz/src/wasm/sample/c/test.ttf create mode 100644 gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/Cargo.toml create mode 100644 gfx/harfbuzz/src/wasm/sample/rust/hello-wasm/src/lib.rs (limited to 'gfx/harfbuzz/src/wasm/sample') diff --git a/gfx/harfbuzz/src/wasm/sample/c/Makefile b/gfx/harfbuzz/src/wasm/sample/c/Makefile new file mode 100644 index 0000000000..4ee073b645 --- /dev/null +++ b/gfx/harfbuzz/src/wasm/sample/c/Makefile @@ -0,0 +1,25 @@ +ADD_TABLE = ../../../addTable.py + +all: test-fallback.wasm.ttf test-ot.wasm.ttf + +%.wasm: %.cc ../../../hb-wasm-api.h + clang \ + --target=wasm32-unknown-wasi \ + -Wl,--no-entry \ + -fvisibility=hidden \ + -Wl,--allow-undefined \ + -nostdlib \ + -I ../../.. \ + $< \ + -o $@ + +test-fallback.wasm.ttf: test.ttf shape-fallback.wasm $(ADD_TABLE) + python $(ADD_TABLE) $< $@ shape-fallback.wasm + +test-ot.wasm.ttf: test.ttf shape-ot.wasm $(ADD_TABLE) + python $(ADD_TABLE) $< $@ shape-ot.wasm + +clean: + $(RM) test-fallback.wasm.ttf test-ot.wasm.ttf shape-fallback.wasm shape-ot.wasm + +.PRECIOUS: *.wasm diff --git a/gfx/harfbuzz/src/wasm/sample/c/shape-fallback.cc b/gfx/harfbuzz/src/wasm/sample/c/shape-fallback.cc new file mode 100644 index 0000000000..7787bbae7a --- /dev/null +++ b/gfx/harfbuzz/src/wasm/sample/c/shape-fallback.cc @@ -0,0 +1,60 @@ +#define HB_WASM_INTERFACE(ret_t, name) __attribute__((export_name(#name))) ret_t name + +#include + +extern "C" { +void debugprint (const char *s); +void debugprint1 (const char *s, int32_t); +void debugprint2 (const char *s, int32_t, int32_t); +} + +bool_t +shape (void *shape_plan, + font_t *font, + buffer_t *buffer, + const feature_t *features, + uint32_t num_features) +{ + face_t *face = font_get_face (font); + + blob_t blob = BLOB_INIT; + face_copy_table (face, TAG ('c','m','a','p'), &blob); + + debugprint1 ("cmap length", blob.length); + + blob_free (&blob); + + buffer_contents_t contents = BUFFER_CONTENTS_INIT; + if (!buffer_copy_contents (buffer, &contents)) + return false; + + debugprint1 ("buffer length", contents.length); + + glyph_outline_t outline = GLYPH_OUTLINE_INIT; + + for (unsigned i = 0; i < contents.length; i++) + { + char name[64]; + + debugprint1 ("glyph at", i); + + font_glyph_to_string (font, contents.info[i].codepoint, name, sizeof (name)); + + debugprint (name); + + contents.info[i].codepoint = font_get_glyph (font, contents.info[i].codepoint, 0); + contents.pos[i].x_advance = font_get_glyph_h_advance (font, contents.info[i].codepoint); + + font_copy_glyph_outline (font, contents.info[i].codepoint, &outline); + debugprint1 ("num outline points", outline.n_points); + debugprint1 ("num outline contours", outline.n_contours); + } + + glyph_outline_free (&outline); + + bool_t ret = buffer_set_contents (buffer, &contents); + + buffer_contents_free (&contents); + + return ret; +} diff --git a/gfx/harfbuzz/src/wasm/sample/c/shape-ot.cc b/gfx/harfbuzz/src/wasm/sample/c/shape-ot.cc new file mode 100644 index 0000000000..9081cfebcc --- /dev/null +++ b/gfx/harfbuzz/src/wasm/sample/c/shape-ot.cc @@ -0,0 +1,18 @@ +#define HB_WASM_INTERFACE(ret_t, name) __attribute__((export_name(#name))) ret_t name + +#include + +extern "C" { +void debugprint1 (const char *s, int32_t); +void debugprint2 (const char *s, int32_t, int32_t); +} + +bool_t +shape (void *shape_plan, + font_t *font, + buffer_t *buffer, + const feature_t *features, + uint32_t num_features) +{ + return shape_with (font, buffer, features, num_features, "ot"); +} diff --git a/gfx/harfbuzz/src/wasm/sample/c/test.ttf b/gfx/harfbuzz/src/wasm/sample/c/test.ttf new file mode 100644 index 0000000000..2ba04f611b Binary files /dev/null and b/gfx/harfbuzz/src/wasm/sample/c/test.ttf differ 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 +} -- cgit v1.2.3