Skip to content

Commit

Permalink
Add an experimental wasm shaper (#122)
Browse files Browse the repository at this point in the history
Closes #117
  • Loading branch information
asibahi authored Jul 12, 2024
1 parent cb08d76 commit 388d78d
Show file tree
Hide file tree
Showing 11 changed files with 778 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Cargo.lock
.directory
.DS_Store
/src/complex/*.ri
.vscode
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ unicode-bidi-mirroring = "0.3.0"
unicode-ccc = "0.3.0"
unicode-properties = { version = "0.1.0", default-features = false, features = ["general-category"] }
unicode-script = "0.5.2"
wasmi = { version = "0.34.0", optional = true }
log = "0.4.22"

[dependencies.ttf-parser]
version = "0.24.0"
Expand All @@ -36,6 +38,7 @@ features = [
[features]
default = ["std"]
std = ["ttf-parser/std"]
wasm-shaper = ["std", "dep:wasmi"]

[dev-dependencies]
pico-args = { version = "0.5", features = ["eq-separator"] }
Expand Down
2 changes: 1 addition & 1 deletion src/hb/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct GlyphPosition {
/// How much the glyph moves on the Y-axis before drawing it, this should
/// not affect how much the line advances.
pub y_offset: i32,
var: u32,
pub(crate) var: u32,
}

unsafe impl bytemuck::Zeroable for GlyphPosition {}
Expand Down
4 changes: 4 additions & 0 deletions src/hb/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,17 @@ impl<'a> hb_font_t<'a> {
}

#[derive(Clone, Copy, Default)]
#[repr(C)]
pub struct hb_glyph_extents_t {
pub x_bearing: i32,
pub y_bearing: i32,
pub width: i32,
pub height: i32,
}

unsafe impl bytemuck::Zeroable for hb_glyph_extents_t {}
unsafe impl bytemuck::Pod for hb_glyph_extents_t {}

fn find_best_cmap_subtable(face: &ttf_parser::Face) -> Option<u16> {
use ttf_parser::PlatformId;

Expand Down
2 changes: 2 additions & 0 deletions src/hb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ mod ot_shaper_vowel_constraints;
mod paint_extents;
mod set_digest;
pub mod shape;
#[cfg(feature = "wasm-shaper")]
mod shape_wasm;
mod tag;
mod tag_table;
mod text_parser;
Expand Down
27 changes: 21 additions & 6 deletions src/hb/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,27 @@ pub fn shape_with_plan(
if buffer.len > 0 {
// Save the original direction, we use it later.
let target_direction = buffer.direction;
shape_internal(&mut hb_ot_shape_context_t {
plan,
face,
buffer: &mut buffer,
target_direction,
});

#[cfg(feature = "wasm-shaper")]
{
super::shape_wasm::shape_with_wasm(face, plan, &mut buffer).unwrap_or_else(|| {
shape_internal(&mut hb_ot_shape_context_t {
plan,
face,
buffer: &mut buffer,
target_direction,
});
});
}
#[cfg(not(feature = "wasm-shaper"))]
{
shape_internal(&mut hb_ot_shape_context_t {
plan,
face,
buffer: &mut buffer,
target_direction,
});
}
}

GlyphBuffer(buffer)
Expand Down
Loading

0 comments on commit 388d78d

Please sign in to comment.