Open nasser opened 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)
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.
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)
Also really keen to try emscripten compiled harfbuzz as well
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.
The example in the README crashes. The
freetype
package does not expose ahandle
property on itsface
object, so the callvar glyphs = hb(face.handle, "This is test text to shape");
passes anundefined
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 allfreetype
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 ashape
andcreateFont
functions.