[wasm-graphite] Ensure native direction here too
Binds buffer_get_script and script_get_horizontal_direction.
This commit is contained in:
parent
cbc71c56bc
commit
ec3270c7bb
|
@ -132,6 +132,14 @@ HB_WASM_API (direction_t, buffer_get_direction) (HB_WASM_EXEC_ENV
|
|||
return (direction_t) hb_buffer_get_direction (buffer);
|
||||
}
|
||||
|
||||
HB_WASM_API (script_t, buffer_get_script) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer))
|
||||
{
|
||||
HB_REF2OBJ (buffer);
|
||||
|
||||
return hb_script_to_iso15924_tag (hb_buffer_get_script (buffer));
|
||||
}
|
||||
|
||||
HB_WASM_API (void, buffer_reverse) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer))
|
||||
{
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright © 2023 Behdad Esfahbod
|
||||
*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
#ifndef HB_WASM_API_COMMON_HH
|
||||
#define HB_WASM_API_COMMON_HH
|
||||
|
||||
#include "hb-wasm-api.hh"
|
||||
|
||||
namespace hb {
|
||||
namespace wasm {
|
||||
|
||||
|
||||
HB_WASM_API (direction_t, script_get_horizontal_direction) (HB_WASM_EXEC_ENV
|
||||
script_t script)
|
||||
{
|
||||
return (direction_t)
|
||||
hb_script_get_horizontal_direction (hb_script_from_iso15924_tag (script));
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif /* HB_WASM_API_COMMON_HH */
|
|
@ -50,6 +50,8 @@ static void debugprint4 (HB_WASM_EXEC_ENV char *str, int32_t i1, int32_t i2, int
|
|||
* https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md */
|
||||
static NativeSymbol _hb_wasm_native_symbols[] =
|
||||
{
|
||||
/* common */
|
||||
NATIVE_SYMBOL ("(i)i", script_get_horizontal_direction),
|
||||
|
||||
/* blob */
|
||||
NATIVE_SYMBOL ("(i)", blob_free),
|
||||
|
@ -60,6 +62,7 @@ static NativeSymbol _hb_wasm_native_symbols[] =
|
|||
NATIVE_SYMBOL ("(ii)", buffer_copy_contents),
|
||||
NATIVE_SYMBOL ("(ii)i", buffer_set_contents),
|
||||
NATIVE_SYMBOL ("(i)i", buffer_get_direction),
|
||||
NATIVE_SYMBOL ("(i)i", buffer_get_script),
|
||||
NATIVE_SYMBOL ("(i)", buffer_reverse),
|
||||
NATIVE_SYMBOL ("(i)", buffer_reverse_clusters),
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "hb-wasm-api-blob.hh"
|
||||
#include "hb-wasm-api-buffer.hh"
|
||||
#include "hb-wasm-api-common.hh"
|
||||
#include "hb-wasm-api-face.hh"
|
||||
#include "hb-wasm-api-font.hh"
|
||||
#include "hb-wasm-api-shape.hh"
|
||||
|
|
|
@ -92,6 +92,14 @@ typedef enum {
|
|||
#define DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5)
|
||||
#define DIRECTION_REVERSE(dir) ((direction_t) (((unsigned int) (dir)) ^ 1))
|
||||
|
||||
typedef tag_t script_t; /* ISO 15924 representation of Unicode scripts. */
|
||||
|
||||
|
||||
/* common */
|
||||
|
||||
HB_WASM_API (direction_t, script_get_horizontal_direction) (HB_WASM_EXEC_ENV
|
||||
script_t script);
|
||||
|
||||
|
||||
/* blob */
|
||||
|
||||
|
@ -151,6 +159,9 @@ HB_WASM_API (bool_t, buffer_set_contents) (HB_WASM_EXEC_ENV
|
|||
HB_WASM_API (direction_t, buffer_get_direction) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer));
|
||||
|
||||
HB_WASM_API (script_t, buffer_get_script) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer));
|
||||
|
||||
HB_WASM_API (void, buffer_reverse) (HB_WASM_EXEC_ENV
|
||||
ptr_d(buffer_t, buffer));
|
||||
|
||||
|
|
|
@ -329,6 +329,7 @@ hb_wasm_sources = files(
|
|||
'hb-wasm-api.hh',
|
||||
'hb-wasm-api-blob.hh',
|
||||
'hb-wasm-api-buffer.hh',
|
||||
'hb-wasm-api-common.hh',
|
||||
'hb-wasm-api-face.hh',
|
||||
'hb-wasm-api-font.hh',
|
||||
'hb-wasm-api-shape.hh',
|
||||
|
|
|
@ -38,15 +38,24 @@ static void free_table (const void *data, const void *table_data)
|
|||
bool_t
|
||||
shape (font_t *font, buffer_t *buffer)
|
||||
{
|
||||
face_t *face = font_get_face (font);
|
||||
|
||||
blob_t blob = face_reference_table (face, TAG ('c','m','a','p'));
|
||||
|
||||
blob_free (&blob);
|
||||
direction_t direction = buffer_get_direction (buffer);
|
||||
direction_t horiz_dir = script_get_horizontal_direction (buffer_get_script (buffer));
|
||||
/* TODO vertical:
|
||||
* The only BTT vertical script is Ogham, but it's not clear to me whether OpenType
|
||||
* Ogham fonts are supposed to be implemented BTT or not. Need to research that
|
||||
* first. */
|
||||
if ((DIRECTION_IS_HORIZONTAL (direction) &&
|
||||
direction != horiz_dir && horiz_dir != DIRECTION_INVALID) ||
|
||||
(DIRECTION_IS_VERTICAL (direction) &&
|
||||
direction != DIRECTION_TTB))
|
||||
{
|
||||
buffer_reverse_clusters (buffer);
|
||||
direction = DIRECTION_REVERSE (direction);
|
||||
}
|
||||
|
||||
buffer_contents_t contents = buffer_copy_contents (buffer);
|
||||
direction_t direction = buffer_get_direction (buffer);
|
||||
|
||||
face_t *face = font_get_face (font);
|
||||
const gr_face_ops ops = {sizeof (gr_face_ops), ©_table, &free_table};
|
||||
gr_face *grface = gr_make_face_with_ops (face, &ops, gr_face_preloadAll);
|
||||
|
||||
|
|
Loading…
Reference in New Issue