From 0a51ed31b0bba05727210f27548ebd3b55052fe3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 24 Feb 2023 10:07:59 -0700 Subject: [PATCH] [wasm-api] Bind buffer_get_direction --- src/hb-wasm-api-buffer.hh | 10 ++++++++++ src/hb-wasm-api-list.hh | 1 + src/hb-wasm-api.h | 17 +++++++++++++++++ src/wasm-graphite/shape.cc | 11 ++++++----- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/hb-wasm-api-buffer.hh b/src/hb-wasm-api-buffer.hh index d4f517421..bb78cd924 100644 --- a/src/hb-wasm-api-buffer.hh +++ b/src/hb-wasm-api-buffer.hh @@ -128,6 +128,16 @@ buffer_set_contents (HB_WASM_EXEC_ENV return true; } +direction_t +buffer_get_direction (HB_WASM_EXEC_ENV + ptr_t(buffer_t) bufferref) +{ + HB_REF2OBJ (buffer); + + return (direction_t) hb_buffer_get_direction (buffer); +} + + }} #endif /* HB_WASM_API_BUFFER_HH */ diff --git a/src/hb-wasm-api-list.hh b/src/hb-wasm-api-list.hh index 5f834dddb..53faca01e 100644 --- a/src/hb-wasm-api-list.hh +++ b/src/hb-wasm-api-list.hh @@ -59,6 +59,7 @@ static NativeSymbol _hb_wasm_native_symbols[] = NATIVE_SYMBOL ("(ii)", buffer_contents_realloc), NATIVE_SYMBOL ("(ii)", buffer_copy_contents), NATIVE_SYMBOL ("(ii)i", buffer_set_contents), + NATIVE_SYMBOL ("(i)i", buffer_get_direction), /* face */ NATIVE_SYMBOL ("(iii)", face_reference_table), diff --git a/src/hb-wasm-api.h b/src/hb-wasm-api.h index 10bd92a74..a0ab24058 100644 --- a/src/hb-wasm-api.h +++ b/src/hb-wasm-api.h @@ -75,6 +75,20 @@ typedef uint32_t hb_mask_t; typedef uint32_t tag_t; #define TAG(c1,c2,c3,c4) ((tag_t)((((uint32_t)(c1)&0xFF)<<24)|(((uint32_t)(c2)&0xFF)<<16)|(((uint32_t)(c3)&0xFF)<<8)|((uint32_t)(c4)&0xFF))) +typedef enum { + DIRECTION_INVALID = 0, + DIRECTION_LTR = 4, + DIRECTION_RTL, + DIRECTION_TTB, + DIRECTION_BTT +} direction_t; +#define DIRECTION_IS_VALID(dir) ((((unsigned int) (dir)) & ~3U) == 4) +#define DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 4) +#define DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 6) +#define DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 4) +#define DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5) +#define DIRECTION_REVERSE(dir) ((direction_t) (((unsigned int) (dir)) ^ 1)) + /* blob */ @@ -131,6 +145,9 @@ HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV ptr_t(buffer_t), ptr_t(const buffer_contents_t)); +HB_WASM_API (direction_t, buffer_get_direction) (HB_WASM_EXEC_ENV + ptr_t(buffer_t)); + /* face */ diff --git a/src/wasm-graphite/shape.cc b/src/wasm-graphite/shape.cc index 08e564d18..b8e848a66 100644 --- a/src/wasm-graphite/shape.cc +++ b/src/wasm-graphite/shape.cc @@ -39,6 +39,7 @@ shape (font_t *font, buffer_t *buffer) blob_free (&blob); buffer_contents_t contents = buffer_copy_contents (buffer); + direction_t direction = buffer_get_direction (buffer); const gr_face_ops ops = {sizeof (gr_face_ops), ©_table, nullptr};//&free_table}; gr_face *grface = gr_make_face_with_ops (face, &ops, gr_face_preloadAll); @@ -59,7 +60,7 @@ shape (font_t *font, buffer_t *buffer) 0, // https://github.com/harfbuzz/harfbuzz/issues/3439#issuecomment-1442650148 nullptr, gr_utf32, chars, contents.length, - 2/* | (buffer_get_direction (buffer) == DIRECTION_RTL ? 1 : 0)*/); + 2 | (direction == DIRECTION_RTL ? 1 : 0)); free (chars); @@ -92,7 +93,7 @@ shape (font_t *font, buffer_t *buffer) float yscale = (float) font_y_scale / upem; yscale *= yscale / xscale; unsigned int curradv = 0; - if (0)//HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) + if (DIRECTION_IS_BACKWARD (direction)) { curradv = gr_slot_origin_X(gr_seg_first_slot(seg)) * xscale; clusters[0].advance = gr_seg_advance_X(seg) * xscale - curradv; @@ -121,7 +122,7 @@ shape (font_t *font, buffer_t *buffer) c->num_chars = before - c->base_char; c->base_glyph = ic; c->num_glyphs = 0; - if (0)//HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) + if (DIRECTION_IS_BACKWARD (direction)) { c->advance = curradv - gr_slot_origin_X(is) * xscale; curradv -= c->advance; @@ -140,7 +141,7 @@ shape (font_t *font, buffer_t *buffer) clusters[ci].num_chars = after + 1 - clusters[ci].base_char; } - if (0)//HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) + if (DIRECTION_IS_BACKWARD (direction)) clusters[ci].advance += curradv; else clusters[ci].advance += gr_seg_advance_X(seg) * xscale - curradv; @@ -162,7 +163,7 @@ shape (font_t *font, buffer_t *buffer) unsigned int currclus = 0xFFFFFFFF; const glyph_info_t *info = contents.info; glyph_position_t *pPos = contents.pos; - if (1)//!HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) + if (!DIRECTION_IS_BACKWARD (direction)) { curradvx = 0; for (is = gr_seg_first_slot (seg); is; pPos++, ++info, is = gr_slot_next_in_segment (is))