See the demo here.
- Install clang, lld and git
Note that if building on Mac OS X, clang 11.0 needs to be installed from Homebrew (
brew install clang). Also note that Homebrew clang is not in
the path by default, so you need to add
/usr/local/opt/llvm/bin to your
path or you will get weird compiled errors.
Usage and testing
(cd examples && node hbjs.example.node.js)
We provide a tiny wrapper (
hbjs.js) around the main functionality of harfbuzz, but it's also easy to use other parts. (See
example/nohbjs.js as an example. However, you may need a custom build to expose additional functionality.)
Can be added with
npm i harfbuzzjs or
yarn add harfbuzzjs, see the examples for
how to use it.
Need more of the library?
harfbuzzjs uses a stripped-down version of Harfbuzz generated by compiling Harfbuzz with
-DHB_TINY. This may mean that some functions you need are not available. Look at
src/hb-config.hh in the Harfbuzz source directory to see what has been removed. For example,
HB_LEAN which (amongst other things) defines
HB_NO_OT_GLYPH_NAMES. If, for example, you really need to get at the glyph names:
- First, undefine the macro in question, by adding e.g.
- Next, export any function that you need by adding a line to
build.sh; in this case
heapu8.subarray. The best way to do this is to look at
hbjs.jsfor functions which use similar signatures.
If you have extended harfbuzzjs in ways that you think others will also benefit from, please raise a pull request. If there are parts of Harfbuzz that you need but the instructions above don't work, describe what you are trying to do in an issue.
Using the library in a bigger emscripten project?
Optionally you can install
binaryen and use
wasm-opt -Oz hb.wasm -o hb.wasm
binaryen also provides
wasm-dis which can be used for,
wasm-dis hb.wasm | grep export wasm-dis hb.wasm | grep import
with that you can check if the built wasm file only exports things you need and doesn't need to import anything, as usual with wasm files built here.