-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS bindings for color needed #87
Comments
You should modify
Indeed.
Yes, we need to bind the |
I got painting to a canvas context working here: chearon@7676278 Since it allows harfbuzz to make calls into JS, it raises the question "should SVG creation in hbjs.cc be ported to JS too?" but I was unsure if I should make such a large change. Either way, we could add painting color glyphs onto that. |
That's great! Is that upstream yet?
I believe so. The SVG was a hack IMO to work around not binding the draw API.
Either way sounds fine to me.
Yeah, that would be great. Then we can port the hb-cairo painting code to a canvas-based implementation. |
Not yet, but I'll make a PR soon. I've got several patches I'm using for a JS text stack that I just need to touch up. Okay, I'll move the SVG stuff into JS. That'll be nice!
I just read the 7.0.0 release notes and it sounds like we should enable the hb-paint API (currently harfbuzzjs uses hb-draw to render to SVG), use that, and then for the emoji part, hand write JS that's based on the hb-cairo glyph drawing functions? It's interesting that the hb-draw and hb-paint APIs draw directly to a context. I always assumed FreeType was the "right" way to draw glyphs because it cached the bitmaps or something. Is that not true? In my JS text layout project, I only draw contours manually if someone does something like color a diacritic. Whenever I can, I use |
This is really promising! In parallel I’ve been generalizing the drawing instructions produced by the Samsa library, removing SVG-specific output, and expecting more from the consumer application to build the SVG (or canvas). This demo page shows Samsa-generated instructions being used for SVG and canvas, presented next to each other (and also native and harfbuzz rendering): https://www.axis-praxis.org/samsa/ap3/ap3.html Using the same approach to deal with COLRv1 will result in JS similar to what is needed for the JS bindings for Harfbuzz, whether I generate SVG or canvas. Note that the SVG solution will not handle radial or conic gradients, but canvas will. BTW the harfbuzz wasm used in the demo page above is built with |
HarfBuzz does not currently have a rasterizer, so the draw API is akin to As for There is a hack, however, that Mozilla’s pdf.js does to work around this: before setting the font on the canvas, modify it by removing all |
FreeType does have a caching subsystem, but that is rarely used. It's still up to the FreeType client to cache the bitmaps. With HarfBuzz, the rasterization is also offloaded to the client, which would then need to cache the canvas rasters in an atlas to do fast blitting... Or the hack Khaled mentioned, if platform-level speed and rasterization is desired but with HarfBuzzJS shaping. |
As a consumer of harfbuzzjs you can shape and wrap a paragraph and then have fast painting to a canvas if you find safe boundaries to call For example if you have It's still a hack since you're assuming the same shaping results as native. Maybe one day we can have shaping and glyph drawing APIs in the browser.
That is very interesting, thank you! Since I found
Ok, thanks for the answer. It would be interesting to try the bitmap caching in a canvas, but since those have to be colored upon drawing, not sure if that negates it. Sounds like I have some profiling to do... |
I managed to re-implment the glyphToPath in JS here #97, it should serve as an example on how to do callbacks. I’m not very well versed in JS or Emscripten, so if actual users of the library can look into this and let me know if it works for them. We probably should do the same to shapeWithTrace and drop hbjs.cc entirely. |
I built a version of hb.wasm to try on COLRv1 fonts. (I used the supplied build.sh script, but commented out
#define HB_NO_COLOR
in hb-config.hh)The new hb.wasm works, but emits monochrome glyphs as before. I guess we need some JS bindings that will allow me to use color. When I came across a related problem for variable fonts (#34), @ebraminio was super helpful. Are you there for me again by any chance? :)
@behdad suggests @khaledhosny may also be able to fix the JS side. Any help appreciated.
The text was updated successfully, but these errors were encountered: