sidorares / node-harfbuzz

node.js harfbuzz bindings
MIT License
3 stars 3 forks source link

Example crashes #3

Open nasser opened 6 years ago

nasser commented 6 years ago

The example in the README crashes. The freetype package does not expose a handle property on its face object, so the call var glyphs = hb(face.handle, "This is test text to shape"); passes an undefined to the native addon, triggering a crash.

There is already a PR open for a better integration with the freetype package, but HarfBuzz is capable of OpenType font parsing on its own, which is all freetype seems to be used for. I don't know that it makes sense to take on an additional native dependency to do something that HarfBuzz itself can already do.

My PR removes the dependency on freetype and fixes the crash. The API changed, the module is no longer a function, instead its an object with a shape and createFont functions.

sidorares commented 6 years ago

This repo was mainly PoC for complex scripts support for https://github.com/sidorares/ntk ntk also needs freetype to rasterize font and upload glyphs to X server, Ideally I want harfbuzz warapper that would allow to pass code to get glyph metrics via js callback to avoid double loading of the font. Do think this is easy to achieve?

At the same time, for other users what you propose is probably much easier to use (no need to create freetype font and pass it manually)

nasser commented 6 years ago

That's a reasonable use case. Ideally, we'd be able to do it without taking on freetype as a dependency, and specifically without making the C++ of this library depend on the C++ of the freetype library. If the freetype library exposed a handle property like in your example, then all we'd have to do is expose the harfbuzz freetype functions and pass in the freetype handle from JavaScript. I wonder what @ericfreese thinks about that.

sidorares commented 6 years ago

What I also want to keep as an option - if for example I start using wasm version of freetype it should be still compatible with harfbuzz module. From my understanding harfbuzz does not care about actual curves in the glyphs, just certain boxes metrics and some extra tables in the font, and I'd really like to pass that explicitly (or have two apis "high level" and "low level" where everything is manual and controlled)

sidorares commented 6 years ago

Also really keen to try emscripten compiled harfbuzz as well

khaledhosny commented 6 years ago

HarfBuzz has callback font functions, exposing this in this module would allow using any implementation that can provide these callback functions, without making it a hard dependency. The default should the internal HarfBuzz ones.