From 425fc7f3ee257b7aee9a481a04d368c4ccf57c4d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 22 Feb 2023 12:19:06 -0700 Subject: [PATCH] [wasm] Add wasm shaper skeleton --- meson.build | 2 + src/Makefile.sources | 1 + src/harfbuzz-subset.cc | 1 + src/harfbuzz.cc | 1 + src/hb-shaper-list.hh | 5 +++ src/hb-wasm-shape.cc | 100 +++++++++++++++++++++++++++++++++++++++++ src/meson.build | 1 + 7 files changed, 111 insertions(+) create mode 100644 src/hb-wasm-shape.cc diff --git a/meson.build b/meson.build index 6bf8d05da..95dbf2795 100644 --- a/meson.build +++ b/meson.build @@ -229,6 +229,8 @@ if chafa_dep.found() conf.set('HAVE_CHAFA', 1) endif +conf.set('HAVE_WASM', 1) + if graphite2_dep.found() or graphite_dep.found() conf.set('HAVE_GRAPHITE2', 1) endif diff --git a/src/Makefile.sources b/src/Makefile.sources index fd7c3b55e..4edea33c8 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -255,6 +255,7 @@ HB_BASE_sources = \ hb-unicode.hh \ hb-utf.hh \ hb-vector.hh \ + hb-wasm-shape.cc \ hb-priority-queue.hh \ hb.hh \ $(NULL) diff --git a/src/harfbuzz-subset.cc b/src/harfbuzz-subset.cc index c0e23b3eb..743a3539d 100644 --- a/src/harfbuzz-subset.cc +++ b/src/harfbuzz-subset.cc @@ -60,3 +60,4 @@ #include "hb-subset.cc" #include "hb-ucd.cc" #include "hb-unicode.cc" +#include "hb-wasm-shape.cc" diff --git a/src/harfbuzz.cc b/src/harfbuzz.cc index d7e8a93f3..5b8196126 100644 --- a/src/harfbuzz.cc +++ b/src/harfbuzz.cc @@ -58,3 +58,4 @@ #include "hb-ucd.cc" #include "hb-unicode.cc" #include "hb-uniscribe.cc" +#include "hb-wasm-shape.cc" diff --git a/src/hb-shaper-list.hh b/src/hb-shaper-list.hh index 4158b7094..f079caf4d 100644 --- a/src/hb-shaper-list.hh +++ b/src/hb-shaper-list.hh @@ -33,6 +33,11 @@ /* v--- Add new shapers in the right place here. */ +#ifdef HAVE_WASM +/* Only picks up fonts that have a "Wasm" table. */ +HB_SHAPER_IMPLEMENT (wasm) +#endif + #ifdef HAVE_GRAPHITE2 /* Only picks up fonts that have a "Silf" table. */ HB_SHAPER_IMPLEMENT (graphite2) diff --git a/src/hb-wasm-shape.cc b/src/hb-wasm-shape.cc new file mode 100644 index 000000000..e67b880dc --- /dev/null +++ b/src/hb-wasm-shape.cc @@ -0,0 +1,100 @@ +/* + * Copyright © 2011 Google, Inc. + * + * 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. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-shaper-impl.hh" + +#ifdef HAVE_WASM + +/* + * shaper face data + */ + +#define HB_WASM_TAG_WASM HB_TAG('W','a','s','m') + +struct hb_wasm_face_data_t { + hb_blob_t *blob; +}; + +hb_wasm_face_data_t * +_hb_wasm_shaper_face_data_create (hb_face_t *face) +{ + hb_blob_t *wasm_blob = hb_face_reference_table (face, HB_WASM_TAG_WASM); + if (!hb_blob_get_length (wasm_blob)) + { + hb_blob_destroy (wasm_blob); + return nullptr; + } + + hb_wasm_face_data_t *data = (hb_wasm_face_data_t *) hb_calloc (1, sizeof (hb_wasm_face_data_t)); + if (unlikely (!data)) + return nullptr; + + data->blob = wasm_blob; + + return data; +} + +void +_hb_wasm_shaper_face_data_destroy (hb_wasm_face_data_t *data) +{ + hb_blob_destroy (data->blob); + hb_free (data); +} + + +/* + * shaper font data + */ + +struct hb_wasm_font_data_t {}; + +hb_wasm_font_data_t * +_hb_wasm_shaper_font_data_create (hb_font_t *font HB_UNUSED) +{ + return (hb_wasm_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_wasm_shaper_font_data_destroy (hb_wasm_font_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper + */ + +hb_bool_t +_hb_wasm_shape (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + return false; +} + +#endif diff --git a/src/meson.build b/src/meson.build index 30b99cf34..263677f84 100644 --- a/src/meson.build +++ b/src/meson.build @@ -256,6 +256,7 @@ hb_base_sources = files( 'hb-unicode.hh', 'hb-utf.hh', 'hb-vector.hh', + 'hb-wasm-shape.cc', 'hb.hh', )