Skip to content

Commit

Permalink
should be done.
Browse files Browse the repository at this point in the history
  • Loading branch information
asibahi committed Jul 11, 2024
1 parent 84b9f58 commit 234ef56
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/hb/shape_wasm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::{borrow::ToOwned, ffi::CString, format};
use core::ffi::CStr;
use ttf_parser::{GlyphId, Tag};
use wasmi::{self, AsContextMut, Caller, Engine, Linker, Module, Store};
use wasmi::{self, AsContextMut, Caller, Config, Engine, Linker, Module, Store};

use super::{
buffer::{hb_buffer_t, GlyphPosition},
Expand All @@ -27,12 +27,13 @@ pub(crate) fn shape_with_wasm(
.raw_face()
.table(ttf_parser::Tag::from_bytes(b"Wasm"))?;

let data = ShapingData { font, plan, buffer };
let mut config = Config::default();
config.compilation_mode(wasmi::CompilationMode::Lazy);
let engine = Engine::new(&config);

let mut store = Store::new(&Engine::default(), data);
let module = Module::new(store.engine(), wasm_blob).ok()?;
let module = Module::new(&engine, wasm_blob).ok()?;

let mut linker = Linker::new(store.engine());
let mut linker = Linker::new(&engine);

// Not every function defined by HarfBuzz is defined here.
// Only the ones used by the harfbuzz_wasm crate
Expand Down Expand Up @@ -70,6 +71,9 @@ pub(crate) fn shape_with_wasm(
.func_wrap("env", "shape_with", shape_with)
.ok()?;

let data = ShapingData { font, plan, buffer };
let mut store = Store::new(&engine, data);

let instance = linker
.instantiate(&mut store, &module)
.ok()?
Expand Down Expand Up @@ -190,7 +194,7 @@ fn font_glyph_to_string(
.font
.glyph_name(GlyphId(glyph as u16))
.map(ToOwned::to_owned)
.unwrap_or(format!("g{glyph:4}"));
.unwrap_or(format!("g{:0>4}", glyph));
name.truncate(len as usize - 1);
let name = CString::new(name).unwrap();
let name = name.as_bytes_with_nul();
Expand Down

0 comments on commit 234ef56

Please sign in to comment.