Skip to content

[wasm] WebAssembly shaper #4131

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

Merged
merged 149 commits into from
May 17, 2023
Merged

[wasm] WebAssembly shaper #4131

merged 149 commits into from
May 17, 2023

Conversation

behdad
Copy link
Member

@behdad behdad commented Feb 22, 2023

This adds a wasm shaper that when called (default, when built), loads a WebAssembly program from the Wasm table of the font and calls its bool shape(font*,buffer*) function to shape the buffer.

The API available to the wasm program is in hb-wasm-api.h.

@behdad behdad marked this pull request as draft February 22, 2023 19:58
@behdad behdad force-pushed the wasm branch 3 times, most recently from 889448b to e06db9d Compare February 22, 2023 22:45
@behdad
Copy link
Member Author

behdad commented Feb 22, 2023

cc @ebraminio

@@ -21,6 +21,8 @@ option('directwrite', type: 'feature', value: 'disabled',
description: 'Enable DirectWrite shaper backend on Windows (experimental)')
option('coretext', type: 'feature', value: 'disabled',
description: 'Enable CoreText shaper backend on macOS')
option('wasm', type: 'feature', value: 'disabled',
description: 'Enable WebAssembly shaper backend')
Copy link
Collaborator

@ebraminio ebraminio Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work. Since this apparently will use a generic 'Wasm' table tag from a font maybe it can be named a 'font backend' in hope someday it gains also outline drawing / painting capabilities.

@behdad behdad force-pushed the wasm branch 11 times, most recently from bcf92a4 to aceea72 Compare February 23, 2023 22:23
@behdad behdad changed the title Wasm WebAssembly shaper Feb 23, 2023
@behdad behdad changed the title WebAssembly shaper [wasm] WebAssembly shaper Feb 23, 2023
@behdad
Copy link
Member Author

behdad commented Feb 23, 2023

cc @jfkthame

@behdad
Copy link
Member Author

behdad commented Feb 24, 2023

I compiled graphite to a wasm library and and integrated it with hb-wasm-api, then embedded it in CharilSIL. The CharisSIL font is 1.7MB. The Wasm table with entire graphite library in it is 110kb. It renders.

cc @mhosken

@behdad behdad marked this pull request as ready for review February 24, 2023 19:09
@behdad
Copy link
Member Author

behdad commented Feb 24, 2023

I think with a bit of polish this can actually be merged as an experimental feature, off by default.

@behdad behdad force-pushed the wasm branch 4 times, most recently from 1da04d3 to 2f8a0f5 Compare February 24, 2023 23:07
Copy link
Member Author

@behdad behdad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API masquerades the font/face/buffer tokens as pointers, for more natural-looking representation. Any reason you explicitly talk about tokens?

You don't do that about blobs.

@behdad
Copy link
Member Author

behdad commented May 17, 2023

Maybe better to add API docs to hb-wasm-api.h and point people to that instead?

@simoncozens
Copy link
Collaborator

The API masquerades the font/face/buffer tokens as pointers, for more natural-looking representation. Any reason you explicitly talk about tokens?
You don't do that about blobs.

I guess it's because they're opaque pointers which refer to memory in Harfbuzz-land, and you can't do anything with them, whereas you can dereference and use the blob data. I've no objection to calling them pointers if you prefer.

Maybe better to add API docs to hb-wasm-api.h and point people to that instead?

I wrote this because I received complaints that "read the header file" was not adequate documentation. :-)

@behdad
Copy link
Member Author

behdad commented May 17, 2023

I've no objection to calling them pointers if you prefer.

I think I prefer that since that's what's in the API. Up to you though.

Maybe better to add API docs to hb-wasm-api.h and point people to that instead?

I wrote this because I received complaints that "read the header file" was not adequate documentation. :-)

I meant documenting the API and having gtkdoc generate API docs like our normal API documentation.

Thanks for this.

@behdad behdad merged commit ccfd7ef into main May 17, 2023
@behdad behdad deleted the wasm branch May 17, 2023 14:00
@behdad behdad mentioned this pull request Jul 8, 2023
@BaGsn
Copy link

BaGsn commented Nov 2, 2023

Hi,
I see that this has been release but I could not find any example/documentation/mention of it anywhere (beside in the code of harfbuzz itself).
Is there any open source source implementation of wasm font example somewhere in the wild? As for example the demo fonts that were shown at ATIPY? That would be very helpfull as a starting point to experiment with wasm. Thanks!

@simoncozens
Copy link
Collaborator

Please see https://github.com/harfbuzz/harfbuzz-wasm-examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants